• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python xrn.hrn_to_urn函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sfa.util.xrn.hrn_to_urn函数的典型用法代码示例。如果您正苦于以下问题:Python hrn_to_urn函数的具体用法?Python hrn_to_urn怎么用?Python hrn_to_urn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了hrn_to_urn函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: get_leases

    def get_leases(self, slice=None, options={}):
        
        now = int(time.time())
        filter={}
        filter.update({'clip':now})
        if slice:
           filter.update({'name':slice['name']})
        return_fields = ['lease_id', 'hostname', 'site_id', 'name', 't_from', 't_until']
        leases = self.driver.shell.GetLeases(filter)
        grain = self.driver.shell.GetLeaseGranularity()

        site_ids = []
        for lease in leases:
            site_ids.append(lease['site_id'])

        # get sites
        sites_dict  = self.get_sites({'site_id': site_ids}) 
  
        rspec_leases = []
        for lease in leases:

            rspec_lease = Lease()
            
            # xxx how to retrieve site['login_base']
            site_id=lease['site_id']
            site=sites_dict[site_id]

            rspec_lease['component_id'] = hrn_to_urn(self.driver.shell.GetNodeHrn(lease['hostname']), 'node')
            slice_hrn = self.driver.shell.GetSliceHrn(lease['slice_id'])
            slice_urn = hrn_to_urn(slice_hrn, 'slice')
            rspec_lease['slice_id'] = slice_urn
            rspec_lease['start_time'] = lease['t_from']
            rspec_lease['duration'] = (lease['t_until'] - lease['t_from']) / grain
            rspec_leases.append(rspec_lease)
        return rspec_leases
开发者ID:aquila,项目名称:sfa,代码行数:35,代码来源:plaggregate.py


示例2: fill_record_sfa_info

    def fill_record_sfa_info(self, records):
        def startswith(prefix, values):
            return [value for value in values if value.startswith(prefix)]

        # get user ids
        user_ids = []
        for record in records:
            user_ids.extend(record.get("user_ids", []))

        # get sfa records for all records associated with these records.
        # we'll replace pl ids (person_ids) with hrns from the sfa records
        # we obtain

        # get the registry records
        user_list, users = [], {}
        user_list = dbsession.query(RegRecord).filter(RegRecord.pointer.in_(user_ids))
        # create a hrns keyed on the sfa record's pointer.
        # Its possible for multiple records to have the same pointer so
        # the dict's value will be a list of hrns.
        users = defaultdict(list)
        for user in user_list:
            users[user.pointer].append(user)

        # get the dummy records
        dummy_user_list, dummy_users = [], {}
        dummy_user_list = self.shell.GetUsers({"user_ids": user_ids})
        dummy_users = list_to_dict(dummy_user_list, "user_id")

        # fill sfa info
        for record in records:
            # skip records with no pl info (top level authorities)
            # if record['pointer'] == -1:
            #    continue
            sfa_info = {}
            type = record["type"]
            logger.info("fill_record_sfa_info - incoming record typed %s" % type)
            if type == "slice":
                # all slice users are researchers
                record["geni_urn"] = hrn_to_urn(record["hrn"], "slice")
                record["PI"] = []
                record["researcher"] = []
                for user_id in record.get("user_ids", []):
                    hrns = [user.hrn for user in users[user_id]]
                    record["researcher"].extend(hrns)

            elif type.startswith("authority"):
                record["url"] = None
                logger.info("fill_record_sfa_info - authority xherex")

            elif type == "node":
                sfa_info["dns"] = record.get("hostname", "")
                # xxx TODO: URI, LatLong, IP, DNS

            elif type == "user":
                logger.info("setting user.email")
                sfa_info["email"] = record.get("email", "")
                sfa_info["geni_urn"] = hrn_to_urn(record["hrn"], "user")
                sfa_info["geni_certificate"] = record["gid"]
                # xxx TODO: PostalAddress, Phone
            record.update(sfa_info)
开发者ID:tubav,项目名称:sfa,代码行数:60,代码来源:dummydriver.py


