def get_last_operation(self, req, instance_id): service = db_cf.get_service_for_instance(instance_id) # NOTE(freerunner): Prevent code 500 if requested environment # already doesn't exist. if not service: LOG.warning(_LW('Requested service for instance {} is not found')) body = {} resp = response.Response(status=410, json_body=body) return resp env_id = service.environment_id token = req.headers["X-Auth-Token"] m_cli = _get_muranoclient(token, req) # NOTE(starodubcevna): we can track only environment status. it's # murano API limitation. m_environment = m_cli.environments.get(env_id) if m_environment.status == 'ready': body = {'state': 'succeeded', 'description': 'operation succeed'} resp = response.Response(status=200, json_body=body) elif m_environment.status in ['pending', 'deleting', 'deploying']: body = { 'state': 'in progress', 'description': 'operation in progress' } resp = response.Response(status=202, json_body=body) elif m_environment.status in ['deploy failure', 'delete failure']: body = { 'state': 'failed', 'description': '{0}. Please correct it manually'.format(m_environment.status) } resp = response.Response(status=200, json_body=body) return resp
def bind(self, req, body, instance_id, app_id): filtered = [u'?', u'instance'] db_service = db_cf.get_service_for_instance(instance_id) if not db_service: return {} service_id = db_service.service_id environment_id = db_service.environment_id tenant = db_service.tenant _, _, keystone = self._check_auth(req, tenant) # Once we get here we were authorized by keystone token = keystone.auth_token m_cli = muranoclient(token) session_id = create_session(m_cli, environment_id) env = m_cli.environments.get(environment_id, session_id) LOG.debug('Got environment {0}'.format(env)) service = self._get_service(env, service_id) LOG.debug('Got service {0}'.format(service)) credentials = {} for k, v in six.iteritems(service): if k not in filtered: credentials[k] = v return {'credentials': credentials}
def get_last_operation(self, req, instance_id): service = db_cf.get_service_for_instance(instance_id) # NOTE(freerunner): Prevent code 500 if requested environment # already doesn't exist. if not service: LOG.warning(_LW('Requested service for instance {} is not found')) body = {} resp = response.Response(status=410, json_body=body) return resp env_id = service.environment_id token = req.headers["X-Auth-Token"] m_cli = _get_muranoclient(token, req) # NOTE(starodubcevna): we can track only environment status. it's # murano API limitation. m_environment = m_cli.environments.get(env_id) if m_environment.status == 'ready': body = {'state': 'succeeded', 'description': 'operation succeed'} resp = response.Response(status=200, json_body=body) elif m_environment.status in ['pending', 'deleting', 'deploying']: body = {'state': 'in progress', 'description': 'operation in progress'} resp = response.Response(status=202, json_body=body) elif m_environment.status in ['deploy failure', 'delete failure']: body = {'state': 'failed', 'description': '{0}. Please correct it manually'.format( m_environment.status)} resp = response.Response(status=200, json_body=body) return resp
def get_last_operation(self, req, instance_id): service = db_cf.get_service_for_instance(instance_id) env_id = service.environment_id tenant = service.tenant _, _, keystone = self._check_auth(req, tenant) # Once we get here we were authorized by keystone token = keystone.auth_token m_cli = muranoclient(token) # NOTE(starodubcevna): we can track only environment status. it's # murano API limitation. m_environment = m_cli.environments.get(env_id) if m_environment.status == 'ready': body = {'state': 'succeeded', 'description': 'operation succeed'} resp = response.Response(status=200, json_body=body) elif m_environment.status in ['pending', 'deleting', 'deploying']: body = {'state': 'in progress', 'description': 'operation in progress'} resp = response.Response(status=202, json_body=body) elif m_environment.status in ['deploy failure', 'delete failure']: body = {'state': 'failed', 'description': '{0}. Please correct it manually'.format( m_environment.status)} resp = response.Response(status=200, json_body=body) return resp
def deprovision(self, req, instance_id): service = db_cf.get_service_for_instance(instance_id) if not service: return {} service_id = service.service_id environment_id = service.environment_id tenant = service.tenant _, _, keystone = self._check_auth(req, tenant) # Once we get here we were authorized by keystone token = keystone.auth_token m_cli = muranoclient(token) try: session_id = create_session(m_cli, environment_id) except exc.HTTPForbidden: # FIXME(Kezar): this is a temporary solution, should be replaced # with 'incomplete' response for Cloud Foudry as soon as we will # know which is right format for it. LOG.warning(_LW("Can't create new session. Please remove service " "manually in environment {0}") .format(environment_id)) return {} m_cli.services.delete(environment_id, '/' + service_id, session_id) m_cli.sessions.deploy(environment_id, session_id) return {}
def deprovision(self, req, instance_id): service = db_cf.get_service_for_instance(instance_id) if not service: return {} service_id = service.service_id environment_id = service.environment_id tenant = service.tenant _, _, keystone = self._check_auth(req, tenant) # Once we get here we were authorized by keystone token = keystone.auth_token m_cli = muranoclient(token) try: session_id = create_session(m_cli, environment_id) except exc.HTTPForbidden: # FIXME(Kezar): this is a temporary solution, should be replaced # with 'incomplete' response for Cloud Foudry as soon as we will # know which is right format for it. LOG.warning( _LW("Can't create new session. Please remove service " "manually in environment {0}").format(environment_id)) return {} m_cli.services.delete(environment_id, '/' + service_id, session_id) m_cli.sessions.deploy(environment_id, session_id) return {}
def bind(self, req, body, instance_id, app_id): db_service = db_cf.get_service_for_instance(instance_id) if not db_service: return {} service_id = db_service.service_id environment_id = db_service.environment_id token = req.headers['X-Auth-Token'] m_cli = _get_muranoclient(token, req) session_id = create_session(m_cli, environment_id) env = m_cli.environments.get(environment_id, session_id) LOG.debug('Got environment {0}'.format(env)) service = self._get_service(env, service_id) LOG.debug('Got service {0}'.format(service)) # NOTE(starodubcevna): Here we need to find an action which will return # us needed credentials. By default we will looking for getCredentials # action. result = {} try: actions = service['?']['_actions'] for action_id in list(actions): if 'getCredentials' in action_id: @retrying.retry( retry_on_exception=lambda e: isinstance(e, TypeError), wait_random_min=1000, wait_random_max=10000, stop_max_delay=30000) def _get_creds(client, task_id, environment_id): result = m_cli.actions.get_result( environment_id, task_id)['result'] return result task_id = m_cli.actions.call(environment_id, action_id) result = _get_creds(m_cli, task_id, environment_id) if not result: LOG.warning( _LW("This application doesn't have action " "getCredentials")) return response.Response(status=500) except KeyError: # NOTE(starodubcevna): In CF service broker API spec return # code for failed bind is not present, so we will return 500. LOG.warning(_LW("This application doesn't have actions at all")) return response.Response(status=500) if 'credentials' in list(result): return result else: return {'credentials': result}
def bind(self, req, body, instance_id, app_id): db_service = db_cf.get_service_for_instance(instance_id) if not db_service: return {} service_id = db_service.service_id environment_id = db_service.environment_id token = req.headers['X-Auth-Token'] m_cli = _get_muranoclient(token, req) session_id = create_session(m_cli, environment_id) env = m_cli.environments.get(environment_id, session_id) LOG.debug('Got environment {0}'.format(env)) service = self._get_service(env, service_id) LOG.debug('Got service {0}'.format(service)) # NOTE(starodubcevna): Here we need to find an action which will return # us needed credentials. By default we will looking for getCredentials # action. result = {} try: actions = service['?']['_actions'] for action_id in list(actions): if 'getCredentials' in action_id: @retrying.retry(retry_on_exception=lambda e: isinstance(e, TypeError), wait_random_min=1000, wait_random_max=10000, stop_max_delay=30000) def _get_creds(client, task_id, environment_id): result = m_cli.actions.get_result(environment_id, task_id)['result'] return result task_id = m_cli.actions.call(environment_id, action_id) result = _get_creds(m_cli, task_id, environment_id) if not result: LOG.warning(_LW("This application doesn't have action " "getCredentials")) return response.Response(status=500) except KeyError: # NOTE(starodubcevna): In CF service broker API spec return # code for failed bind is not present, so we will return 500. LOG.warning(_LW("This application doesn't have actions at all")) return response.Response(status=500) if 'credentials' in list(result): return result else: return {'credentials': result}
def deprovision(self, req, instance_id): service = db_cf.get_service_for_instance(instance_id) if not service: return {} service_id = service.service_id environment_id = service.environment_id token = req.headers['X-Auth-Token'] m_cli = _get_muranoclient(token, req) session_id = create_session(m_cli, environment_id) m_cli.services.delete(environment_id, '/' + service_id, session_id) m_cli.sessions.deploy(environment_id, session_id) return response.Response(status=202, json_body={})
def deprovision(self, req, instance_id): service = db_cf.get_service_for_instance(instance_id) if not service: return {} service_id = service.service_id environment_id = service.environment_id tenant = service.tenant _, _, keystone = self._check_auth(req, tenant) # Once we get here we were authorized by keystone token = keystone.auth_token m_cli = muranoclient(token) session_id = create_session(m_cli, environment_id) m_cli.services.delete(environment_id, '/' + service_id, session_id) m_cli.sessions.deploy(environment_id, session_id) return response.Response(status=202, json_body={})
def bind(self, req, body, instance_id, app_id): filtered = [u'?', u'instance'] db_service = db_cf.get_service_for_instance(instance_id) if not db_service: return {} service_id = db_service.service_id environment_id = db_service.environment_id token = req.headers['X-Auth-Token'] m_cli = muranoclient(token) session_id = create_session(m_cli, environment_id) env = m_cli.environments.get(environment_id, session_id) LOG.debug('Got environment {0}'.format(env)) service = self._get_service(env, service_id) LOG.debug('Got service {0}'.format(service)) credentials = {} for k, v in six.iteritems(service): if k not in filtered: credentials[k] = v return {'credentials': credentials}