示例#1
0
    def Delete(self, api, xrn, creds, options):
        call_id = options.get('call_id')
        if Callids().already_handled(call_id): return ""

        def _Delete(server, xrn, creds, options):
            return server.Delete(xrn, creds, options)

        (hrn, type) = urn_to_hrn(xrn[0])
        # get the callers hrn
        valid_cred = api.auth.checkCredentials(creds, 'deletesliver', hrn)[0]
        caller_hrn = Credential(cred=valid_cred).get_gid_caller().get_hrn()

        # attempt to use delegated credential first
        cred = api.getDelegatedCredential(creds)
        if not cred:
            cred = api.getCredential()
        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)
            multiclient.run(_Delete, server, xrn, [cred], options)
        
        results = []
        for result in multiclient.get_results():
            results += ReturnValue.get_value(result)
        return results
示例#2
0
    def delete_instance(self, instance):
    
        def _delete_security_group(inst):
            security_group = inst.metadata.get('security_groups', '')
            if security_group:
                manager = SecurityGroup(self.driver)
                timeout = 10.0 # wait a maximum of 10 seconds before forcing the security group delete
                start_time = time.time()
                instance_deleted = False
                while instance_deleted == False and (time.time() - start_time) < timeout:
                    tmp_inst = self.driver.shell.compute_manager.servers.findall(id=inst.id)
                    if not tmp_inst:
                        instance_deleted = True
                    time.sleep(.5)
                manager.delete_security_group(security_group)

        multiclient = MultiClient()
        tenant = self.driver.shell.auth_manager.tenants.find(id=instance.tenant_id)
        
        # Update connection for the current client
        xrn = Xrn(tenant.name)
        user_name = xrn.get_authority_hrn() + '.' + xrn.leaf.split('-')[0]
        self.driver.shell.compute_manager.connect(username=user_name, tenant=tenant.name, password=user_name)

        args = { 'name': instance.name,
                 'id': instance.id }
        instances = self.driver.shell.compute_manager.servers.findall(**args)
        security_group_manager = SecurityGroup(self.driver)
        for instance in instances:
            # destroy instance
            self.driver.shell.compute_manager.servers.delete(instance)
            # deleate this instance's security groups
            multiclient.run(_delete_security_group, instance)
        return 1
示例#3
0
    def delete_instance(self, instance):
    
        def _delete_security_group(inst):
            security_group = inst.metadata.get('security_groups', '')
            if security_group:
                manager = SecurityGroup(self.driver)
                timeout = 10.0 # wait a maximum of 10 seconds before forcing the security group delete
                start_time = time.time()
                instance_deleted = False
                while instance_deleted == False and (time.time() - start_time) < timeout:
                    tmp_inst = self.driver.shell.nova_manager.servers.findall(id=inst.id)
                    if not tmp_inst:
                        instance_deleted = True
                    time.sleep(.5)
                manager.delete_security_group(security_group)

        multiclient = MultiClient()
        tenant = self.driver.shell.auth_manager.tenants.find(id=instance.tenant_id)  
        self.driver.shell.nova_manager.connect(tenant=tenant.name)
        args = {'name': instance.name,
                'id': instance.id}
        instances = self.driver.shell.nova_manager.servers.findall(**args)
        security_group_manager = SecurityGroup(self.driver)
        for instance in instances:
            # destroy instance
            self.driver.shell.nova_manager.servers.delete(instance)
            # deleate this instance's security groups
            multiclient.run(_delete_security_group, instance)
        return 1
示例#4
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
        }            
示例#5
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
        }            