示例3: fill_record_sfa_info

    def fill_record_sfa_info(self, records):
        
        def startswith(prefix, values):
            return [value for value in values if value.startswith(prefix)]

        # get user ids
        user_ids = []
        for record in records:
            user_ids.extend(record.get("user_ids", []))
        
        # get the registry records
        user_list, users = [], {}
        user_list = dbsession.query(RegRecord).filter(RegRecord.pointer.in_(user_ids)).all()
        # create a hrns keyed on the sfa record's pointer.
        # Its possible for multiple records to have the same pointer so
        # the dict's value will be a list of hrns.
        users = defaultdict(list)
        for user in user_list:
            users[user.pointer].append(user)

        # get the nitos records
        nitos_user_list, nitos_users = [], {}
        nitos_all_users = self.convert_id(self.shell.getUsers())
        nitos_user_list = [user for user in nitos_all_users if user['user_id'] in user_ids]
        nitos_users = list_to_dict(nitos_user_list, 'user_id')


        # fill sfa info
        for record in records:
            if record['pointer'] == -1:
                continue 

            sfa_info = {}
            type = record['type']
            logger.info("fill_record_sfa_info - incoming record typed %s"%type)
            if (type == "slice"):
                # all slice users are researchers
                record['geni_urn'] = hrn_to_urn(record['hrn'], 'slice')
                record['researcher'] = []
                for user_id in record.get('user_ids', []):
                    hrns = [user.hrn for user in users[user_id]]
                    record['researcher'].extend(hrns)                
                
            elif (type == "node"):
                sfa_info['dns'] = record.get("hostname", "")
                # xxx TODO: URI, LatLong, IP, DNS
    
            elif (type == "user"):
                logger.info('setting user.email')
                sfa_info['email'] = record.get("email", "")
                sfa_info['geni_urn'] = hrn_to_urn(record['hrn'], 'user')
                sfa_info['geni_certificate'] = record['gid'] 
                # xxx TODO: PostalAddress, Phone
            record.update(sfa_info)
开发者ID:tubav,项目名称:sfa,代码行数:54,代码来源:nitosdriver.py


示例4: fill_record_info

    def fill_record_info(self, records):
        """
        Given a (list of) SFA record, fill in the PLC specific 
        and SFA specific fields in the record. 
        """
        if not isinstance(records, list):
            records = [records]

        for record in records:
            if record['type'] == 'user':
                record = self.fill_user_record_info(record)
            elif record['type'] == 'slice':
                record = self.fill_slice_record_info(record)
            elif record['type'].startswith('authority'):
                record = self.fill_auth_record_info(record)
            else:
                continue
            record['geni_urn'] = hrn_to_urn(record['hrn'], record['type'])
            record['geni_certificate'] = record['gid'] 
            #if os_record.created_at is not None:    
            #    record['date_created'] = datetime_to_string(utcparse(os_record.created_at))
            #if os_record.updated_at is not None:
            #    record['last_updated'] = datetime_to_string(utcparse(os_record.updated_at))
 
        return records
开发者ID:tubav,项目名称:sfa,代码行数:25,代码来源:nova_driver.py


示例5: node_to_rspec_node

    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['ip'] = node['ip']
        rspec_node['protocol'] = node['protocol']     
        rspec_node['port'] = node['port']                
        rspec_node['component_manager_id'] = Xrn(self.driver.hrn, 'authority+cm').get_urn()
        rspec_node['authority_id'] = hrn_to_urn(unigetestbedXrn.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': 'endpoint'}),
                                        HardwareType({'name': 'sensor'})]
        
        resources = []
        for resource in node['resources']:
            resources.append(Resource({'name':resource.get('name'),'path':resource.get('path'),
                                       'type':resource.get('type'),
                                       'unit':resource.get('unit'),
                                       'data_type':resource.get('datatype')}))
        
        rspec_node['resources'] = resources
        logger.info(rspec_node)
        
        
        if site['longitude'] and site['latitude']:
            location = Location({'longitude': site['longitude'], 'latitude': site['latitude'], 'country': 'unknown'})
            rspec_node['location'] = location
        
        logger.info(rspec_node);        
        return rspec_node
