Exemplo n.º 1
0
def GetVersion(api):
    # peers explicitly in aggregates.xml
    peers =dict ([ (peername,get_serverproxy_url(v)) for (peername,v) in api.aggregates.iteritems()
                   if peername != api.hrn])
    version_manager = VersionManager()
    ad_rspec_versions = []
    request_rspec_versions = []
    for rspec_version in version_manager.versions:
        if rspec_version.content_type in ['*', 'ad']:
            ad_rspec_versions.append(rspec_version.to_dict())
        if rspec_version.content_type in ['*', 'request']:
            request_rspec_versions.append(rspec_version.to_dict())
    default_rspec_version = version_manager.get_version("sfa 1").to_dict()
    xrn=Xrn(api.hrn, 'authority+sa')
    version_more = {'interface':'slicemgr',
                    'hrn' : xrn.get_hrn(),
                    'urn' : xrn.get_urn(),
                    'peers': peers,
                    'request_rspec_versions': request_rspec_versions,
                    'ad_rspec_versions': ad_rspec_versions,
                    'default_ad_rspec': default_rspec_version
                    }
    sm_version=version_core(version_more)
    # local aggregate if present needs to have localhost resolved
    if api.hrn in api.aggregates:
        local_am_url=get_serverproxy_url(api.aggregates[api.hrn])
        sm_version['peers'][api.hrn]=local_am_url.replace('localhost',sm_version['hostname'])
    return sm_version
Exemplo n.º 2
0
    def get_rspec(self, slice_xrn=None, version = None, options={}):

        version_manager = VersionManager()
        version = version_manager.get_version(version)
        if not slice_xrn:
            rspec_version = version_manager._get_version(version.type, version.version, 'ad')
        else:
            rspec_version = version_manager._get_version(version.type, version.version, 'manifest')

        slice, slivers = self.get_slice_and_slivers(slice_xrn)
        rspec = RSpec(version=rspec_version, user_options=options)
        if slice and 'expires' in slice:
            rspec.xml.set('expires',  datetime_to_string(utcparse(slice['expires'])))

        nodes = self.get_nodes(slice_xrn, slice, slivers, options)
        rspec.version.add_nodes(nodes)
        # add sliver defaults
        default_sliver = slivers.get(None, [])
        if default_sliver:
            default_sliver_attribs = default_sliver.get('tags', [])
            for attrib in default_sliver_attribs:
                 logger.info(attrib)
                 rspec.version.add_default_sliver_attribute(attrib['tagname'], attrib['value'])
        
        return rspec.toxml()
Exemplo n.º 3
0
    def describe(self, urns, version=None, options=None):
        if options is None: options={}
        version_manager = VersionManager()
        version = version_manager.get_version(version)
        rspec_version = version_manager._get_version(version.type, version.version, 'manifest')
        rspec = RSpec(version=rspec_version, user_options=options)

        # Update connection for the current user
        xrn = Xrn(urns[0], type='slice')
        user_name = xrn.get_authority_hrn() + '.' + xrn.leaf.split('-')[0]
        tenant_name = OSXrn(xrn=urns[0], type='slice').get_hrn()
        self.driver.shell.compute_manager.connect(username=user_name, tenant=tenant_name, password=user_name)

        # For delay to collect instance info 
        time.sleep(3)
        # Get instances from the Openstack
        instances = self.get_instances(xrn)

        # Add sliver(s) from instance(s)
        geni_slivers = []
        rspec.xml.set( 'expires',  datetime_to_string(utcparse(time.time())) )
        rspec_nodes = []
        for instance in instances:
            rspec_nodes.append(self.instance_to_rspec_node(instance))
            geni_sliver = self.instance_to_geni_sliver(instance)
            geni_slivers.append(geni_sliver)
        rspec.version.add_nodes(rspec_nodes)

        result = { 'geni_urn': xrn.get_urn(),
                   'geni_rspec': rspec.toxml(), 
                   'geni_slivers': geni_slivers }
        return result
Exemplo n.º 4
0
    def create_sliver (self, slice_urn, slice_hrn, creds, rspec_string, users, options):
   
        aggregate = OSAggregate(self)

        # assume first user is the caller and use their context
        # for the ec2/euca api connection. Also, use the first users
        # key as the project key.
        key_name = None
        if len(users) > 1:
            key_name = aggregate.create_instance_key(slice_hrn, users[0])

        # collect public keys
        pubkeys = []
        for user in users:
            pubkeys.extend(user['keys'])
           
        rspec = RSpec(rspec_string)
        instance_name = hrn_to_os_slicename(slice_hrn)
        tenant_name = OSXrn(xrn=slice_hrn, type='slice').get_tenant_name()
        instances = aggregate.run_instances(instance_name, tenant_name, rspec_string, key_name, pubkeys)
        rspec_nodes = []
        for instance in instances:
            rspec_nodes.append(aggregate.instance_to_rspec_node(slice_urn, instance))    
        version_manager = VersionManager()
        manifest_version = version_manager._get_version(rspec.version.type, rspec.version.version, 'manifest')
        manifest_rspec = RSpec(version=manifest_version, user_options=options)
        manifest_rspec.version.add_nodes(rspec_nodes) 
         
        return manifest_rspec.toxml()
Exemplo n.º 5
0
 def list_resources (self, slice_urn, slice_hrn, creds, options):
     cached_requested = options.get('cached', True) 
 
     version_manager = VersionManager()
     # get the rspec's return format from options
     rspec_version = version_manager.get_version(options.get('geni_rspec_version'))
     version_string = "rspec_%s" % (rspec_version)
 
     #panos adding the info option to the caching key (can be improved)
     if options.get('info'):
         version_string = version_string + "_"+options.get('info', 'default')
 
     # look in cache first
     if cached_requested and self.cache and not slice_hrn:
         rspec = self.cache.get(version_string)
         if rspec:
             logger.debug("OpenStackDriver.ListResources: returning cached advertisement")
             return rspec 
 
     #panos: passing user-defined options
     #print "manager options = ",options
     aggregate = OSAggregate(self)
     rspec =  aggregate.get_rspec(slice_xrn=slice_urn, version=rspec_version, 
                                  options=options)
 
     # cache the result
     if self.cache and not slice_hrn:
         logger.debug("OpenStackDriver.ListResources: stores advertisement in cache")
         self.cache.add(version_string, rspec)
 
     return rspec
Exemplo n.º 6
0
    def provision(self, urns, options=None):
        if options is None: options={}
        # update sliver allocation states and set them to geni_provisioned
        aggregate = OSAggregate(self)

        # Update connection for the current client
        xrn = Xrn(urns[0], type='slice')
        user_name = xrn.get_authority_hrn() + '.' + xrn.leaf.split('-')[0]
        tenant_name = OSXrn(xrn=urns[0], type='slice').get_hrn() 
        self.shell.compute_manager.connect(username=user_name, tenant=tenant_name, password=user_name)
        
        instances = aggregate.get_instances(xrn)
        # Allocate new floating IP per the instance
        servers = aggregate.check_floatingip(instances, True)
        aggregate.create_floatingip(tenant_name, servers)

        sliver_ids=[]
        for instance in instances:
            sliver_id = OSXrn(name=('koren'+'.'+ instance.name), id=instance.id, type='node+openstack').get_urn()
            sliver_ids.append(sliver_id)
        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)
Exemplo n.º 7
0
def ListResources(api, creds, options, call_id):
    if Callids().already_handled(call_id): return ""
    # get slice's hrn from options
    xrn = options.get('geni_slice_urn', None)
    (hrn, type) = urn_to_hrn(xrn)

    version_manager = VersionManager()
    # get the rspec's return format from options
    rspec_version = version_manager.get_version(options.get('rspec_version'))
    version_string = "rspec_%s" % (rspec_version.to_string())

    #panos adding the info option to the caching key (can be improved)
    if options.get('info'):
        version_string = version_string + "_"+options.get('info', 'default')

    # look in cache first
    if caching and api.cache and not xrn:
        rspec = api.cache.get(version_string)
        if rspec:
            api.logger.info("aggregate.ListResources: returning cached value for hrn %s"%hrn)
            return rspec 

    #panos: passing user-defined options
    #print "manager options = ",options
    aggregate = Aggregate(api, options)
    rspec =  aggregate.get_rspec(slice_xrn=xrn, version=rspec_version)

    # cache the result
    if caching and api.cache and not xrn:
        api.cache.add(version_string, rspec)

    return rspec
