示例#1
0
def show_storage_account_usage():
    ''' Show the current count and limit of the storage accounts under the subscription. '''
    scf = storage_client_factory()
    return next(
        (x
         for x in scf.usage.list().value if x.name.value == 'StorageAccounts'),
        None)  #pylint: disable=no-member
示例#2
0
def show_storage_account_connection_string(resource_group_name,
                                           account_name,
                                           protocol='https',
                                           blob_endpoint=None,
                                           file_endpoint=None,
                                           queue_endpoint=None,
                                           table_endpoint=None,
                                           key_name='primary'):
    """ Generate connection string for a storage account."""
    from azure.cli.core._profile import CLOUD
    scf = storage_client_factory()
    keys = scf.storage_accounts.list_keys(resource_group_name,
                                          account_name).keys  # pylint: disable=no-member
    endpoint_suffix = CLOUD.suffixes.storage_endpoint
    connection_string = 'DefaultEndpointsProtocol={};EndpointSuffix={};AccountName={};AccountKey={}'.format(
        protocol, endpoint_suffix, account_name,
        keys[0].value if key_name == 'primary' else keys[1].value)  # pylint: disable=no-member
    connection_string = '{}{}'.format(
        connection_string,
        ';BlobEndpoint={}'.format(blob_endpoint) if blob_endpoint else '')
    connection_string = '{}{}'.format(
        connection_string,
        ';FileEndpoint={}'.format(file_endpoint) if file_endpoint else '')
    connection_string = '{}{}'.format(
        connection_string,
        ';QueueEndpoint={}'.format(queue_endpoint) if queue_endpoint else '')
    connection_string = '{}{}'.format(
        connection_string,
        ';TableEndpoint={}'.format(table_endpoint) if table_endpoint else '')
    return {'connectionString': connection_string}
示例#3
0
def validate_storage_account_name(namespace):
    client = storage_client_factory().storage_accounts

    if namespace.storage_account_name:
        storage_account_name = namespace.storage_account_name
        if arm_get_storage_account_by_name(storage_account_name) is None:
            logger.warning('Command to create a storage account:')
            logger.warning(
                '  az storage account create ' +\
                '-n <name> -g <resource-group> -l <location> --sku Standard_LRS')
            logger.warning(
                'The container registry must be at the same location as the storage account.'
            )
            raise CLIError(
                'The storage account {} does not exist in the current subscription.'\
                .format(storage_account_name))
    else:
        while True:
            storage_account_name = str(uuid.uuid4()).replace('-', '')[:24]
            if client.check_name_availability(
                    storage_account_name).name_available is True:  #pylint: disable=no-member
                namespace.storage_account_name = storage_account_name
                logger.warning(
                    'New storage account with name %s will be created and used.',
                    storage_account_name)
                return
示例#4
0
def create_storage_account(resource_group_name, account_name, sku, location=None, kind=None, tags=None,
                           custom_domain=None, encryption_services=None, access_tier=None, https_only=None,
                           bypass=None, default_action=None, assign_identity=False):
    StorageAccountCreateParameters, Kind, Sku, CustomDomain, AccessTier, Identity, Encryption, NetworkRuleSet = get_sdk(
        ResourceType.MGMT_STORAGE,
        'StorageAccountCreateParameters',
        'Kind',
        'Sku',
        'CustomDomain',
        'AccessTier',
        'Identity',
        'Encryption',
        'StorageNetworkAcls',
        mod='models')
    scf = storage_client_factory()
    params = StorageAccountCreateParameters(sku=Sku(sku), kind=Kind(kind), location=location, tags=tags)
    if custom_domain:
        params.custom_domain = CustomDomain(custom_domain, None)
    if encryption_services:
        params.encryption = Encryption(services=encryption_services)
    if access_tier:
        params.access_tier = AccessTier(access_tier)
    if assign_identity:
        params.identity = Identity()
    if https_only:
        params.enable_https_traffic_only = https_only

    if NetworkRuleSet and (bypass or default_action):
        if bypass and not default_action:
            raise CLIError('incorrect usage: --default-action ACTION [--bypass SERVICE ...]')
        params.network_acls = NetworkRuleSet(bypass=bypass, default_action=default_action, ip_rules=None,
                                             virtual_network_rules=None)

    return scf.storage_accounts.create(resource_group_name, account_name, params)
