def update(self, provisioning = False, attributes = None): """ deploy updated SICs. """ LOG.debug('Executing update deployment logic') # Check if attributes are being updated if attributes: if 'mcn.endpoint.maas' in attributes: self.maas_endpoint = str(attributes['mcn.endpoint.maas']) if 'mcn.endpoint.mobaas' in attributes: self.mobaas_endpoint = str(attributes['mcn.endpoint.mobaas']) # Get new template generator = icnaas.template_generator.ICNaaSTemplateGenerator(self.routers, self.maas_endpoint, \ self.mobaas_endpoint) template = generator.generate(provisioning, FMC_ENABLED) # Wait for any pending operation to complete while (True): if self.stack_id is not None: tmp = self.deployer.details(self.stack_id, self.token) if tmp['state'] == 'CREATE_COMPLETE' or tmp['state'] == 'UPDATE_COMPLETE': break else: time.sleep(10) # Deploy new template if self.stack_id is not None: self.deployer.update(self.stack_id, template, self.token) # Mark as updated for SOD self.updated = True
def run(self): """ Decision part implementation goes here. """ while True: # It is unlikely that logic executed will be of any use until the provisioning phase has completed LOG.debug('Waiting for deploy and provisioning to finish') self.event.wait() LOG.debug('Starting runtime logic...') # Decision logic # Until service instance is destroyed while self.so_e.stack_id is not None: # Check if update is complete while True: tmp = self.so_e.deployer.details(self.so_e.stack_id, self.so_e.token) if tmp['state'] == 'UPDATE_COMPLETE': break else: time.sleep(10) # Set updated back to False self.so_e.updated = False # Update the information about CCNx routers self.so_e.state() # Then, attempt to connect to MaaS self.monitor = icnaas.monitor.ICNaaSMonitorCCNRouter(self.so_e.maas_endpoint) # Afterwards, keep checking the metrics until service is updated while not self.so_e.updated: self.check_metrics() for i in range(0, 6): if self.so_e.updated: break time.sleep(10) self.event = ready_event
def checkRequirementsDependencies(requirements=[], service_instances=[]): for requirement in requirements: try: counter = 0 LOG.debug("Check dependencies for requirement \"%s\"." % requirement.name) for service_instance in service_instances: if requirement.source == service_instance.name: LOG.debug("source \"%s\" was found." % requirement.source) if requirement.parameter == 'private_ip' or requirement.parameter == 'public_ip': LOG.debug("parameter \"%s\" is available." % requirement.parameter) for obj in service_instance.networks: if requirement.obj_name == obj.name: LOG.debug("obj_name \"%s\" was found." % requirement.obj_name) counter += 1 else: raise InvalidInputException("parameter:\"%s\" is not available." % requirement.parameter) if counter == 0: raise NotFoundException("requirement:\"%s\" was not found (\"source:%s\", \"obj_name:%s\")." % ( requirement.name, requirement.source, requirement.obj_name)) elif counter == 1: LOG.debug("requirement \"%s\" is valid." % requirement.name) else: raise InvalidInputException("is not valid. Found sources or objects several times.") except Exception, exc: exc.message = 'Requirement:\"%s\"->%s' % (requirement.name, exc.message) raise exc
def state(self): """ Report on state. """ # TODO ideally here you compose what attributes should be returned to the SM # In this case only the state attributes are returned. resolver_state = self.resolver.state() LOG.info('Resolver state:') LOG.info(resolver_state.__repr__()) if self.stack_id is not None: tmp = self.deployer.details(self.stack_id, self.token) # Update routers dictionary and service endpoint if tmp.get('output', None) is not None: for i in tmp['output']: # CCNx Router IP if i['output_key'].startswith('mcn.ccnx'): router_id = i['output_key'].split('.')[2][6:] self.routers[int(router_id)]['public_ip'] = str(i['output_value']) # ICNaaS Service Endpoint elif i['output_key'] == 'mcn.endpoint.icnaas': self.endpoint = 'http://' + str(i['output_value']) + ':5000' i['output_value'] = self.endpoint return tmp['state'], self.stack_id, tmp['output'] else: return tmp['state'], self.stack_id, None else: return 'Unknown', 'N/A'
def checkNetworksUniqueness(networks): LOG.debug("\"Check uniqueness of networks.\"") for network in networks: for comp_network in networks: if network.name == comp_network.name and network != comp_network: raise NotUniqueException("network:\"%s\" is not unique." % network.name) LOG.debug("network \"%s\" is unique." % network.name)
def check(action=None, alarm=None, flavor=None, image=None, key=None, network=None, policy=None, security_group=None, service=None, service_instance=None, service_type=None, topology=None, unit=None): try: if action: checkAction(action) if alarm: checkAlarm(alarm) if flavor: checkFlavor(flavor) if image: checkImage(image) if key: checkKey(key) if network: checkNetwork(network) if policy: checkPolicy(policy) if security_group: checkSecurityGroupUniqueness(security_group) checkSecurityGroup(security_group) if service: checkServiceUniqueness(service) checkService(service) if service_instance: checkServiceInstance(service_instance) if service_type: checkServiceType(service_type) if topology: checkTopolgoyUniqueness(topology) checkTopology(topology) if unit: checkUnit(unit) except Exception, exc: LOG.exception(exc) raise
def checkPoliciesUnqiueness(policies): LOG.debug("Check uniqueness of policies.") for policy in policies: for comp_policy in policies: if policy.name == comp_policy and policy != comp_policy: raise NotUniqueException("policy:\"%s\" is not unique." % policy.name) LOG.debug("policy \"%s\" is unique." % policy.name)
def checkTopolgoyUniqueness(topology): db = DatabaseManager() # check names LOG.debug("Check uniqueness of name of the toplogy \"%s\"." % topology.name) for top in db.get_all(Topology): if topology.ext_name == top.ext_name and topology.id != top.id: raise NotUniqueException("Topology name \"%s\" is already used." % topology.name)
def update(self, attributes): """ It configures a running EPCaaS using parameters passed by SM. :param attributes: is a dict that contains the OCCI attributes passed by SM (X-OCCI-ATTRIBUTE) """ LOG.debug("Executing update/provisioning logic") stack_state, stack_id, output = self.state() if not (stack_state == "CREATE_COMPLETE" or stack_state == "UPDATE_COMPLETE"): LOG.debug("Stack is not in a stable state a.t.m.. Retry") return False confg = Configurator( token=self.token, tenant=self.tenant_name, region=self.region_name, sm_parameters=self.sm_parameters, conf_param=self.conf_param, attributes=attributes, epc_config=self.epc_config, output=output, event=self.event, ) # XXX no management of this thread is done confg.start()
def design(self): LOG.info("designing stack") """ Do initial design steps here. """ LOG.info('Entered design() - nothing to do here')
def provision(self): """ (Optional) if not done during deployment - provision. """ LOG.debug('Executing resource provisioning logic') # once logic executes, deploy phase is done self.event.set()
def provision(self): # super(SOEExtn, self).provision() # TODO check that the provision descriptor is present # TODO: refactor this to: for region_name, region in self.service_manifest['resources'].iteritems() for region in self.service_manifest['resources'].keys(): if len(self.service_manifest['resources'][region]['stack_id']) > 0: self.service_manifest['resources'][region]['client'].update(self.service_manifest['resources'][region]['stack_id'], self.service_manifest['resources'][region]['provision'], self.token) LOG.info('Stack ID: ' + self.service_manifest['resources'][region]['stack_id']) if self.db: # persist data document_filter = { "_id": self.service_manifest['resources'][region]['stack_id'], "region": region } data = { "_id": self.service_manifest['resources'][region]['stack_id'], "token": self.token, "region": region, "provision": self.service_manifest['resources'][region]['provision'] } current = self.db.find_one(document_filter) if not current: self.db.insert(data) else: self.db.update_one(document_filter, { "$set": { 'provision': data['provision'], 'token': data['token'] } })
def get_endpoint(service_type, endpoint_type=None,region_name=None): from clients import keystone # ##Init keystone client ksclient = keystone.Client() endpoint = ksclient.get_endpoint(service_type=service_type, endpoint_type=endpoint_type, region_name=region_name) LOG.debug("endpoint for service_type %s is %s" %(service_type,endpoint,)) return endpoint
def provision(self): """ Provision SICs Run scripts. """ LOG.info('Calling provision...') stack_outputs =\ self.deployer.details(self.stack_id, self.token)['output'] # Store host IPs in a dictionary (host_ips), # where key = $(HOST_NAME)_{external, private}_ip # e.g. ralf public ip => host_ips['ralf_external_ip'] # e.g. dns private ip => host_ips['dns_private_ip'] self.host_ips = {} for o in stack_outputs: self.host_ips[o['output_key']] = o['output_value'] LOG.info('Host IPs: %s' % self.host_ips) # Create temporary PEM file self._save_file(self.pem_path, self._get_private_key()) # Provision DNS self._provision_dns() # Provision ClearWater components components = ['homer', 'homestead', 'sprout', 'bono', 'ellis', 'ralf'] processes = {} for c in components: processes[c] = Process(target=self._provision_cw_comp, args=(c,)) processes[c].start() for k in processes.keys(): processes[k].join() self._delete_file(self.pem_path)
def __init__(self, token, tenant): # this python thread event is used to notify the SOD that the runtime phase can execute its logic self.event = threading.Event() self.so_e = SOE(token=token, tenant=tenant, ready_event=self.event) self.so_d = SOD(so_e=self.so_e, token=token, ready_event=self.event) LOG.debug('Starting SOD thread...') self.so_d.start()
def __init__(self, so_e, token, tenant_name, ready_event, stop_event): # super(EPCSODecision, self).__init__(so_e, token, tenant_name) service_orchestrator.Decision.__init__(self, so_e, token, tenant_name) threading.Thread.__init__(self) self.ready_event = ready_event self.stop_event = stop_event self.so_e = so_e self.token = token self.pol_eng = PolicyEngine() self.scaling_allowed = True # self.scaleout_triggered = True # self.scaleout_success = True # self.scalein_triggered = True # self.scalein_success = True # time.time() when last MME scaling (up/down) occured self.last_mme_scaling_time = 0 # time.time() when last GW scaling (up/down) occured self.last_gw_scaling_time = 0 self.num_of_mme = 1 self.num_of_gw = 1 LOG.debug("EPC SO Decision init")
def state(self): """ Report on state. """ LOG.info("retrieving state of the running stack with id %s" % self.stack_id) # LOG.info('Resolver state:') # LOG.info(resolver_state.__repr__()) if self.stack_id is not None: topology = TopologyOrchestrator.get(self.stack_id) stk = self.deployer.details(topology.ext_id) res = {'state': stk['stack_status'], 'name': stk['stack_name'], 'id': stk['id']} if 'outputs' in stk: res['output'] = stk['outputs'] output = '' try: output = res['output'] except KeyError: pass LOG.debug(" state %s, output %s"%(res['state'],output)) return res['state'], str(self.stack_id), output else: return 'CREATE_COMPLETE', 'N/A', ''
def provision(self, attributes): """ Takes care of the provisioning of a deployed instance of OpenEPC It calls the service-specific, implementation-specific method to actually configure service parameters on the SIC :param attributes: OCCI attributes passed by SM. Must match the attributes definition of the service in the SM. E.g. in this way the SM can pass to a SO parameters to be used in the config call. This is useful when an higher level SM, e.g. an E2E SM, manages also one or more support services, like DNSaaS or MaaS. The E2E SM will pass the EPCaaS SM the relevant parameters of the support services, like e.g. IP address for managing a MaaS. """ # SR 16/6/2015: currently empty, # since the epcaas VMs will be configured when the MaaS and DNSaaS ip # addresses will be available, namely when update is called from the # SM. LOG.debug("Executing provisioning logic") # NOTE: change this when real params are passed to config # parameters = attributes # if self.epc_config.config(parameters=parameters) != 0: # LOG.debug('Provisioning failed') pass
def provision(self): """ (Optional) if not done during deployment - provision. """ LOG.info('Calling provision') super(SOE, self).provision()
def update(self, provisioning = False, attributes = None): """ deploy updated SICs. """ LOG.debug('Executing update deployment logic') # Check if attributes are being updated if attributes: if 'mcn.endpoint.maas' in attributes: self.maas_endpoint = str(attributes['mcn.endpoint.maas']) # Get new template templ_file = open(os.path.join(BUNDLE_DIR, 'data', 'influxdb-cyclops.yaml'), 'r') self.graph = templ_file.read() # Wait for any pending operation to complete while (True): if self.stack_id is not None: tmp = self.deployer.details(self.stack_id, self.token) if tmp['state'] == 'CREATE_COMPLETE' or tmp['state'] == 'UPDATE_COMPLETE': break else: time.sleep(10) # Deploy new template if self.stack_id is not None: self.deployer.update(self.stack_id, self.graph, self.token) # Mark as updated for SOD self.updated = True
def set_ips(self, unit, ext_id): """ Sets the fixed- and floating-ips of the given unit. :param unit: the to be processed unit :param ext_id: id of the stack containing the unit """ timeout = time.time() + 60 * 5 while True: template = self.client.stacks.get(ext_id).to_dict() if u"outputs" in template or time.time() > timeout: LOG.debug("outputs: " + str(template["outputs"])) break else: time.sleep(10) for ip in template["outputs"]: if ip["output_key"].split(".")[2] == unit.hostname: if ip["output_key"].endswith("public"): k = ip["output_key"].split(".")[-2] unit.floating_ips[k] = ip["output_value"] LOG.debug(ip["output_value"] + " is a floating ip") elif ip["output_key"].endswith("private"): k = ip["output_key"].split(".")[-2] unit.ips[k] = ip["output_value"] LOG.debug(ip["output_value"] + " is a fixed ip") LOG.debug("ips: " + str(unit.ips)) LOG.debug("floating_ips: " + str(unit.floating_ips))
def create_tables(engine): """ Drop all and recreate """ LOG.debug("drop and create tables") Base.metadata.drop_all(engine) Base.metadata.create_all(engine)
def run(self): """ Decision part implementation goes here. """ self.hosts_cpu_load.append(MyList()) self.hosts_cpu_util.append(MyList()) self.hosts_memory.append(MyList()) while True: LOG.debug('Waiting for deploy and provisioning to finish') self.event.wait() LOG.debug('Starting runtime logic...') # Decision logic # Until service instance is destroyed while self.so_e.stack_id is not None: # Check if update is complete while True: #tmp = self.so_e.deployer.details(self.so_e.stack_id, self.so_e.token) tmp = self.so_e.state() if tmp[0] == 'UPDATE_COMPLETE': break else: time.sleep(myparameters.STACK_CREATION_UPDATE) # Set updated back to False self.so_e.updated = False # Update the information about CCNx routers self.so_e.state() # Monitor the resources self.monitoring() self.event = ready_event
def state(self): """ Report on state. """ state = "Unknown" svc_insts = "None" insts = "" resolver_state = self.resolver.state() LOG.info("Resolver state:" + resolver_state.__repr__()) # XXX might there be the case where the value is just CREATE_COMPLETE? try: for key in resolver_state.keys(): if str(resolver_state[key]["occi.mcn.stack.state"]) != "UPDATE_COMPLETE": state = "Unknown" break else: state = resolver_state[key]["occi.mcn.stack.state"] insts = insts + key + " " svc_insts = insts[0:-1] except KeyError: pass return state, svc_insts
def deploy(self): """ deploy SICs. """ LOG.debug('Executing deployment logic') if self.stack_id is None: self.stack_id = self.deployer.deploy(self.template, self.token)
def __init__(self, token, tenant): # this python thread event is used to notify the SOD that the runtime phase can execute its logic self.event = threading.Event() self.so_e = ServiceOrchestratorExecution(token, tenant, self.event) self.so_d = ServiceOrchestratorDecision(self.so_e, token, self.event) LOG.debug('Starting SOD thread...') self.so_d.start()
def list_net(self): res = [] LOG.debug('Requesting list of networks...') lst = self.neutron.list_networks() for net in lst.get('networks'): res.append(Network(net.get('name'), net.get('id'), net.get('router:external'))) return res
def state(self): # super(SOEExtn, self).state() stack_state = '' stack_ids = '' outputs = [] for region in self.service_manifest['resources'].keys(): tmp = self.service_manifest['resources'][region]['client'].details(self.service_manifest['resources'][region]['stack_id'], self.token) LOG.info('Returning Stack output state') # for stack state, we return the least successful one # e.g. one stack "CREATE_COMPLETED', one "CREATE_FAILED" -> we return CREATE_FAILED # one stack with "CREATE_IN_PROGRESS", one "CREATE_COMPLETED" -> we return CREATE_IN_PROGRESS # successful_states = ['CREATE_COMPLETE', 'UPDATE_COMPLETE'] ongoing_states = ['CREATE_IN_PROGRESS', 'UPDATE_IN_PROGRESS'] failed_states = ['CREATE_FAILED', 'UPDATE_FAILED'] no_state = [''] current_state = tmp['state'] if stack_state == '': stack_state = current_state else: # we already have a state present... if current_state in successful_states: # no need to write a successful state back pass if current_state in ongoing_states: # if the saved state is 'better', overwrite if stack_state in successful_states: stack_state = current_state if current_state in failed_states: # if the saved state is 'better', overwrite if stack_state in successful_states or stack_state in ongoing_states: stack_state = current_state # for stack_id, we concat them together with their region-names: # region1:stack-id1,region2:stack-id2 if len(stack_ids) == 0: stack_ids = '%s:%s' % (region, self.service_manifest['resources'][region]['stack_id']) else: stack_ids = '%s,%s:%s' %(stack_ids, region, self.service_manifest['resources'][region]['stack_id']) # for stack_output, we add the region name at the end of every key # a.b.c in region 1 becomes a.b.c.region1 try: current_outputs = tmp['output'] for output in current_outputs: outputs.append({ 'output_key': '%s.%s' % (output['output_key'], region.replace(' ', '')), 'output_value': output['output_value'] }) except KeyError: pass return stack_state, stack_ids, outputs
def dispose(self): """ Dispose SICs. """ LOG.info('Calling dispose') if self.stack_id is not None: self.deployer.dispose(self.stack_id, self.token) self.stack_id = None
def dispose(self): """ Dispose SICs. """ LOG.debug('Executing disposal logic') if self.stack_id is not None: self.deployer.dispose(self.stack_id, self.token) self.stack_id = None
def __init__(self, token, tenant): # when provisioning is complete then only the run functionality can execute self.provision_event = threading.Event() # when soe.destroy is called this signals to stop the billing cycle self.destroy_event = threading.Event() self.so_e = SOE(token=token, tenant=tenant, ready_event=self.provision_event, destroy_event=self.destroy_event) self.so_d = SOD(so_e=self.so_e, tenant=tenant, token=token, ready_event=self.provision_event, destroy_event=self.destroy_event) LOG.debug('Starting SOD thread...') self.so_d.start()
def dispose(self): """ Dispose SICs. """ LOG.info('Disposing of 3rd party service instances...') self.resolver.dispose() if self.stack_id is not None: LOG.info('Disposing of resource instances...') self.deployer.dispose(self.stack_id, self.token) self.endpoint = None self.maas_endpoint = None self.routers = { 1: { 'public_ip': 'unassigned', 'layer': 0, 'cell_id': 200, \ 'provisioned': False, 'scale_in_count': 0, 'scale_out_count': 0 }, \ 2: { 'public_ip': 'unassigned', 'layer': 1, 'cell_id': 0, \ 'provisioned': False, 'scale_in_count': 0, 'scale_out_count': 0 } } self.stack_id = None
def state(self): """ Get the current state of a stack, if deployed """ LOG.debug('Executing state retrieval logic') if self.stack_id is not None: tmp = self.deployer.details(self.stack_id, self.token) try: output = tmp['output'] LOG.debug('State: ' + tmp['state']) return tmp['state'], self.stack_id, output except KeyError: # LOG.debug('************* KeyError raised ****************') return tmp['state'], self.stack_id, '' else: return 'Unknown', 'N/A', ''
def run(self): """ Decision part implementation goes here. """ LOG.debug('AAAaaS SOD - Waiting for deploy and provisioning to finish') self.ready_event.wait() LOG.debug('AAAaaS SOD - Starting runtime logic...') # RUN-TIME MANAGEMENT while not self.stop_event.isSet(): event_is_set = self.stop_event.wait(self.time_wait) if self.so_e.dns_info_configured is not True and self.so_e.dns_api is not None: res_Openam = False res_Profile = False state, stack_id, stack_output = self.so_e.state() if stack_output is not None: for line in stack_output: if line['output_key'] == 'mcn.endpoint.aaa-profile-instance': self.so_e.recInfoProfile = str(line['output_value']) res_Openam = self.perform_dnsconf(self.so_e.dnsaas, self.so_e.aaaDomainName, self.so_e.recProfile, self.so_e.recInfoProfile) if line['output_key'] == 'mcn.endpoint.aaa-openam-instance': self.so_e.recInfoOpenam = str(line['output_value']) res_Profile = self.perform_dnsconf(self.so_e.dnsaas, self.so_e.aaaDomainName, self.so_e.recOpenam, self.so_e.recInfoOpenam) if res_Openam and res_Profile: self.so_e.dns_info_configured = True LOG.info('DNS information for AAA configured') self.time_wait = self.so_e.time_wait_after_dns #wait more work is done if self.stop_event.isSet(): LOG.debug('AAAaaS SOD - STOP event set after disposal') if self.so_e.dns_info_configured: res_Openam = self.remove_dnsconf(self.so_e.dnsaas, self.so_e.aaaDomainName, self.so_e.recProfile, self.so_e.recInfoProfile) res_Profile = self.remove_dnsconf(self.so_e.dnsaas, self.so_e.aaaDomainName, self.so_e.recOpenam, self.so_e.recInfoOpenam) if res_Openam and res_Profile: self.so_e.dns_info_configured = True LOG.info('DNS information remove successfully!')
def remove_dnsconf(self, dnsaas, domain, record, info_rec, rec_type='A'): if dnsaas is not None: LOG.info('Remove Record ' + record + ' domain=' + domain + ' info_rec=' + info_rec) result = -1 while (result != 1): time.sleep(1) result = dnsaas.delete_record(domain, record, rec_type, self.token) try: if result.get('status', None) is not None: if(result['status'] == '404'): break except: break return True else: LOG.info('Something wrong dnsaasclient not set!') return False
def __init__(self, token, tenant_name): """ Constructor """ super(SoExecution, self).__init__(token, tenant_name) # by default self.topology_type = "topology-maas-bern.json" self.token = token self.tenant_name = tenant_name self.stack_id = None self.maas = None self.location = 'bern' # make sure we can talk to deployer... LOG.debug("sending request to the url %s" % os.environ['DESIGN_URI']) self.conf = sys_util().get_sys_conf() LOG.debug("instantiating deployer %s" % self.conf['deployer']) self.deployer = None
def set_ips(self, unit): for k, v in self.nova.servers.get(unit.ext_id).networks.iteritems(): for ip in v: try: unit.floating_ips[k] = self.get_floating_ip(ip).ip LOG.debug(ip + " is a floating ip") except NotFoundException as e: unit.ips[k] = ip LOG.debug(ip + " is a fixed ip") LOG.debug("ips: " + str(unit.ips)) LOG.debug("floating_ips: " + str(unit.floating_ips))
def get_ports(self, unit): ports = [] lst = self.neutron.list_ports() for pt in lst.get('ports'): for subnet, ip in unit.ips.iteritems(): for net in pt.get('fixed_ips'): if ip == net.get('ip_address'): ips = {net.get('subnet_id'): ip} p = Port(pt.get('name'), pt.get('id'), pt.get('mac_address'), ips=ips) LOG.debug("Adding port " + str(p) + " to unit " + unit.hostname) ports.append(p) for subnet, ip in unit.floating_ips.iteritems(): for net in pt.get('fixed_ips'): if ip == net.get('ip_address'): ips = {net.get('subnet_id'): ip} p = Port(pt.get('name'), pt.get('id'), pt.get('mac_address'), ips=ips) LOG.debug("Adding port " + str(p) + " to unit " + unit.hostname) ports.append(p) return ports
def get_credentials(): # print "Fetch credentials from environment variables" creds = {} # creds['tenant_name'] = os.environ.get('OS_TENANT_NAME', '') # creds['username'] = os.environ.get('OS_USERNAME', '') # creds['password'] = os.environ.get('OS_PASSWORD', '') # creds['auth_url'] = os.environ.get('OS_AUTH_URL', '') # print 'Credentials: %s' % creds # ##Fetch Credentials from Configuration LOG.debug("Fetch Credentials from SysUtil") conf = SysUtil().get_sys_conf() # conf = DatabaseManager().get_by_name(Configuration, "SystemConfiguration")[0] #print "props: %s" % conf.props creds['tenant_name'] = conf.get('os_tenant', '') creds['username'] = conf.get('os_username', '') creds['password'] = conf.get('os_password', '') creds['auth_url'] = conf.get('os_auth_url', '') LOG.debug('Credentials: %s' % creds) return creds
def state(self): """ Report on state. """ LOG.debug('Executing state retrieval logic') if self.stack_id is not None: tmp = self.deployer.details(self.stack_id, self.token) #if tmp['output'] is not None: if tmp.get('output', None) is not None: for i in tmp['output']: if i['output_key'] == 'mcn.endpoint.mobaas': self.endpoint = 'http://' + str( i['output_value']) + ':5000' i['output_value'] = self.endpoint print 'Endpoint is: ' + self.endpoint return tmp['state'], self.stack_id, tmp['output'] else: return tmp['state'], self.stack_id, None return 'Unknown', 'N/A'
def update_topology_state(self): #get stack details and set the topology state try: stack_details = self.heatclient.show(stack_id=self.topology.ext_id) LOG.debug('Stack details of %s: %s' % (self.topology.ext_name, stack_details)) old_state = self.topology.state old_detailed_state = self.topology.detailed_state if stack_details: self.topology.state = translate( stack_details.get('stack_status'), HEAT_TO_EMM_STATE) self.topology.detailed_state = stack_details.get( 'stack_status_reason') if old_state != self.topology.state or old_detailed_state != self.topology.detailed_state: self.db.update(self.topology) except Exception, exc: LOG.exception(exc) self.topology.state = 'ERROR' raise
def provision(self, attributes=None): """ (Optional) if not done during deployment - provision. """ self.resolver.provision() LOG.debug('ICN SO provision - Getting EPs') for ep_entity in self.resolver.service_inst_endpoints: for item in ep_entity: if 'mcn.endpoint.mobaas' in item['attributes']: self.mobaas_endpoint = item['attributes'][ 'mcn.endpoint.mobaas'] # EP is only the IP if self.mobaas_endpoint is not None and self.mobaas_endpoint.startswith( 'http'): self.mobaas_endpoint = self.mobaas_endpoint.split('/')[2].split( ':')[0] LOG.info( 'Now I can provision my resources once my resources are created. Service info:' ) LOG.info(self.resolver.service_inst_endpoints) # Wait for create/update to be completed while (True): if self.stack_id is not None: tmp = self.deployer.details(self.stack_id, self.token) if tmp['state'] == 'CREATE_COMPLETE' or tmp[ 'state'] == 'UPDATE_COMPLETE': break else: time.sleep(10) LOG.debug('Executing resource provisioning logic') # XXX note that provisioning of external services must happen before resource provisioning # Get endpoint of MaaS if attributes: #print attributes if 'mcn.endpoint.maas' in attributes: self.maas_endpoint = str(attributes['mcn.endpoint.maas']) if 'mcn.endpoint.mobaas' in attributes: self.mobaas_endpoint = str(attributes['mcn.endpoint.mobaas']) # Update stack self.update(True) # Mark all routers as provisioned for r in self.routers: self.routers[r]['provisioned'] = True # once logic executes, deploy phase is done self.event.set()
def design(self): """ Do initial design steps here. """ LOG.debug('Executing design logic') self.resolver.design() # Create topology routers_count = 0 init_cell_id = 200 for layer in range(NUM_LAYERS): self.layers[layer] = { 'cpu_scale_in_count': 0, 'cpu_scale_out_count': 0, \ 'int_scale_in_count': 0, 'int_scale_out_count': 0 } for i in range(1, NUM_ROUTERS_LAYER + 1): routers_count += 1 cell_id = 0 if layer == 0: cell_id = init_cell_id init_cell_id += 1 self.routers[routers_count] = { 'public_ip': 'unassigned', 'layer': layer, \ 'cell_id': cell_id, 'provisioned': False }
def state(self): """ Report on state of the stack """ if self.stack_id is not None: tmp = self.deployer.details( self.stack_id, self.token) stack_state = tmp['state'] LOG.info('Returning stack output') # XXX type should be consistent output = '' try: output = tmp['output'] except KeyError: pass return stack_state, self.stack_id, output else: LOG.info('Stack output: none - Unknown, N/A') return 'Unknown', 'N/A', None
def deploy(self): """ deploy SICs. """ LOG.debug('Executing deployment logic') if self.stack_id is None: username = '' password = '' if username == '' or password == '': raise RuntimeError( 'No username or password set. Please set one') self.stack_id = self.deployer.deploy(self.template, self.token, parameters={ 'UserName': username, 'Password': password }) LOG.info('Resource dependencies - stack id: ' + self.stack_id)
def dispose(self): """ Dispose SICs. """ # LOG.info('Disposing of 3rd party service instances...') # self.resolver.dispose() if self.stack_id is not None: LOG.info('Disposing of resource instances...') self.deployer.dispose(self.stack_id, self.token) self.stack_id = None # TODO on disposal, the SOE should notify the SOD to shutdown its thread # Removing users, alarm-def rt = runtime.Monasca(self.token, self.tenant, auth_url=os.environ['DESIGN_URI']) rt.delete_user(self.mon_id) for n_id in self.mon_not_ids: rt.dispose_monasca(n_id)
def __init__(self, token, tenant_name, region_name): """ Initialize the EPC Service Orchestrator object. """ # this python thread event is used to notify the SOD that the # runtime phase can execute its logic self.ready_event = threading.Event() # this python thread event is used to notify the SOD to stop runtime # phase after a delete(and end the thread) self.stop_event = threading.Event() self.so_e = EPCSOExecution(token, tenant_name, self.ready_event, self.stop_event, region_name=region_name) self.so_d = EPCSODecision(self.so_e, token, tenant_name, self.ready_event, self.stop_event) LOG.debug('Starting SOD thread...') self.so_d.start()
def update(cls, new_topology_args, old_topology): conf = sys_util().get_sys_conf() db = FactoryAgent().get_agent(conf['database_manager']) topology_manager = FactoryAgent().get_agent(conf['topology_manager']) checker = FactoryAgent().get_agent(conf['checker']) if old_topology.state in ['DEPLOYED','UPDATED']: old_topology.state = 'UPDATING' else: raise ActionInProgressException('Cannot update topology while another action is in progress. Topology state is \"%s\".' % old_topology.state) db.update(old_topology) try: new_topology = topology_manager.create(new_topology_args) checker.check(topology=new_topology) updated_topology = topology_manager.update(new_topology, old_topology) #checker.check(topology=updated_topology) db.update(updated_topology) except Exception, exc: LOG.exception(exc.message) raise exc
def run(self): LOG.debug("Starting new thread") i = 0 while i < 18: for service_instance in self.topology.service_instances: for unit in service_instance.units: if i == 0: unit.state = 'Initialised' else: unit.state = 'Started' dbm_name = SysUtil().get_sys_conf()['database_manager'] db = FactoryAgent.get_agent(dbm_name) db.update(unit) # conf = SysUtil().get_sys_conf().props # runtime_agent = FactoryAgent().get_agent(conf['runtime_agent']) # runtime_agent.run(self.topology) if i > 1: return time.sleep(2) i += 1 LOG.error("Can't get info on the units after 180 seconds, is there a problem?")
def state(self): """ Report on state for both stacks in site_A and site_B """ if (self.site_A_stack_id is not None and self.site_B_stack_id is not None): tmp = self.site_A_deployer.details(self.site_A_stack_id, self.token) site_A_stack_state = tmp['state'] LOG.info('Returning Stack output state of site_A') # XXX type should be consistent site_A_output = '' try: site_A_output = tmp['output'] except KeyError: pass tmp = self.site_B_deployer.details(self.site_B_stack_id, self.token) site_B_stack_state = tmp['state'] LOG.info('Returning Stack output state of site_B') site_B_output = '' try: site_B_output = tmp['output'] except KeyError: pass return [site_A_stack_state, site_B_stack_state ], [self.site_A_stack_id, self.site_B_stack_id], [site_A_output, site_B_output] else: LOG.info('Stack output: none - Unknown, N/A') return 'Unknown', 'N/A', None
def dispose(self): """ Dispose all SICs of a stack deployed. """ LOG.debug('Executing disposal logic') # stack_state, stack_id, output = self.state() # Dispose Maas, if created if self.maas is not None: LOG.debug('Disposing MaaS') util.dispose_maas(self.token, self.maas) # Dispose DNSaaS, if created if self.dnsaas is not None: LOG.debug('Disposing DNSaaS') util.dispose_dnsaas(self.token, self.dnsaas) # Dispose heat stack if self.stack_id is not None: self.deployer.dispose(self.stack_id, self.token) self.stack_id = None # on disposal, the SOE should notify the SOD to shutdown its thread self.stop_event.set()
def bill_start_events(self, client, log_server): start_billing_query = SearchQuery( search_range=self.sr, query='phase_event:done AND so_phase:provision') try: start_results = log_server.search(start_billing_query) LOG.debug('Number of start billing events found: ' + str(len(start_results.messages))) for start_event in start_results.messages: rcb_message = {} start_message = json.loads(start_event.message) rcb_message['service_type'] = start_message.get( 'sm_name', 'none') rcb_message['instance_id'] = start_message.get('so_id', 'none') rcb_message['tenant_id'] = start_message.get( 'tenant', 'mcntub') rcb_message['status'] = 'start' LOG.debug('Sending start billing event to RCB: ' + rcb_message.__repr__()) promise = client.basic_publish(exchange='mcn', routing_key='events', body=json.dumps(rcb_message)) client.wait(promise) except Exception as e: LOG.error( 'Cannot issue query to the log service to extract start events.' ) raise e
def dump_to_dict(self): resource = {} server_config = {} server_config['type'] = self.type properties = {} properties['name'] = self.name properties['image'] = self.image properties['flavor'] = self.flavor if self.key_name is not None: properties['key_name'] = self.key_name if self.availability_zone is not None: properties['availability_zone'] = self.availability_zone if self.network_ports is not None: networks = [] LOG.debug(self.network_ports) for network_port in self.network_ports: networks.append({'port': {'get_resource': network_port.name}}) properties['networks'] = networks if self.user_data: properties['user_data_format'] = 'SOFTWARE_CONFIG' server_config['properties'] = properties resource[self.name] = server_config return resource
def checkSize(size={}): if size.get('def'): if isinstance(size.get('def'), (long, int)): if size.get('def') > 0: LOG.debug("default size \"%s\" is valid." % size.get('def')) else: raise InvalidInputException( "default size:\"%s\" must be bigger than 0." % size.get('def')) else: raise TypeErrorException( "default size:\"%s\" must be an integer." % size.get('def')) else: raise NotDefinedException("default size is not defined.") if size.get('min'): if isinstance(size.get('min'), (long, int)): if size.get('min') > 0: LOG.debug("minimal size \"%s\" is valid." % size.get('min')) else: raise InvalidInputException( "minimal size:\"%s\" is not valid. minimal_size must be bigger than 0." % size.get('min')) else: raise TypeErrorException( "minimal size:\"%s\" must be an integer." % size.get('min')) else: raise NotDefinedException("minimal size is not defined.") if size.get('max'): if isinstance(size.get('max'), (long, int)): if size.get('max') > 0: LOG.debug("maximal size \"%s\" is valid." % size.get('max')) else: raise InvalidInputException( "maximal size:\"%s\" is not valid. maximal size must be bigger than 0." % size.get('max')) else: raise TypeErrorException( "maximal size:\"\%s\" must be an integer." % size.get('max')) else: raise NotDefinedException("maximal size is not defined.") if size.get('min') and size.get('max'): if size.get('min') <= size.get('max'): LOG.debug( "minimal size \"%s\" and maximal size \"%s\" are valid. minimal size is equal or lower than maximal size." % (size.get('min'), size.get('max'))) else: raise InvalidInputException( "minimal size:\"%s\" and maximal size:\"%s\" are not valid. minimal size must be equal or lower than maximal size." % (size.get('min'), size.get('max')))
def dispose(self, topology): # checker_thread = self.checker_thread # LOG.debug("Get RuntimeAgent for topology %s" % topology.id) # runtime_agent = self.runtime_agents.get(topology.id) #LOG.debug("Got RuntimeAgent: %s" % self.runtime_agent) stack_details = None topology.state = 'DELETING' self.db.update(topology) if self.runtime_agent: self.runtime_agent.stop(topology.id) try: stack_details = self.heatclient.delete(topology.ext_id) except HTTPNotFound, exc: exc.message = 'Topology \"%s\" was not found on OpenStack anymore. (%s)' % ( topology.name, exc.message) topology.state = 'DELETED' topology.detailed_state = exc.message self.db.update(topology) LOG.error(exc.message) raise exc except Exception, msg: LOG.error(msg) topology.state = 'ERROR'
def __init_services(self): LOG.debug("=============Add Services ===============") for file in os.listdir(os.path.join('%s/data/services/' % PATH)): LOG.debug("creating service from file %s" % file) f = open(os.path.join('%s/data/services/' % PATH, file)) config_file = f.read() f.close() json_file = config_file resp = ServiceOrchestrator.create(json.loads(json_file)) LOG.debug('response: %s' % resp)
def dispose(self): """ Dispose SICs """ LOG.info('Calling dispose...') if self.site_A_stack_id is not None: LOG.debug('Deleting stack: %s' % self.site_A_stack_id) self.site_A_deployer.dispose(self.site_A_stack_id, self.token) self.site_A_stack_id = None if self.site_B_stack_id is not None: LOG.debug('Deleting stack: %s' % self.site_B_stack_id) self.site_B_deployer.dispose(self.site_B_stack_id, self.token) self.site_B_stack_id = None
class FactoryServiceAdapter(object): @staticmethod def get_agent(module, cl, **kwargs): _package = "adapters" _module = module _class = cl LOG.debug("Instantiating %s from %s.%s"%(_class, _package,_module)) try: _loaded_module = __import__(name='%s.%s' % (_package,_module), fromlist=[_module]) except ImportError, exc: exc.message = 'FactoryServiceAdapter -> %s' % exc.message LOG.exception(exc) raise ImportError(exc.message) try: _loaded_class = getattr(_loaded_module, _class) except AttributeError, exc: exc.message = 'FactoryServiceAdapter -> %s' % exc.message LOG.exception(exc) raise AttributeError(exc.message)
def setup_amqp(self, amqp_url, client): LOG.debug('AMQP exchange declaration: mcn') promise = client.exchange_declare(exchange='mcn', type='topic', durable=True) client.wait(promise) LOG.debug('AMQP queue declaration: mcnevents') promise = client.queue_declare('mcnevents', durable=True) client.wait(promise) LOG.debug( 'AMQP queue/exchange binding: mcnevents->mcn Routing key: events') promise = client.queue_bind(queue='mcnevents', exchange='mcn', routing_key='events') client.wait(promise)