Exemplo n.º 8
0
    def describe(self, urns, version=None, options={}):
        # update nova connection
        tenant_name = OSXrn(xrn=urns[0], type='slice').get_tenant_name()
        self.driver.shell.nova_manager.connect(tenant=tenant_name)
        instances = self.get_instances(urns)
        # lookup the sliver allocations
        sliver_ids = [sliver['sliver_id'] for sliver in slivers]
        constraint = SliverAllocation.sliver_id.in_(sliver_ids)
        sliver_allocations = self.driver.api.dbsession().query(SliverAllocation).filter(constraint)
        sliver_allocation_dict = {}
        for sliver_allocation in sliver_allocations:
            sliver_allocation_dict[sliver_allocation.sliver_id] = sliver_allocation

        geni_slivers = []
        rspec_nodes = []
        for instance in instances:
            rspec_nodes.append(self.instance_to_rspec_node(instance))
            geni_sliver = self.instance_to_geni_sliver(instance, sliver_sllocation_dict)
            geni_slivers.append(geni_sliver)
        version_manager = VersionManager()
        version = version_manager.get_version(version)
        rspec_version = version_manager._get_version(version.type, version.version, 'manifest')
        rspec = RSpec(version=rspec_version, user_options=options)
        rspec.xml.set('expires',  datetime_to_string(utcparse(time.time())))
        rspec.version.add_nodes(rspec_nodes)
        result = {'geni_urn': Xrn(urns[0]).get_urn(),
                  'geni_rspec': rspec.toxml(), 
                  'geni_slivers': geni_slivers}
        
        return result
Exemplo n.º 9
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)
Exemplo n.º 10
0
def ListResources(api, creds, options,call_id):
    if Callids().already_handled(call_id): return ""
    # get slice's hrn from options
    xrn = options.get('geni_slice_urn', '')
    hrn, type = urn_to_hrn(xrn)

    version_manager = VersionManager()
    # get the rspec's return format from options
    rspec_version = version_manager.get_version(options.get('rspec_version'))
    version_string = "rspec_%s" % (rspec_version.to_string())
    
    # look in cache first
    if api.cache and not xrn:
        rspec = api.cache.get(version_string)
        if rspec:
            api.logger.info("aggregate.ListResources: returning cached value for hrn %s"%hrn)
            return rspec

    aggregate = ViniAggregate(api, options) 
    rspec =  aggregate.get_rspec(slice_xrn=xrn, version=rspec_version)
           
    # cache the result
    if api.cache and not xrn:
        api.cache.add('nodes', rspec)

    return rspec
Exemplo n.º 11
0
    def Describe(self, api, creds, urns, options):
        call_id = options.get('call_id')
        if Callids().already_handled(call_id): return ""

        version_manager = VersionManager()
        rspec_version = version_manager.get_version(options.get('geni_rspec_version'))
        return api.driver.describe(urns, rspec_version, options)
Exemplo n.º 12
0
    def Provision(self, api, xrn, creds, options):
        call_id = options.get('call_id')
        if Callids().already_handled(call_id): return ""

        version_manager = VersionManager()
        def _Provision(aggregate, server, xrn, credential, options):
            tStart = time.time()
            try:
                # Need to call GetVersion at an aggregate to determine the supported
                # rspec type/format beofre calling CreateSliver at an Aggregate.
                server_version = api.get_cached_server_version(server)
                result = server.Provision(xrn, credential, options)
                return {"aggregate": aggregate, "result": result, "elapsed": time.time()-tStart, "status": "success"}
            except:
                logger.log_exc('Something wrong in _Allocate with URL %s'%server.url)
                return {"aggregate": aggregate, "elapsed": time.time()-tStart, "status": "exception", "exc_info": sys.exc_info()}

        # attempt to use delegated credential first
        cred = api.getDelegatedCredential(creds)
        if not cred:
            cred = api.getCredential()

        # get the callers hrn
        valid_cred = api.auth.checkCredentials(creds, 'createsliver', xrn)[0]
        caller_hrn = Credential(cred=valid_cred).get_gid_caller().get_hrn()
        multiclient = MultiClient()
        for aggregate in api.aggregates:
            # prevent infinite loop. Dont send request back to caller
            # unless the caller is the aggregate's SM
            if caller_hrn == aggregate and aggregate != api.hrn:
                continue
            interface = api.aggregates[aggregate]
            server = api.server_proxy(interface, cred)
            # Just send entire RSpec to each aggregate
            multiclient.run(_Provision, aggregate, server, xrn, [cred], options)

        results = multiclient.get_results()
        # Set the manifest of KOREN
        manifest_version = version_manager._get_version('KOREN', '1', 'manifest')
#        manifest_version = version_manager._get_version('GENI', '3', 'manifest')
        result_rspec = RSpec(version=manifest_version)
        geni_slivers = []
        geni_urn  = None  
        for result in results:
            self.add_slicemgr_stat(result_rspec, "Provision", result["aggregate"], result["elapsed"],
                                   result["status"], result.get("exc_info",None))
            if result["status"]=="success":
                try:
                    res = result['result']['value']
                    geni_urn = res['geni_urn']
                    result_rspec.version.merge(ReturnValue.get_value(res['geni_rspec']))
                    geni_slivers.extend(res['geni_slivers'])
                except:
                    api.logger.log_exc("SM.Provision: Failed to merge aggregate rspec")
        return {
            'geni_urn': geni_urn,
            'geni_rspec': result_rspec.toxml(),
            'geni_slivers': geni_slivers
        }            
Exemplo n.º 13
0
 def list_resources(self, version=None, options={}):
     version_manager = VersionManager()
     version = version_manager.get_version(version)
     rspec_version = version_manager._get_version(version.type, version.version, 'ad')
     rspec = RSpec(version=version, user_options=options)
     nodes = self.get_aggregate_nodes()
     rspec.version.add_nodes(nodes)
     return rspec.toxml()
Exemplo n.º 14
0
    def Describe(self, api, creds, urns, options):
        call_id = options.get('call_id')
        if Callids().already_handled(call_id): return ""

        version_manager = VersionManager()
        rspec_version = version_manager.get_version(options.get('geni_rspec_version'))
        options['creds']=creds
        return api.driver.describe(urns, rspec_version, options)
Exemplo n.º 15
0
    def Provision(self, api, xrn, creds, options):
        call_id = options.get('call_id')
        if Callids().already_handled(call_id): return ""

        version_manager = VersionManager()
        def _Provision(aggregate, server, xrn, credential, options):
            tStart = time.time()
            try:
                # Need to call GetVersion at an aggregate to determine the supported
                # rspec type/format beofre calling CreateSliver at an Aggregate.
                server_version = api.get_cached_server_version(server)
                result = server.Provision(xrn, credential, options)
                return {"aggregate": aggregate, "result": result, "elapsed": time.time()-tStart, "status": "success"}
            except:
                logger.log_exc('Something wrong in _Allocate with URL %s'%server.url)
                return {"aggregate": aggregate, "elapsed": time.time()-tStart, "status": "exception", "exc_info": sys.exc_info()}

        # attempt to use delegated credential first
        cred = api.getDelegatedCredential(creds)
        if not cred:
            cred = api.getCredential()

        # get the callers hrn
        valid_cred = api.auth.checkCredentials(creds, 'createsliver', xrn)[0]
        caller_hrn = Credential(cred=valid_cred).get_gid_caller().get_hrn()
        multiclient = MultiClient()
        for aggregate in api.aggregates:
            # prevent infinite loop. Dont send request back to caller
            # unless the caller is the aggregate's SM
            if caller_hrn == aggregate and aggregate != api.hrn:
                continue
            interface = api.aggregates[aggregate]
            server = api.server_proxy(interface, cred)
            # Just send entire RSpec to each aggregate
            multiclient.run(_Provision, aggregate, server, xrn, [cred], options)

        results = multiclient.get_results()
        manifest_version = version_manager._get_version('GENI', '3', 'manifest')
        result_rspec = RSpec(version=manifest_version)
        geni_slivers = []
        geni_urn  = None  
        for result in results:
            self.add_slicemgr_stat(result_rspec, "Provision", result["aggregate"], result["elapsed"],
                                   result["status"], result.get("exc_info",None))
            if result["status"]=="success":
                try:
                    res = result['result']['value']
                    geni_urn = res['geni_urn']
                    result_rspec.version.merge(ReturnValue.get_value(res['geni_rspec']))
                    geni_slivers.extend(res['geni_slivers'])
                except:
                    api.logger.log_exc("SM.Provision: Failed to merge aggregate rspec")
        return {
            'geni_urn': geni_urn,
            'geni_rspec': result_rspec.toxml(),
            'geni_slivers': geni_slivers
        }            