示例#5
0
def create_storage_account(resource_group_name,
                           account_name,
                           sku,
                           location=None,
                           kind=None,
                           tags=None,
                           custom_domain=None,
                           encryption=None,
                           access_tier=None,
                           https_only=None):
    StorageAccountCreateParameters, Kind, Sku, CustomDomain, AccessTier = get_sdk(
        ResourceType.MGMT_STORAGE,
        'StorageAccountCreateParameters',
        'Kind',
        'Sku',
        'CustomDomain',
        'AccessTier',
        mod='models')
    scf = storage_client_factory()
    params = StorageAccountCreateParameters(
        sku=Sku(sku),
        kind=Kind(kind),
        location=location,
        tags=tags,
        custom_domain=CustomDomain(custom_domain, None)
        if custom_domain else None,
        encryption=encryption,
        access_tier=AccessTier(access_tier) if access_tier else None)

    if https_only:
        params.enable_https_traffic_only = https_only

    return scf.storage_accounts.create(resource_group_name, account_name,
                                       params)
示例#6
0
def show_storage_account_connection_string(
        resource_group_name, account_name, protocol='https', blob_endpoint=None,
        file_endpoint=None, queue_endpoint=None, table_endpoint=None, key_name='primary'):
    """ Generate connection string for a storage account."""
    from azure.cli.core._profile import CLOUD
    scf = storage_client_factory()
    obj = scf.storage_accounts.list_keys(resource_group_name, account_name)  # pylint: disable=no-member
    try:
        keys = [obj.keys[0].value, obj.keys[1].value]  # pylint: disable=no-member
    except AttributeError:
        # Older API versions have a slightly different structure
        keys = [obj.key1, obj.key2]  # pylint: disable=no-member

    endpoint_suffix = CLOUD.suffixes.storage_endpoint
    connection_string = 'DefaultEndpointsProtocol={};EndpointSuffix={};AccountName={};AccountKey={}'.format(
        protocol,
        endpoint_suffix,
        account_name,
        keys[0] if key_name == 'primary' else keys[1])  # pylint: disable=no-member
    connection_string = '{}{}'.format(connection_string,
                                      ';BlobEndpoint={}'.format(blob_endpoint) if blob_endpoint else '')
    connection_string = '{}{}'.format(connection_string,
                                      ';FileEndpoint={}'.format(file_endpoint) if file_endpoint else '')
    connection_string = '{}{}'.format(connection_string,
                                      ';QueueEndpoint={}'.format(queue_endpoint) if queue_endpoint else '')
    connection_string = '{}{}'.format(connection_string,
                                      ';TableEndpoint={}'.format(table_endpoint) if table_endpoint else '')
    return {'connectionString': connection_string}
示例#7
0
def create_storage_account(resource_group_name, account_name, sku, location=None, kind=None, tags=None,
                           custom_domain=None, encryption_services=None, access_tier=None, https_only=None,
                           bypass=None, default_action=None, assign_identity=False):
    StorageAccountCreateParameters, Kind, Sku, CustomDomain, AccessTier, Identity, Encryption, NetworkRuleSet = get_sdk(
        ResourceType.MGMT_STORAGE,
        'StorageAccountCreateParameters',
        'Kind',
        'Sku',
        'CustomDomain',
        'AccessTier',
        'Identity',
        'Encryption',
        'VirtualNetworkRules',
        mod='models')
    scf = storage_client_factory()
    params = StorageAccountCreateParameters(sku=Sku(sku), kind=Kind(kind), location=location, tags=tags)
    if custom_domain:
        params.custom_domain = CustomDomain(custom_domain, None)
    if encryption_services:
        params.encryption = Encryption(services=encryption_services)
    if access_tier:
        params.access_tier = AccessTier(access_tier)
    if assign_identity:
        params.identity = Identity()
    if https_only:
        params.enable_https_traffic_only = https_only

    if NetworkRuleSet and (bypass or default_action):
        if bypass and not default_action:
            raise CLIError('incorrect usage: --default-action ACTION [--bypass SERVICE ...]')
        params.network_acls = NetworkRuleSet(bypass=bypass, default_action=default_action, ip_rules=None,
                                             virtual_network_rules=None)

    return scf.storage_accounts.create(resource_group_name, account_name, params)
