From 0cb0beac1f1015b7c49c342189ef2140e4133bea Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Mon, 11 Mar 2013 10:53:26 -0400 Subject: [PATCH] added check_whitelist(). fix bugs --- PLC/Nodes.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/PLC/Nodes.py b/PLC/Nodes.py index 37b10598..6886b78d 100644 --- a/PLC/Nodes.py +++ b/PLC/Nodes.py @@ -22,7 +22,7 @@ from PLC.SliceNodeWhitelists import SliceNodeWhitelist from PLC.PCUNodes import PCUNode from PLC.PCUNodePorts import PCUNodePort from PLC.NodeTags import NodeTag -from PLC.NodeGroups import NodeGroup +from PLC.NodeNodeGroups import NodeNodeGroup def valid_hostname(hostname): # 1. Each part begins and ends with a letter or number. @@ -116,6 +116,13 @@ class Node(AlchemyObj): validate_last_pcu_reboot = AlchemyObj.validate_timestamp validate_last_pcu_confirmation = AlchemyObj.validate_timestamp + def check_whitelist(self, slice, caller): + if self['slice_ids_whitelist'] and \ + slice['slice_id'] not in self['slice_ids_whitelist'] and \ + not set(caller['site_ids']).intersection([self['site_id']]): + raise PLCInvalidArgument, "%s is not allowed on %s (not on the whitelist)" % \ + (slice['name'], self['hostname']) + def update_readonly_int(self, col_name, commit = True): assert 'node_id' in self @@ -327,7 +334,7 @@ class Nodes(list): node['conf_file_ids'] = [rec.conf_file_id for rec in conf_files] if not columns or 'slice_ids' in columns: slice_nodes = SliceNode().select(filter={'node_id': node['node_id']}) - node['slice_ids'] = [rec.slice_id for rec in slices_nodes] + node['slice_ids'] = [rec.slice_id for rec in slice_nodes] if not columns or 'slice_ids_whitelist' in columns: slice_whitelist = SliceNodeWhitelist().select(filter={'node_id': node['node_id']}) node['slice_ids_whitelist'] = [rec.slice_id for rec in slice_whitelist] @@ -341,7 +348,7 @@ class Nodes(list): node_tags = NodeTag().select(filter={'node_id': node['node_id']}) node['node_tag_ids'] = [rec.node_tag_id for rec in node_tags] if not columns or 'nodegroup_ids' in columns: - nodegroups = NodeGroup().select(filter={'node_id': node['node_id']}) + nodegroups = NodeNodeGroup().select(filter={'node_id': node['node_id']}) node['nodegroup_ids'] = [rec.nodegroup_id for rec in nodegroups] self.append(node) -- 2.47.0