Exemplo n.º 16
0
    def to_sfa_rspec(rspec, content_type=None):
        if not isinstance(rspec, RSpec):
            pg_rspec = RSpec(rspec)
        else:
            pg_rspec = rspec

        version_manager = VersionManager()
        sfa_version = version_manager._get_version('sfa', '1')
        sfa_rspec = RSpec(version=sfa_version)

        #nodes = pg_rspec.version.get_nodes()
        #sfa_rspec.version.add_nodes(nodes())
        #sfa_rspec.version.add_links(pg_rspec.version.get_links())
        #return sfa_rspec.toxml()

        # get network
        networks = pg_rspec.version.get_networks()
        network_hrn = networks[0]["name"]
        network_element = sfa_rspec.xml.add_element('network',
                                                    name=network_hrn,
                                                    id=network_hrn)

        # get nodes
        pg_nodes_elements = pg_rspec.version.get_nodes()
        nodes_with_slivers = pg_rspec.version.get_nodes_with_slivers()
        i = 1
        for pg_node in pg_nodes_elements:
            attribs = dict(pg_node.items())
            attribs['id'] = 'n' + str(i)

            node_element = network_element.add_element('node')
            for attrib in attribs:
                if type(attribs[attrib]) == str:
                    node_element.set(attrib, attribs[attrib])
            urn = pg_node["component_id"]
            if urn:
                if type(urn) == list:
                    # legacy code, not sure if urn is ever a list...
                    urn = urn[0]
                hostname = Xrn.urn_split(urn)[-1]
                hostname_element = node_element.add_element('hostname')
                hostname_element.set_text(hostname)
                if hostname in nodes_with_slivers:
                    node_element.add_element('sliver')

            for hardware_type in pg_node["hardware_types"]:
                if "name" in hardware_type:
                    node_element.add_element("hardware_type",
                                             name=hardware_type["name"])

            # just copy over remaining child elements
            #for child in pg_node_element.getchildren():
            #    node_element.append(transform(child).getroot())
            i = i + 1

        return sfa_rspec.toxml()
Exemplo n.º 17
0
 def to_sfa_rspec(in_rspec, content_type=None):
     rspec = RSpec(in_rspec)
     version_manager = VersionManager()
     sfa_version = version_manager._get_version("sfa", "1")
     pg_version = version_manager._get_version("protogeni", "2")
     if rspec.version.type.lower() == sfa_version.type.lower():
         return in_rspec
     elif rspec.version.type.lower() == pg_version.type.lower():
         return PGRSpecConverter.to_sfa_rspec(in_rspec, content_type)
     else:
         return in_rspec
Exemplo n.º 18
0
    def list_resources(self, slice_urn, slice_hrn, creds, options):

        version_manager = VersionManager()
        # get the rspec's return format from options
        rspec_version = version_manager.get_version(options.get("geni_rspec_version"))
        version_string = "rspec_%s" % (rspec_version)

        aggregate = DummyAggregate(self)
        rspec = aggregate.get_rspec(slice_xrn=slice_urn, version=rspec_version, options=options)

        return rspec
Exemplo n.º 19
0
    def list_resources(self, version = None, options=None):
        """
        Returns an advertisement Rspec of available resources at this
        aggregate. This Rspec contains a resource listing along with their
        description, providing sufficient information for clients to be able to
        select among available resources.

        :param options: various options. The valid options are: {boolean
            geni_compressed <optional>; struct geni_rspec_version { string type;
            #case insensitive , string version; # case insensitive}} . The only
            mandatory options if options is specified is geni_rspec_version.
        :type options: dictionary

        :returns: On success, the value field of the return struct will contain
            a geni.rspec advertisment RSpec
        :rtype: Rspec advertisement in xml.

        .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3/CommonConcepts#RSpecdatatype
        .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3#ListResources
        """

        if options is None: options={}
        version_manager = VersionManager()
        version = version_manager.get_version(version)
        rspec_version = version_manager._get_version(version.type,
                                                    version.version, 'ad')
        rspec = RSpec(version=rspec_version, user_options=options)
        # variable ldap_username to be compliant with  get_all_leases
        # prototype. Now unused in geni-v3 since we are getting all the leases
        # here
        ldap_username = None
        if not options.get('list_leases') or options['list_leases'] != 'leases':
            # get nodes
            nodes_dict  = self.get_nodes(options)

            # no interfaces on iotlab nodes
            # convert nodes to rspec nodes
            rspec_nodes = []
            for node_id in nodes_dict:
                node = nodes_dict[node_id]
                rspec_node = self.node_to_rspec_node(node)
                rspec_nodes.append(rspec_node)
            rspec.version.add_nodes(rspec_nodes)

            # add links
            # links = self.get_links(sites, nodes_dict, interfaces)
            # rspec.version.add_links(links)

        if not options.get('list_leases') or options.get('list_leases') \
            and options['list_leases'] != 'resources':
            leases = self.get_all_leases(ldap_username)
            rspec.version.add_leases(leases)

        return rspec.toxml()
Exemplo n.º 20
0
    def list_resources(self, version=None, options={}):
        """
        Returns an advertisement Rspec of available resources at this
        aggregate. This Rspec contains a resource listing along with their
        description, providing sufficient information for clients to be able to
        select among available resources.

        :param options: various options. The valid options are: {boolean
            geni_compressed <optional>; struct geni_rspec_version { string type;
            #case insensitive , string version; # case insensitive}} . The only
            mandatory options if options is specified is geni_rspec_version.
        :type options: dictionary

        :returns: On success, the value field of the return struct will contain
            a geni.rspec advertisment RSpec
        :rtype: Rspec advertisement in xml.

        .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3/CommonConcepts#RSpecdatatype
        .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3#ListResources
        """

        version_manager = VersionManager()
        version = version_manager.get_version(version)
        rspec_version = version_manager._get_version(version.type,
                                                     version.version, 'ad')
        rspec = RSpec(version=rspec_version, user_options=options)
        # variable ldap_username to be compliant with  get_all_leases
        # prototype. Now unused in geni-v3 since we are getting all the leases
        # here
        ldap_username = None
        if not options.get(
                'list_leases') or options['list_leases'] != 'leases':
            # get nodes
            nodes_dict = self.get_nodes(options)

            # no interfaces on iotlab nodes
            # convert nodes to rspec nodes
            rspec_nodes = []
            for node_id in nodes_dict:
                node = nodes_dict[node_id]
                rspec_node = self.node_to_rspec_node(node)
                rspec_nodes.append(rspec_node)
            rspec.version.add_nodes(rspec_nodes)

            # add links
            # links = self.get_links(sites, nodes_dict, interfaces)
            # rspec.version.add_links(links)

        if not options.get('list_leases') or options.get('list_leases') \
            and options['list_leases'] != 'resources':
            leases = self.get_all_leases(ldap_username)
            rspec.version.add_leases(leases)

        return rspec.toxml()
Exemplo n.º 21
0
 def to_sfa_rspec(in_rspec, content_type=None):
     rspec = RSpec(in_rspec)
     version_manager = VersionManager()
     sfa_version = version_manager._get_version('sfa', '1')
     pg_version = version_manager._get_version('protogeni', '2')
     if rspec.version.type.lower() == sfa_version.type.lower():
         return in_rspec
     elif rspec.version.type.lower() == pg_version.type.lower():
         return PGRSpecConverter.to_sfa_rspec(in_rspec, content_type)
     else:
         return in_rspec
Exemplo n.º 22
0
 def get_rspec(self, slice_xrn=None, version=None, options={}):
     version_manager = VersionManager()
     version = version_manager.get_version(version)
     if not slice_xrn:
         rspec_version = version_manager._get_version(version.type, version.version, 'ad')
         nodes = self.get_aggregate_nodes()
     else:
         rspec_version = version_manager._get_version(version.type, version.version, 'manifest')
         nodes = self.get_slice_nodes(slice_xrn)
     rspec = RSpec(version=rspec_version, user_options=options)
     rspec.version.add_nodes(nodes)
     return rspec.toxml()
Exemplo n.º 23
0
    def to_sfa_rspec(rspec, content_type = None):
        if not isinstance(rspec, RSpec):
            pg_rspec = RSpec(rspec)
        else:
            pg_rspec = rspec
        
        version_manager = VersionManager()
        sfa_version = version_manager._get_version('sfa', '1')    
        sfa_rspec = RSpec(version=sfa_version)

        #nodes = pg_rspec.version.get_nodes()
        #sfa_rspec.version.add_nodes(nodes())
        #sfa_rspec.version.add_links(pg_rspec.version.get_links())
        #return sfa_rspec.toxml() 

        # get network
        networks = pg_rspec.version.get_networks()
        network_hrn = networks[0]["name"]
        network_element = sfa_rspec.xml.add_element('network', name=network_hrn, id=network_hrn)
        
        # get nodes
        pg_nodes_elements = pg_rspec.version.get_nodes()
        nodes_with_slivers = pg_rspec.version.get_nodes_with_slivers()
        i = 1
        for pg_node in pg_nodes_elements:
            attribs = dict(pg_node.items())
            attribs['id'] = 'n'+str(i)
            
            node_element = network_element.add_element('node')
            for attrib in attribs:
                if type(attribs[attrib]) == str:
                    node_element.set(attrib, attribs[attrib])
            urn = pg_node["component_id"]
            if urn:
                if type(urn)==list:
                    # legacy code, not sure if urn is ever a list...
                    urn = urn[0]
                hostname = Xrn.urn_split(urn)[-1]
                hostname_element = node_element.add_element('hostname')
                hostname_element.set_text(hostname)
                if hostname in nodes_with_slivers:
                    node_element.add_element('sliver')

            for hardware_type in pg_node["hardware_types"]:
                if "name" in hardware_type:
                    node_element.add_element("hardware_type", name=hardware_type["name"])
                     
            # just copy over remaining child elements  
            #for child in pg_node_element.getchildren():
            #    node_element.append(transform(child).getroot())
            i = i+1
 
        return sfa_rspec.toxml()
