Exemplo n.º 1
0
    def process_request(self, req):
        # We only handle POST requests
        if req.method != 'POST':
            return

        # Extract webhook (receiver) ID and params
        results = self._parse_url(req.url)
        if not results:
            return

        (receiver_id, params) = results

        api_version = str(req.version_request)
        ctx = context.RequestContext(is_admin=True, api_version=api_version)
        req.context = ctx

        obj = util.parse_request('ReceiverGetRequest', req,
                                 {'identity': receiver_id})
        rpcc = rpc.get_engine_client()
        receiver = rpcc.call(ctx, 'receiver_get', obj)

        svc_ctx = context.get_service_credentials()
        kwargs = {
            'auth_url': svc_ctx['auth_url'],
            'username': svc_ctx['username'],
            'user_domain_name': svc_ctx['user_domain_name'],
            'password': svc_ctx['password']
        }
        kwargs.update(receiver['actor'])

        # Get token and fill it into the request header
        token = self._get_token(**kwargs)
        req.headers['X-Auth-Token'] = token
Exemplo n.º 2
0
 def __init__(self, project_id, cluster_id, recover_action):
     super(NovaNotificationEndpoint, self).__init__(project_id, cluster_id,
                                                    recover_action)
     self.filter_rule = messaging.NotificationFilter(
         publisher_id='^compute.*',
         event_type='^compute\.instance\..*',
         context={'project_id': '^%s$' % project_id})
     self.rpc = rpc_client.get_engine_client()
     self.target = messaging.Target(
         topic=cfg.CONF.health_manager.nova_notification_topic,
         exchange=cfg.CONF.health_manager.nova_control_exchange,
     )
Exemplo n.º 3
0
    def _get_trust(self, req):
        """List trusts with current user as the trustor.

        :param req: The WSGI request object.
        :return: ID of the trust or exception of InternalError.
        """
        rpcc = rpc.get_engine_client()

        ctx = req.context
        params = {'user': ctx.user_id, 'project': ctx.project_id}
        obj = util.parse_request('CredentialGetRequest', req, params)
        res = rpcc.call(ctx, 'credential_get', obj)
        if res:
            trust_id = res.get('trust', None)
            if trust_id:
                return trust_id

        params = {
            'auth_url': ctx.auth_url,
            'token': ctx.auth_token,
            'project_id': ctx.project_id,
            'user_id': ctx.user_id,
        }
        kc = driver_base.SenlinDriver().identity(params)
        service_cred = context.get_service_credentials()
        admin_id = kc.get_user_id(**service_cred)
        try:
            trust = kc.trust_get_by_trustor(ctx.user_id, admin_id,
                                            ctx.project_id)
        except exception.InternalError as ex:
            if ex.code == 400:
                trust = None
            else:
                raise
        if not trust:
            # Create a trust if no existing one found
            trust = kc.trust_create(ctx.user_id, admin_id, ctx.project_id,
                                    ctx.roles)

        # If credential not exists, create it, otherwise update it.
        cred = {'openstack': {'trust': trust.id}}
        params = {'cred': cred}
        obj = util.parse_request('CredentialCreateRequest', req, params)
        rpcc.call(ctx, 'credential_create', obj)

        return trust.id
Exemplo n.º 4
0
    def __init__(self, ctx, engine_id, cluster_id, check_type, interval,
                 node_update_timeout, params, enabled):
        self.rpc_client = rpc_client.get_engine_client()
        self.ctx = ctx
        self.engine_id = engine_id

        self.cluster_id = cluster_id
        self.check_type = check_type
        self.interval = interval
        self.node_update_timeout = node_update_timeout
        self.params = params
        self.enabled = enabled
        self.timer = None
        self.listener = None

        self.health_check_types = []
        self.recover_action = {}
        self.type = None
        self.get_health_check_types()
        self.get_recover_actions()
Exemplo n.º 5
0
 def __init__(self, options):
     self.options = options
     self.rpc_client = rpc_client.get_engine_client()