" where node_id = %d" % (self['node_id']) )
self.sync(commit)
+ def update_tags(self, tags):
+ from PLC.Shell import Shell
+ from PLC.NodeTags import NodeTags
+ from PLC.Methods.AddNodeTag import AddNodeTag
+ from PLC.Methods.UpdateNodeTag import UpdateNodeTag
+ shell = Shell()
+ 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__(shell.auth,node['node_id'],tagname,value)
+ else:
+ UpdateNodeTag(self.api).__call__(shell.auth,node_tags[0]['node_tag_id'],value)
+
def associate_interfaces(self, auth, field, value):
- """
- Delete interfaces not found in value list (using DeleteInterface)
- Add interfaces found in value list (using AddInterface)
- Updates interfaces found w/ interface_id in value list (using UpdateInterface)
- """
+ """
+ Delete interfaces not found in value list (using DeleteInterface)
+ Add interfaces found in value list (using AddInterface)
+ Updates interfaces found w/ interface_id in value list (using UpdateInterface)
+ """
- assert 'interface_ids' in self
+ assert 'interface_ids' in self
assert 'node_id' in self
assert isinstance(value, list)
from types import StringTypes
from urlparse import urlparse
+import PLC.Auth
from PLC.Faults import *
+from PLC.Namespace import hostname_to_hrn
from PLC.Parameter import Parameter, Mixed
from PLC.Filter import Filter
from PLC.Table import Row, Table
-import PLC.Auth
-
from PLC.Sites import Site, Sites
from PLC.Persons import Person, Persons
from PLC.Keys import Key, Keys
from PLC.Nodes import Node, Nodes
from PLC.TagTypes import TagType, TagTypes
+from PLC.NodeTags import NodeTag, NodeTags
from PLC.SliceTags import SliceTag, SliceTags
from PLC.Slices import Slice, Slices
'peer_node_id': peer_node_id},
commit = commit)
- # calling UpdateNode with the node's hostname
- # will force the 'hrn' tag to be updated with the
- # correct root auth
- from PLC.Methods.UpdateNode import UpdateNode
- UpdateNode.__call__(UpdateNode(self.api), auth, node['node_id'], {'hostname': node['hostname']})
+ # attempt to manually update the 'hrn' tag
+ root_auth = self['hrn_root']
+ sites = Sites(self.api, node['site_id'], ['login_base'])
+ site = sites[0]
+ login_base = site['login_base']
+ hrn = hostname_to_hrn(root_auth, login_base, node['hostname'])
+ tags = {'hrn': hrn}
+ Node(self.api, node).update_tags(tags)
def remove_node(self, node, commit = True):
"""
remove = Row.remove_object(Node, 'peer_node')
remove(self, node, commit)
-
- # calling UpdateNode with the node's hostname
- # will force the 'hrn' tag to be updated with the
- # correct root auth
- from PLC.Methods.UpdateNode import UpdateNode
- UpdateNode.__call__(UpdateNode(self.api), auth, node['node_id'], {'hostname': node['hostname']})
+ # attempt to manually update the 'hrn' tag
+ root_auth = self.api.config.PLC_HRN_ROOT
+ sites = Sites(self.api, node['site_id'], ['login_base'])
+ site = sites[0]
+ login_base = site['login_base']
+ hrn = hostname_to_hrn(root_auth, login_base, node['hostname'])
+ tags = {'hrn': hrn}
+ Node(self.api, node).update_tags(tags)
def add_slice(self, slice, peer_slice_id, commit = True):
"""