开发者ID:tcslab,项目名称:unige_sfawrap,代码行数:33,代码来源:unigetestbedaggregate.py


示例6: redeem_ticket

 def redeem_ticket(self, opts, args):
     ticket_file = args[0]
     
     # get slice hrn from the ticket
     # use this to get the right slice credential 
     ticket = SfaTicket(filename=ticket_file)
     ticket.decode()
     slice_hrn = ticket.gidObject.get_hrn()
     slice_urn = hrn_to_urn(slice_hrn, 'slice') 
     #slice_hrn = ticket.attributes['slivers'][0]['hrn']
     user_cred = self.get_user_cred()
     slice_cred = self.get_slice_cred(slice_hrn).save_to_string(save_parents=True)
     
     # get a list of node hostnames from the RSpec 
     tree = etree.parse(StringIO(ticket.rspec))
     root = tree.getroot()
     hostnames = root.xpath("./network/site/node/hostname/text()")
     
     # create an xmlrpc connection to the component manager at each of these
     # components and gall redeem_ticket
     connections = {}
     for hostname in hostnames:
         try:
             self.logger.info("Calling redeem_ticket at %(hostname)s " % locals())
             server = self.get_server(hostname, CM_PORT, self.key_file, \
                                      self.cert_file, self.options.debug)
             server.RedeemTicket(ticket.save_to_string(save_parents=True), slice_cred)
             self.logger.info("Success")
         except socket.gaierror:
             self.logger.error("redeem_ticket failed: Component Manager not accepting requests")
         except Exception, e:
             self.logger.log_exc(e.message)
开发者ID:planetlab,项目名称:sfa,代码行数:32,代码来源:sfi.py


示例7: slice_status

def slice_status(api, slice_xrn, creds):
    urn = hrn_to_urn(slice_xrn, 'slice')
    result = {}
    top_level_status = 'unknown'
    slice_id = get_plc_slice_id(creds, urn)
    (ret, output) = call_am_apiclient("QuerySliceNetworkClient", [slice_id,], 5)
    # parse output into rspec XML
    if output.find("Unkown Rspec:") > 0:
        top_level_staus = 'failed'
        result['geni_resources'] = ''
    else:
        has_failure = 0
        all_active = 0
        if output.find("Status => FAILED") > 0:
            top_level_staus = 'failed'
        elif (    output.find("Status => ACCEPTED") > 0 or output.find("Status => PENDING") > 0
               or output.find("Status => INSETUP") > 0 or output.find("Status => INCREATE") > 0
             ):
            top_level_status = 'configuring'
        else:
            top_level_status = 'ready'
        result['geni_resources'] = parse_resources(output, slice_xrn)
    result['geni_urn'] = urn
    result['geni_status'] = top_level_status
    return result
开发者ID:planetlab,项目名称:sfa,代码行数:25,代码来源:aggregate_manager_max.py


示例8: get_slice_and_slivers

    def get_slice_and_slivers(self, slice_xrn, login=None):
        """
        Returns a dict of slivers keyed on the sliver's node_id
        """
        slivers = {}
        sfa_slice = None
        if not slice_xrn:
            return (sfa_slice, slivers)
        slice_urn = hrn_to_urn(slice_xrn, 'slice')
        slice_hrn, _ = urn_to_hrn(slice_xrn)
        slice_name = slice_hrn

        slices = self.driver.GetSlices(slice_filter= str(slice_name), \
                                                slice_filter_type = 'slice_hrn', login=login)
        
        logger.debug("Slabaggregate api \tget_slice_and_slivers \
                        sfa_slice %s \r\n slices %s self.driver.hrn %s" \
                        %(sfa_slice, slices, self.driver.hrn))
        if not slices:
            return (sfa_slice, slivers)
        #if isinstance(sfa_slice, list):
            #sfa_slice = slices[0]
        #else:
            #sfa_slice = slices

        # sort slivers by node id , if there is a job
        #and therfore, node allocated to this slice
        for sfa_slice in slices:
            try:
                node_ids_list =  sfa_slice['node_ids']  
            except KeyError:
                logger.log_exc("SLABAGGREGATE \t \
                                        get_slice_and_slivers KeyError ")
                continue
                                        
            for node in node_ids_list:
                sliver_xrn = Xrn(slice_urn, type='sliver', id=node)
                sliver_xrn.set_authority(self.driver.hrn)
                #node_id = self.driver.root_auth + '.' + node_id
                sliver = Sliver({'sliver_id':sliver_xrn.urn, 
                                'name': sfa_slice['hrn'],
                                'type': 'slab-node', 
                                'tags': []})
                
                slivers[node] = sliver
          
        
        #Add default sliver attribute :
        #connection information for senslab
        if get_authority (sfa_slice['hrn']) == self.driver.root_auth: 
            tmp = sfa_slice['hrn'].split('.')
            ldap_username = tmp[1].split('_')[0]
            vmaddr = 'ssh ' + ldap_username + '@grenoble.senslab.info'
            slivers['default_sliver'] =  {'vm': vmaddr , 'login': ldap_username}
            
        #TODO get_slice_and_slivers Find the login of the external user

        logger.debug("SLABAGGREGATE api get_slice_and_slivers  slivers %s "\
                                                             %(slivers))
        return (slices, slivers)