def list_storage_accounts(resource_group_name=None):
    """ List storage accounts within a subscription or resource group. """
    scf = storage_client_factory()
    if resource_group_name:
        accounts = scf.storage_accounts.list_by_resource_group(resource_group_name)
    else:
        accounts = scf.storage_accounts.list()
    return list(accounts)
示例#9
0
def list_storage_accounts(resource_group_name=None):
    """ List storage accounts within a subscription or resource group. """
    scf = storage_client_factory()
    if resource_group_name:
        accounts = scf.storage_accounts.list_by_resource_group(resource_group_name)
    else:
        accounts = scf.storage_accounts.list()
    return list(accounts)
示例#10
0
def create_storage_account_with_account_type(resource_group_name, account_name, account_type, location=None, tags=None):
    StorageAccountCreateParameters, AccountType = get_sdk(
        ResourceType.MGMT_STORAGE,
        'StorageAccountCreateParameters',
        'AccountType',
        mod='models')
    scf = storage_client_factory()
    params = StorageAccountCreateParameters(location, AccountType(account_type), tags)
    return scf.storage_accounts.create(resource_group_name, account_name, params)
示例#11
0
def show_storage_account_connection_string(resource_group_name, account_name, protocol='https'):
    """ Show the connection string for a storage account."""
    scf = storage_client_factory()
    keys = scf.storage_accounts.list_keys(resource_group_name, account_name).keys #pylint: disable=no-member
    connection_string = 'DefaultEndpointsProtocol={};AccountName={};AccountKey={}'.format(
        protocol,
        account_name,
        keys[0].value) #pylint: disable=no-member
    return {'ConnectionString':connection_string}
示例#12
0
def create_storage_account_with_account_type(resource_group_name, account_name, location, account_type, tags=None):
    StorageAccountCreateParameters, AccountType = get_sdk(
        ResourceType.MGMT_STORAGE,
        'StorageAccountCreateParameters',
        'AccountType',
        mod='models')
    scf = storage_client_factory()
    params = StorageAccountCreateParameters(location, AccountType(account_type), tags)
    return scf.storage_accounts.create(resource_group_name, account_name, params)
示例#13
0
def show_storage_account_connection_string(resource_group_name, account_name, use_http='https'):
    ''' Show the connection string for a storage account.
    :param str use_http:use http as the default endpoint protocol '''
    scf = storage_client_factory()
    keys = scf.storage_accounts.list_keys(resource_group_name, account_name).keys #pylint: disable=no-member
    connection_string = 'DefaultEndpointsProtocol={};AccountName={};AccountKey={}'.format(
        use_http,
        account_name,
        keys[0].value) #pylint: disable=no-member
    return {'ConnectionString':connection_string}
示例#14
0
def list_storage_accounts(resource_group_name=None):
    ''' List storage accounts. '''
    from azure.mgmt.storage.models import StorageAccount
    from msrestazure.azure_active_directory import UserPassCredentials
    scf = storage_client_factory()
    if resource_group_name:
        accounts = scf.storage_accounts.list_by_resource_group(resource_group_name)
    else:
        accounts = scf.storage_accounts.list()
    return list(accounts)
示例#15
0
def list_storage_accounts(resource_group_name=None):
    """ List storage accounts within a subscription or resource group. """
    from azure.mgmt.storage.models import StorageAccount
    from msrestazure.azure_active_directory import UserPassCredentials
    scf = storage_client_factory()
    if resource_group_name:
        accounts = scf.storage_accounts.list_by_resource_group(resource_group_name)
    else:
        accounts = scf.storage_accounts.list()
    return list(accounts)
示例#16
0
def renew_storage_account_keys(resource_group_name, account_name, key='both'):
    """ Regenerate one or both keys for a storage account. """
    from azure.cli.command_modules.storage._params import storage_account_key_options
    scf = storage_client_factory()
    for k in storage_account_key_options[key]:
        result = scf.storage_accounts.regenerate_key(
            resource_group_name=resource_group_name,
            account_name=account_name,
            key_name=k)
    return result
