From 79f6ad9ca996f5ef93e603393de747b513cf373e Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Tue, 14 Apr 2009 02:44:30 +0000 Subject: [PATCH] added more methods --- geni/methods/__init__.py | 5 +++++ geni/methods/create_slice.py | 35 +++++++++++++++++++++++++++++++++++ geni/methods/delete_slice.py | 33 +++++++++++++++++++++++++++++++++ geni/methods/reset_slice.py | 32 ++++++++++++++++++++++++++++++++ geni/methods/slices.py | 19 ++++--------------- geni/methods/start_slice.py | 33 +++++++++++++++++++++++++++++++++ geni/methods/stop_slice.py | 33 +++++++++++++++++++++++++++++++++ 7 files changed, 175 insertions(+), 15 deletions(-) create mode 100644 geni/methods/create_slice.py create mode 100644 geni/methods/delete_slice.py create mode 100644 geni/methods/reset_slice.py create mode 100644 geni/methods/start_slice.py create mode 100644 geni/methods/stop_slice.py diff --git a/geni/methods/__init__.py b/geni/methods/__init__.py index 198dceb4..9e871f50 100644 --- a/geni/methods/__init__.py +++ b/geni/methods/__init__.py @@ -1,12 +1,17 @@ methods=""" create_gid +create_slice +delete_slice get_credential get_ticket list register remove +reset_slice resolve resources slices +start_slice +stop_slice update """.split() diff --git a/geni/methods/create_slice.py b/geni/methods/create_slice.py new file mode 100644 index 00000000..ace5a8b1 --- /dev/null +++ b/geni/methods/create_slice.py @@ -0,0 +1,35 @@ +from geni.util.faults import * +from geni.util.excep import * +from geni.util.misc import * +from geni.util.method import Method +from geni.util.parameter import Parameter, Mixed +from geni.util.auth import Auth +from geni.util.slices import Slices + +class create_slices(Method): + """ + Instantiate the specified slice according to whats defined in the specified rspec + + @param cred credential string specifying the rights of the caller + @param hrn human readable name of slice to instantiate + @param rspec resource specification + @return 1 is successful, faults otherwise + """ + + interfaces = ['aggregate', 'slicemgr'] + + accepts = [ + Parameter(str, "Credential string"), + Parameter(str, "Human readable name of slice to instantiate"), + Parameter(str, "Resource specification"), + ] + + returns = [Parameter(int, "1 if successful")] + + def call(self, cred, hrn, rspec): + + self.api.auth.check(cred, 'createslice') + slices = Slices(self.api) + slices.create_slice(hrn, rspec): + + return 1 diff --git a/geni/methods/delete_slice.py b/geni/methods/delete_slice.py new file mode 100644 index 00000000..7aecc1e5 --- /dev/null +++ b/geni/methods/delete_slice.py @@ -0,0 +1,33 @@ +from geni.util.faults import * +from geni.util.excep import * +from geni.util.misc import * +from geni.util.method import Method +from geni.util.parameter import Parameter, Mixed +from geni.util.auth import Auth +from geni.aggregate import Aggregates +from geni.util.slices import Slices + +class delete_slice(Method): + """ + Remove the slice from all nodes. + + @param cred credential string specifying the rights of the caller + @param hrn human readable name specifying the slice to delete + @return 1 if successful, faults otherwise + """ + + interfaces = ['aggregate', 'slicemgr'] + + accepts = [ + Parameter(str, "Credential string"), + Parameter(str, "Human readable name of slice to delete"), + ] + + returns = [Parameter(int, "1 if successful")] + + def call(self, cred, hrn): + + self.api.auth.check(cred, 'deleteslice') + slices = Slices(self.api) + slices.delete_slice(hrn) + return 1 diff --git a/geni/methods/reset_slice.py b/geni/methods/reset_slice.py new file mode 100644 index 00000000..4b84942d --- /dev/null +++ b/geni/methods/reset_slice.py @@ -0,0 +1,32 @@ +from geni.util.faults import * +from geni.util.excep import * +from geni.util.misc import * +from geni.util.method import Method +from geni.util.parameter import Parameter, Mixed +from geni.util.auth import Auth +from geni.util.slices import Slices + +class reset_slices(Method): + """ + Reset the specified slice + + @param cred credential string specifying the rights of the caller + @param hrn human readable name of slice to instantiate + @return 1 is successful, faults otherwise + """ + + interfaces = ['aggregate', 'slicemgr'] + + accepts = [ + Parameter(str, "Credential string"), + Parameter(str, "Human readable name of slice to instantiate"), + ] + + returns = [Parameter(int, "1 if successful")] + + def call(self, cred, hrn): + + self.api.auth.check(cred, 'resetslice') + ## XX Not yet implemented + + return 1 diff --git a/geni/methods/slices.py b/geni/methods/slices.py index fc569d00..91134ceb 100644 --- a/geni/methods/slices.py +++ b/geni/methods/slices.py @@ -4,7 +4,7 @@ from geni.util.misc import * from geni.util.method import Method from geni.util.parameter import Parameter, Mixed from geni.util.auth import Auth -from geni.aggregate import Aggregates +from geni.util.slices import Slices class slices(Method): """ @@ -25,17 +25,6 @@ class slices(Method): def call(self, cred): self.api.auth.check(cred, 'listslices') - slice_hrns = [] - - if self.api.interface in ['aggregate']: - slices = self.api.plshell.GetSlices(self.api.plauth, {}, ['name']) - slice_hrns = [slicename_to_hrn(self.api.hrn, slice['name']) for slice in slices] - - else: - aggregates = Aggregates() - credential = self.api.getCredential() - for aggregate in aggregates: - slices = aggregates[aggregate].slices(credential) - slice_hrns.extend(slices) - - return slice_hrns + slices = Slices(self.api) + slices.refresh() + return slices['hrn'] diff --git a/geni/methods/start_slice.py b/geni/methods/start_slice.py new file mode 100644 index 00000000..d3023d39 --- /dev/null +++ b/geni/methods/start_slice.py @@ -0,0 +1,33 @@ +from geni.util.faults import * +from geni.util.excep import * +from geni.util.misc import * +from geni.util.method import Method +from geni.util.parameter import Parameter, Mixed +from geni.util.auth import Auth +from geni.util.slices import Slices + +class start_slices(Method): + """ + Start the specified slice + + @param cred credential string specifying the rights of the caller + @param hrn human readable name of slice to instantiate + @return 1 is successful, faults otherwise + """ + + interfaces = ['aggregate', 'slicemgr'] + + accepts = [ + Parameter(str, "Credential string"), + Parameter(str, "Human readable name of slice to instantiate"), + ] + + returns = [Parameter(int, "1 if successful")] + + def call(self, cred, hrn): + + self.api.auth.check(cred, 'startslice') + slices = Slices(self.api) + slices.stop_slice(hrn): + + return 1 diff --git a/geni/methods/stop_slice.py b/geni/methods/stop_slice.py new file mode 100644 index 00000000..ab5e1652 --- /dev/null +++ b/geni/methods/stop_slice.py @@ -0,0 +1,33 @@ +from geni.util.faults import * +from geni.util.excep import * +from geni.util.misc import * +from geni.util.method import Method +from geni.util.parameter import Parameter, Mixed +from geni.util.auth import Auth +from geni.util.slices import Slices + +class stop_slice(Method): + """ + Stop the specified slice + + @param cred credential string specifying the rights of the caller + @param hrn human readable name of slice to instantiate + @return 1 is successful, faults otherwise + """ + + interfaces = ['aggregate', 'slicemgr'] + + accepts = [ + Parameter(str, "Credential string"), + Parameter(str, "Human readable name of slice to instantiate"), + ] + + returns = [Parameter(int, "1 if successful")] + + def call(self, cred, hrn): + + self.api.auth.check(cred, 'startslice') + slices = Slices(self.api) + slices.stop_slice(hrn): + + return 1 -- 2.43.0