Ejemplo n.º 1
0
 def authenticate(self):
     try:
         self.gcp_compute
         return True
     except Exception as e:
         raise ProviderConnectionException(
             'Authentication with Google cloud provider failed: %s', e)
Ejemplo n.º 2
0
    def _get_or_create_storage_account(self):
        if self._storage_account:
            return self._storage_account
        else:
            try:
                self._storage_account = \
                    self.get_storage_account(self.storage_account)
            except CloudError as cloud_error:
                if cloud_error.error.error == "ResourceNotFound":
                    storage_account_params = {
                        'sku': {
                            'name': 'Standard_LRS'
                        },
                        'kind': 'storage',
                        'location': self.region_name,
                    }
                    try:
                        self._storage_account = \
                            self.create_storage_account(self.storage_account,
                                                        storage_account_params)
                    except CloudError as cloud_error2:  # pragma: no cover
                        if cloud_error2.error.error == "AuthorizationFailed":
                            mess = 'The following error was returned by ' \
                                   'Azure:\n%s\n\nThis is likely because the' \
                                   ' Role associated with the provided ' \
                                   'credentials does not allow for Storage ' \
                                   'Account creation.\nA Storage Account is ' \
                                   'necessary in order to perform the ' \
                                   'desired operation. You must either ' \
                                   'provide an existing Storage Account name' \
                                   ' as part of the configuration, or ' \
                                   'elevate the associated Role.\nFor more ' \
                                   'information on roles, see: https://docs.' \
                                   'microsoft.com/en-us/azure/role-based-' \
                                   'access-control/overview\n' % cloud_error2
                            raise ProviderConnectionException(mess)

                        elif cloud_error2.error.error == \
                                "StorageAccountAlreadyTaken":
                            mess = 'The following error was ' \
                                   'returned by Azure:\n%s\n\n' \
                                   'Note that Storage Account names must be ' \
                                   'unique across Azure (not just in your ' \
                                   'subscription).\nFor more information ' \
                                   'see https://docs.microsoft.com/en-us/' \
                                   'azure/azure-resource-manager/resource-' \
                                   'manager-storage-account-name-errors\n' \
                                   % cloud_error2
                            raise InvalidLabelException(mess)
                        else:
                            raise cloud_error2
                else:
                    raise cloud_error
Ejemplo n.º 3
0
    def _initialize(self):
        """
        Verifying that resource group and storage account exists
        if not create one with the name provided in the
        configuration
        """
        try:
            self._azure_client.get_resource_group(self.resource_group)

        except CloudError as cloud_error:
            if cloud_error.error.error == "ResourceGroupNotFound":
                resource_group_params = {'location': self.region_name}
                try:
                    self._azure_client.\
                        create_resource_group(self.resource_group,
                                              resource_group_params)
                except CloudError as cloud_error2:  # pragma: no cover
                    if cloud_error2.error.error == "AuthorizationFailed":
                        mess = 'The following error was returned by Azure:\n' \
                               '%s\n\nThis is likely because the Role' \
                               'associated with the given credentials does ' \
                               'not allow for Resource Group creation.\nA ' \
                               'Resource Group is necessary to manage ' \
                               'resources in Azure. You must either ' \
                               'provide an existing Resource Group as part ' \
                               'of the configuration, or elevate the ' \
                               'associated role.\nFor more information on ' \
                               'roles, see: https://docs.microsoft.com/' \
                               'en-us/azure/role-based-access-control/' \
                               'overview\n' % cloud_error2
                        raise ProviderConnectionException(mess)
                    else:
                        raise cloud_error2

            else:
                raise cloud_error