开发者ID:tubav,项目名称:sfa,代码行数:60,代码来源:slabaggregate.py


示例9: get_key_from_incoming_ip

    def get_key_from_incoming_ip (self, api):
        dbsession=api.dbsession()
        # verify that the callers's ip address exist in the db and is an interface
        # for a node in the db
        (ip, port) = api.remote_addr
        interfaces = api.driver.shell.GetInterfaces({'ip': ip}, ['node_id'])
        if not interfaces:
            raise NonExistingRecord("no such ip %(ip)s" % locals())
        nodes = api.driver.shell.GetNodes([interfaces[0]['node_id']], ['node_id', 'hostname'])
        if not nodes:
            raise NonExistingRecord("no such node using ip %(ip)s" % locals())
        node = nodes[0]
       
        # look up the sfa record
        record=dbsession.query(RegRecord).filter_by(type='node',pointer=node['node_id']).first()
        if not record:
            raise RecordNotFound("node with pointer %s"%node['node_id'])
        
        # generate a new keypair and gid
        uuid = create_uuid()
        pkey = Keypair(create=True)
        urn = hrn_to_urn(record.hrn, record.type)
        gid_object = api.auth.hierarchy.create_gid(urn, uuid, pkey)
        gid = gid_object.save_to_string(save_parents=True)
        record.gid = gid

        # update the record
        dbsession.commit()
  
        # attempt the scp the key
        # and gid onto the node
        # this will only work for planetlab based components
        (kfd, key_filename) = tempfile.mkstemp() 
        (gfd, gid_filename) = tempfile.mkstemp() 
        pkey.save_to_file(key_filename)
        gid_object.save_to_file(gid_filename, save_parents=True)
        host = node['hostname']
        key_dest="/etc/sfa/node.key"
        gid_dest="/etc/sfa/node.gid" 
        scp = "/usr/bin/scp" 
        #identity = "/etc/planetlab/root_ssh_key.rsa"
        identity = "/etc/sfa/root_ssh_key"
        scp_options=" -i %(identity)s " % locals()
        scp_options+="-o StrictHostKeyChecking=no " % locals()
        scp_key_command="%(scp)s %(scp_options)s %(key_filename)s [email protected]%(host)s:%(key_dest)s" %\
                         locals()
        scp_gid_command="%(scp)s %(scp_options)s %(gid_filename)s [email protected]%(host)s:%(gid_dest)s" %\
                         locals()    

        all_commands = [scp_key_command, scp_gid_command]
        
        for command in all_commands:
            (status, output) = commands.getstatusoutput(command)
            if status:
                raise Exception, output

        for filename in [key_filename, gid_filename]:
            os.unlink(filename)

        return 1 
开发者ID:aquila,项目名称:sfa,代码行数:60,代码来源:registry_manager.py