示例#17
0
def create_storage_account(resource_group_name, account_name, location, account_type, tags=None):
    ''' Create a storage account. '''
    from azure.mgmt.storage.models import StorageAccountCreateParameters, Sku
    scf = storage_client_factory()
    # TODO Add the other new params from rc5
    # https://github.com/Azure/azure-sdk-for-python/blob/v2.0.0rc5/
    # azure-mgmt-storage/azure/mgmt/storage/models/storage_account_create_parameters.py
    # accountType is now called sku.name also.
    params = StorageAccountCreateParameters(Sku(account_type), 'Storage', location, tags)
    return scf.storage_accounts.create(resource_group_name, account_name, params)
示例#18
0
def show_storage_account_connection_string(resource_group_name,
                                           account_name,
                                           use_http='https'):
    ''' Show the connection string for a storage account.
    :param str use_http:use http as the default endpoint protocol '''
    scf = storage_client_factory()
    keys = scf.storage_accounts.list_keys(resource_group_name,
                                          account_name).keys  #pylint: disable=no-member
    connection_string = 'DefaultEndpointsProtocol={};AccountName={};AccountKey={}'.format(
        use_http, account_name, keys[0].value)  #pylint: disable=no-member
    return {'ConnectionString': connection_string}
示例#19
0
def set_storage_account_properties(
        resource_group_name, account_name, account_type=None, tags='', custom_domain=None):
    ''' Update storage account property (only one at a time).
    :param str custom_domain:the custom domain name
    '''
    from azure.mgmt.storage.models import StorageAccountUpdateParameters, CustomDomain, Sku
    scf = storage_client_factory()
    # TODO Add the new params encryption and access_tier after rc5 update
    sku = Sku(account_type) if account_type else None
    params = StorageAccountUpdateParameters(sku=sku, tags=tags, custom_domain=custom_domain)
    return scf.storage_accounts.update(resource_group_name, account_name, params)
示例#20
0
def renew_storage_account_keys(resource_group_name, account_name, key=None):
    ''' Regenerate one or both keys for a storage account.
    :param str key:Key to renew.'''
    from azure.cli.command_modules.storage._params import storage_account_key_options
    scf = storage_client_factory()
    for k in [storage_account_key_options[key]] if key \
        else storage_account_key_options.values():
        result = scf.storage_accounts.regenerate_key(
            resource_group_name=resource_group_name,
            account_name=account_name,
            key_name=k)
    return result
示例#21
0
def renew_storage_account_keys(resource_group_name, account_name, key=None):
    ''' Regenerate one or both keys for a storage account.
    :param str key:Key to renew.'''
    from azure.cli.command_modules.storage._params import storage_account_key_options
    scf = storage_client_factory()
    for k in [storage_account_key_options[key]] if key \
        else storage_account_key_options.values():
        result = scf.storage_accounts.regenerate_key(
            resource_group_name=resource_group_name,
            account_name=account_name,
            key_name=k)
    return result
示例#22
0
def set_storage_account_properties(
        resource_group_name, account_name, sku=None, tags=None, custom_domain=None,
        encryption=None, access_tier=None):
    ''' Update storage account property (only one at a time).'''
    from azure.mgmt.storage.models import \
        (StorageAccountUpdateParameters, Sku, CustomDomain, Encryption, AccessTier)
    scf = storage_client_factory()
    params = StorageAccountUpdateParameters(
        sku=Sku(sku) if sku else None,
        tags=tags,
        custom_domain=CustomDomain(custom_domain) if custom_domain else None,
        encryption=encryption,
        access_tier=AccessTier(access_tier) if access_tier else None)
    return scf.storage_accounts.update(resource_group_name, account_name, params)
