Example #1
0
    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]          
        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)

        version_manager = VersionManager()
        rspec_version = version_manager.get_version(options['geni_rspec_version']) 
        return self.describe(urns, rspec_version, options=options)
Example #2
0
 def renew (self, urns, expiration_time, options={}):
     aggregate = PlAggregate(self)
     slivers = aggregate.get_slivers(urns)
     if not slivers:
         raise SearchFailed(urns)
     slice = slivers[0]
     requested_time = utcparse(expiration_time)
     record = {'expires': int(datetime_to_epoch(requested_time))}
     self.shell.UpdateSlice(slice['slice_id'], record)
     description = self.describe(urns, 'GENI 3', options)
     return description['geni_slivers']
Example #3
0
 def renew(self, urns, expiration_time, options={}):
     aggregate = PlAggregate(self)
     slivers = aggregate.get_slivers(urns)
     if not slivers:
         raise SearchFailed(urns)
     slice = slivers[0]
     requested_time = utcparse(expiration_time)
     record = {'expires': int(datetime_to_epoch(requested_time))}
     self.shell.UpdateSlice(slice['slice_id'], record)
     description = self.describe(urns, 'GENI 3', options)
     return description['geni_slivers']
Example #4
0
    def delete(self, urns, 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
Example #5
0
    def provision(self, urns, 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]
        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)

        version_manager = VersionManager()
        rspec_version = version_manager.get_version(
            options['geni_rspec_version'])
        return self.describe(urns, rspec_version, options=options)
Example #6
0
    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