示例10: create_top_level_auth_records

    def create_top_level_auth_records(self, hrn):
        """
        Create top level records (includes root and sub authorities (local/remote)
        """
        urn = hrn_to_urn(hrn, 'authority')
        # make sure parent exists
        parent_hrn = get_authority(hrn)
        if not parent_hrn:
            parent_hrn = hrn
        if not parent_hrn == hrn:
            self.create_top_level_auth_records(parent_hrn)

        # create the authority if it doesnt already exist 
        if not self.AuthHierarchy.auth_exists(urn):
            self.logger.info("Import: creating top level authorities")
            self.AuthHierarchy.create_auth(urn)
        
        # create the db record if it doesnt already exist    
        auth_info = self.AuthHierarchy.get_auth_info(hrn)
        table = SfaTable()
        auth_record = table.find({'type': 'authority', 'hrn': hrn})

        if not auth_record:
            auth_record = SfaRecord(hrn=hrn, gid=auth_info.get_gid_object(), type="authority", pointer=-1)
            auth_record['authority'] = get_authority(auth_record['hrn'])
            self.logger.info("Import: inserting authority record for %s"%hrn)
            table.insert(auth_record)
开发者ID:planetlab,项目名称:sfa,代码行数:27,代码来源:sfaImport.py


示例11: import_site

    def import_site(self, hrn, site):
        shell = self.shell
        plc_auth = self.plc_auth
        urn = hrn_to_urn(hrn, 'authority')
        self.logger.info("Import: site %s"%hrn)

        # create the authority
        if not self.AuthHierarchy.auth_exists(urn):
            self.AuthHierarchy.create_auth(urn)

        auth_info = self.AuthHierarchy.get_auth_info(urn)

        table = SfaTable()
        auth_record = SfaRecord(hrn=hrn, gid=auth_info.get_gid_object(), type="authority", pointer=site['site_id'])
        auth_record['authority'] = get_authority(auth_record['hrn'])
        existing_records = table.find({'hrn': hrn, 'type': 'authority', 'pointer': site['site_id']})
        if not existing_records:
            table.insert(auth_record)
        else:
            self.logger.info("Import: %s exists, updating " % hrn)
            existing_record = existing_records[0]
            auth_record['record_id'] = existing_record['record_id']
            table.update(auth_record)

        return hrn
开发者ID:planetlab,项目名称:sfa,代码行数:25,代码来源:sfaImport.py


示例12: import_slice

    def import_slice(self, parent_hrn, slice):
        slicename = slice['name'].split("_",1)[-1]
        slicename = _cleanup_string(slicename)

        if not slicename:
            self.logger.error("Import: failed to parse slice name %s" %slice['name'])
            return

        hrn = parent_hrn + "." + slicename
        self.logger.info("Import: slice %s"%hrn)

        pkey = Keypair(create=True)
        urn = hrn_to_urn(hrn, 'slice')
        slice_gid = self.AuthHierarchy.create_gid(urn, create_uuid(), pkey)
        slice_record = SfaRecord(hrn=hrn, gid=slice_gid, type="slice", pointer=slice['slice_id'])
        slice_record['authority'] = get_authority(slice_record['hrn'])
        table = SfaTable()
        existing_records = table.find({'hrn': hrn, 'type': 'slice', 'pointer': slice['slice_id']})
        if not existing_records:
            table.insert(slice_record)
        else:
            self.logger.info("Import: %s exists, updating " % hrn)
            existing_record = existing_records[0]
            slice_record['record_id'] = existing_record['record_id']
            table.update(slice_record)
开发者ID:planetlab,项目名称:sfa,代码行数:25,代码来源:sfaImport.py


示例13: list_slices

    def list_slices(self, creds, options):

        slices = self.shell.GetSlices()
        slice_hrns = [slicename_to_hrn(self.hrn, slice["slice_name"]) for slice in slices]
        slice_urns = [hrn_to_urn(slice_hrn, "slice") for slice_hrn in slice_hrns]

        return slice_urns
开发者ID:tubav,项目名称:sfa,代码行数:7,代码来源:dummydriver.py


