示例#1
0
文件: dummydriver.py 项目: aquila/sfa
 def shutdown (self, xrn, options={}):
     xrn = DummyXrn(xrn=xrn, type='slice')
     slicename = xrn.pl_slicename()
     slices = self.shell.GetSlices({'name': slicename}, ['slice_id'])
     if not slices:
         raise RecordNotFound(slice_hrn)
     slice_id = slices[0]['slice_id']
     slice_tags = self.shell.GetSliceTags({'slice_id': slice_id, 'tagname': 'enabled'})
     if not slice_tags:
         self.shell.AddSliceTag(slice_id, 'enabled', '0')
     elif slice_tags[0]['value'] != "0":
         tag_id = slice_tags[0]['slice_tag_id']
         self.shell.UpdateSliceTag(tag_id, '0')
     return 1
示例#2
0
    def check_sliver_credentials(self, creds, urns):
        # build list of cred object hrns
        slice_cred_names = []
        for cred in creds:
            slice_cred_hrn = Credential(cred=cred).get_gid_object().get_hrn()
            slice_cred_names.append(
                DummyXrn(xrn=slice_cred_hrn).dummy_slicename())

        # look up slice name of slivers listed in urns arg
        slice_ids = []
        for urn in urns:
            sliver_id_parts = Xrn(xrn=urn).get_sliver_id_parts()
            try:
                slice_ids.append(int(sliver_id_parts[0]))
            except ValueError:
                pass

        if not slice_ids:
            raise Forbidden("sliver urn not provided")

        slices = self.shell.GetSlices({'slice_ids': slice_ids})
        sliver_names = [slice['slice_name'] for slice in slices]

        # make sure we have a credential for every specified sliver ierd
        for sliver_name in sliver_names:
            if sliver_name not in slice_cred_names:
                msg = "Valid credential not found for target: %s" % sliver_name
                raise Forbidden(msg)
示例#3
0
 def shutdown(self, xrn, options={}):
     xrn = DummyXrn(xrn=xrn, type='slice')
     slicename = xrn.pl_slicename()
     slices = self.shell.GetSlices({'name': slicename}, ['slice_id'])
     if not slices:
         raise RecordNotFound(slice_hrn)
     slice_id = slices[0]['slice_id']
     slice_tags = self.shell.GetSliceTags({
         'slice_id': slice_id,
         'tagname': 'enabled'
     })
     if not slice_tags:
         self.shell.AddSliceTag(slice_id, 'enabled', '0')
     elif slice_tags[0]['value'] != "0":
         tag_id = slice_tags[0]['slice_tag_id']
         self.shell.UpdateSliceTag(tag_id, '0')
     return 1
示例#4
0
    def node_to_rspec_node(self, node, options={}):
        rspec_node = NodeElement()
        site=self.driver.testbedInfo
        rspec_node['component_id'] = hostname_to_urn(self.driver.hrn, site['name'], node['hostname'])
        rspec_node['component_name'] = node['hostname']
        rspec_node['component_manager_id'] = Xrn(self.driver.hrn, 'authority+cm').get_urn()
        rspec_node['authority_id'] = hrn_to_urn(DummyXrn.site_hrn(self.driver.hrn, site['name']), 'authority+sa')
        #distinguish between Shared and Reservable nodes
        rspec_node['exclusive'] = 'false'

        rspec_node['hardware_types'] = [HardwareType({'name': 'dummy-pc'}),
                                        HardwareType({'name': 'pc'})]
        if site['longitude'] and site['latitude']:
            location = Location({'longitude': site['longitude'], 'latitude': site['latitude'], 'country': 'unknown'})
            rspec_node['location'] = location
        return rspec_node
示例#5
0
    def get_nodes(self, slice_xrn, slice=None,slivers=[], options={}):
        # if we are dealing with a slice that has no node just return 
        # and empty list    
        if slice_xrn:
            if not slice or 'node_ids' not in slice.keys() or not slice['node_ids']:
                return []

        filter = {}
        if slice and 'node_ids' in slice and slice['node_ids']:
            filter['node_ids'] = slice['node_ids']

        nodes = self.driver.shell.GetNodes(filter)
        
        rspec_nodes = []
        for node in nodes:
            rspec_node = Node()
            # xxx how to retrieve site['login_base']
            site=self.driver.testbedInfo
            rspec_node['component_id'] = hostname_to_urn(self.driver.hrn, site['name'], node['hostname'])
            rspec_node['component_name'] = node['hostname']
            rspec_node['component_manager_id'] = Xrn(self.driver.hrn, 'authority+cm').get_urn()
            rspec_node['authority_id'] = hrn_to_urn(DummyXrn.site_hrn(self.driver.hrn, site['name']), 'authority+sa')
            rspec_node['exclusive'] = 'false'
            rspec_node['hardware_types'] = [HardwareType({'name': 'plab-pc'}),
                                            HardwareType({'name': 'pc'})]
             # add site/interface info to nodes.
            # assumes that sites, interfaces and tags have already been prepared.
            if site['longitude'] and site['latitude']:  
                location = Location({'longitude': site['longitude'], 'latitude': site['latitude'], 'country': 'unknown'})
                rspec_node['location'] = location

            if node['node_id'] in slivers:
                # add sliver info
                sliver = slivers[node['node_id']]
                rspec_node['client_id'] = node['hostname']
                rspec_node['slivers'] = [sliver]
                
                # slivers always provide the ssh service
                login = Login({'authentication': 'ssh-keys', 'hostname': node['hostname'], 'port':'22', 'username': slice['slice_name']})
                service = Services({'login': login})
                rspec_node['services'] = [service]
            rspec_nodes.append(rspec_node)
        return rspec_nodes