Exemplo n.º 24
0
   def status (self, urns, options=None):
       if options is None: options={}
       aggregate = OSAggregate(self)
 
       # TODO: Change to more dynamic
       version_manager = VersionManager()
       version_dict = {'type':'KOREN', 'version':'1', 'content_type':'manifest'}
       version = version_manager.get_version(version_dict)
       desc = aggregate.describe(urns, version=version, options=options)
       status = {'geni_urn': desc['geni_urn'],
                 'geni_slivers': desc['geni_slivers']}
       return status
Exemplo n.º 25
0
 def provision(self, urns, options={}):
     # update sliver allocation states and set them to geni_provisioned
     aggregate = OSAggregate(self)
     instances = aggregate.get_instances(urns)
     sliver_ids = []
     for instance in instances:
         sliver_hrn = "%s.%s" % (self.driver.hrn, instance.id)
         sliver_ids.append(Xrn(sliver_hrn, type='sliver').urn)
     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) 
Exemplo n.º 26
0
 def provision(self, urns, options={}):
     # update sliver allocation states and set them to geni_provisioned
     aggregate = OSAggregate(self)
     instances = aggregate.get_instances(urns)
     sliver_ids = []
     for instance in instances:
         sliver_hrn = "%s.%s" % (self.driver.hrn, instance.id)
         sliver_ids.append(Xrn(sliver_hrn, type='sliver').urn)
     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)
Exemplo n.º 27
0
 def provision(self, urns, options={}):
     # update users
     slices = unigetestbedSlices(self)
     aggregate = unigetestbedAggregate(self)
     slivers = aggregate.get_slivers(urns)
     slice = slivers[0]
     geni_users = options.get('geni_users', [])
     #users = slices.verify_users(None, slice, geni_users, 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)
Exemplo n.º 28
0
    def describe(self, urns, version=None, options={}):
        version_manager = VersionManager()
        version = version_manager.get_version(version)
        rspec_version = version_manager._get_version(version.type,
                                                     version.version,
                                                     'manifest')
        rspec = RSpec(version=rspec_version, user_options=options)

        # get slivers
        geni_slivers = []
        slivers = self.get_slivers(urns, options)
        if slivers:
            rspec_expires = datetime_to_string(utcparse(slivers[0]['expires']))
        else:
            rspec_expires = datetime_to_string(utcparse(time.time()))
        rspec.xml.set('expires', rspec_expires)

        # lookup the sliver allocations
        geni_urn = urns[0]
        sliver_ids = [sliver['sliver_id'] for sliver in slivers]
        constraint = SliverAllocation.sliver_id.in_(sliver_ids)
        sliver_allocations = self.driver.api.dbsession().query(
            SliverAllocation).filter(constraint)
        sliver_allocation_dict = {}
        for sliver_allocation in sliver_allocations:
            geni_urn = sliver_allocation.slice_urn
            sliver_allocation_dict[
                sliver_allocation.sliver_id] = sliver_allocation

        # add slivers
        nodes_dict = {}
        for sliver in slivers:
            nodes_dict[sliver['node_id']] = sliver
        rspec_nodes = []
        for sliver in slivers:
            rspec_node = self.sliver_to_rspec_node(sliver,
                                                   sliver_allocation_dict)
            rspec_nodes.append(rspec_node)
            geni_sliver = self.rspec_node_to_geni_sliver(
                rspec_node, sliver_allocation_dict)
            geni_slivers.append(geni_sliver)
        rspec.version.add_nodes(rspec_nodes)

        return {
            'geni_urn': geni_urn,
            'geni_rspec': rspec.toxml(),
            'geni_slivers': geni_slivers
        }
Exemplo n.º 29
0
 def GetVersion(self, api, options):
     # peers explicitly in aggregates.xml
     peers =dict ([ (peername,interface.get_url()) for (peername,interface) in api.aggregates.iteritems()
                    if peername != api.hrn])
     version_manager = VersionManager()
     ad_rspec_versions = []
     request_rspec_versions = []
     cred_types = [{'geni_type': 'geni_sfa', 'geni_version': str(i)} for i in range(4)[-2:]]
     for rspec_version in version_manager.versions:
         if rspec_version.content_type in ['*', 'ad']:
             ad_rspec_versions.append(rspec_version.to_dict())
         if rspec_version.content_type in ['*', 'request']:
             request_rspec_versions.append(rspec_version.to_dict())
     xrn=Xrn(api.hrn, 'authority+sm')
     version_more = {
         'interface':'slicemgr',
         'sfa': 2,
         'geni_api': 3,
         'geni_api_versions': {'3': 'http://%s:%s' % (api.config.SFA_SM_HOST, api.config.SFA_SM_PORT)},
         'hrn' : xrn.get_hrn(),
         'urn' : xrn.get_urn(),
         'peers': peers,
         'geni_single_allocation': 0, # Accept operations that act on as subset of slivers in a given state.
         'geni_allocate': 'geni_many',# Multiple slivers can exist and be incrementally added, including those which connect or overlap in some way.
         'geni_credential_types': cred_types,
         }
     sm_version=version_core(version_more)
     # local aggregate if present needs to have localhost resolved
     if api.hrn in api.aggregates:
         local_am_url=api.aggregates[api.hrn].get_url()
         sm_version['peers'][api.hrn]=local_am_url.replace('localhost',sm_version['hostname'])
     return sm_version
Exemplo n.º 30
0
    def list_resources(self, slice_urn, slice_hrn, creds, options):
        cached_requested = options.get('cached', True)
        version_manager = VersionManager()
        # get the rspec's return format from options
        #rspec_version = version_manager.get_version(options.get('geni_rspec_version'))
        # rspec's return format for nitos aggregate is version  NITOS 1
        rspec_version = version_manager.get_version('NITOS 1')
        version_string = "rspec_%s" % (rspec_version)

        #panos adding the info option to the caching key (can be improved)
        if options.get('info'):
            version_string = version_string + "_" + options.get(
                'info', 'default')

        # Adding the list_leases option to the caching key
        if options.get('list_leases'):
            version_string = version_string + "_" + options.get(
                'list_leases', 'default')

        # Adding geni_available to caching key
        if options.get('geni_available'):
            version_string = version_string + "_" + str(
                options.get('geni_available'))

        # look in cache first
        if cached_requested and self.cache and not slice_hrn:
            rspec = self.cache.get(version_string)
            if rspec:
                logger.debug(
                    "NitosDriver.ListResources: returning cached advertisement"
                )
                return rspec

        #panos: passing user-defined options
        #print "manager options = ",options
        aggregate = NitosAggregate(self)
        rspec = aggregate.get_rspec(slice_xrn=slice_urn,
                                    version=rspec_version,
                                    options=options)

        # cache the result
        if self.cache and not slice_hrn:
            logger.debug(
                "NitosDriver.ListResources: stores advertisement in cache")
            self.cache.add(version_string, rspec)

        return rspec
Exemplo n.º 31
0
 def provision(self, urns, options={}):
     # update users
     slices = DummySlices(self)
     aggregate = DummyAggregate(self)
     slivers = aggregate.get_slivers(urns)
     slice = slivers[0]
     geni_users = options.get('geni_users', [])
     #users = slices.verify_users(None, slice, geni_users, 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)
Exemplo n.º 32
0
 def __init__(self, rspec="", version=None, user_options={}):
     self.header = '<?xml version="1.0"?>\n'
     self.template = """<RSpec></RSpec>"""
     self.version = None
     self.xml = XML()
     self.version_manager = VersionManager()
     self.user_options = user_options
     self.elements = {}
     if rspec:
         if version:
             self.version = self.version_manager.get_version(version)
             self.parse_xml(rspec, version)
         else:
             self.parse_xml(rspec)
     elif version:
         self.create(version)
     else:
         raise InvalidRSpec("No RSpec or version specified. Must specify a valid rspec string or a valid version") 
Exemplo n.º 33
0
    def list_resources(self, version=None, options={}):

        version_manager = VersionManager()
        version = version_manager.get_version(version)
        rspec_version = version_manager._get_version(version.type,
                                                     version.version, 'ad')
        rspec = RSpec(version=rspec_version, user_options=options)

        if not options.get(
                'list_leases') or options['list_leases'] != 'leases':
            # get nodes
            nodes = self.get_nodes(options)
            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
            sites = self.get_sites({'site_id': site_ids})
            interfaces = self.get_interfaces({'interface_id': interface_ids})
            node_tags = self.get_node_tags({'node_tag_id': tag_ids})
            pl_initscripts = self.get_pl_initscripts()
            # convert nodes to rspec nodes
            rspec_nodes = []
            for node in nodes:
                rspec_node = self.node_to_rspec_node(node, sites, interfaces,
                                                     node_tags, pl_initscripts)
                rspec_nodes.append(rspec_node)
            rspec.version.add_nodes(rspec_nodes)

            # add links
            links = self.get_links(sites, nodes_dict, interfaces)
            rspec.version.add_links(links)

        if not options.get('list_leases') or options.get(
                'list_leases') and options['list_leases'] != 'resources':
            leases = self.get_leases()
            rspec.version.add_leases(leases)

        return rspec.toxml()
