- slice = slivers[0]
- peer = slices.get_peer(slice['hrn'])
- sfa_peer = slices.get_sfa_peer(slice['hrn'])
- users = options.get('geni_users', [])
- persons = slices.verify_persons(slice['hrn'], slice, users, peer, sfa_peer, options=options)
- slices.handle_peer(None, None, persons, peer)
- # update sliver allocation states and set them to geni_provisioned
- sliver_ids = [sliver['sliver_id'] for sliver in slivers]
- SliverAllocation.set_allocations(sliver_ids, 'geni_provisioned')
+ if not slivers:
+ sliver_id_parts = Xrn(urns[0]).get_sliver_id_parts()
+ # 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: {}".format(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)
+ 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)
+