from sfa.planetlab.plshell import PlShell
from sfa.planetlab.plaggregate import PlAggregate
from sfa.planetlab.plslices import PlSlices
-from sfa.planetlab.plxrn import PlXrn, slicename_to_hrn, hostname_to_hrn, hrn_to_pl_slicename, xrn_to_hostname, top_auth, hash_loginbase
+from sfa.planetlab.plxrn import PlXrn, slicename_to_hrn, hostname_to_hrn, hrn_to_pl_slicename, top_auth, hash_loginbase
def list_to_dict(recs, key):
return {}
# first 2 args are None in case of resource discovery
- def list_resources (self, version=None, options={}):
+ def list_resources (self, version=None, options=None):
+ if options is None: options={}
aggregate = PlAggregate(self)
rspec = aggregate.list_resources(version=version, options=options)
return rspec
- def describe(self, urns, version, options={}):
+ def describe(self, urns, version, options=None):
+ if options is None: options={}
aggregate = PlAggregate(self)
return aggregate.describe(urns, version=version, options=options)
- def status (self, urns, options={}):
+ def status (self, urns, options=None):
+ if options is None: options={}
aggregate = PlAggregate(self)
desc = aggregate.describe(urns, version='GENI 3')
status = {'geni_urn': desc['geni_urn'],
'geni_slivers': desc['geni_slivers']}
return status
- def allocate (self, urn, rspec_string, expiration, options={}):
+ def allocate (self, urn, rspec_string, expiration, options=None):
+ if options is None: options={}
xrn = Xrn(urn)
aggregate = PlAggregate(self)
slices = PlSlices(self)
return aggregate.describe([xrn.get_urn()], version=rspec.version)
- def provision(self, urns, options={}):
+ def provision(self, urns, options=None):
+ if options is None: options={}
# update users
slices = PlSlices(self)
aggregate = PlAggregate(self)
slivers = aggregate.get_slivers(urns)
if not slivers:
sliver_id_parts = Xrn(urns[0]).get_sliver_id_parts()
- filter = {}
- try:
- filter['slice_id'] = int(sliver_id_parts[0])
- except ValueError:
- filter['name'] = sliver_id_parts[0]
- slices = self.shell.GetSlices(filter,['hrn'])
- if not slices:
- raise Forbidden("Unable to locate slice record for sliver: %s" % xrn)
- slice = slices[0]
- slice_urn = hrn_to_urn(slice['hrn'], type='slice')
- urns = [slice_urn]
+ # allow to be called with an empty rspec, meaning flush reservations
+ if sliver_id_parts:
+ filter = {}
+ try:
+ filter['slice_id'] = int(sliver_id_parts[0])
+ except ValueError:
+ filter['name'] = sliver_id_parts[0]
+ slices = self.shell.GetSlices(filter,['hrn'])
+ if not slices:
+ raise Forbidden("Unable to locate slice record for sliver: %s" % xrn)
+ slice = slices[0]
+ slice_urn = hrn_to_urn(slice['hrn'], type='slice')
+ urns = [slice_urn]
else:
slice_id = slivers[0]['slice_id']
slice_hrn = self.shell.GetSliceHrn(slice_id)
rspec_version = version_manager.get_version(options['geni_rspec_version'])
return self.describe(urns, rspec_version, options=options)
- def delete(self, urns, options={}):
+ def delete(self, urns, options=None):
+ if options is None: options={}
# collect sliver ids so we can update sliver allocation states after
# we remove the slivers.
aggregate = PlAggregate(self)
'geni_expires': datetime_to_string(utcparse(sliver['expires']))})
return geni_slivers
- def renew (self, urns, expiration_time, options={}):
+ def renew (self, urns, expiration_time, options=None):
+ if options is None: options={}
aggregate = PlAggregate(self)
slivers = aggregate.get_slivers(urns)
if not slivers:
return description['geni_slivers']
- def perform_operational_action (self, urns, action, options={}):
+ def perform_operational_action (self, urns, action, options=None):
+ if options is None: options={}
# MyPLC doesn't support operational actions. Lets pretend like it
# supports start, but reject everything else.
action = action.lower()
return geni_slivers
# set the 'enabled' tag to 0
- def shutdown (self, xrn, options={}):
+ def shutdown (self, xrn, options=None):
+ if options is None: options={}
hrn, _ = urn_to_hrn(xrn)
top_auth_hrn = top_auth(hrn)
site_hrn = '.'.join(hrn.split('.')[:-1])