Esempio n. 1
0
    def account_has_blob_containers(self):
        '''
        If there are blob containers, then there are likely VMs depending on this account and it should
        not be deleted.
        '''
        self.log('Checking for existing blob containers')
        keys = dict()
        try:
            # Get keys from the storage account
            account_keys = self.storage_client.storage_accounts.list_keys(
                self.resource_group, self.name)
            keys['key1'] = account_keys.key1
            keys['key2'] = account_keys.key2
        except AzureHttpError as e:
            self.fail(
                "check_for_container:Failed to get account keys: {0}".format(
                    e))

        try:
            cloud_storage = CloudStorageAccount(
                self.name, keys['key1']).create_page_blob_service()
        except Exception as e:
            self.fail(
                "check_for_container:Error creating blob service: {0}".format(
                    e))

        try:
            response = cloud_storage.list_containers()
        except AzureMissingResourceHttpError:
            # No blob storage available?
            return False

        if len(response.items) > 0:
            return True
        return False
Esempio n. 2
0
    def account_has_blob_containers(self):
        '''
        If there are blob containers, then there are likely VMs depending on this account and it should
        not be deleted.
        '''
        self.log('Checking for existing blob containers')
        try:
            # Get keys from the storage account
            account_keys = self.storage_client.storage_accounts.list_keys(self.resource_group, self.name)
            keys = {v.key_name: v.value for v in account_keys.keys}
        except AzureHttpError as e:
            self.fail("check_for_container:Failed to get account keys: {0}".format(e))

        try:
            cloud_storage = CloudStorageAccount(self.name, keys['key1']).create_page_blob_service()
        except Exception as e:
            self.fail("check_for_container:Error creating blob service: {0}".format(e))

        try:
            response = cloud_storage.list_containers()
        except AzureMissingResourceHttpError:
            # No blob storage available?
            return False

        if len(response.items) > 0:
            return True
        return False