Exemplo n.º 34
0
    def Provision(self, api, xrns, creds, options):
        """
        Create the sliver[s] (slice) at this aggregate.    
        Verify HRN and initialize the slice record in PLC if necessary.
        """
        call_id = options.get('call_id')
        if Callids().already_handled(call_id): return ""

        # make sure geni_rspec_version is specified in options
        if 'geni_rspec_version' not in options:
            msg = 'geni_rspec_version is required and must be set in options struct'
            raise SfaInvalidArgument(msg, 'geni_rspec_version')
        # make sure we support the requested rspec version
        version_manager = VersionManager()
        rspec_version = version_manager.get_version(options['geni_rspec_version']) 
        if not rspec_version:
            raise InvalidRSpecVersion(options['geni_rspec_version'])
        options['creds']=creds               
        return api.driver.provision(xrns, options)
Exemplo n.º 35
0
    def Provision(self, api, xrns, creds, options):
        """
        Create the sliver[s] (slice) at this aggregate.    
        Verify HRN and initialize the slice record in PLC if necessary.
        """
        call_id = options.get('call_id')
        if Callids().already_handled(call_id): return ""

        # make sure geni_rspec_version is specified in options
        if 'geni_rspec_version' not in options:
            msg = 'geni_rspec_version is required and must be set in options struct'
            raise SfaInvalidArgument(msg, 'geni_rspec_version')
        # make sure we support the requested rspec version
        version_manager = VersionManager()
        rspec_version = version_manager.get_version(options['geni_rspec_version']) 
        if not rspec_version:
            raise InvalidRSpecVersion(options['geni_rspec_version'])
                       
        return api.driver.provision(xrns, options)
Exemplo n.º 36
0
    def get_rspec(self, slice_xrn=None, version=None, options={}):

        version_manager = VersionManager()
        version = version_manager.get_version(version)

        if not slice_xrn:
            rspec_version = version_manager._get_version(
                version.type, version.version, 'ad')
        else:
            rspec_version = version_manager._get_version(
                version.type, version.version, 'manifest')

        slice, slivers = self.get_slice_and_slivers(slice_xrn)

        rspec = RSpec(version=rspec_version, user_options=options)

        if slice and 'expires' in slice:
            rspec.xml.set('expires',
                          datetime_to_string(utcparse(slice['expires'])))

        if not options.get('list_leases') or options.get(
                'list_leases') and options['list_leases'] != 'leases':
            nodes = self.get_nodes(slice_xrn, slice, slivers, options)
            rspec.version.add_nodes(nodes)
            # add sliver defaults
            default_sliver = slivers.get(None, [])
            if default_sliver:
                default_sliver_attribs = default_sliver.get('tags', [])
                for attrib in default_sliver_attribs:
                    logger.info(attrib)
                    rspec.version.add_default_sliver_attribute(
                        attrib['tagname'], attrib['value'])
            # add wifi channels
            channels = self.get_channels(slice, options)
            rspec.version.add_channels(channels)

        if not options.get('list_leases') or options.get(
                'list_leases') and options['list_leases'] != 'resources':
            leases_channels = self.get_leases_and_channels(slice, slice_xrn)
            rspec.version.add_leases(leases_channels)

        return rspec.toxml()
Exemplo n.º 37
0
def GetVersion(api):

    version_manager = VersionManager()
    ad_rspec_versions = []
    request_rspec_versions = []
    for rspec_version in version_manager.versions:
        if rspec_version.content_type in ['*', 'ad']:
            ad_rspec_versions.append(rspec_version.to_dict())
        if rspec_version.content_type in ['*', 'request']:
            request_rspec_versions.append(rspec_version.to_dict()) 
    default_rspec_version = version_manager.get_version("sfa 1").to_dict()
    xrn=Xrn(api.hrn)
    version_more = {'interface':'aggregate',
                    'testbed':'myplc',
                    'hrn':xrn.get_hrn(),
                    'request_rspec_versions': request_rspec_versions,
                    'ad_rspec_versions': ad_rspec_versions,
                    'default_ad_rspec': default_rspec_version
                    }
    return version_core(version_more)
Exemplo n.º 38
0
    def describe(self, urns, version=None, options=None):
        if options is None: options={}
        version_manager = VersionManager()
        version = version_manager.get_version(version)
        rspec_version = version_manager._get_version(version.type, version.version, 'manifest')
        rspec = RSpec(version=rspec_version, user_options=options)

        # get slivers
        geni_slivers = []
        slivers = self.get_slivers(urns, options)
        if slivers:
            rspec_expires = datetime_to_string(utcparse(slivers[0]['expires']))
        else:
            rspec_expires = datetime_to_string(utcparse(time.time()))
        rspec.xml.set('expires',  rspec_expires)

        # lookup the sliver allocations
        geni_urn = urns[0]
        sliver_ids = [sliver['sliver_id'] for sliver in slivers]
        constraint = SliverAllocation.sliver_id.in_(sliver_ids)
        sliver_allocations = self.driver.api.dbsession().query(SliverAllocation).filter(constraint)
        sliver_allocation_dict = {}
        for sliver_allocation in sliver_allocations:
            geni_urn = sliver_allocation.slice_urn
            sliver_allocation_dict[sliver_allocation.sliver_id] = sliver_allocation

        # add slivers
        nodes_dict = {}
        for sliver in slivers:
            nodes_dict[sliver['node_id']] = sliver
        rspec_nodes = []
        for sliver in slivers:
            rspec_node = self.sliver_to_rspec_node(sliver, sliver_allocation_dict)
            rspec_nodes.append(rspec_node)
            geni_sliver = self.rspec_node_to_geni_sliver(rspec_node, sliver_allocation_dict)
            geni_slivers.append(geni_sliver)
        rspec.version.add_nodes(rspec_nodes)

        return {'geni_urn': geni_urn,
                'geni_rspec': rspec.toxml(),
                'geni_slivers': geni_slivers}
Exemplo n.º 39
0
    def Describe(self, api, creds, xrns, options):
        def _Describe(server, xrn, creds, options):
            return server.Describe(xrn, creds, options)

        call_id = options.get('call_id')
        if Callids().already_handled(call_id): return {}
        # attempt to use delegated credential first
        cred = api.getDelegatedCredential(creds)
        if not cred:
            cred = api.getCredential()
        multiclient = MultiClient()
        for aggregate in api.aggregates:
            interface = api.aggregates[aggregate]
            server = api.server_proxy(interface, cred)
            multiclient.run (_Describe, server, xrns, [cred], options)
        results = [ReturnValue.get_value(result) for result in multiclient.get_results()]

        # get rid of any void result - e.g. when call_id was hit, where by convention we return {}
        results = [ result for result in results if result and result.get('geni_urn')]

        # do not try to combine if there's no result
        if not results : return {}

        # otherwise let's merge stuff
        version_manager = VersionManager()
        manifest_version = version_manager._get_version('GENI', '3', 'manifest')
        result_rspec = RSpec(version=manifest_version)
        geni_slivers = []
        geni_urn  = None
        for result in results:
            try:
                geni_urn = result['geni_urn']
                result_rspec.version.merge(ReturnValue.get_value(result['geni_rspec']))
                geni_slivers.extend(result['geni_slivers'])
            except:
                api.logger.log_exc("SM.Provision: Failed to merge aggregate rspec")
        return {
            'geni_urn': geni_urn,
            'geni_rspec': result_rspec.toxml(),    
            'geni_slivers': geni_slivers
        }  
Exemplo n.º 40
0
    def to_sfa_rspec(rspec, content_type = None):
        if not isinstance(rspec, RSpec):
            pg_rspec = RSpec(rspec)
        else:
            pg_rspec = rspec
        
        version_manager = VersionManager()
        sfa_version = version_manager._get_version('sfa', '1')    
        sfa_rspec = RSpec(version=sfa_version)

        # get network
        network_urn = pg_rspec.version.get_network()
        network,  _ = urn_to_hrn(network_urn)
        network_element = sfa_rspec.xml.add_element('network', {'name': network, 'id': network})
        
        # get nodes
        pg_nodes_elements = pg_rspec.version.get_node_elements()
        nodes_with_slivers = pg_rspec.version.get_nodes_with_slivers()
        i = 1
        for pg_node_element in pg_nodes_elements:
            attribs = dict(pg_node_element.attrib.items()) 
            attribs['id'] = 'n'+str(i)
            
            node_element = sfa_rspec.xml.add_element('node', attribs, parent=network_element)
            urn = pg_node_element.xpath('@component_id', namespaces=pg_rspec.namespaces)
            if urn:
                urn = urn[0]
                hostname = Xrn.urn_split(urn)[-1]
                hostname_element = sfa_rspec.xml.add_element('hostname', parent=node_element, text=hostname)
                if hostname in nodes_with_slivers:
                    sfa_rspec.xml.add_element('sliver', parent=node_element)
                     
            urn_element = sfa_rspec.xml.add_element('urn', parent=node_element, text=urn)


            # just copy over remaining child elements  
            for child in pg_node_element.getchildren():
                node_element.append(transform(child).getroot())
            i = i+1
 
        return sfa_rspec.toxml()