示例#6
0
    def delete(self, urns, options={}):
        # collect sliver ids so we can update sliver allocation states after
        # we remove the slivers.
        aggregate = DummyAggregate(self)
        slivers = aggregate.get_slivers(urns)
        if slivers:
            slice_id = slivers[0]['slice_id']
            node_ids = []
            sliver_ids = []
            for sliver in slivers:
                node_ids.append(sliver['node_id'])
                sliver_ids.append(sliver['sliver_id'])

            # 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
            slice_hrn = DummyXrn(auth=self.hrn,
                                 slicename=slivers[0]['slice_name']).get_hrn()
            try:
                self.shell.DeleteSliceFromNodes({
                    'slice_id': slice_id,
                    'node_ids': node_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
示例#7
0
    def get_slivers(self, urns, options=None):
        if options is None: options={}
        slice_names = set()
        slice_ids = set()
        node_ids = []
        for urn in urns:
            xrn = DummyXrn(xrn=urn)
            if xrn.type == 'sliver':
                 # id: slice_id-node_id
                try:
                    sliver_id_parts = xrn.get_sliver_id_parts()
                    slice_id = int(sliver_id_parts[0])
                    node_id = int(sliver_id_parts[1])
                    slice_ids.add(slice_id)
                    node_ids.append(node_id)
                except ValueError:
                    pass
            else:
                slice_names.add(xrn.dummy_slicename())

        filter = {}
        if slice_names:
            filter['slice_name'] = list(slice_names)
        if slice_ids:
            filter['slice_id'] = list(slice_ids)
        # get slices
        slices = self.driver.shell.GetSlices(filter)
        if not slices:
            return []
        slice = slices[0]
        slice['hrn'] = DummyXrn(auth=self.driver.hrn, slicename=slice['slice_name']).hrn

        # get sliver users
        users = []
        user_ids = []
        for slice in slices:
            if 'user_ids' in slice.keys():
                user_ids.extend(slice['user_ids'])
        if user_ids:
            users = self.driver.shell.GetUsers({'user_ids': user_ids})

        # construct user key info
        users_list = []
        for user in users:
            name = user['email'][0:user['email'].index('@')]
            user = {
                'login': slice['slice_name'],
                'user_urn': Xrn('%s.%s' % (self.driver.hrn, name), type='user').urn,
                'keys': user['keys']
            }
            users_list.append(user)

        if node_ids:
            node_ids = [node_id for node_id in node_ids if node_id in slice['node_ids']]
            slice['node_ids'] = node_ids
        nodes_dict = self.get_slice_nodes(slice, options)
        slivers = []
        for node in nodes_dict.values():
            node.update(slice)
            sliver_hrn = '%s.%s-%s' % (self.driver.hrn, slice['slice_id'], node['node_id'])
            node['sliver_id'] = Xrn(sliver_hrn, type='sliver').urn
            node['urn'] = node['sliver_id']
            node['services_user'] = users
            slivers.append(node)
        return slivers
示例#8
0
    def get_slivers(self, urns, options={}):
        slice_names = set()
        slice_ids = set()
        node_ids = []
        for urn in urns:
            xrn = DummyXrn(xrn=urn)
            if xrn.type == 'sliver':
                 # id: slice_id-node_id
                try:
                    sliver_id_parts = xrn.get_sliver_id_parts()
                    slice_id = int(sliver_id_parts[0])
                    node_id = int(sliver_id_parts[1])
                    slice_ids.add(slice_id)
                    node_ids.append(node_id)
                except ValueError:
                    pass
            else:
                slice_names.add(xrn.dummy_slicename())

        filter = {}
        if slice_names:
            filter['slice_name'] = list(slice_names)
        if slice_ids:
            filter['slice_id'] = list(slice_ids)
        # get slices
        slices = self.driver.shell.GetSlices(filter)
        if not slices:
            return []
        slice = slices[0]
        slice['hrn'] = DummyXrn(auth=self.driver.hrn, slicename=slice['slice_name']).hrn

        # get sliver users
        users = []
        user_ids = []
        for slice in slices:
            user_ids.extend(slice['user_ids'])
        if user_ids:
            users = self.driver.shell.GetUsers({'user_ids': user_ids})

        # construct user key info
        users_list = []
        for user in users:
            name = user['email'][0:user['email'].index('@')]
            user = {
                'login': slice['slice_name'],
                'user_urn': Xrn('%s.%s' % (self.driver.hrn, name), type='user').urn,
                'keys': user['keys']
            }
            users_list.append(user)

        if node_ids:
            node_ids = [node_id for node_id in node_ids if node_id in slice['node_ids']]
            slice['node_ids'] = node_ids
        nodes_dict = self.get_slice_nodes(slice, options)
        slivers = []
        for node in nodes_dict.values():
            node.update(slice)
            sliver_hrn = '%s.%s-%s' % (self.driver.hrn, slice['slice_id'], node['node_id'])
            node['sliver_id'] = Xrn(sliver_hrn, type='sliver').urn
            node['urn'] = node['sliver_id']
            node['services_user'] = users
            slivers.append(node)
        return slivers