示例#23
0
def show_storage_account_connection_string(
        resource_group_name, account_name, protocol='https', blob_endpoint=None,
        file_endpoint=None, queue_endpoint=None, table_endpoint=None, key_name='primary'):
    """ Generate connection string for a storage account."""
    scf = storage_client_factory()
    keys = scf.storage_accounts.list_keys(resource_group_name, account_name).keys #pylint: disable=no-member
    connection_string = 'DefaultEndpointsProtocol={};AccountName={};AccountKey={}'.format(
        protocol,
        account_name,
        keys[0].value if key_name == 'primary' else keys[1].value) #pylint: disable=no-member
    connection_string = '{}{}'.format(connection_string, ';BlobEndpoint={}'.format(blob_endpoint) if blob_endpoint else '')
    connection_string = '{}{}'.format(connection_string, ';FileEndpoint={}'.format(file_endpoint) if file_endpoint else '')
    connection_string = '{}{}'.format(connection_string, ';QueueEndpoint={}'.format(queue_endpoint) if queue_endpoint else '')
    connection_string = '{}{}'.format(connection_string, ';TableEndpoint={}'.format(table_endpoint) if table_endpoint else '')
    return {'connectionString': connection_string}
示例#24
0
def create_storage_account(resource_group_name, account_name, sku, location,
                           kind=Kind.storage.value, tags=None, custom_domain=None,
                           encryption=None, access_tier=None):
    ''' Create a storage account. '''
    from azure.mgmt.storage.models import \
        (StorageAccountCreateParameters, Sku, CustomDomain, Encryption, AccessTier)
    scf = storage_client_factory()
    params = StorageAccountCreateParameters(
        sku=Sku(sku),
        kind=Kind(kind),
        location=location,
        tags=tags,
        custom_domain=CustomDomain(custom_domain) if custom_domain else None,
        encryption=encryption,
        access_tier=AccessTier(access_tier) if access_tier else None)
    return scf.storage_accounts.create(resource_group_name, account_name, params)
示例#25
0
def create_storage_account(resource_group_name,
                           account_name,
                           location,
                           account_type,
                           tags=None):
    ''' Create a storage account. '''
    from azure.mgmt.storage.models import StorageAccountCreateParameters, Sku
    scf = storage_client_factory()
    # TODO Add the other new params from rc5
    # https://github.com/Azure/azure-sdk-for-python/blob/v2.0.0rc5/
    # azure-mgmt-storage/azure/mgmt/storage/models/storage_account_create_parameters.py
    # accountType is now called sku.name also.
    params = StorageAccountCreateParameters(Sku(account_type), 'Storage',
                                            location, tags)
    return scf.storage_accounts.create(resource_group_name, account_name,
                                       params)
示例#26
0
def set_storage_account_properties(resource_group_name,
                                   account_name,
                                   account_type=None,
                                   tags='',
                                   custom_domain=None):
    ''' Update storage account property (only one at a time).
    :param str custom_domain:the custom domain name
    '''
    from azure.mgmt.storage.models import StorageAccountUpdateParameters, CustomDomain, Sku
    scf = storage_client_factory()
    # TODO Add the new params encryption and access_tier after rc5 update
    sku = Sku(account_type) if account_type else None
    params = StorageAccountUpdateParameters(sku=sku,
                                            tags=tags,
                                            custom_domain=custom_domain)
    return scf.storage_accounts.update(resource_group_name, account_name,
                                       params)
示例#27
0
def create_storage_account(resource_group_name, account_name, sku, location,
                           kind=None, tags=None, custom_domain=None,
                           encryption=None, access_tier=None):
    StorageAccountCreateParameters, Kind, Sku, CustomDomain, AccessTier = get_sdk(
        ResourceType.MGMT_STORAGE,
        'StorageAccountCreateParameters',
        'Kind',
        'Sku',
        'CustomDomain',
        'AccessTier',
        mod='models')
    scf = storage_client_factory()
    params = StorageAccountCreateParameters(
        sku=Sku(sku),
        kind=Kind(kind),
        location=location,
        tags=tags,
        custom_domain=CustomDomain(custom_domain, None) if custom_domain else None,
        encryption=encryption,
        access_tier=AccessTier(access_tier) if access_tier else None)
    return scf.storage_accounts.create(resource_group_name, account_name, params)