Exemplo n.º 41
0
Arquivo: sfi.py Projeto: planetlab/sfa
    def resources(self, opts, args):
        user_cred = self.get_user_cred().save_to_string(save_parents=True)
        server = self.slicemgr
        call_options = {}
        server = self.get_server_from_opts(opts)
        
        if args:
            cred = self.get_slice_cred(args[0]).save_to_string(save_parents=True)
            hrn = args[0]
	    call_options = {'geni_slice_urn': hrn_to_urn(hrn, 'slice')}
        else:
            cred = user_cred
            hrn = None
     
        creds = [cred]
        if opts.delegate:
            delegated_cred = self.delegate_cred(cred, get_authority(self.authority))
            creds.append(delegated_cred)
        if opts.rspec_version:
            version_manager = VersionManager()
            server_version = self.get_cached_server_version(server)
            if 'sfa' in server_version:
                # just request the version the client wants 
                call_options['rspec_version'] = version_manager.get_version(opts.rspec_version).to_dict()
            else:
                # this must be a protogeni aggregate. We should request a v2 ad rspec
                # regardless of what the client user requested 
                call_options['rspec_version'] = version_manager.get_version('ProtoGENI 2').to_dict()     
        #panos add info options
        if opts.info:
            call_options['info'] = opts.info 

        call_args = [creds, call_options]
        if self.server_supports_call_id_arg(server):
            call_args.append(unique_call_id())
        result = server.ListResources(*call_args)
        if opts.file is None:
            display_rspec(result, opts.format)
        else:
            save_rspec_to_file(result, opts.file)
        return
Exemplo n.º 42
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)
Exemplo n.º 43
0
    def list_resources(self, version = None, options={}):

        version_manager = VersionManager()
        version = version_manager.get_version(version)
        rspec_version = version_manager._get_version(version.type, version.version, 'ad')
        rspec = RSpec(version=rspec_version, user_options=options)

        # get nodes
        nodes  = self.get_nodes(options)
        nodes_dict = {}
        for node in nodes:
            nodes_dict[node['node_id']] = node

        # convert nodes to rspec nodes
        rspec_nodes = []
        for node in nodes:
            rspec_node = self.node_to_rspec_node(node)
            rspec_nodes.append(rspec_node)
        rspec.version.add_nodes(rspec_nodes)

        return rspec.toxml()
Exemplo n.º 44
0
 def __init__(self, rspec="", version=None, user_options={}):
     self.header = '<?xml version="1.0"?>\n'
     self.template = """<RSpec></RSpec>"""
     self.version = None
     self.xml = XML()
     self.version_manager = VersionManager()
     self.user_options = user_options
     self.elements = {}
     if rspec:
         self.parse_xml(rspec)
     else:
         self.create(version)
Exemplo n.º 45
0
    def list_resources(self, version = None, options=None):
        if options is None: options={}

        version_manager = VersionManager()
        version = version_manager.get_version(version)
        rspec_version = version_manager._get_version(version.type, version.version, 'ad')
        rspec = RSpec(version=rspec_version, user_options=options)
       
        if not options.get('list_leases') or options['list_leases'] != 'leases':
            # get nodes
            nodes  = self.get_nodes(options)
            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
            sites = self.get_sites({'site_id': site_ids})
            interfaces = self.get_interfaces({'interface_id':interface_ids})
            node_tags = self.get_node_tags({'node_tag_id': tag_ids})
            pl_initscripts = self.get_pl_initscripts()
            # convert nodes to rspec nodes
            rspec_nodes = []
            for node in nodes:
                rspec_node = self.node_to_rspec_node(node, sites, interfaces, node_tags, pl_initscripts)
                rspec_nodes.append(rspec_node)
            rspec.version.add_nodes(rspec_nodes)

            # add links
            links = self.get_links(sites, nodes_dict, interfaces)        
            rspec.version.add_links(links)

        if not options.get('list_leases') or options.get('list_leases') and options['list_leases'] != 'resources':
           leases = self.get_leases()
           rspec.version.add_leases(leases)

        return rspec.toxml()
Exemplo n.º 46
0
 def rspec_versions(self):
     version_manager = VersionManager()
     ad_rspec_versions = []
     request_rspec_versions = []
     for rspec_version in version_manager.versions:
         if rspec_version.content_type in ['*', 'ad']:
             ad_rspec_versions.append(rspec_version.to_dict())
         if rspec_version.content_type in ['*', 'request']:
             request_rspec_versions.append(rspec_version.to_dict())
     return {
         'geni_request_rspec_versions': request_rspec_versions,
         'geni_ad_rspec_versions': ad_rspec_versions,
         }
Exemplo n.º 47
0
    def ListResources(self, api, creds, options):
        call_id = options.get('call_id')
        if Callids().already_handled(call_id): return ""

        # get the rspec's return format from options
        version_manager = VersionManager()
        rspec_version = version_manager.get_version(options.get('geni_rspec_version'))
        version_string = self.get_rspec_version_string(rspec_version, options)

        # look in cache first
        cached_requested = options.get('cached', True)
        if cached_requested and api.driver.cache:
            rspec = api.driver.cache.get(version_string)
            if rspec:
                logger.debug("%s.ListResources returning cached advertisement" % (api.driver.__module__))
                return rspec
        options['creds']=creds
        rspec = api.driver.list_resources (rspec_version, options) 
        if api.driver.cache:
            logger.debug("%s.ListResources stores advertisement in cache" % (api.driver.__module__))
            api.driver.cache.add(version_string, rspec)    
        return rspec
Exemplo n.º 48
0
 def aggregate_version(self):
     version_manager = VersionManager()
     ad_rspec_versions = []
     request_rspec_versions = []
     for rspec_version in version_manager.versions:
         if rspec_version.content_type in ['*', 'ad']:
             ad_rspec_versions.append(rspec_version.to_dict())
         if rspec_version.content_type in ['*', 'request']:
             request_rspec_versions.append(rspec_version.to_dict())
     return {
         'testbed': self.testbed_name(),
         'geni_request_rspec_versions': request_rspec_versions,
         'geni_ad_rspec_versions': ad_rspec_versions,
     }
Exemplo n.º 49
0
    def ListResources(self, api, creds, options):
        call_id = options.get('call_id') 
        if Callids().already_handled(call_id): return ""

        version_manager = VersionManager()

        def _ListResources(aggregate, server, credential, options):
            forward_options = copy(options)
            tStart = time.time()
            try:
                version = api.get_cached_server_version(server)
                # force ProtoGENI aggregates to give us a v2 RSpec
                forward_options['geni_rspec_version'] = options.get('geni_rspec_version')
                result = server.ListResources(credential, forward_options)
                return {"aggregate": aggregate, "result": result, "elapsed": time.time()-tStart, "status": "success"}
            except Exception, e:
                api.logger.log_exc("ListResources failed at %s" %(server.url))
                return {"aggregate": aggregate, "elapsed": time.time()-tStart, "status": "exception", "exc_info": sys.exc_info()}
