- node.update(node_fields)
- node.sync()
-
- # Logging variables
- self.event_objects = {'Node': [node['node_id']]}
- self.message = 'Node %d updated: %s.' % \
- (node['node_id'], ", ".join(node_fields.keys()))
- if 'boot_state' in node_fields.keys():
- self.message += ' boot_state updated to %s' % node_fields['boot_state']
+ # Make requested associations
+ for (k,v) in related.iteritems():
+ node.associate(auth, k,v)
+
+ node.update(native)
+ node.update_last_updated(commit=False)
+ node.sync(commit=True)
+
+ # if hostname was modifed make sure to update the hrn
+ # tag
+ if 'hostname' in native:
+ root_auth = self.api.config.PLC_HRN_ROOT
+ # sub auth is the login base of this node's site
+ sites = Sites(self.api, node['site_id'], ['login_base'])
+ site = sites[0]
+ login_base = site['login_base']
+ tags['hrn'] = hostname_to_hrn(root_auth, login_base, node['hostname'])
+
+ for (tagname,value) in tags.iteritems():
+ # the tagtype instance is assumed to exist, just check that
+ if not TagTypes(self.api,{'tagname':tagname}):
+ raise PLCInvalidArgument,"No such TagType %s"%tagname
+ node_tags=NodeTags(self.api,{'tagname':tagname,'node_id':node['node_id']})
+ if not node_tags:
+ AddNodeTag(self.api).__call__(auth,node['node_id'],tagname,value)
+ else:
+ UpdateNodeTag(self.api).__call__(auth,node_tags[0]['node_tag_id'],value)
+
+ # Logging variables
+ self.event_objects = {'Node': [node['node_id']]}
+ if 'hostname' in node:
+ self.message = 'Node %s updated'%node['hostname']
+ else:
+ self.message = 'Node %d updated'%node['node_id']
+ self.message += " [%s]." % (", ".join(node_fields.keys()),)
+ if 'boot_state' in node_fields.keys():
+ self.message += ' boot_state updated to %s' % node_fields['boot_state']