示例14: get_slice_and_slivers

    def get_slice_and_slivers(self, slice_xrn):
        """
        Returns a dict of slivers keyed on the sliver's node_id
        """
        slivers = {}
        slice = None
        if not slice_xrn:
            return (slice, slivers)
        slice_urn = hrn_to_urn(slice_xrn, 'slice')
        slice_hrn, _ = urn_to_hrn(slice_xrn)
        slice_name = hrn_to_nitos_slicename(slice_hrn)
        slices = self.driver.shell.getSlices({'slice_name': slice_name}, [])
        #filter results
        for slc in slices:
             if slc['slice_name'] == slice_name:
                 slice = slc
                 break

        if not slice:
            return (slice, slivers)
      
        reserved_nodes = self.driver.shell.getReservedNodes({'slice_id': slice['slice_id']}, [])
        reserved_node_ids = []
        # filter on the slice
        for node in reserved_nodes:
             if node['slice_id'] == slice['slice_id']:
                 reserved_node_ids.append(node['node_id'])
        #get all the nodes
        all_nodes = self.driver.shell.getNodes({}, [])
       
        for node in all_nodes:
             if node['node_id'] in reserved_node_ids:
                 slivers[node['node_id']] = node
        
        return (slice, slivers)
开发者ID:aquila,项目名称:sfa,代码行数:35,代码来源:nitosaggregate.py


示例15: parse_resources

def parse_resources(text, slice_xrn):
    resources = []
    urn = hrn_to_urn(slice_xrn, 'sliver')
    plc_slice = re.search("Slice Status => ([^\n]+)", text)
    if plc_slice.group(1) != 'NONE':
        res = {}
        res['geni_urn'] = urn + '_plc_slice'
        res['geni_error'] = ''
        res['geni_status'] = 'unknown'
        if plc_slice.group(1) == 'CREATED':
            res['geni_status'] = 'ready'
        resources.append(res)
    vlans = re.findall("GRI => ([^\n]+)\n\t  Status => ([^\n]+)", text)
    for vlan in vlans:
        res = {}
        res['geni_error'] = ''
        res['geni_urn'] = urn + '_vlan_' + vlan[0]
        if vlan[1] == 'ACTIVE':
            res['geni_status'] = 'ready'
        elif vlan[1] == 'FAILED':
            res['geni_status'] = 'failed'
        else:
            res['geni_status'] = 'configuring'
        resources.append(res)
    return resources
开发者ID:planetlab,项目名称:sfa,代码行数:25,代码来源:aggregate_manager_max.py


示例16: provision

    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)
开发者ID:nfvproject,项目名称:SFA,代码行数:35,代码来源:pldriver.py


示例17: get_nodes

    def get_nodes(self, slice_xrn, slice=None,slivers=None, options=None):
        if slivers is None: slivers={}
        if options is None: options={}
        # if we are dealing with a slice that has no node just return 
        # and empty list    
        if slice_xrn:
            if not slice or not slivers:
                return []
            else:
                nodes = [slivers[sliver] for sliver in slivers]
        else:
            nodes = self.driver.shell.getNodes({}, [])
        
        # get the granularity in second for the reservation system
        grain = self.driver.testbedInfo['grain']
        #grain = 1800
       

        rspec_nodes = []
        for node in nodes:
            rspec_node = NodeElement()
            site_name = self.driver.testbedInfo['name']
            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(NitosXrn.site_hrn(self.driver.hrn, site_name), 'authority+sa')
            # do not include boot state (<available> element) in the manifest rspec
            #if not slice:     
            #    rspec_node['boot_state'] = node['boot_state']
            rspec_node['exclusive'] = 'true'
            # site location
            longitude = self.driver.testbedInfo['longitude']
            latitude = self.driver.testbedInfo['latitude']  
            if longitude and latitude:  
                location = Location({'longitude': longitude, 'latitude': latitude, 'country': 'unknown'})
                rspec_node['location'] = location
            # 3D position
            position_3d = Position3D({'x': node['position']['X'], 'y': node['position']['Y'], 'z': node['position']['Z']})
            #position_3d = Position3D({'x': 1, 'y': 2, 'z': 3})
            rspec_node['position_3d'] = position_3d 
            # Granularity
            granularity = Granularity({'grain': grain})
            rspec_node['granularity'] = granularity

            # HardwareType
            rspec_node['hardware_type'] = node['node_type']
            #rspec_node['hardware_type'] = "orbit"
            
            #slivers
            if node['node_id'] in slivers:
                # add sliver info
                sliver = slivers[node['node_id']]
                rspec_node['sliver_id'] = sliver['node_id']
                rspec_node['client_id'] = node['hostname']
                rspec_node['slivers'] = [sliver]

                
            rspec_nodes.append(rspec_node)
        return rspec_nodes 
