table_name = 'nodes'
primary_key = 'node_id'
- # Thierry -- we use delete on interfaces so the related InterfaceSettings get deleted too
- join_tables = ['nodegroup_node', 'conf_file_node', 'pcu_node', 'slice_node', 'slice_attribute', 'node_session', 'peer_node','node_slice_whitelist']
+ join_tables = [ 'slice_node', 'peer_node', 'slice_attribute',
+ 'node_session', 'node_slice_whitelist',
+ 'node_tag', 'conf_file_node', 'pcu_node', ]
fields = {
'node_id': Parameter(int, "Node identifier"),
'hostname': Parameter(str, "Fully qualified hostname", max = 255),
'key': Parameter(str, "(Admin only) Node key", max = 256),
'session': Parameter(str, "(Admin only) Node session value", max = 256, ro = True),
'interface_ids': Parameter([int], "List of network interfaces that this node has"),
- 'nodegroup_ids': Parameter([int], "List of node groups that this node is in"),
'conf_file_ids': Parameter([int], "List of configuration files specific to this node"),
# 'root_person_ids': Parameter([int], "(Admin only) List of people who have root access to this node"),
'slice_ids': Parameter([int], "List of slices on this node"),
'peer_id': Parameter(int, "Peer to which this node belongs", nullok = True),
'peer_node_id': Parameter(int, "Foreign node identifier at peer", nullok = True),
'tag_ids' : Parameter ([int], "List of tags attached to this node"),
+ 'nodegroup_ids': Parameter([int], "List of node groups that this node is in"),
}
related_fields = {
'interfaces': [Mixed(Parameter(int, "Interface identifier"),
'slices_whitelist': [Mixed(Parameter(int, "Slice identifier"),
Parameter(str, "Slice name"))]
}
- # for Cache
- class_key = 'hostname'
- foreign_fields = ['boot_state','model','version']
- # forget about these ones, they are read-only anyway
- # handling them causes Cache to re-sync all over again
- # 'date_created','last_updated'
- foreign_xrefs = [
- # in this case, we dont need the 'table' but Cache will look it up, so...
- {'field' : 'site_id' , 'class' : 'Site' , 'table' : 'unused-on-direct-refs' } ,
- ]
def validate_hostname(self, hostname):
if not valid_hostname(hostname):
def associate_interfaces(self, auth, field, value):
"""
- Delete interfaces not found in value list (using DeleteNodeNetwor)k
+ 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 'interfacep_ids' in self
+ assert 'interface_ids' in self
assert 'node_id' in self
assert isinstance(value, list)
for stale_interface in stale_interfaces:
DeleteInterface.__call__(DeleteInterface(self.api), auth, stale_interface['interface_id'])
- def associate_nodegroups(self, auth, field, value):
- """
- Add node to nodegroups found in value list (AddNodeToNodegroup)
- Delete node from nodegroup not found in value list (DeleteNodeFromNodegroup)
- """
-
- from PLC.NodeGroups import NodeGroups
-
- assert 'nodegroup_ids' in self
- assert 'node_id' in self
- assert isinstance(value, list)
-
- (nodegroup_ids, nodegroup_names) = self.separate_types(value)[0:2]
-
- if nodegroup_names:
- nodegroups = NodeGroups(self.api, nodegroup_names, ['nodegroup_id']).dict('nodegroup_id')
- nodegroup_ids += nodegroups.keys()
-
- if self['nodegroup_ids'] != nodegroup_ids:
- from PLC.Methods.AddNodeToNodeGroup import AddNodeToNodeGroup
- from PLC.Methods.DeleteNodeFromNodeGroup import DeleteNodeFromNodeGroup
-
- new_nodegroups = set(nodegroup_ids).difference(self['nodegroup_ids'])
- stale_nodegroups = set(self['nodegroup_ids']).difference(nodegroup_ids)
-
- for new_nodegroup in new_nodegroups:
- AddNodeToNodeGroup.__call__(AddNodeToNodeGroup(self.api), auth, self['node_id'], new_nodegroup)
- for stale_nodegroup in stale_nodegroups:
- DeleteNodeFromNodeGroup.__call__(DeleteNodeFromNodeGroup(self.api), auth, self['node_id'], stale_nodegroup)
-
-
-
def associate_conf_files(self, auth, field, value):
"""
Add conf_files found in value list (AddConfFileToNode)
for stale_conf_file in stale_conf_files:
DeleteConfFileFromNode.__call__(DeleteConfFileFromNode(self.api), auth, stale_conf_file, self['node_id'])
-
def associate_slices(self, auth, field, value):
"""
Add slices found in value list to (AddSliceToNode)