Exemple #1
0
def ucp_service_endpoint(self, svc_type):

    # Initialize variables
    retry = 0
    int_endpoint = None

    # Retrieve Keystone Session
    sess = ucp_keystone_session(self)

    # We will allow 1 retry in getting the Keystone Endpoint with a
    # backoff interval of 10 seconds in case there is a temporary
    # glitch in the network or transient problems with the keystone-api
    # pod
    while retry <= 1:
        # Retrieve Keystone Endpoint
        # We will make use of internal endpoint
        logging.info("Get Keystone Endpoint")
        int_endpoint = sess.get_endpoint(interface='internal',
                                         service_type=svc_type)

        # Retry if we fail to get keystone endpoint
        if int_endpoint:
            logging.info("Successfully Retrieved Keystone Endpoint")
            break
        else:
            logging.info("Unable to get Keystone endpoint on first attempt")
            logging.info("Retrying after 10 seconds...")
            time.sleep(10)
            retry += 1

    # Raise Execptions if we fail to get the keystone endpoint
    if not int_endpoint:
        raise AirflowException("Unable to get Keystone Endpoint!")
    else:
        return int_endpoint
Exemple #2
0
    def keystone_token_get(self, context):
        """This function retrieves Keystone token for UCP Services

        :param context: Information on the current workflow

        Example::

            from service_token import shipyard_service_token

            @shipyard_service_token
            def on_get(self, context):
                svc_token=context['svc_token']

                # Use the token to perform tasks such as setting
                # up a DrydockSession which requires keystone
                # token for authentication
        """
        # Initialize variables
        retry = 0
        token = None

        # Retrieve Keystone Session
        sess = ucp_keystone_session(self, context)

        # We will allow 1 retry in getting the Keystone Token with a
        # backoff interval of 10 seconds in case there is a temporary
        # glitch in the network or transient problems with the keystone-api
        # pod
        while retry <= 1:
            # Retrieve Keystone Token
            logging.info("Get Keystone Token")
            token = sess.get_auth_headers().get('X-Auth-Token')

            # Retry if we fail to get the keystone token
            if token:
                logging.info("Successfully Retrieved Keystone Token")
                context['svc_token'] = token
                break
            else:
                logging.info("Unable to get Keystone Token on first attempt")
                logging.info("Retrying after 10 seconds...")
                time.sleep(10)
                retry += 1

        # Raise Execptions if we fail to get a proper response
        if not token:
            raise AirflowException("Unable to get Keystone Token!")
        else:
            return func(self, context)