Ejemplo n.º 1
0
    def ecs_client(self, region):
        self.log('Geting ECS client')
        config = HttpConfig.get_default_config()
        config.ignore_ssl_verification = True
        if self.credentials["project_id"] and self.credentials[
                "access_key"] and self.credentials["secret_key"] and region:
            _credentials = BasicCredentials(self.credentials["access_key"],
                                            self.credentials["secret_key"],
                                            self.credentials["project_id"])

            if self.credentials["identity_endpoint"]:
                _credentials.iam_endpoint = self.credentials[
                    "identity_endpoint"]

            if self.credentials["cloud"]:
                endpoint = 'https://ecs.{}.{}'.format(
                    region, self.credentials["cloud"])
            else:
                endpoint = 'https://ecs.{}.myhuaweicloud.com'.format(region)
            ecs_client = EcsClient.new_builder() \
            .with_http_config(config) \
            .with_credentials(_credentials) \
            .with_endpoint(endpoint) \
            .build()
        else:
            raise HwcModuleException(
                'Getting ECS client failed: "project_id", "access_key", "access_key" and "region" are required for ECS client'
            )

        return ecs_client
    def cce_client(self):
        self.log('Geting CCE client')
        if not self._cce_client:
            config = HttpConfig.get_default_config()
            config.ignore_ssl_verification = True
            if self.module.params["project_id"]:
                credentials = BasicCredentials(
                    self.module.params["access_key"],
                    self.module.params["secret_key"],
                    self.module.params["project_id"])

                if self.module.params["identity_endpoint"]:
                    credentials.iam_endpoint = self.module.params[
                        "identity_endpoint"]

                endpoint = 'https://cce.{}.{}'.format(
                    self.module.params["region"], self.module.params["cloud"])
                self._cce_client = CceClient.new_builder() \
                .with_http_config(config) \
                .with_credentials(credentials) \
                .with_endpoint(endpoint) \
                .build()
            else:
                raise HwcModuleException(
                    'Getting CCE client failed: "project_id" is required for CCE client'
                )

        return self._cce_client