示例#1
0
    def Delete(self) -> None:
        """Delete a volume.

    Raises:
      ResourceDeletionError: If the volume could not be deleted.
    """
        client = self.aws_account.ClientApi(common.EC2_SERVICE)
        try:
            client.delete_volume(VolumeId=self.volume_id)
        except client.exceptions.ClientError as exception:
            raise errors.ResourceDeletionError(
                'Could not delete volume {0:s}: {1:s}'.format(
                    self.volume_id, str(exception)), __name__)
示例#2
0
    def Delete(self) -> None:
        """Delete a snapshot.

    Raises:
      ResourceDeletionError: If the snapshot could not be deleted.
    """

        client = self.aws_account.ClientApi(common.EC2_SERVICE)
        try:
            client.delete_snapshot(SnapshotId=self.snapshot_id)
        except client.exceptions.ClientError as exception:
            raise errors.ResourceDeletionError(
                'Could not delete snapshot {0:s}: {1:s}'.format(
                    self.snapshot_id, str(exception)), __name__)
示例#3
0
  def DeleteStorageAccount(self, storage_account_name: str) -> None:
    """Delete an account storage.

    Raises:
      ResourceDeletionError: if the storage account could not be deleted.
    """
    try:
      logger.info('Deleting storage account: {0:s}'.format(
          storage_account_name))
      self.storage_client.storage_accounts.delete(
          self.az_account.default_resource_group_name, storage_account_name)
      logger.info('Storage account {0:s} successfully deleted'.format(
          storage_account_name))
    except azure_exceptions.CloudError as exception:
      raise errors.ResourceDeletionError(
          'Could not delete account storage {0:s}: {1:s}'.format(
              storage_account_name, str(exception)), __name__) from exception
示例#4
0
  def Delete(self) -> None:
    """Delete a snapshot.

    Raises:
      ResourceDeletionError: If the snapshot could not be deleted.
    """

    try:
      logger.info('Deleting snapshot: {0:s}'.format(self.name))
      request = self.compute_client.snapshots.delete(
          self.resource_group_name, self.name)
      while not request.done():
        sleep(5)  # Wait 5 seconds before checking snapshot status again
      logger.info('Snapshot {0:s} successfully deleted.'.format(self.name))
    except azure_exceptions.CloudError as exception:
      raise errors.ResourceDeletionError(
          'Could not delete snapshot {0:s}: {1!s}'.format(
              self.resource_id, exception), __name__)
示例#5
0
    def DeleteKMSKey(self, kms_key_id: Optional[str] = None) -> None:
        """Delete a KMS key.

    Schedule the KMS key for deletion. By default, users have a 30 days
        window before the key gets deleted.

    Args:
      kms_key_id (str): The ID of the KMS key to delete.

    Raises:
      ResourceDeletionError: If the key could not be scheduled for deletion.
    """

        if not kms_key_id:
            return

        client = self.aws_account.ClientApi(common.KMS_SERVICE)
        try:
            client.schedule_key_deletion(KeyId=kms_key_id)
        except client.exceptions.ClientError as exception:
            raise errors.ResourceDeletionError(
                'Could not schedule the KMS key {0:s} for deletion {1!s}'.
                format(exception, kms_key_id), __name__)