def __call__(self, environ, response): token = environ.get('HTTP_X_AUTH_TOKEN', '') if token == '': LOG.error('No X-Auth-Token header supplied.') raise HTTPError(400, 'No X-Auth-Token header supplied.') tenant = environ.get('HTTP_X_TENANT_NAME', '') if tenant == '': LOG.error('No X-Tenant-Name header supplied.') raise HTTPError(400, 'No X-Tenant-Name header supplied.') design_uri = CONFIG.get('service_manager', 'design_uri', '') if design_uri == '': LOG.fatal('No design_uri parameter supplied in sm.cfg') raise Exception('No design_uri parameter supplied in sm.cfg') auth = KeyStoneAuthService(design_uri) if not auth.verify(token=token, tenant_name=tenant): raise HTTPError( 401, 'Token is not valid. You likely need an updated token.') return self._call_occi(environ, response, token=token, tenant_name=tenant, registry=self.registry)
def __init__(self, app, srv_type=None): # openstack objects tracking the keystone service and endpoint self.srv_ep = None self.ep = None self.DEBUG = True self.app = app self.service_backend = ServiceBackend(app) LOG.info('Using configuration file: ' + CONFIG_PATH) self.token, self.tenant_name = self.get_service_credentials() self.design_uri = CONFIG.get('service_manager', 'design_uri', '') if self.design_uri == '': LOG.fatal('No design_uri parameter supplied in sm.cfg') raise Exception('No design_uri parameter supplied in sm.cfg') self.stg = None stg_path = CONFIG.get('service_manager', 'manifest', '') if stg_path == '': raise RuntimeError('No STG specified in the configuration file.') with open(stg_path) as stg_content: self.stg = json.load(stg_content) stg_content.close() if not srv_type: srv_type = self.create_service_type() self.srv_type = srv_type self.reg_srv = CONFIG.getboolean('service_manager_admin', 'register_service') if self.reg_srv: self.region = CONFIG.get('service_manager_admin', 'region', '') if self.region == '': LOG.info( 'No region parameter specified in sm.cfg, defaulting to an OpenStack default: RegionOne' ) self.region = 'RegionOne' self.service_endpoint = CONFIG.get('service_manager_admin', 'service_endpoint') if self.service_endpoint != '': LOG.warn( 'DEPRECATED: service_endpoint parameter supplied in sm.cfg! Endpoint is now specified in ' 'service manifest as service_endpoint') LOG.info('Using ' + self.stg['service_endpoint'] + ' as the service_endpoint value ' 'from service manifest') up = urlparse(self.stg['service_endpoint']) self.service_endpoint = up.scheme + '://' + up.hostname + ':' + str( up.port) + '/' + str('mobaas') LOG.info(self.service_endpoint)
def __init__(self, app, srv_type=None): # openstack objects tracking the keystone service and endpoint self.srv_ep = None self.ep = None self.DEBUG = True self.app = app self.service_backend = ServiceBackend(app) LOG.info("Using configuration file: " + CONFIG_PATH) self.token, self.tenant_name = self.get_service_credentials() self.design_uri = CONFIG.get("service_manager", "design_uri", "") if self.design_uri == "": LOG.fatal("No design_uri parameter supplied in sm.cfg") raise Exception("No design_uri parameter supplied in sm.cfg") self.stg = None stg_path = CONFIG.get("service_manager", "manifest", "") if stg_path == "": raise RuntimeError("No STG specified in the configuration file.") with open(stg_path) as stg_content: self.stg = json.load(stg_content) stg_content.close() if not srv_type: srv_type = self.create_service_type() self.srv_type = srv_type self.reg_srv = CONFIG.getboolean("service_manager_admin", "register_service") if self.reg_srv: self.region = CONFIG.get("service_manager_admin", "region", "") if self.region == "": LOG.info("No region parameter specified in sm.cfg, defaulting to an OpenStack default: RegionOne") self.region = "RegionOne" self.service_endpoint = CONFIG.get("service_manager_admin", "service_endpoint") if self.service_endpoint != "": LOG.warn( "DEPRECATED: service_endpoint parameter supplied in sm.cfg! Endpoint is now specified in " "service manifest as service_endpoint" ) LOG.info( "Using " + self.stg["service_endpoint"] + " as the service_endpoint value " "from service manifest" ) up = urlparse(self.stg["service_endpoint"]) self.service_endpoint = up.scheme + "://" + up.hostname + ":" + str(up.port)
def __init__(self, app, srv_type=None): # openstack objects tracking the keystone service and endpoint self.srv_ep = None self.ep = None self.DEBUG = True self.app = app self.service_backend = ServiceBackend(app) LOG.info('Using configuration file: ' + CONFIG_PATH) self.token, self.tenant_name = self.get_service_credentials() self.design_uri = CONFIG.get('service_manager', 'design_uri', '') if self.design_uri == '': LOG.fatal('No design_uri parameter supplied in sm.cfg') raise Exception('No design_uri parameter supplied in sm.cfg') self.stg = None stg_path = CONFIG.get('service_manager', 'manifest', '') if stg_path == '': raise RuntimeError('No STG specified in the configuration file.') with open(stg_path) as stg_content: self.stg = json.load(stg_content) stg_content.close() if not srv_type: srv_type = self.create_service_type() self.srv_type = srv_type self.reg_srv = CONFIG.getboolean('service_manager_admin', 'register_service') if self.reg_srv: self.region = CONFIG.get('service_manager_admin', 'region', '') if self.region == '': LOG.info('No region parameter specified in sm.cfg, defaulting to an OpenStack default: RegionOne') self.region = 'RegionOne' self.service_endpoint = CONFIG.get('service_manager_admin', 'service_endpoint') if self.service_endpoint != '': LOG.warn('DEPRECATED: service_endpoint parameter supplied in sm.cfg! Endpoint is now specified in ' 'service manifest as service_endpoint') LOG.info('Using ' + self.stg['service_endpoint'] + ' as the service_endpoint value ' 'from service manifest') up = urlparse(self.stg['service_endpoint']) self.service_endpoint = up.scheme + '://' + up.hostname + ':' + str(up.port) + '/' + str('mobaas') LOG.info(self.service_endpoint)
def __call__(self, environ, response): token = environ.get('HTTP_X_AUTH_TOKEN', '') # design_uri is needed for the case that no token was given design_uri = CONFIG.get('service_manager', 'design_uri', '') if design_uri == '': LOG.fatal('No design_uri parameter supplied in sm.cfg') raise Exception('No design_uri parameter supplied in sm.cfg') tenantname = environ.get('HTTP_X_TENANT_NAME', '') region = environ.get('HTTP_X_REGION_NAME','') username = environ.get('HTTP_X_USER_NAME','') password = environ.get('HTTP_X_PASSWORD','') # for checking the authenticity auth = KeyStoneAuthService(design_uri) # get the token from username, tenant and region combination from HTTP # headers if token is '': try: # get all the required variables - as the tenant name has a # special role, it's queried separately kc = client.Client(auth_url=design_uri, username=username, password=password, tenant_name=tenantname ) environ['HTTP_X_AUTH_TOKEN'] = kc.auth_token token = kc.auth_token except: raise Exception('Either no design uri, username, ' 'password, or tenant name respectively ' 'provided or the login didn\'t succeed') else: if not auth.verify(token=token, tenant_name=tenantname): LOG.error('Token has probably expired') raise HTTPError(401, 'Token is not valid. You likely need an updated token.') # the arguments at the back will become the extras variable within the individual SM classes return self._call_occi(environ, response, username=username, design_uri=design_uri, password=password, token=token, tenant_name=tenantname, registry=self.registry, region=region)
def __call__(self, environ, response): token = environ.get('HTTP_X_AUTH_TOKEN', '') if token == '': LOG.error('No X-Auth-Token header supplied.') raise HTTPError(400, 'No X-Auth-Token header supplied.') tenant = environ.get('HTTP_X_TENANT_NAME', '') if tenant == '': LOG.error('No X-Tenant-Name header supplied.') raise HTTPError(400, 'No X-Tenant-Name header supplied.') design_uri = CONFIG.get('service_manager', 'design_uri', '') if design_uri == '': LOG.fatal('No design_uri parameter supplied in sm.cfg') raise Exception('No design_uri parameter supplied in sm.cfg') auth = KeyStoneAuthService(design_uri) if not auth.verify(token=token, tenant_name=tenant): raise HTTPError(401, 'Token is not valid. You likely need an updated token.') return self._call_occi(environ, response, token=token, tenant_name=tenant, registry=self.registry)
def __call__(self, environ, response): token = environ.get("HTTP_X_AUTH_TOKEN", "") if token == "": LOG.error("No X-Auth-Token header supplied.") raise HTTPError(400, "No X-Auth-Token header supplied.") tenant = environ.get("HTTP_X_TENANT_NAME", "") if tenant == "": LOG.error("No X-Tenant-Name header supplied.") raise HTTPError(400, "No X-Tenant-Name header supplied.") design_uri = CONFIG.get("service_manager", "design_uri", "") if design_uri == "": LOG.fatal("No design_uri parameter supplied in sm.cfg") raise Exception("No design_uri parameter supplied in sm.cfg") auth = KeyStoneAuthService(design_uri) if not auth.verify(token=token, tenant_name=tenant): raise HTTPError(401, "Token is not valid. You likely need an updated token.") return self._call_occi(environ, response, token=token, tenant_name=tenant, registry=self.registry)
def run(self): LOG.debug("running destroy") self.start_time = time.time() infoDict = { 'sm_name': self.entity.kind.term, 'phase': 'destroy', 'phase_event': 'start', 'response_time': 0, } LOG.debug(json.dumps(infoDict)) self.entity.attributes['mcn.service.state'] = 'destroy' # Do destroy work here # first, the SO has to be notified that it should destroy the computing # cluster... token = self.extras['token'] heads = { 'X-Auth-Token':token, 'X-Tenant-Name':CONFIG.get('openstackso','tenantname'), 'Content-Type':'text/occi', 'Accept':'text/occi' } # this happens with the delete command self.sofloatingip = self.entity.attributes['sofloatingip'] http_retriable_request('DELETE', "http://"+self.sofloatingip+':8080/orchestrator/default', headers=heads) # this time, we don't have to wait anymore until the SO's VM is # destroyed because it's OpenStack's duty to worry about that...so # let's destroy the SO's VM straight away global soStackId # design_uri contains the keystone endpoint design_uri = CONFIG.get('openstackso', 'heat_endpoint', '') if design_uri == '': LOG.fatal('No design_uri parameter supplied in sm.cfg') raise Exception('No design_uri parameter supplied in sm.cfg') # get the connection handle to keytone heatClient = client.Client(HEAT_VERSION, design_uri, token=token) # get the floating IP of the SO's VM try: self.sofloatingip = self.entity.attributes['sofloatingip'] except: raise Exception("argument sofloatingip not given") try: from novaclient import client as novaclient # the following doesn't work, but maybe with nova.servers.remove_floating_ip(server,ip) # heatClient.v2.floating_ips.delete(self.sofloatingip) heatClient.stacks.delete(soStackId[self.sofloatingip]) except: LOG.debug("either openstack_so_manager::heatClient or openstack_so_manager::soStackId wasn't defined") # at this point, the computing cluster as well as the SO's VM have been # deleted on OpenStack elapsed_time = time.time() - self.start_time infoDict = { 'sm_name': self.entity.kind.term, 'phase': 'destroy', 'phase_event': 'done', 'response_time': elapsed_time, } LOG.debug(json.dumps(infoDict)) return self.entity, self.extras
def __deploy_so_vm(self): global soStackId global stackName # this will be the template that deploys the SO's VM on OpenStack template = """heat_template_version: 2014-10-16 parameters: resources: so_port: type: OS::Neutron::Port properties: network: e6340b75-252a-4b71-a810-418f3c3c006d fixed_ips: - subnet_id: 17b5a076-7699-4658-82cd-c844a23bbbe7 security_groups: [{ get_resource: so_sec_group }] floating_ip_assoc: type: OS::Neutron::FloatingIPAssociation properties: floatingip_id: $floatingip$ port_id: { get_resource: so_port } so_sec_group: type: OS::Neutron::SecurityGroup properties: # name: so_sg_$randomstring$ rules: [ {"direction":"ingress","protocol":"tcp","port_range_min":"22","port_range_max":"22"}, {"direction":"ingress","protocol":"tcp","port_range_min":"8080","port_range_max":"8080"}, ] hadoop_master: type: OS::Nova::Server properties: name: testso_$randomstring$ image: serviceorchestrator # Ubuntu-Trusty-Tahr-14.04.2-LTS flavor: m1.smaller # m1.tiny key_name: MNMBA2 networks: - port: { get_resource: so_port } user_data: | #!/bin/bash { SECONDS=0 # apt-get update # apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade # apt-get install -y python git python-pip python-dev # cd ~ # git clone https://github.com/icclab/hurtle_cc_sdk.git # cd ~/hurtle_cc_sdk # pip install --upgrade requests # python setup.py install # cd ~ # git clone https://github.com/icclab/hurtle_sm.git # cd ~/hurtle_sm # python setup.py install cd ~ git clone $sogitaddress$ export DESIGN_URI='$design_uri$' python $soapplication$ } 2> ~/error.log | tee ~/debug.log outputs: """ # set the needed values within the VM randomstring = str(uuid.uuid1()) template = template.replace("$design_uri$",CONFIG.get('service_manager','design_uri')) template = template.replace("$floatingip$",self.sofloatingipid) template = template.replace("$randomstring$",randomstring) template = template.replace("$sogitaddress$",CONFIG.get('openstackso','sogitaddress')) template = template.replace("$soapplication$",CONFIG.get('openstackso','soapplication')) LOG.debug('deploying template '+template) # deyloy the Heat orchestration template on OpenStack: token = self.extras['token'] # design_uri contains the keystone endpoint design_uri = CONFIG.get('openstackso', 'heat_endpoint', '') if design_uri == '': LOG.fatal('No design_uri parameter supplied in sm.cfg') raise Exception('No design_uri parameter supplied in sm.cfg') # get the connection handle to keytone heatClient = client.Client(HEAT_VERSION, design_uri, token=token) curStackName = 'so_'+randomstring body = { 'stack_name': curStackName, 'template': template } LOG.debug('the stack\'s name is '+body['stack_name']) # here is where the actual SO deployment happens tmp = heatClient.stacks.create(**body) soStackId[self.sofloatingip] = tmp['stack']['id'] stackName[self.sofloatingip] = curStackName LOG.debug("new stack's ID: "+tmp['stack']['id'])