예제 #1
0
    def node_to_rspec_node(self, node, sites, interfaces, node_tags, pl_initscripts=None, grain=None, options=None):
        if pl_initscripts is None: pl_initscripts=[]
        if options is None: options={}
        rspec_node = NodeElement()
        # xxx how to retrieve site['login_base']
        site=sites[node['site_id']]
        rspec_node['component_id'] = hostname_to_urn(self.driver.hrn, site['login_base'], 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(PlXrn.site_hrn(self.driver.hrn, site['login_base']), 'authority+sa')
        # do not include boot state (<available> element) in the manifest rspec
        rspec_node['boot_state'] = node['boot_state']
        if node['boot_state'] == 'boot': 
            rspec_node['available'] = 'true'
        else:
            rspec_node['available'] = 'false'

        #distinguish between Shared and Reservable nodes
        if node['node_type'] == 'reservable':
            rspec_node['exclusive'] = 'true'
        else:
            rspec_node['exclusive'] = 'false'

        rspec_node['hardware_types'] = [HardwareType({'name': 'plab-pc'}),
                                        HardwareType({'name': 'pc'})]
        # only doing this because protogeni rspec needs
        # to advertise available initscripts
        rspec_node['pl_initscripts'] = pl_initscripts.values()
        # 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
        # Granularity
        granularity = Granularity({'grain': grain})
        rspec_node['granularity'] = granularity
        rspec_node['interfaces'] = []
        if_count=0
        for if_id in node['interface_ids']:
            interface = Interface(interfaces[if_id])
            interface['ipv4'] = interface['ip']
            interface['component_id'] = PlXrn(auth=self.driver.hrn,
                                              interface='node%s:eth%s' % (node['node_id'], if_count)).get_urn()
            # interfaces in the manifest need a client id
            if slice:
                interface['client_id'] = "%s:%s" % (node['node_id'], if_id)
            rspec_node['interfaces'].append(interface)
            if_count+=1
        tags = [PLTag(node_tags[tag_id]) for tag_id in node['node_tag_ids'] if tag_id in node_tags]
        rspec_node['tags'] = tags
        return rspec_node
예제 #2
0
파일: plaggregate.py 프로젝트: tubav/sfa
    def get_leases(self, slice_xrn=None, slice=None, options={}):
        
        if slice_xrn and not slice:
            return []

        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['lease_id'] = lease['lease_id']
            rspec_lease['component_id'] = hostname_to_urn(self.driver.hrn, site['login_base'], lease['hostname'])
            if slice_xrn:
                slice_urn = slice_xrn
                slice_hrn = urn_to_hrn(slice_urn)
            else:
                slice_hrn = slicename_to_hrn(self.driver.hrn, lease['name'])
                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
예제 #3
0
    def node_to_rspec_node(self,
                           node,
                           sites,
                           interfaces,
                           node_tags,
                           pl_initscripts=[],
                           grain=None,
                           options={}):
        rspec_node = NodeElement()
        # xxx how to retrieve site['login_base']
        site = sites[node['site_id']]
        rspec_node['component_id'] = hostname_to_urn(self.driver.hrn,
                                                     site['login_base'],
                                                     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(
            PlXrn.site_hrn(self.driver.hrn, site['login_base']),
            'authority+sa')
        # do not include boot state (<available> element) in the manifest rspec
        rspec_node['boot_state'] = node['boot_state']
        if node['boot_state'] == 'boot':
            rspec_node['available'] = 'true'
        else:
            rspec_node['available'] = 'false'

        #distinguish between Shared and Reservable nodes
        if node['node_type'] == 'reservable':
            rspec_node['exclusive'] = 'true'
        else:
            rspec_node['exclusive'] = 'false'

        rspec_node['hardware_types'] = [
            HardwareType({'name': 'plab-pc'}),
            HardwareType({'name': 'pc'})
        ]
        # only doing this because protogeni rspec needs
        # to advertise available initscripts
        rspec_node['pl_initscripts'] = pl_initscripts.values()
        # 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
        # Granularity
        granularity = Granularity({'grain': grain})
        rspec_node['granularity'] = granularity
        rspec_node['interfaces'] = []
        if_count = 0
        for if_id in node['interface_ids']:
            interface = Interface(interfaces[if_id])
            interface['ipv4'] = interface['ip']
            interface['component_id'] = PlXrn(
                auth=self.driver.hrn,
                interface='node%s:eth%s' %
                (node['node_id'], if_count)).get_urn()
            # interfaces in the manifest need a client id
            if slice:
                interface['client_id'] = "%s:%s" % (node['node_id'], if_id)
            rspec_node['interfaces'].append(interface)
            if_count += 1
        tags = [
            PLTag(node_tags[tag_id]) for tag_id in node['node_tag_ids']
            if tag_id in node_tags
        ]
        rspec_node['tags'] = tags
        return rspec_node
예제 #4
0
파일: plaggregate.py 프로젝트: tubav/sfa
    def get_nodes_and_links(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 not slice['node_ids']:
                return ([],[])

        filter = {}
        tags_filter = {}
        if slice and 'node_ids' in slice and slice['node_ids']:
            filter['node_id'] = slice['node_ids']
            tags_filter=filter.copy()

        geni_available = options.get('geni_available')    
        if geni_available == True:
            filter['boot_state'] = 'boot'     
        
        filter.update({'peer_id': None})
        nodes = self.driver.shell.GetNodes(filter)
        
        # get the granularity in second for the reservation system
        grain = self.driver.shell.GetLeaseGranularity()
       
        site_ids = []
        interface_ids = []
        tag_ids = []
        nodes_dict = {}
        for node in nodes:
            site_ids.append(node['site_id'])
            interface_ids.extend(node['interface_ids'])
            tag_ids.extend(node['node_tag_ids'])
            nodes_dict[node['node_id']] = node
 
        # get sites
        sites_dict  = self.get_sites({'site_id': site_ids}) 
        # get interfaces
        interfaces = self.get_interfaces({'interface_id':interface_ids}) 
        # get tags
        node_tags = self.get_node_tags(tags_filter)
        # get initscripts
        pl_initscripts = self.get_pl_initscripts()
        
        links = self.get_links(sites_dict, nodes_dict, interfaces)

        rspec_nodes = []
        for node in nodes:
            # skip whitelisted nodes
            if node['slice_ids_whitelist']:
                if not slice or slice['slice_id'] not in node['slice_ids_whitelist']:
                    continue
            rspec_node = Node()
            # xxx how to retrieve site['login_base']
            site_id=node['site_id']
            site=sites_dict[site_id]
            rspec_node['component_id'] = hostname_to_urn(self.driver.hrn, site['login_base'], 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(PlXrn.site_hrn(self.driver.hrn, site['login_base']), 'authority+sa')
            # do not include boot state (<available> element) in the manifest rspec
            if not slice:     
                rspec_node['boot_state'] = node['boot_state']

            #add the exclusive tag to distinguish between Shared and Reservable nodes
            if node['node_type'] == 'reservable':
                rspec_node['exclusive'] = 'true'
            else:
                rspec_node['exclusive'] = 'false'

            rspec_node['hardware_types'] = [HardwareType({'name': 'plab-pc'}),
                                            HardwareType({'name': 'pc'})]
            # only doing this because protogeni rspec needs
            # to advertise available initscripts 
            rspec_node['pl_initscripts'] = pl_initscripts.values()
             # add site/interface info to nodes.
            # assumes that sites, interfaces and tags have already been prepared.
            site = sites_dict[node['site_id']]
            if site['longitude'] and site['latitude']:  
                location = Location({'longitude': site['longitude'], 'latitude': site['latitude'], 'country': 'unknown'})
                rspec_node['location'] = location
            # Granularity
            granularity = Granularity({'grain': grain})
            rspec_node['granularity'] = granularity

            rspec_node['interfaces'] = []
            if_count=0
            for if_id in node['interface_ids']:
                interface = Interface(interfaces[if_id]) 
                interface['ipv4'] = interface['ip']
                interface['component_id'] = PlXrn(auth=self.driver.hrn, 
                                                  interface='node%s:eth%s' % (node['node_id'], if_count)).get_urn()
                # interfaces in the manifest need a client id
                if slice:
                    interface['client_id'] = "%s:%s" % (node['node_id'], if_id)            
                rspec_node['interfaces'].append(interface)
                if_count+=1

            tags = [PLTag(node_tags[tag_id]) for tag_id in node['node_tag_ids']\
                    if tag_id in node_tags]
            rspec_node['tags'] = tags
            if node['node_id'] in slivers:
                # add sliver info
                sliver = slivers[node['node_id']]
                rspec_node['sliver_id'] = sliver['sliver_id']
                rspec_node['slivers'] = [sliver]
                for tag in sliver['tags']:
                    if tag['tagname'] == 'client_id':
                         rspec_node['client_id'] = tag['value']
                
                # slivers always provide the ssh service
                login = Login({'authentication': 'ssh-keys', 'hostname': node['hostname'], 'port':'22', 'username': sliver['name']})
                service = Services({'login': login})
                rspec_node['services'] = [service]
            rspec_nodes.append(rspec_node)
        return (rspec_nodes, links)