示例#28
0
def create_storage_account(resource_group_name,
                           account_name,
                           sku,
                           assign_identity=False,
                           location=None,
                           kind=None,
                           encryption_services=None,
                           tags=None,
                           custom_domain=None,
                           access_tier=None,
                           https_only=None):
    StorageAccountCreateParameters, Kind, Sku, CustomDomain, AccessTier, Identity, Encryption = get_sdk(
        ResourceType.MGMT_STORAGE,
        'StorageAccountCreateParameters',
        'Kind',
        'Sku',
        'CustomDomain',
        'AccessTier',
        'Identity',
        'Encryption',
        mod='models')
    scf = storage_client_factory()
    params = StorageAccountCreateParameters(sku=Sku(sku),
                                            kind=Kind(kind),
                                            location=location,
                                            tags=tags)
    if custom_domain:
        params.custom_domain = CustomDomain(custom_domain, None)
    if encryption_services:
        params.encryption = Encryption(services=encryption_services)
    if access_tier:
        params.access_tier = AccessTier(access_tier)
    if assign_identity:
        params.identity = Identity()
    if https_only:
        params.enable_https_traffic_only = https_only

    return scf.storage_accounts.create(resource_group_name, account_name,
                                       params)
示例#29
0
block_blob_path = 'azure.storage.blob.blockblobservice#BlockBlobService.'
base_blob_path = 'azure.storage.blob.baseblobservice#BaseBlobService.'
table_path = 'azure.storage.table.tableservice#TableService.'
queue_path = 'azure.storage.queue.queueservice#QueueService.'


def _dont_fail_not_exist(ex):
    from azure.storage._error import AzureMissingResourceHttpError
    if isinstance(ex, AzureMissingResourceHttpError):
        return None
    else:
        raise ex


# storage account commands
factory = lambda kwargs: storage_client_factory(
).storage_accounts  # noqa: E731 lambda vs def
cli_command(__name__, 'storage account check-name',
            mgmt_path + 'check_name_availability', factory)
cli_command(__name__,
            'storage account delete',
            mgmt_path + 'delete',
            factory,
            confirmation=True)
cli_command(__name__,
            'storage account show',
            mgmt_path + 'get_properties',
            factory,
            exception_handler=empty_on_404)
cli_command(__name__, 'storage account create',
            custom_path + 'create_storage_account')
cli_command(__name__, 'storage account list',
示例#30
0
def show_storage_account_usage():
    """ Show the current count and limit of the storage accounts under the subscription. """
    scf = storage_client_factory()
    return next((x for x in scf.usage.list() if x.name.value == 'StorageAccounts'), None)  # pylint: disable=no-member
示例#31
0
     table_data_service_factory, queue_data_service_factory, cloud_storage_account_service_factory)
from azure.cli.command_modules.storage.custom import \
    (create_storage_account, list_storage_accounts, show_storage_account_usage,
     set_storage_account_properties, show_storage_account_connection_string,
     upload_blob, get_acl_policy,
     create_acl_policy, delete_acl_policy, list_acl_policies, set_acl_policy,
     insert_table_entity, list_cors, add_cors, clear_cors,
     get_logging, set_logging, get_metrics, set_metrics)
from azure.cli.command_modules.storage._validators import \
    (transform_acl_list_output, transform_cors_list_output, transform_entity_query_output,
     transform_file_list_output, transform_logging_list_output, transform_metrics_list_output,
     transform_url, transform_storage_list_output, transform_storage_exists_output,
     transform_storage_boolean_output, transform_container_permission_output)

# storage account commands
factory = lambda kwargs: storage_client_factory().storage_accounts
cli_command('storage account check-name', StorageAccountsOperations.check_name_availability, factory)
cli_command('storage account delete', StorageAccountsOperations.delete, factory)
cli_command('storage account show', StorageAccountsOperations.get_properties, factory)
cli_command('storage account create', create_storage_account)
cli_command('storage account list', list_storage_accounts)
cli_command('storage account show-usage', show_storage_account_usage)
cli_command('storage account update', set_storage_account_properties)
cli_command('storage account show-connection-string', show_storage_account_connection_string)
cli_command('storage account keys renew', StorageAccountsOperations.regenerate_key, factory)
cli_command('storage account keys list', StorageAccountsOperations.list_keys, factory)
cli_storage_data_plane_command('storage account generate-sas', CloudStorageAccount.generate_shared_access_signature, cloud_storage_account_service_factory)

# container commands
factory = blob_data_service_factory
cli_storage_data_plane_command('storage container list', BlockBlobService.list_containers, factory, transform=transform_storage_list_output)
示例#32
0
from azure.cli.commands import cli_command

