def _init_barbican_client(self):
        """Creates barbican client instance.

        Verifies that client can communicate with Barbican, retrying
        multiple times in case either Barbican or Keystone services are
        still starting up.
        """
        max_attempts = 5
        sleep_time = 5
        n_attempts = 0
        while n_attempts <= max_attempts:
            n_attempts += 1
            try:
                if self.auth_version == "v3":
                    auth = v3.Password(
                        username=self.username,
                        password=self.password,
                        auth_url=self.auth_url,
                        user_domain_name=self.user_domain_name,
                        project_domain_name=self.project_domain_name,
                        project_name=self.project_name)

                else:
                    # assume v2 auth
                    auth = v2.Password(
                        username=self.username,
                        password=self.password,
                        auth_url=self.auth_url,
                        tenant_name=self.tenant_name)

                # NOTE: Session is deprecated in keystoneclient 2.1.0
                # and will be removed in a future keystoneclient release.
                sess = Session(auth=auth)
                self.barbican = Client(session=sess)

                # test barbican service
                self.barbican.containers.list()

                # success
                LOG.debug(
                    "Barbican client initialized using Keystone %s "
                    "authentication." % self.auth_version)
                break

            except Exception as exc:
                if n_attempts < max_attempts:
                    LOG.debug("Barbican client initialization failed. "
                              "Trying again.")
                    time.sleep(sleep_time)
                else:
                    raise InvalidBarbicanConfig(
                        "Unable to initialize Barbican client. %s" %
                        exc.message)
Esempio n. 2
0
    def __init__(self,
                 url,
                 api_version,
                 auth_endpoint=None,
                 user=None,
                 password=None,
                 tenant_name=None,
                 authenticate=None,
                 request=None,
                 **kwargs):
        self.url = url
        self.api_version = api_version
        self.endpoint = '{base}/{api_version}'.format(
            base=self.url, api_version=self.api_version)
        self.keystone = KeystoneAuthV2(auth_url=auth_endpoint,
                                       username=user,
                                       password=password,
                                       tenant_name=tenant_name)
        # Fix: We need to create an auth plugin for Keystone and CloudCAFE
        self.keystone._barbican_url = self.endpoint
        self.conn = Client(auth_plugin=self.keystone)

        self.tenant_id = self.keystone.tenant_id
        self.tenant_token = self.keystone.auth_token