Exemplo n.º 50
0
    def describe(self, urns, version=None, options={}):
        """
        Retrieve a manifest RSpec describing the resources contained by the
        named entities, e.g. a single slice or a set of the slivers in a slice.
        This listing and description should be sufficiently descriptive to allow
        experimenters to use the resources.

        :param urns: If a slice urn is supplied and there are no slivers in the
            given slice at this aggregate, then geni_rspec shall be a valid
            manifest RSpec, containing no node elements - no resources.
        :type urns: list  or strings
        :param options: various options. the valid options are: {boolean
            geni_compressed <optional>; struct geni_rspec_version { string type;
            #case insensitive , string version; # case insensitive}}
        :type options: dictionary

        :returns: On success returns the following dictionary {geni_rspec:
            <geni.rspec, a Manifest RSpec>, geni_urn: <string slice urn of the
            containing slice>, geni_slivers:{ geni_sliver_urn:
            <string sliver urn>, geni_expires:  <dateTime.rfc3339 allocation
            expiration string, as in geni_expires from SliversStatus>,
            geni_allocation_status: <string sliver state - e.g. geni_allocated
            or geni_provisioned >, geni_operational_status:
            <string sliver operational state>, geni_error: <optional string.
            The field may be omitted entirely but may not be null/None,
            explaining any failure for a sliver.>}

        .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3#Describe
        .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3/CommonConcepts#urns
        """
        version_manager = VersionManager()
        version = version_manager.get_version(version)
        rspec_version = version_manager._get_version(version.type,
                                                     version.version,
                                                     'manifest')
        rspec = RSpec(version=rspec_version, user_options=options)

        # get slivers
        geni_slivers = []
        slivers = self.get_slivers(urns, options)
        if slivers:
            rspec_expires = datetime_to_string(utcparse(slivers[0]['expires']))
        else:
            rspec_expires = datetime_to_string(utcparse(time.time()))
        rspec.xml.set('expires', rspec_expires)

        # lookup the sliver allocations
        geni_urn = urns[0]
        sliver_ids = [sliver['sliver_id'] for sliver in slivers]
        logger.debug(" Cortexlabaggregate.PY \tDescribe  sliver_ids %s " %
                     (sliver_ids))
        constraint = SliverAllocation.sliver_id.in_(sliver_ids)
        query = self.driver.api.dbsession().query(SliverAllocation)
        sliver_allocations = query.filter((constraint)).all()
        logger.debug(
            " Cortexlabaggregate.PY \tDescribe  sliver_allocations %s " %
            (sliver_allocations))
        sliver_allocation_dict = {}
        for sliver_allocation in sliver_allocations:
            geni_urn = sliver_allocation.slice_urn
            sliver_allocation_dict[sliver_allocation.sliver_id] = \
                                                            sliver_allocation

        # add slivers
        nodes_dict = {}
        for sliver in slivers:
            nodes_dict[sliver['node_id']] = sliver
        rspec_nodes = []
        for sliver in slivers:
            rspec_node = self.sliver_to_rspec_node(sliver,
                                                   sliver_allocation_dict)
            rspec_nodes.append(rspec_node)
            logger.debug(
                " Cortexlabaggregate.PY \tDescribe  sliver_allocation_dict %s "
                % (sliver_allocation_dict))
            geni_sliver = self.rspec_node_to_geni_sliver(
                rspec_node, sliver_allocation_dict)
            geni_slivers.append(geni_sliver)

        logger.debug(" Cortexlabaggregate.PY \tDescribe rspec_nodes %s\
                        rspec %s " % (rspec_nodes, rspec))
        rspec.version.add_nodes(rspec_nodes)

        return {
            'geni_urn': geni_urn,
            'geni_rspec': rspec.toxml(),
            'geni_slivers': geni_slivers
        }
Exemplo n.º 51
0
    def get_rspec(self,
                  slice_xrn=None,
                  login=None,
                  version=None,
                  options=None):
        """
        Returns xml rspec:
        - a full advertisement rspec with the testbed resources if slice_xrn is
        not specified.If a lease option is given, also returns the leases
        scheduled on the testbed.
        - a manifest Rspec with the leases and nodes in slice's leases if
        slice_xrn is not None.

        :param slice_xrn: srn of the slice
        :type slice_xrn: string
        :param login: user'uid (ldap login) on cortexlab
        :type login: string
        :param version: can be set to sfa or cortexlab
        :type version: RSpecVersion
        :param options: used to specify if the leases should also be included in
            the returned rspec.
        :type options: dict

        :returns: Xml Rspec.
        :rtype: XML


        """

        ldap_username = None
        rspec = None
        version_manager = VersionManager()
        version = version_manager.get_version(version)
        logger.debug("CortexlabAggregate \t get_rspec ***version %s \
                    version.type %s  version.version %s options %s \r\n" %
                     (version, version.type, version.version, options))

        if slice_xrn is None:
            rspec_version = version_manager._get_version(
                version.type, version.version, 'ad')

        else:
            rspec_version = version_manager._get_version(
                version.type, version.version, 'manifest')

        slices, slivers = self.get_slice_and_slivers(slice_xrn, login)
        if slice_xrn and slices is not None:
            #Get user associated with this slice
            #for one_slice in slices :
            ldap_username = self.find_ldap_username_from_slice(slices[0])
            # ldap_username = slices[0]['reg_researchers'][0].__dict__['hrn']
            #  # ldap_username = slices[0]['user']
            # tmp = ldap_username.split('.')
            # ldap_username = tmp[1]
            logger.debug("CortexlabAggregate \tget_rspec **** \
                    LDAP USERNAME %s \r\n" \
                    % (ldap_username))
        #at this point sliver may be empty if no cortexlab job
        #is running for this user/slice.
        rspec = RSpec(version=rspec_version, user_options=options)

        logger.debug("\r\n \r\n CortexlabAggregate \tget_rspec *** \
                      slice_xrn %s slices  %s\r\n \r\n" % (slice_xrn, slices))

        if options is not None:
            lease_option = options['list_leases']
        else:
            #If no options are specified, at least print the resources
            lease_option = 'all'
        #if slice_xrn :
        #lease_option = 'all'

        if lease_option in ['all', 'resources']:
            #if not options.get('list_leases') or options.get('list_leases')
            #and options['list_leases'] != 'leases':
            nodes = self.get_nodes()
            logger.debug("\r\n")
            logger.debug("CortexlabAggregate \t lease_option %s \
                          get rspec  ******* nodes %s" % (lease_option, nodes))

            sites_set = set([node['location']['site'] for node in nodes])

            #In case creating a job,  slice_xrn is not set to None
            rspec.version.add_nodes(nodes)
            if slice_xrn and slices is not None:
                #     #Get user associated with this slice
                #     #for one_slice in slices :
                #     ldap_username = slices[0]['reg_researchers']
                #      # ldap_username = slices[0]['user']
                #     tmp = ldap_username.split('.')
                #     ldap_username = tmp[1]
                #      # ldap_username = tmp[1].split('_')[0]

                logger.debug("CortexlabAggregate \tget_rspec **** \
                        version type %s ldap_ user %s \r\n" \
                        % (version.type, ldap_username))
                #TODO : Change the version of Rspec here in case of pbm -SA 09/01/14
                if version.type in ["Cortexlab", "Iotlab"]:
                    rspec.version.add_connection_information(
                        ldap_username, sites_set)

            default_sliver = slivers.get('default_sliver', [])
            if default_sliver and len(nodes) is not 0:
                #default_sliver_attribs = default_sliver.get('tags', [])
                logger.debug("CortexlabAggregate \tget_rspec **** \
                        default_sliver%s \r\n" % (default_sliver))
                for attrib in default_sliver:
                    rspec.version.add_default_sliver_attribute(
                        attrib, default_sliver[attrib])

        if lease_option in ['all', 'leases']:
            leases = self.get_all_leases(ldap_username)
            rspec.version.add_leases(leases)
            logger.debug("CortexlabAggregate \tget_rspec **** \
                       FINAL RSPEC %s \r\n" % (rspec.toxml()))
        return rspec.toxml()
Exemplo n.º 52
0
class RSpec:
 
    def __init__(self, rspec="", version=None, user_options={}):
        self.header = '<?xml version="1.0"?>\n'
        self.template = """<RSpec></RSpec>"""
        self.version = None
        self.xml = XML()
        self.version_manager = VersionManager()
        self.user_options = user_options
        self.elements = {}
        if rspec:
            if version:
                self.version = self.version_manager.get_version(version)
                self.parse_xml(rspec, version)
            else:
                self.parse_xml(rspec)
        elif version:
            self.create(version)
        else:
            raise InvalidRSpec("No RSpec or version specified. Must specify a valid rspec string or a valid version") 

    def create(self, version=None):
        """
        Create root element
        """
        self.version = self.version_manager.get_version(version)
        self.namespaces = self.version.namespaces
        self.parse_xml(self.version.template, self.version) 
        # eg. 2011-03-23T19:53:28Z 
        date_format = '%Y-%m-%dT%H:%M:%SZ'
        now = datetime.utcnow()
        generated_ts = now.strftime(date_format)
        expires_ts = (now + timedelta(hours=1)).strftime(date_format) 
        self.xml.set('expires', expires_ts)
        self.xml.set('generated', generated_ts)

    def parse_xml(self, xml, version=None):
        self.xml.parse_xml(xml)
        if not version:
            if self.xml.schema:
                self.version = self.version_manager.get_version_by_schema(self.xml.schema)
            else:
                #raise InvalidRSpec('unknown rspec schema: %s' % schema)
                # TODO: Should start raising an exception once SFA defines a schema.
                # for now we just  default to sfa 
                self.version = self.version_manager.get_version({'type':'sfa','version': '1'})
        self.version.xml = self.xml    
        self.namespaces = self.xml.namespaces
    
    def load_rspec_elements(self, rspec_elements):
        self.elements = {}
        for rspec_element in rspec_elements:
            if isinstance(rspec_element, RSpecElement):
                self.elements[rspec_element.type] = rspec_element

    def register_rspec_element(self, element_type, element_name, element_path):
        if element_type not in RSpecElements:
            raise InvalidRSpecElement(element_type, extra="no such element type: %s. Must specify a valid RSpecElement" % element_type)
        self.elements[element_type] = RSpecElement(element_type, element_name, element_path)

    def get_rspec_element(self, element_type):
        if element_type not in self.elements:
            msg = "ElementType %s not registerd for this rspec" % element_type
            raise InvalidRSpecElement(element_type, extra=msg)
        return self.elements[element_type]

    def get(self, element_type, filter={}, depth=0):
        elements = self.get_elements(element_type, filter)
        elements = [self.xml.get_element_attributes(elem, depth=depth) for elem in elements]
        return elements

    def get_elements(self, element_type, filter={}):
        """
        search for a registered element
        """
        if element_type not in self.elements:
            msg = "Unable to search for element %s in rspec, expath expression not found." % \
                   element_type
            raise InvalidRSpecElement(element_type, extra=msg)
        rspec_element = self.get_rspec_element(element_type)
        xpath = rspec_element.path + XpathFilter.xpath(filter)
        return self.xml.xpath(xpath)

    def merge(self, in_rspec):
        self.version.merge(in_rspec)

    def filter(self, filter):
        if 'component_manager_id' in filter:    
            nodes = self.version.get_nodes()
            for node in nodes:
                if 'component_manager_id' not in node.attrib or \
                  node.attrib['component_manager_id'] != filter['component_manager_id']:
                    parent = node.getparent()
                    parent.remove(node.element) 
        

    def toxml(self, header=True):
        if header:
            return self.header + self.xml.toxml()
        else:
            return self.xml.toxml()
    

    def save(self, filename):
        return self.xml.save(filename)