from azure.cli.command_modules.storage._command_type import cli_storage_data_plane_command
from azure.cli.command_modules.storage._factory import \
    (storage_client_factory, blob_data_service_factory, file_data_service_factory,
     table_data_service_factory, queue_data_service_factory, cloud_storage_account_service_factory)
from azure.cli.command_modules.storage.custom import \
    (create_storage_account, list_storage_accounts, show_storage_account_usage,
     set_storage_account_properties, show_storage_account_connection_string,
     renew_storage_account_keys, upload_blob, get_acl_policy,
     create_acl_policy, delete_acl_policy, list_acl_policies, set_acl_policy,
     insert_table_entity)
from azure.cli.command_modules.storage._validators import transform_acl_list_output, transform_url

# storage account commands
factory = lambda kwargs: storage_client_factory().storage_accounts
cli_command('storage account check-name', StorageAccountsOperations.check_name_availability, factory)
cli_command('storage account delete', StorageAccountsOperations.delete, factory)
cli_command('storage account show', StorageAccountsOperations.get_properties, factory)
cli_command('storage account create', create_storage_account)
cli_command('storage account list', list_storage_accounts, simple_output_query='[*].{Name: name, ResourceGroup: resourceGroup, Location: location, SkuName: sku.name, SkuTier: sku.tier} | sort_by(@, &Name)')
cli_command('storage account show-usage', show_storage_account_usage, simple_output_query='{Name:name.localizedValue, Current:currentValue, Max:limit}')
cli_command('storage account update', set_storage_account_properties)
cli_command('storage account connection-string', show_storage_account_connection_string)
cli_command('storage account keys renew', renew_storage_account_keys)
cli_command('storage account keys list', StorageAccountsOperations.list_keys, factory)
cli_storage_data_plane_command('storage account generate-sas', CloudStorageAccount.generate_shared_access_signature, cloud_storage_account_service_factory)

# container commands
factory = blob_data_service_factory
cli_storage_data_plane_command('storage container list', BlockBlobService.list_containers, factory, simple_output_query='items[*].{Name: name, LeaseState: properties.leaseState} | sort_by(@, &Name)')
示例#33
0
block_blob_path = 'azure.storage.blob.blockblobservice#BlockBlobService.'
base_blob_path = 'azure.storage.blob.baseblobservice#BaseBlobService.'
table_path = 'azure.storage.table.tableservice#TableService.'
queue_path = 'azure.storage.queue.queueservice#QueueService.'


def _dont_fail_not_exist(ex):
    from azure.storage._error import AzureMissingResourceHttpError
    if isinstance(ex, AzureMissingResourceHttpError):
        return None
    else:
        raise ex


# storage account commands
factory = lambda kwargs: storage_client_factory().storage_accounts  # noqa: E731 lambda vs def
cli_command(__name__, 'storage account check-name', mgmt_path + 'check_name_availability', factory)
cli_command(__name__, 'storage account delete', mgmt_path + 'delete', factory, confirmation=True)
cli_command(__name__, 'storage account show', mgmt_path + 'get_properties', factory, exception_handler=empty_on_404)
cli_command(__name__, 'storage account create', custom_path + 'create_storage_account')
cli_command(__name__, 'storage account list', custom_path + 'list_storage_accounts')
cli_command(__name__, 'storage account show-usage', custom_path + 'show_storage_account_usage')
cli_command(__name__, 'storage account show-connection-string', custom_path + 'show_storage_account_connection_string')
cli_command(__name__, 'storage account keys renew', mgmt_path + 'regenerate_key', factory, transform=lambda x: x.keys)
cli_command(__name__, 'storage account keys list', mgmt_path + 'list_keys', factory, transform=lambda x: x.keys)
cli_generic_update_command(__name__, 'storage account update',
                           mgmt_path + 'get_properties',
                           mgmt_path + 'create', factory,
                           custom_function_op=custom_path + 'update_storage_account')
cli_storage_data_plane_command('storage account generate-sas', 'azure.storage.cloudstorageaccount#CloudStorageAccount.generate_shared_access_signature', cloud_storage_account_service_factory)