开发者ID:kongseokhwan,项目名称:sfa,代码行数:59,代码来源:nitosaggregate.py


示例18: create

    def create(self, opts, args):
        server = self.get_server_from_opts(opts)
        server_version = self.get_cached_server_version(server)
        slice_hrn = args[0]
        slice_urn = hrn_to_urn(slice_hrn, 'slice') 
        user_cred = self.get_user_cred()
        slice_cred = self.get_slice_cred(slice_hrn).save_to_string(save_parents=True)
        # delegate the cred to the callers root authority
        delegated_cred = self.delegate_cred(slice_cred, get_authority(self.authority)+'.slicemanager')
        #delegated_cred = self.delegate_cred(slice_cred, get_authority(slice_hrn))
        #creds.append(delegated_cred)
        rspec_file = self.get_rspec_file(args[1])
        rspec = open(rspec_file).read()

        # need to pass along user keys to the aggregate.  
        # users = [
        #  { urn: urn:publicid:IDN+emulab.net+user+alice
        #    keys: [<ssh key A>, <ssh key B>] 
        #  }]
        users = []
        slice_records = self.registry.Resolve(slice_urn, [user_cred.save_to_string(save_parents=True)])
        if slice_records and 'researcher' in slice_records[0] and slice_records[0]['researcher']!=[]:
            slice_record = slice_records[0]
            user_hrns = slice_record['researcher']
            user_urns = [hrn_to_urn(hrn, 'user') for hrn in user_hrns]
            user_records = self.registry.Resolve(user_urns, [user_cred.save_to_string(save_parents=True)])
            
            if 'sfa' not in server_version:
                users = pg_users_arg(user_records)
                rspec = RSpec(rspec)
                rspec.filter({'component_manager_id': server_version['urn']})
                rspec = RSpecConverter.to_pg_rspec(rspec.toxml(), content_type='request')
                creds = [slice_cred]
            else:
                users = sfa_users_arg(user_records, slice_record)
                creds = [slice_cred, delegated_cred]
        call_args = [slice_urn, creds, rspec, users]
        if self.server_supports_call_id_arg(server):
            call_args.append(unique_call_id())
           
        result = server.CreateSliver(*call_args)
        if opts.file is None:
            print result
        else:
            save_rspec_to_file (result, opts.file)
        return result
开发者ID:planetlab,项目名称:sfa,代码行数:46,代码来源:sfi.py


示例19: _get_resources_urn

    def _get_resources_urn(self, resources_hrn):
        """
        Builds list of resources' urn based on hrn.
        """
        resources_urn = list()

        for resource in resources_hrn:
            resources_urn.append(hrn_to_urn(resource, 'node'))
            
        return resources_urn
开发者ID:phiros,项目名称:nepi,代码行数:10,代码来源:sfaapi.py


示例20: shutdown

 def shutdown(self, opts, args):
     slice_hrn = args[0]
     slice_urn = hrn_to_urn(slice_hrn, 'slice') 
     slice_cred = self.get_slice_cred(slice_hrn).save_to_string(save_parents=True)
     creds = [slice_cred]
     if opts.delegate:
         delegated_cred = self.delegate_cred(slice_cred, get_authority(self.authority))
         creds.append(delegated_cred)
     server = self.get_server_from_opts(opts)
     return server.Shutdown(slice_urn, creds)         
开发者ID:planetlab,项目名称:sfa,代码行数:10,代码来源:sfi.py



注:本文中的sfa.util.xrn.hrn_to_urn函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python xrn.urn_to_hrn函数代码示例发布时间:2022-05-27
下一篇:
Python xrn.get_authority函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap