def test_retrieve_endpoint_for_sanity(self): """ Test retrieval of endpoint for sanity. """ tmp = services.get_service_endpoint('orchestration', self.token) self.assertIsNot(tmp.find(':8004/v1'), -1) tmp = services.get_service_endpoint('identity', self.token) self.assertIsNot(tmp.find(':5000/v2.0'), -1)
def test_retrieve_endpoint_for_failure(self): """ Test for failure/None. """ tmp = services.get_service_endpoint('foobar', self.token) self.assertIsNone(tmp) tmp = services.get_service_endpoint('heat', self.token, tenant_name='foo') self.assertIsNone(tmp)
def test_design_uri_injection(self): """ Test if design uri can be set via environment variable. """ if 'DESIGN_URI' in os.environ: return os.environ['DESIGN_URI'] = 'http://localhost:35357/v2.0' services.list_services(self.token) services.get_service_endpoint('heat', self.token) os.environ.pop('DESIGN_URI')
def __sm_stg_ops(self, svc_list): # purpose: take the stg and insert valid SM endpoints, maintain the input params of service svc_type_endpoint = [] for svc_type in svc_list: if isinstance(svc_type, dict): # or isinstance(svc_type, unicode): # XXX if there are more than two keys this will be a prob # XXX note that currently all services must be RegionOne (default in heat) region = 'RegionOne' ep = services.get_service_endpoint(svc_type.keys()[0], self.token, tenant_name=self.tenant, region=region) if ep is None: raise RuntimeError(svc_type.keys()[0] + ' endpoint could not be found - is the service registered?') LOG.info('Service type: ' + svc_type.keys()[0].__repr__() + ' can be instantiated at: ' + ep) inputs = svc_type[svc_type.keys()[0]]['inputs'] type_ep = { svc_type.keys()[0]: { 'inputs': inputs, 'endpoint': ep } } svc_type_endpoint.append(type_ep) else: LOG.error('Service type schema is now as expected. It is: ' + svc_type.__repr__()) raise RuntimeError('Service type schema is now as expected. It is: ' + svc_type.__repr__()) return svc_type_endpoint
def get_dnsaas(token, **kwargs): """ Return a instance of the DNSaaS. A new instance is deployed if don't exist one :param token: The token """ if kwargs['tenant_name'] is not None: tenant = kwargs['tenant_name'] else: tenant = 'demo' endpoint = services.get_service_endpoint('http://schemas.mobile-cloud-networking.eu/occi/sm#dnsaas', token, **kwargs) if endpoint is None: print ("Error: Initiate the SM") return None else: maas_address=None maas_endpoint=None dispose_maas=False if 'mcn_endpoint_api' in kwargs: dns_api = kwargs['mcn_endpoint_api'] dns_action = dnsaasclient.DNSaaSClientAction(endpoint, tenant, token, dns_api) else: dns_action = dnsaasclient.DNSaaSClientAction(endpoint, tenant, token) if dns_action.init_dns(): return dns_action else: return None
def get_dnsaas(token, **kwargs): """ Return a instance of the DNSaaS. A new instance is deployed if don't exist one :param token: The token """ if kwargs['tenant_name'] is not None: tenant = kwargs['tenant_name'] else: tenant = 'demo' endpoint = services.get_service_endpoint( 'http://schemas.mobile-cloud-networking.eu/occi/sm#dnsaas', token, **kwargs) if endpoint is None: print("Error: Initiate the SM") return None else: maas_address = None maas_endpoint = None dispose_maas = False if 'mcn_endpoint_api' in kwargs: dns_api = kwargs['mcn_endpoint_api'] dns_action = dnsaasclient.DNSaaSClientAction( endpoint, tenant, token, dns_api) else: dns_action = dnsaasclient.DNSaaSClientAction( endpoint, tenant, token) if dns_action.init_dns(): return dns_action else: return None
def __get_endpoint(self, svc_type): # XXX note that currently all services in the service manifest must be in the same region!!! ep = services.get_service_endpoint(svc_type, self.token, tenant_name=self.tenant, region=self.region) return ep
def get_maas(token, mtype='maas', **kwargs): """ Return a instance of the monitoring helper. :param token: The token. :param mtype: Defaults to 'zabbix' :param kwargs: optional parameters """ if kwargs['tenant_name'] is not None: tenant = kwargs['tenant_name'] else: tenant = 'demo' if mtype == 'maas': endpoint = services.get_service_endpoint( 'http://schemas.mobile-cloud-networking.eu/occi/sm#maas', token, **kwargs) if endpoint is not None: # deploy logic maas = monitoring.ZabbixMonitoring(endpoint) if maas.get_location() is None: # POST instantiation, GET location maas.set_tenant(tenant) header = {'Category': 'maas; scheme="http://schemas.mobile-cloud-networking.eu/occi/sm#"; class="kind";', 'content-type': 'text/occi', 'x-tenant-name': tenant, 'x-auth-token': token} response = requests.post(endpoint+'/', headers=header) maas.set_location(response.headers.get('location')) return maas else: return None else: return None
def __get_endpoint(self, svc_type): # XXX note that currently all services in the service manifest must be in the same region!!! ep = services.get_service_endpoint( svc_type, self.token, tenant_name=self.tenant, region=self.region) return ep
def __init__(self, token): self.token = token # Find out service endpoint self.endpoint = services.get_service_endpoint("cdnaas", token, tenant_name='zhaw_test') if self.endpoint is None: raise Exception("No CDN endpoint") # Find out user submitted parameters (through SM) self.password = '******' self.userid = None self.origin = None
def get_security_service(token, stype='identity'): """ Returns a instance of the auth service. :param token: The token. :param dtype: Defaults to 'keystone'. """ if stype == 'identity': endpoint = services.get_service_endpoint(stype, token) return security.KeyStoneAuthService(endpoint) else: return None
def get_deployer(token, dtype='orchestration', **kwargs): """ Returns a instance of the deployment helper. Return None if no deployer can be found. :param token: The token. :param dtype: Defaults to 'heat'. """ if dtype == 'orchestration': endpoint = services.get_service_endpoint(dtype, token, **kwargs) if endpoint is not None: return deployment.HeatDeployer(endpoint) else: return None else: return None
def get_maas(token, mtype='maas', **kwargs): """ Return a instance of the monitoring helper. :param token: The token. :param mtype: Defaults to 'zabbix' :param kwargs: optional parameters """ if kwargs['tenant_name'] is not None: tenant = kwargs['tenant_name'] else: tenant = 'demo' if mtype == 'maas': endpoint = services.get_service_endpoint( 'http://schemas.mobile-cloud-networking.eu/occi/sm#maas', token, **kwargs) if endpoint is not None: # deploy logic maas = monitoring.ZabbixMonitoring(endpoint) if maas.get_location() is None: # POST instantiation, GET location maas.set_tenant(tenant) header = { 'Category': 'maas; scheme="http://schemas.mobile-cloud-networking.eu/occi/sm#"; class="kind";', 'content-type': 'text/occi', 'x-tenant-name': tenant, 'x-auth-token': token } response = requests.post(endpoint + '/', headers=header) maas.set_location(response.headers.get('location')) return maas else: return None else: return None
def __sm_stg_ops(self, svc_list): # purpose: take the stg and insert valid SM endpoints, maintain the input params of service svc_type_endpoint = [] for svc_type in svc_list: if isinstance(svc_type, dict): # or isinstance(svc_type, unicode): # XXX if there are more than two keys this will be a prob # XXX note that currently all services must be RegionOne (default in heat) region = 'RegionOne' ep = services.get_service_endpoint(svc_type.keys()[0], self.token, tenant_name=self.tenant, region=region) if ep is None: raise RuntimeError( svc_type.keys()[0] + ' endpoint could not be found - is the service registered?' ) LOG.info('Service type: ' + svc_type.keys()[0].__repr__() + ' can be instantiated at: ' + ep) inputs = svc_type[svc_type.keys()[0]]['inputs'] type_ep = { svc_type.keys()[0]: { 'inputs': inputs, 'endpoint': ep } } svc_type_endpoint.append(type_ep) else: LOG.error('Service type schema is now as expected. It is: ' + svc_type.__repr__()) raise RuntimeError( 'Service type schema is now as expected. It is: ' + svc_type.__repr__()) return svc_type_endpoint