当前位置: 首页>>代码示例>>Python>>正文


Python xrn.hrn_to_urn函数代码示例

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


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


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