Exemplo n.º 53
0
    print "Missing link list -- exiting"
    command.parser.print_help()
    sys.exit(1)

if command.opts.infile:
    infile = file(command.opts.infile)
else:
    infile = sys.stdin
if command.opts.outfile:
    outfile = file(command.opts.outfile, "w")
else:
    outfile = sys.stdout
ad_rspec = RSpec(infile)
links = file(command.opts.linkfile).read().split('\n')
link_tuples = map(lambda x: tuple(x.split()), links)

version_manager = VersionManager()
try:
    type = ad_rspec.version.type
    version_num = ad_rspec.version.version
    request_version = version_manager._get_version(type, version_num,
                                                   'request')
    request_rspec = RSpec(version=request_version)
    request_rspec.version.merge(ad_rspec)
    request_rspec.version.add_link_requests(link_tuples)
except:
    logger.log_exc("sfiAddLinks FAILED with links %s" % links)
    sys.exit(1)
print >> outfile, request_rspec.toxml()
sys.exit(0)
Exemplo n.º 54
0
    def describe(self, urns, version=None, options={}):
        version_manager = VersionManager()
        version = version_manager.get_version(version)
        rspec_version = version_manager._get_version(version.type,
                                                     version.version,
                                                     'manifest')
        rspec = RSpec(version=rspec_version, user_options=options)

        # get slivers
        geni_slivers = []
        slivers = self.get_slivers(urns, options)
        if slivers:
            rspec_expires = datetime_to_string(utcparse(slivers[0]['expires']))
        else:
            rspec_expires = datetime_to_string(utcparse(time.time()))
        rspec.xml.set('expires', rspec_expires)

        # lookup the sliver allocations
        geni_urn = urns[0]
        sliver_ids = [sliver['sliver_id'] for sliver in slivers]
        constraint = SliverAllocation.sliver_id.in_(sliver_ids)
        sliver_allocations = self.driver.api.dbsession().query(
            SliverAllocation).filter(constraint)
        sliver_allocation_dict = {}
        for sliver_allocation in sliver_allocations:
            geni_urn = sliver_allocation.slice_urn
            sliver_allocation_dict[
                sliver_allocation.sliver_id] = sliver_allocation

        if not options.get(
                'list_leases') or options['list_leases'] != 'leases':
            # add slivers
            site_ids = []
            interface_ids = []
            tag_ids = []
            nodes_dict = {}
            for sliver in slivers:
                site_ids.append(sliver['site_id'])
                interface_ids.extend(sliver['interface_ids'])
                tag_ids.extend(sliver['node_tag_ids'])
                nodes_dict[sliver['node_id']] = sliver
            sites = self.get_sites({'site_id': site_ids})
            interfaces = self.get_interfaces({'interface_id': interface_ids})
            node_tags = self.get_node_tags({'node_tag_id': tag_ids})
            pl_initscripts = self.get_pl_initscripts()
            rspec_nodes = []
            for sliver in slivers:
                if sliver['slice_ids_whitelist'] and sliver[
                        'slice_id'] not in sliver['slice_ids_whitelist']:
                    continue
                rspec_node = self.sliver_to_rspec_node(sliver, sites,
                                                       interfaces, node_tags,
                                                       pl_initscripts,
                                                       sliver_allocation_dict)
                # manifest node element shouldn't contain available attribute
                rspec_node.pop('available')
                rspec_nodes.append(rspec_node)
                geni_sliver = self.rspec_node_to_geni_sliver(
                    rspec_node, sliver_allocation_dict)
                geni_slivers.append(geni_sliver)
            rspec.version.add_nodes(rspec_nodes)

            # add sliver defaults
            #default_sliver = slivers.get(None, [])
            #if default_sliver:
            #    default_sliver_attribs = default_sliver.get('tags', [])
            #    for attrib in default_sliver_attribs:
            #        rspec.version.add_default_sliver_attribute(attrib['tagname'], attrib['value'])

            # add links
            links = self.get_links(sites, nodes_dict, interfaces)
            rspec.version.add_links(links)

        if not options.get(
                'list_leases') or options['list_leases'] != 'resources':
            if slivers:
                leases = self.get_leases(slivers[0])
                rspec.version.add_leases(leases)

        return {
            'geni_urn': geni_urn,
            'geni_rspec': rspec.toxml(),
            'geni_slivers': geni_slivers
        }
Exemplo n.º 55
0
    def Allocate(self, api, xrn, creds, rspec_str, expiration, options):
        call_id = options.get('call_id')
        if Callids().already_handled(call_id): return ""
    
        version_manager = VersionManager()
        def _Allocate(aggregate, server, xrn, credential, rspec, options):
            tStart = time.time()
            try:
                # Need to call GetVersion at an aggregate to determine the supported
                # rspec type/format beofre calling CreateSliver at an Aggregate.
                #server_version = api.get_cached_server_version(server)
                #if 'sfa' not in server_version and 'geni_api' in server_version:
                    # sfa aggregtes support both sfa and pg rspecs, no need to convert
                    # if aggregate supports sfa rspecs. otherwise convert to pg rspec
                    #rspec = RSpec(RSpecConverter.to_pg_rspec(rspec, 'request'))
                    #filter = {'component_manager_id': server_version['urn']}
                    #rspec.filter(filter)
                    #rspec = rspec.toxml()
                result = server.Allocate(xrn, credential, rspec, options)
                return {"aggregate": aggregate, "result": result, "elapsed": time.time()-tStart, "status": "success"}
            except:
                logger.log_exc('Something wrong in _Allocate with URL %s'%server.url)
                return {"aggregate": aggregate, "elapsed": time.time()-tStart, "status": "exception", "exc_info": sys.exc_info()}

        # Validate the RSpec against PlanetLab's schema --disabled for now
        # The schema used here needs to aggregate the PL and VINI schemas
        # schema = "/var/www/html/schemas/pl.rng"
        rspec = RSpec(rspec_str)
    #    schema = None
    #    if schema:
    #        rspec.validate(schema)
    
        # if there is a <statistics> section, the aggregates don't care about it,
        # so delete it.
        self.drop_slicemgr_stats(rspec)
    
        # attempt to use delegated credential first
        cred = api.getDelegatedCredential(creds)
        if not cred:
            cred = api.getCredential()
    
        # get the callers hrn
        hrn, type = urn_to_hrn(xrn)
        valid_cred = api.auth.checkCredentials(creds, 'createsliver', hrn)[0]
        caller_hrn = Credential(cred=valid_cred).get_gid_caller().get_hrn()
        multiclient = MultiClient()
        for aggregate in api.aggregates:
            # prevent infinite loop. Dont send request back to caller
            # unless the caller is the aggregate's SM 
            if caller_hrn == aggregate and aggregate != api.hrn:
                continue
            interface = api.aggregates[aggregate]
            server = api.server_proxy(interface, cred)
            # Just send entire RSpec to each aggregate
            multiclient.run(_Allocate, aggregate, server, xrn, [cred], rspec.toxml(), options)
                
        results = multiclient.get_results()
        manifest_version = version_manager._get_version(rspec.version.type, rspec.version.version, 'manifest')
        result_rspec = RSpec(version=manifest_version)
        geni_urn = None
        geni_slivers = []

        for result in results:
            self.add_slicemgr_stat(result_rspec, "Allocate", result["aggregate"], result["elapsed"], 
                                   result["status"], result.get("exc_info",None))
            if result["status"]=="success":
                try:
                    res = result['result']['value']
                    geni_urn = res['geni_urn']
                    result_rspec.version.merge(ReturnValue.get_value(res['geni_rspec']))
                    geni_slivers.extend(res['geni_slivers'])
                except:
                    api.logger.log_exc("SM.Allocate: Failed to merge aggregate rspec")
        return {
            'geni_urn': geni_urn,
            'geni_rspec': result_rspec.toxml(),
            'geni_slivers': geni_slivers
        }