From e76605a62282e7c10c6b87c75420b000d1829af7 Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Tue, 16 Jan 2007 16:53:59 +0000 Subject: [PATCH] Initial checkin of deprecated API implementation --- PLC/Methods/SliceExtendedInfo.py | 66 ++++++++++++++++++++++++++++++ PLC/Methods/SliceInfo.py | 66 ++++++++++++++++++++++++++++++ PLC/Methods/SliceListNames.py | 56 +++++++++++++++++++++++++ PLC/Methods/SliceListUserSlices.py | 42 +++++++++++++++++++ PLC/Methods/SliceNodesAdd.py | 30 ++++++++++++++ PLC/Methods/SliceNodesDel.py | 30 ++++++++++++++ PLC/Methods/SliceNodesList.py | 38 +++++++++++++++++ PLC/Methods/SliceRenew.py | 34 +++++++++++++++ PLC/Methods/SliceUpdate.py | 37 +++++++++++++++++ PLC/Methods/SliceUserAdd.py | 55 +++++++++++++++++++++++++ PLC/Methods/SliceUserDel.py | 56 +++++++++++++++++++++++++ PLC/Methods/SliceUsersList.py | 56 +++++++++++++++++++++++++ 12 files changed, 566 insertions(+) create mode 100644 PLC/Methods/SliceExtendedInfo.py create mode 100644 PLC/Methods/SliceInfo.py create mode 100644 PLC/Methods/SliceListNames.py create mode 100644 PLC/Methods/SliceListUserSlices.py create mode 100644 PLC/Methods/SliceNodesAdd.py create mode 100644 PLC/Methods/SliceNodesDel.py create mode 100644 PLC/Methods/SliceNodesList.py create mode 100644 PLC/Methods/SliceRenew.py create mode 100644 PLC/Methods/SliceUpdate.py create mode 100644 PLC/Methods/SliceUserAdd.py create mode 100644 PLC/Methods/SliceUserDel.py create mode 100644 PLC/Methods/SliceUsersList.py diff --git a/PLC/Methods/SliceExtendedInfo.py b/PLC/Methods/SliceExtendedInfo.py new file mode 100644 index 0000000..25eeab6 --- /dev/null +++ b/PLC/Methods/SliceExtendedInfo.py @@ -0,0 +1,66 @@ +from PLC.Method import Method +from PLC.Parameter import Parameter, Mixed +from PLC.Filter import Filter +from PLC.Auth import Auth +from PLC.Slices import Slice, Slices +from PLC.Sites import Site, Sites + +class SliceExtendedInfo(Method): + """ + Deprecated. Can be implemented with GetSlices. + + Returns an array of structs containing details about slices. + The summary can optionally include the list of nodes in and + users of each slice. + + Users may only query slices of which they are members. PIs may + query any of the slices at their sites. Admins may query any + slice. If a slice that cannot be queried is specified in + slice_filter, details about that slice will not be returned. + """ + + roles = ['admin', 'pi', 'user'] + + accepts = [ + Auth(), + [Slice.fields['slice_name']], + Parameter(bool, "Whether or not to return users for the slices", nullok = True), + Parameter(bool, "Whether or not to return nodes for the slices", nullok = True) + ] + + returns = [Slice.fields] + + + def call(self, auth, slice_name_list=None, return_users=None, return_nodes=None): + # If we are not admin, make sure to return only viewable + # slices. + slice_filter = slice_name_list + slices = Slices(self.api, slice_filter) + if not slices: + raise PLCInvalidArgument, "No such slice" + + if 'admin' not in self.caller['roles']: + # Get slices that we are able to view + valid_slice_ids = self.caller['slice_ids'] + if 'pi' in self.caller['roles'] and self.caller['site_ids']: + sites = Sites(self.api, self.caller['site_ids']) + for site in sites: + valid_slice_ids += site['slice_ids'] + + if not valid_slice_ids: + return [] + + slices = filter(lambda slice: slice['slice_id'] in valid_slice_ids, slices) + + for slice in slices: + slices.pop(slice) + person_ids = slice.pop('person_ids') + node_ids = slice.pop('node_ids') + if return_users: + slice['users'] = person_ids + if return_nodes: + slice['nodes'] = node_ids + slices.add(slice) + + + return slices diff --git a/PLC/Methods/SliceInfo.py b/PLC/Methods/SliceInfo.py new file mode 100644 index 0000000..6551085 --- /dev/null +++ b/PLC/Methods/SliceInfo.py @@ -0,0 +1,66 @@ +from PLC.Method import Method +from PLC.Parameter import Parameter, Mixed +from PLC.Filter import Filter +from PLC.Auth import Auth +from PLC.Slices import Slice, Slices +from PLC.Sites import Site, Sites + +class SliceInfo(Method): + """ + Deprecated. Can be implemented with GetSlices. + + Returns an array of structs containing details about slices. + The summary can optionally include the list of nodes in and + users of each slice. + + Users may only query slices of which they are members. PIs may + query any of the slices at their sites. Admins may query any + slice. If a slice that cannot be queried is specified in + slice_filter, details about that slice will not be returned. + """ + + roles = ['admin', 'pi', 'user'] + + accepts = [ + Auth(), + [Mixed(Slice.fields['slice_name']], + Parameter(bool, "Whether or not to return users for the slices", nullok = True) + Parameter(bool, "Whether or not to return nodes for the slices", nullok = True) + ] + + returns = [Slice.fields] + + + def call(self, auth, slice_name_list=None, return_users=None, return_nodes=None): + # If we are not admin, make sure to return only viewable + # slices. + slice_filter = slice_name_list + slices = Slices(self.api, slice_filter) + if not slices: + raise PLCInvalidArgument, "No such slice" + + if 'admin' not in self.caller['roles']: + # Get slices that we are able to view + valid_slice_ids = self.caller['slice_ids'] + if 'pi' in self.caller['roles'] and self.caller['site_ids']: + sites = Sites(self.api, self.caller['site_ids']) + for site in sites: + valid_slice_ids += site['slice_ids'] + + if not valid_slice_ids: + return [] + + slices = filter(lambda slice: slice['slice_id'] in valid_slice_ids, slices) + + for slice in slices: + slices.pop(slice) + person_ids = slice.pop('person_ids') + node_ids = slice.pop('node_ids') + if return_users: + slice['users'] = person_ids + if return_nodes: + slice['nodes'] = node_ids + slices.add(slice) + + + return slices diff --git a/PLC/Methods/SliceListNames.py b/PLC/Methods/SliceListNames.py new file mode 100644 index 0000000..0e45887 --- /dev/null +++ b/PLC/Methods/SliceListNames.py @@ -0,0 +1,56 @@ +from PLC.Method import Method +from PLC.Parameter import Parameter, Mixed +from PLC.Filter import Filter +from PLC.Auth import Auth +from PLC.Slices import Slice, Slices + +class SliceListNames(Method): + """ + Deprecated. Can be implemented with GetSlices. + + List the names of registered slices. + + Users may only query slices of which they are members. PIs may + query any of the slices at their sites. Admins may query any + slice. If a slice that cannot be queried is specified in + slice_filter, details about that slice will not be returned. + """ + + roles = ['admin', 'pi', 'user'] + + accepts = [ + Auth(), + Parameter(str, "Slice prefix", nullok = True) + ] + + returns = [Slice.fields] + + + def call(self, auth, prefix=None): + + slice_filter = None + if prefix: + slice_filter = {'name': prefix+'*'} + + slices = Slices(self.api, slice_filter) + if not slices: + raise PLCInvalidArgument, "No such slice" + + # If we are not admin, make sure to return only viewable + # slices. + if 'admin' not in self.caller['roles']: + # Get slices that we are able to view + valid_slice_ids = self.caller['slice_ids'] + if 'pi' in self.caller['roles'] and self.caller['site_ids']: + sites = Sites(self.api, self.caller['site_ids']) + for site in sites: + valid_slice_ids += site['slice_ids'] + + if not valid_slice_ids: + return [] + + slices = filter(lambda slice: slice['slice_id'] in valid_slice_ids, slices) + + slice_names = [slice['name'] for slice in slices] + + return slice_names diff --git a/PLC/Methods/SliceListUserSlices.py b/PLC/Methods/SliceListUserSlices.py new file mode 100644 index 0000000..86f9778 --- /dev/null +++ b/PLC/Methods/SliceListUserSlices.py @@ -0,0 +1,42 @@ +from PLC.Method import Method +from PLC.Parameter import Parameter, Mixed +from PLC.Filter import Filter +from PLC.Auth import Auth +from PLC.Slices import Slice, Slices +from PLC.Persons import Person, Persons + +class SliceListUserSlices(Method): + """ + Deprecated. Can be implemented with GetPersons. + + Return the slices the specified user (by email address) is a member of. + + Users may only query slices of which they are members. PIs may + query any of the slices at their sites. Admins may query any + slice. If a slice that cannot be queried is specified in + slice_filter, details about that slice will not be returned. + """ + + roles = ['admin', 'pi', 'user'] + + accepts = [ + Auth(), + Parameter(str, "Slice prefix", nullok = True) + ] + + returns = [Slice.fields] + + + def call(self, auth, email): + + persons = Persons(self.api, [email]) + if not persons: + return [] + person = persons[0] + slice_ids = person['slice_ids'] + if not slice_ids: + return [] + slices = Slices(self.api, slice_ids) + slice_names = [slice['name'] for slice in slices] + + return slice_names diff --git a/PLC/Methods/SliceNodesAdd.py b/PLC/Methods/SliceNodesAdd.py new file mode 100644 index 0000000..2ecbb06 --- /dev/null +++ b/PLC/Methods/SliceNodesAdd.py @@ -0,0 +1,30 @@ +from PLC.Faults import * +from PLC.Method import Method +from PLC.Parameter import Parameter, Mixed +from PLC.Nodes import Node, Nodes +from PLC.Slices import Slice, Slices +from PLC.Auth import Auth +from PLC.Methods.AddSliceToNodes import AddSliceToNodes + +class SliceNodesAdd(Method): + """ + Deprecated. See AddSliceToNodes. + + """ + + status = "deprecated" + + roles = ['admin', 'pi', 'user'] + + accepts = [ + Auth(), + Slice.fields['name'], + [Node.fields['hostname']] + ] + + returns = Parameter(int, '1 if successful') + + + def call(self, auth, slice_name, nodes_list): + + return AddSliceToNodes.call(self, auth, slice_name, nodes_list) diff --git a/PLC/Methods/SliceNodesDel.py b/PLC/Methods/SliceNodesDel.py new file mode 100644 index 0000000..6de7a1b --- /dev/null +++ b/PLC/Methods/SliceNodesDel.py @@ -0,0 +1,30 @@ +from PLC.Faults import * +from PLC.Method import Method +from PLC.Parameter import Parameter, Mixed +from PLC.Nodes import Node, Nodes +from PLC.Slices import Slice, Slices +from PLC.Auth import Auth +from PLC.Methods.DeleteSliceFromNodes import DeleteSliceFromNodes + +class SliceNodesDel(Method): + """ + Deprecated. See DeleteSliceFromNodes. + + """ + + status = "deprecated" + + roles = ['admin', 'pi', 'user'] + + accepts = [ + Auth(), + Slice.fields['name'], + [Node.fields['hostname']] + ] + + returns = Parameter(int, '1 if successful') + + + def call(self, auth, slice_name, nodes_list): + + return DeleteSliceFromNodes.call(self, auth, slice_name, nodes_list) diff --git a/PLC/Methods/SliceNodesList.py b/PLC/Methods/SliceNodesList.py new file mode 100644 index 0000000..556cb17 --- /dev/null +++ b/PLC/Methods/SliceNodesList.py @@ -0,0 +1,38 @@ +from PLC.Method import Method +from PLC.Parameter import Parameter, Mixed +from PLC.Filter import Filter +from PLC.Auth import Auth +from PLC.Slices import Slice, Slices +from PLC.Nodes import Node, Nodes +from PLC.Methods.GetSlices import GetSlices + +class SliceNodesList(Method): + """ + Deprecated. Can be implemented with GetSlices. + + """ + + status = "deprecated" + + roles = ['admin', 'pi', 'user'] + + accepts = [ + Auth(), + Slice.fields['slice_name'] + ] + + returns = [Node.fields['hostname']] + + + def call(self, auth, slice_name): + # If we are not admin, make sure to return only viewable + # slices. + slices = GetSlices(self, auth, [slice_name]) + slice = slices[0] + nodes = Nodes(self.api, slice['node_ids']) + if not nodes: + return [] + + node_hostnames = [node['hostname'] for node in nodes] + + return node_hostnames diff --git a/PLC/Methods/SliceRenew.py b/PLC/Methods/SliceRenew.py new file mode 100644 index 0000000..d90cb39 --- /dev/null +++ b/PLC/Methods/SliceRenew.py @@ -0,0 +1,34 @@ +import time + +from PLC.Faults import * +from PLC.Method import Method +from PLC.Parameter import Parameter, Mixed +from PLC.Slices import Slice, Slices +from PLC.Auth import Auth +from PLC.Methods.UpdateSlice import UpdateSlice + +class SliceRenew(Method): + """ + Deprecated. See UpdateSlice. + + """ + + status = "deprecated" + + roles = ['admin', 'pi', 'user'] + + accepts = [ + Auth(), + Slice.fields['name'], + Slice.fields['expires'] + ] + + returns = Parameter(int, '1 if successful') + + def call(self, auth, slice_name, slice_expires): + + slice_fields = {} + slice_fields['expires'] = slice_expires + + return UpdateSlice.call(self, auth, slice_name, slice_fields) + diff --git a/PLC/Methods/SliceUpdate.py b/PLC/Methods/SliceUpdate.py new file mode 100644 index 0000000..86af928 --- /dev/null +++ b/PLC/Methods/SliceUpdate.py @@ -0,0 +1,37 @@ +import time + +from PLC.Faults import * +from PLC.Method import Method +from PLC.Parameter import Parameter, Mixed +from PLC.Slices import Slice, Slices +from PLC.Auth import Auth +from PLC.Methods.UpdateSlice import UpdateSlice + +class SliceUpdate(Method): + """ + Deprecated. See UpdateSlice. + + """ + + status = 'deprecated' + + roles = ['admin', 'pi', 'user'] + + accepts = [ + Auth(), + Slice.fields['name'], + Slice.fields['url'], + Slice.fields['description'], + ] + + returns = Parameter(int, '1 if successful') + + def call(self, auth, slice_name, url, description): + + slice_fields = {} + slice_fields['url'] = url + slice_fields['description'] = description + + return UpdateSlice.call(self, auth, slice_name, slice_fields) + + return 1 diff --git a/PLC/Methods/SliceUserAdd.py b/PLC/Methods/SliceUserAdd.py new file mode 100644 index 0000000..c771a1f --- /dev/null +++ b/PLC/Methods/SliceUserAdd.py @@ -0,0 +1,55 @@ +from PLC.Faults import * +from PLC.Method import Method +from PLC.Parameter import Parameter, Mixed +from PLC.Persons import Person, Persons +from PLC.Slices import Slice, Slices +from PLC.Auth import Auth +from PLC.Methods.AddPersonToSlice import AddPersonToSlice + +class SliceUserAdd(Method): + """ + Deprecated. See AddPersonToSlice. + + """ + + status = "deprecated" + + roles = ['admin', 'pi'] + + accepts = [ + Auth(), + Slice.fields['name'], + [Person.fields['email']], + ] + + returns = Parameter(int, '1 if successful') + + def call(self, auth, slice_name, user_list): + # Get account information + persons = Persons(self.api, user_list) + if not persons: + raise PLCInvalidArgument, "No such account" + + # Get slice information + slices = Slices(self.api, [slice_id_or_name]) + if not slices: + raise PLCInvalidArgument, "No such slice" + + slice = slices[0] + if slice['peer_id'] is not None: + raise PLCInvalidArgument, "Not a local slice" + + # If we are not admin, make sure the caller is a PI + # of the site associated with the slice + if 'admin' not in self.caller['roles']: + if slice['site_id'] not in self.caller['site_ids']: + raise PLCPermissionDenied, "Not allowed to add users to this slice" + + for person in persons: + if person['person_id'] not in slice['person_ids']: + slice.add_person(person, commit = False) + + slice.sync() + self.object_ids = [slice['slice_id']] + + return 1 diff --git a/PLC/Methods/SliceUserDel.py b/PLC/Methods/SliceUserDel.py new file mode 100644 index 0000000..04c13fe --- /dev/null +++ b/PLC/Methods/SliceUserDel.py @@ -0,0 +1,56 @@ +from PLC.Faults import * +from PLC.Method import Method +from PLC.Parameter import Parameter, Mixed +from PLC.Persons import Person, Persons +from PLC.Slices import Slice, Slices +from PLC.Auth import Auth + +class SliceUserDel(Method): + """ + Deprecated. Can be implemented with DeletePersonFromSlice. + + Removes the specified users from the specified slice. If the person is + already a member of the slice, no errors are returned. + + Returns 1 if successful, faults otherwise. + """ + + roles = ['admin', 'pi'] + + accepts = [ + Auth(), + Slice.fields['name'], + [Person.fields['email']], + ] + + returns = Parameter(int, '1 if successful') + + def call(self, auth, slice_name, user_list): + # Get account information + persons = Persons(self.api, user_list) + if not persons: + raise PLCInvalidArgument, "No such account" + + # Get slice information + slices = Slices(self.api, [slice_id_or_name]) + if not slices: + raise PLCInvalidArgument, "No such slice" + + slice = slices[0] + if slice['peer_id'] is not None: + raise PLCInvalidArgument, "Not a local slice" + + # If we are not admin, make sure the caller is a PI + # of the site associated with the slice + if 'admin' not in self.caller['roles']: + if slice['site_id'] not in self.caller['site_ids']: + raise PLCPermissionDenied, "Not allowed to add users to this slice" + + for person in persons: + if person['person_id'] in slice['person_ids']: + slice.remove_person(person, False) + + slice.sync() + self.object_ids = [slice['slice_id']] + + return 1 diff --git a/PLC/Methods/SliceUsersList.py b/PLC/Methods/SliceUsersList.py new file mode 100644 index 0000000..9100691 --- /dev/null +++ b/PLC/Methods/SliceUsersList.py @@ -0,0 +1,56 @@ +from PLC.Method import Method +from PLC.Parameter import Parameter, Mixed +from PLC.Filter import Filter +from PLC.Auth import Auth +from PLC.Slices import Slice, Slices +from PLC.Persons import Person, Persons + +class SliceUsersList(Method): + """ + Deprecated. Can be implemented with GetSlices. + + List users that are members of the named slice. + + Users may only query slices of which they are members. PIs may + query any of the slices at their sites. Admins may query any + slice. If a slice that cannot be queried is specified details + about that slice will not be returned. + """ + + roles = ['admin', 'pi', 'user'] + + accepts = [ + Auth(), + Slice.fields['name'] + ] + + returns = [Person.fields['email']] + + + def call(self, auth, slice_name): + # If we are not admin, make sure to return only viewable + # slices. + slice_filter = [slice_name] + slices = Slices(self.api, slice_filter) + if not slices: + raise PLCInvalidArgument, "No such slice" + slice = slices[0] + + if 'admin' not in self.caller['roles']: + # Get slices that we are able to view + valid_slice_ids = self.caller['slice_ids'] + if 'pi' in self.caller['roles'] and self.caller['site_ids']: + sites = Sites(self.api, self.caller['site_ids']) + for site in sites: + valid_slice_ids += site['slice_ids'] + + if not valid_slice_ids: + return [] + + if slice['slice_id'] not in valid_slice_ids: + return [] + + persons = Persons(self.api, slice['person_ids']) + person_names = [person['email'] for person in persons] + + return person_names -- 2.45.2