- node_ids = slice['node_ids']
- slice_hrn = PlXrn(auth=self.hrn, slicename=slice['name']).get_hrn()
- # determine if this is a peer slice
- # xxx I wonder if this would not need to use PlSlices.get_peer instead
- # in which case plc.peers could be deprecated as this here
- # is the only/last call to this last method in plc.peers
- peer = peers.get_peer(self, slice_hrn)
- try:
- if peer:
- self.shell.UnBindObjectFromPeer('slice', slice['slice_id'], peer)
- self.shell.DeleteSliceFromNodes(slice['slice_id'], node_ids)
- finally:
- if peer:
- self.shell.BindObjectToPeer('slice', slice['slice_id'], peer, slice['peer_slice_id'])
- return True
-
- def renew (self, urns, expiration_time, options={}):
- # we can only renew slices, not individual slivers. ignore sliver
- # ids in the urn
- names = []
- for urn in urns:
- xrn = PlXrn(xrn=urn, type='slice')
- names.append(xrn.pl_slicename())
- slices = self.shell.GetSlices(names, ['slice_id'])
- if not slices:
+ slice_id = slivers[0]['slice_id']
+ slice_hrn = self.shell.GetSliceHrn(slice_id)
+ slice = self.shell.GetSlices({'slice_id': slice_id})[0]
+ slice['hrn'] = slice_hrn
+ sfa_peer = slices.get_sfa_peer(slice['hrn'])
+ users = options.get('geni_users', [])
+ persons = slices.verify_persons(
+ slice['hrn'], slice, users, sfa_peer, options=options)
+ # update sliver allocation states and set them to geni_provisioned
+ sliver_ids = [sliver['sliver_id'] for sliver in slivers]
+ dbsession = self.api.dbsession()
+ SliverAllocation.set_allocations(
+ sliver_ids, 'geni_provisioned', dbsession)
+
+ version_manager = VersionManager()
+ rspec_version = version_manager.get_version(
+ options['geni_rspec_version'])
+ return self.describe(urns, rspec_version, options=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)
+ slivers = aggregate.get_slivers(urns)
+ if slivers:
+ slice_id = slivers[0]['slice_id']
+ slice_name = slivers[0]['name']
+ node_ids = []
+ sliver_ids = []
+ for sliver in slivers:
+ node_ids.append(sliver['node_id'])
+ sliver_ids.append(sliver['sliver_id'])
+
+ # leases
+ leases = self.shell.GetLeases(
+ {'name': slice_name, 'node_id': node_ids})
+ leases_ids = [lease['lease_id'] for lease in leases]
+
+ slice_hrn = self.shell.GetSliceHrn(int(slice_id))
+ try:
+ self.shell.DeleteSliceFromNodes(slice_id, node_ids)
+ if len(leases_ids) > 0:
+ self.shell.DeleteLeases(leases_ids)
+
+ # delete sliver allocation states
+ dbsession = self.api.dbsession()
+ SliverAllocation.delete_allocations(sliver_ids, dbsession)
+ finally:
+ pass
+
+ # prepare return struct
+ geni_slivers = []
+ for sliver in slivers:
+ geni_slivers.append(
+ {'geni_sliver_urn': sliver['sliver_id'],
+ 'geni_allocation_status': 'geni_unallocated',
+ 'geni_expires': datetime_to_string(utcparse(sliver['expires']))})
+ return geni_slivers
+
+ def renew(self, urns, expiration_time, options=None):
+ if options is None:
+ options = {}
+ aggregate = PlAggregate(self)
+ slivers = aggregate.get_slivers(urns)
+ if not slivers: