From 6705baeb8913af0c97c9db5be6f8676a7a532970 Mon Sep 17 00:00:00 2001 From: Mark Huang Date: Mon, 16 Oct 2006 17:45:13 +0000 Subject: [PATCH] implement as wrappers around new functions --- PLC/Methods/AdmAddNode.py | 55 ++++------------------- PLC/Methods/AdmAddNodeGroup.py | 18 +++----- PLC/Methods/AdmAddSite.py | 43 ++---------------- PLC/Methods/AdmDeleteNode.py | 46 ++----------------- PLC/Methods/AdmDeleteNodeGroup.py | 36 ++------------- PLC/Methods/AdmDeleteSite.py | 39 ++-------------- PLC/Methods/AdmUpdateNode.py | 68 ++-------------------------- PLC/Methods/AdmUpdateNodeGroup.py | 43 ++---------------- PLC/Methods/AdmUpdateSite.py | 75 ++----------------------------- 9 files changed, 40 insertions(+), 383 deletions(-) diff --git a/PLC/Methods/AdmAddNode.py b/PLC/Methods/AdmAddNode.py index 872a04a7..8026a8f8 100644 --- a/PLC/Methods/AdmAddNode.py +++ b/PLC/Methods/AdmAddNode.py @@ -2,26 +2,16 @@ from PLC.Faults import * from PLC.Method import Method from PLC.Parameter import Parameter, Mixed from PLC.Nodes import Node, Nodes -from PLC.NodeGroups import NodeGroup, NodeGroups from PLC.Sites import Site, Sites from PLC.Auth import PasswordAuth +from PLC.Methods.AddNode import AddNode -class AdmAddNode(Method): +class AdmAddNode(AddNode): """ - Adds a new node. Any values specified in optional_vals are used, - otherwise defaults are used. - - PIs and techs may only add nodes to their own sites. Admins may - add nodes to any site. - - Returns the new node_id (> 0) if successful, faults otherwise. + Deprecated. See AddNode. """ - roles = ['admin', 'pi', 'tech'] - - can_update = lambda (field, value): field in \ - ['model', 'version'] - update_fields = dict(filter(can_update, Node.fields.items())) + status = "deprecated" accepts = [ PasswordAuth(), @@ -29,38 +19,9 @@ class AdmAddNode(Method): Site.fields['login_base']), Node.fields['hostname'], Node.fields['boot_state'], - update_fields + AddNode.update_fields ] - returns = Parameter(int, 'New node_id (> 0) if successful') - - def call(self, auth, site_id_or_login_base, hostname, boot_state, optional_vals = {}): - if filter(lambda field: field not in self.update_fields, optional_vals): - raise PLCInvalidArgument, "Invalid fields specified" - - # Get site information - sites = Sites(self.api, [site_id_or_login_base]) - if not sites: - raise PLCInvalidArgument, "No such site" - - site = sites.values()[0] - - # Authenticated function - assert self.caller is not None - - # If we are not an admin, make sure that the caller is a - # member of the site. - if 'admin' not in self.caller['roles']: - if site['site_id'] not in self.caller['site_ids']: - assert self.caller['person_id'] not in site['person_ids'] - raise PLCPermissionDenied, "Not allowed to add nodes to specified site" - else: - assert self.caller['person_id'] in site['person_ids'] - - node = Node(self.api, optional_vals) - node['hostname'] = hostname - node['boot_state'] = boot_state - node['site_id'] = site['site_id'] - node.sync() - - return node['node_id'] + def call(self, auth, site_id_or_login_base, hostname, boot_state, node_fields = {}): + node_fields['boot_state'] = boot_state + return AddNode.call(self, auth, site_id_or_login_base, hostname, node_fields) diff --git a/PLC/Methods/AdmAddNodeGroup.py b/PLC/Methods/AdmAddNodeGroup.py index 328bb43b..1ecb9bef 100644 --- a/PLC/Methods/AdmAddNodeGroup.py +++ b/PLC/Methods/AdmAddNodeGroup.py @@ -3,16 +3,14 @@ from PLC.Method import Method from PLC.Parameter import Parameter, Mixed from PLC.NodeGroups import NodeGroup, NodeGroups from PLC.Auth import PasswordAuth +from PLC.Methods.AddNodeGroup import AddNodeGroup -class AdmAddNodeGroup(Method): +class AdmAddNodeGroup(AddNodeGroup): """ - Adds a new node group. Any values specified in optional_vals are used, - otherwise defaults are used. - - Returns the new nodegroup_id (> 0) if successful, faults otherwise. + Deprecated. See AddNodeGroup. """ - roles = ['admin'] + status = "deprecated" accepts = [ PasswordAuth(), @@ -20,11 +18,5 @@ class AdmAddNodeGroup(Method): NodeGroup.fields['description'] ] - returns = Parameter(int, 'New nodegroup_id (> 0) if successful') - def call(self, auth, name, description): - # Create node group - nodegroup = NodeGroup(self.api, {'name': name, 'description': description}) - nodegroup.sync() - - return nodegroup['nodegroup_id'] + return AddNodeGroup.call(self, auth, name, {'description': description}) diff --git a/PLC/Methods/AdmAddSite.py b/PLC/Methods/AdmAddSite.py index e8c7dbc6..d49c070e 100644 --- a/PLC/Methods/AdmAddSite.py +++ b/PLC/Methods/AdmAddSite.py @@ -1,43 +1,8 @@ -from PLC.Faults import * -from PLC.Method import Method -from PLC.Parameter import Parameter, Mixed -from PLC.Sites import Site, Sites -from PLC.Auth import PasswordAuth +from PLC.Methods.AddSite import AddSite -class AdmAddSite(Method): +class AdmAddSite(AddSite): """ - Adds a new site, and creates a node group for that site. Any - fields specified in optional_vals are used, otherwise defaults are - used. - - Returns the new site_id (> 0) if successful, faults otherwise. + Deprecated. See AddSite. """ - roles = ['admin'] - - can_update = lambda (field, value): field in \ - ['is_public', 'latitude', 'longitude', 'url', - 'organization_id', 'ext_consortium_id'] - update_fields = dict(filter(can_update, Site.fields.items())) - - accepts = [ - PasswordAuth(), - Site.fields['name'], - Site.fields['abbreviated_name'], - Site.fields['login_base'], - update_fields - ] - - returns = Parameter(int, 'New site_id (> 0) if successful') - - def call(self, auth, name, abbreviated_name, login_base, optional_vals = {}): - if filter(lambda field: field not in self.update_fields, optional_vals): - raise PLCInvalidArgument, "Invalid field specified" - - site = Site(self.api, optional_vals) - site['name'] = name - site['abbreviated_name'] = abbreviated_name - site['login_base'] = login_base - site.sync() - - return site['site_id'] + status = "deprecated" diff --git a/PLC/Methods/AdmDeleteNode.py b/PLC/Methods/AdmDeleteNode.py index 3e308fce..8c3fd1a9 100644 --- a/PLC/Methods/AdmDeleteNode.py +++ b/PLC/Methods/AdmDeleteNode.py @@ -1,46 +1,8 @@ -from PLC.Faults import * -from PLC.Method import Method -from PLC.Parameter import Parameter, Mixed -from PLC.Auth import PasswordAuth -from PLC.Nodes import Node, Nodes +from PLC.Methods.DeleteNode import DeleteNode -class AdmDeleteNode(Method): +class AdmDeleteNode(DeleteNode): """ - Mark an existing node as deleted. - - PIs and techs may only delete nodes at their own sites. Admins may - delete nodes at any site. - - Returns 1 if successful, faults otherwise. + Deprecated. See DeleteNode. """ - roles = ['admin', 'pi', 'tech'] - - accepts = [ - PasswordAuth(), - Mixed(Node.fields['node_id'], - Node.fields['hostname']) - ] - - returns = Parameter(int, '1 if successful') - - def call(self, auth, node_id_or_hostname): - # Get account information - nodes = Nodes(self.api, [node_id_or_hostname]) - if not nodes: - raise PLCInvalidArgument, "No such node" - - node = nodes.values()[0] - - # If we are not an admin, make sure that the caller is a - # member of the site at which the node is located. - if 'admin' not in self.caller['roles']: - # Authenticated function - assert self.caller is not None - - if node['site_id'] not in self.caller['site_ids']: - raise PLCPermissionDenied, "Not allowed to delete nodes from specified site" - - node.delete() - - return 1 + status = "deprecated" diff --git a/PLC/Methods/AdmDeleteNodeGroup.py b/PLC/Methods/AdmDeleteNodeGroup.py index 3f910050..b5b2cb6c 100644 --- a/PLC/Methods/AdmDeleteNodeGroup.py +++ b/PLC/Methods/AdmDeleteNodeGroup.py @@ -1,36 +1,8 @@ -from PLC.Faults import * -from PLC.Method import Method -from PLC.Parameter import Parameter, Mixed -from PLC.Auth import PasswordAuth -from PLC.NodeGroups import NodeGroup, NodeGroups +from PLC.Methods.DeleteNodeGroup import DeleteNodeGroup -class AdmDeleteNodeGroup(Method): +class AdmDeleteNodeGroup(DeleteNodeGroup): """ - Delete an existing Node Group. - - Admins may delete any node group - - Returns 1 if successful, faults otherwise. + Deprecated. See DeleteNodeGroup. """ - roles = ['admin'] - - accepts = [ - PasswordAuth(), - Mixed(NodeGroup.fields['nodegroup_id'], - NodeGroup.fields['name']) - ] - - returns = Parameter(int, '1 if successful') - - def call(self, auth, node_group_id_or_name): - # Get account information - nodegroups = NodeGroups(self.api, [node_group_id_or_name]) - if not nodegroups: - raise PLCInvalidArgument, "No such node group" - - nodegroup = nodegroups.values()[0] - - nodegroup.delete() - - return 1 + status = "deprecated" diff --git a/PLC/Methods/AdmDeleteSite.py b/PLC/Methods/AdmDeleteSite.py index e8581ffe..7501ad5a 100644 --- a/PLC/Methods/AdmDeleteSite.py +++ b/PLC/Methods/AdmDeleteSite.py @@ -1,39 +1,8 @@ -from PLC.Faults import * -from PLC.Method import Method -from PLC.Parameter import Parameter, Mixed -from PLC.Sites import Site, Sites -from PLC.Persons import Person, Persons -from PLC.Nodes import Node, Nodes -from PLC.PCUs import PCU, PCUs -from PLC.Auth import PasswordAuth +from PLC.Methods.DeleteSite import DeleteSite -class AdmDeleteSite(Method): +class AdmDeleteSite(DeleteSite): """ - Mark an existing site as deleted. The accounts of people who are - not members of at least one other non-deleted site will also be - marked as deleted. Nodes, PCUs, and slices associated with the - site will be deleted. - - Returns 1 if successful, faults otherwise. + Deprecated. See DeleteSite. """ - roles = ['admin'] - - accepts = [ - PasswordAuth(), - Mixed(Site.fields['site_id'], - Site.fields['login_base']) - ] - - returns = Parameter(int, '1 if successful') - - def call(self, auth, site_id_or_login_base): - # Get account information - sites = Sites(self.api, [site_id_or_login_base]) - if not sites: - raise PLCInvalidArgument, "No such site" - - site = sites.values()[0] - site.delete() - - return 1 + status = "deprecated" diff --git a/PLC/Methods/AdmUpdateNode.py b/PLC/Methods/AdmUpdateNode.py index 39f1f544..ba4b3f1d 100644 --- a/PLC/Methods/AdmUpdateNode.py +++ b/PLC/Methods/AdmUpdateNode.py @@ -1,68 +1,8 @@ -from PLC.Faults import * -from PLC.Method import Method -from PLC.Parameter import Parameter, Mixed -from PLC.Nodes import Node, Nodes -from PLC.Auth import PasswordAuth +from PLC.Methods.UpdateNode import UpdateNode -class AdmUpdateNode(Method): +class AdmUpdateNode(UpdateNode): """ - Updates a node. Only the fields specified in update_fields are - updated, all other fields are left untouched. - - To remove a value without setting a new one in its place (for - example, to remove an address from the node), specify -1 for int - and double fields and 'null' for string fields. hostname and - boot_state cannot be unset. - - PIs and techs can only update the nodes at their sites. - - Returns 1 if successful, faults otherwise. + Deprecated. See UpdateNode. """ - roles = ['admin', 'pi', 'tech'] - - can_update = lambda (field, value): field in \ - ['hostname', 'boot_state', 'model', 'version'] - update_fields = dict(filter(can_update, Node.fields.items())) - - accepts = [ - PasswordAuth(), - Mixed(Node.fields['node_id'], - Node.fields['hostname']), - update_fields - ] - - returns = Parameter(int, '1 if successful') - - def call(self, auth, node_id_or_hostname, update_fields): - if filter(lambda field: field not in self.update_fields, update_fields): - raise PLCInvalidArgument, "Invalid field specified" - - # XML-RPC cannot marshal None, so we need special values to - # represent "unset". - for key, value in update_fields.iteritems(): - if value == -1 or value == "null": - if key in ['hostname', 'boot_state']: - raise PLCInvalidArgument, "hostname and boot_state cannot be unset" - update_fields[key] = None - - # Get account information - nodes = Nodes(self.api, [node_id_or_hostname]) - if not nodes: - raise PLCInvalidArgument, "No such node" - - node = nodes.values()[0] - - # Authenticated function - assert self.caller is not None - - # If we are not an admin, make sure that the caller is a - # member of the site at which the node is located. - if 'admin' not in self.caller['roles']: - if node['site_id'] not in self.caller['site_ids']: - raise PLCPermissionDenied, "Not allowed to delete nodes from specified site" - - node.update(update_fields) - node.sync() - - return 1 + status = "deprecated" diff --git a/PLC/Methods/AdmUpdateNodeGroup.py b/PLC/Methods/AdmUpdateNodeGroup.py index e246a7cc..0b0ee5dc 100644 --- a/PLC/Methods/AdmUpdateNodeGroup.py +++ b/PLC/Methods/AdmUpdateNodeGroup.py @@ -1,43 +1,6 @@ -from PLC.Faults import * -from PLC.Method import Method -from PLC.Parameter import Parameter, Mixed -from PLC.NodeGroups import NodeGroup, NodeGroups -from PLC.Auth import PasswordAuth +from PLC.Methods.UpdateNodeGroup import UpdateNodeGroup -class AdmUpdateNodeGroup(Method): +class AdmUpdateNodeGroup(UpdateNodeGroup): """ - Updates a custom node group. - - Returns 1 if successful, faults otherwise. + Deprecated. See UpdateNodeGroup. """ - - roles = ['admin'] - - accepts = [ - PasswordAuth(), - Mixed(NodeGroup.fields['nodegroup_id'], - NodeGroup.fields['name']), - NodeGroup.fields['name'], - NodeGroup.fields['description'] - ] - - returns = Parameter(int, '1 if successful') - - def call(self, auth, nodegroup_id_or_name, name, description): - # Get nodegroup information - nodegroups = NodeGroups(self.api, [nodegroup_id_or_name]) - if not nodegroups: - raise PLCInvalidArgument, "No such nodegroup" - - nodegroup = nodegroups.values()[0] - - # Modify node group - update_fields = { - 'name': name, - 'description': description - } - - nodegroup.update(update_fields) - nodegroup.sync() - - return 1 diff --git a/PLC/Methods/AdmUpdateSite.py b/PLC/Methods/AdmUpdateSite.py index d44713d5..0b6c26ae 100644 --- a/PLC/Methods/AdmUpdateSite.py +++ b/PLC/Methods/AdmUpdateSite.py @@ -1,75 +1,8 @@ -from PLC.Faults import * -from PLC.Method import Method -from PLC.Parameter import Parameter, Mixed -from PLC.Sites import Site, Sites -from PLC.Auth import PasswordAuth +from PLC.Methods.UpdateSite import UpdateSite -class AdmUpdateSite(Method): +class AdmUpdateSite(UpdateSite): """ - Updates a site. Only the fields specified in update_fields are - updated, all other fields are left untouched. - - To remove a value without setting a new one in its place (for - example, to remove an address from the node), specify -1 for int - and double fields and 'null' for string fields. hostname and - boot_state cannot be unset. - - PIs can only update sites they are a member of. Only admins can - update max_slices. - - Returns 1 if successful, faults otherwise. + Deprecated. See UpdateSite. """ - roles = ['admin', 'pi'] - - can_update = lambda (field, value): field in \ - ['name', 'abbreviated_name', - 'is_public', 'latitude', 'longitude', 'url', - 'max_slices', 'max_slivers'] - update_fields = dict(filter(can_update, Site.fields.items())) - - accepts = [ - PasswordAuth(), - Mixed(Site.fields['site_id'], - Site.fields['login_base']), - update_fields - ] - - returns = Parameter(int, '1 if successful') - - def call(self, auth, site_id_or_login_base, update_fields): - # Check for invalid fields - if filter(lambda field: field not in self.update_fields, update_fields): - raise PLCInvalidArgument, "Invalid field specified" - - # XML-RPC cannot marshal None, so we need special values to - # represent "unset". - for key, value in update_fields.iteritems(): - if value == -1 or value == "null": - if key not in ['latitude', 'longitude', 'url']: - raise PLCInvalidArgument, "%s cannot be unset" % key - update_fields[key] = None - - # Get site information - sites = Sites(self.api, [site_id_or_login_base]) - if not sites: - raise PLCInvalidArgument, "No such site" - - site = sites.values()[0] - - # Authenticated function - assert self.caller is not None - - # If we are not an admin, make sure that the caller is a - # member of the site. - if 'admin' not in self.caller['roles']: - if site['site_id'] not in self.caller['site_ids']: - raise PLCPermissionDenied, "Not allowed to modify specified site" - - if 'max_slices' or 'max_slivers' in update_fields: - raise PLCInvalidArgument, "Only admins can update max_slices and max_slivers" - - site.update(update_fields) - site.sync() - - return 1 + status = "deprecated" -- 2.47.0