示例#6
0
    def Renew(self, api, xrn, creds, expiration_time, options):
        call_id = options.get('call_id')
        if Callids().already_handled(call_id): return True

        def _Renew(aggregate, server, xrn, creds, expiration_time, options):
            try:
                result=server.Renew(xrn, creds, expiration_time, options)
                if type(result)!=dict:
                    result = {'code': {'geni_code': 0}, 'value': result}
                result['aggregate'] = aggregate
                return result
            except:
                logger.log_exc('Something wrong in _Renew with URL %s'%server.url)
                return {'aggregate': aggregate, 'exc_info': traceback.format_exc(),
                        'code': {'geni_code': -1},
                        'value': False, 'output': ""}

        # get the callers hrn
        valid_cred = api.auth.checkCredentials(creds, 'renewsliver', xrn)[0]
        caller_hrn = Credential(cred=valid_cred).get_gid_caller().get_hrn()

        # attempt to use delegated credential first
        cred = api.getDelegatedCredential(creds)
        if not cred:
            cred = api.getCredential(minimumExpiration=31*86400)
        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)
            multiclient.run(_Renew, aggregate, server, xrn, [cred], expiration_time, options)

        results = multiclient.get_results()

        geni_code = 0
        geni_output = ",".join([x.get('output',"") for x in results])
        geni_value = reduce (lambda x,y: x and y, [result.get('value',False) for result in results], True)
        for agg_result in results:
            agg_geni_code = agg_result['code'].get('geni_code',0)
            if agg_geni_code:
                geni_code = agg_geni_code

        results = {'aggregates': results, 'code': {'geni_code': geni_code}, 'value': geni_value, 'output': geni_output}

        return results
示例#7
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
        }  
示例#8
0
    def Status(self, api, slice_xrn, creds, options):
        def _Status(server, xrn, creds, options):
            return server.Status(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 (_Status, server, slice_xrn, [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['geni_slivers']]
    
        # do not try to combine if there's no result
        if not results : return {}
    
        # otherwise let's merge stuff
        geni_slivers = []
        geni_urn  = None
        for result in results:
            try:
                geni_urn = result['geni_urn']
                geni_slivers.extend(result['geni_slivers'])
            except:
                api.logger.log_exc("SM.Provision: Failed to merge aggregate rspec")
        return {
            'geni_urn': geni_urn,
            'geni_slivers': geni_slivers
        }
示例#9
0
 def PerformOperationalAction(self, api, xrn, creds, action, options):
     # get the callers hrn
     valid_cred = api.auth.checkCredentials(creds, 'createsliver', xrn)[0]
     caller_hrn = Credential(cred=valid_cred).get_gid_caller().get_hrn()
 
     # attempt to use delegated credential first
     cred = api.getDelegatedCredential(creds)
     if not cred:
         cred = api.getCredential()
     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)    
         multiclient.run(server.PerformOperationalAction, xrn, [cred], action, options)
     multiclient.get_results()    
     return 1
示例#10
0
 def Shutdown(self, api, xrn, creds, options={}):
     xrn = Xrn(xrn)  
     # get the callers hrn
     valid_cred = api.auth.checkCredentials(creds, 'stopslice', xrn.hrn)[0]
     caller_hrn = Credential(cred=valid_cred).get_gid_caller().get_hrn()
 
     # attempt to use delegated credential first
     cred = api.getDelegatedCredential(creds)
     if not cred:
         cred = api.getCredential()
     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)
         multiclient.run(server.Shutdown, xrn.urn, cred)
     multiclient.get_results()    
     return 1
示例#11
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
        }
示例#12
0
     cached_requested = options.get('cached', True)
     if not xrn and self.cache and cached_requested:
         rspec =  self.cache.get(version_string)
         if rspec:
             api.logger.debug("SliceManager.ListResources returns cached advertisement")
             return rspec
 
     # get the callers hrn
     valid_cred = api.auth.checkCredentials(creds, 'listnodes', hrn)[0]
     caller_hrn = Credential(cred=valid_cred).get_gid_caller().get_hrn()
 
     # attempt to use delegated credential first
     cred = api.getDelegatedCredential(creds)
     if not cred:
         cred = api.getCredential()
     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
 
         # get the rspec from the aggregate
         interface = api.aggregates[aggregate]
         server = api.server_proxy(interface, cred)
         multiclient.run(_ListResources, aggregate, server, [cred], options)
 
 
     results = multiclient.get_results()
     rspec_version = version_manager.get_version(options.get('geni_rspec_version'))
     if xrn: