Пример #1
0
def load_arguments(self, _):

    with self.argument_context('backup') as c:
        c.argument('force',
                   action='store_true',
                   help='Force completion of the requested action.')

    # Vault
    with self.argument_context('backup vault') as c:
        c.argument('vault_name',
                   vault_name_type,
                   options_list=['--name', '-n'],
                   id_part='name')
        c.argument('location',
                   validator=get_default_location_from_resource_group)

    with self.argument_context('backup vault create') as c:
        c.argument('tags', arg_type=tags_type)

    with self.argument_context('backup vault backup-properties set') as c:
        c.argument(
            'backup_storage_redundancy',
            arg_type=get_enum_type(['GeoRedundant', 'LocallyRedundant']),
            help='Sets backup storage properties for a Recovery Services vault.'
        )
        c.argument(
            'soft_delete_feature_state',
            arg_type=get_enum_type(['Enable', 'Disable']),
            help='Set soft-delete feature state for a Recovery Services Vault.'
        )
        c.argument(
            'cross_region_restore_flag',
            arg_type=get_enum_type(['True', 'False']),
            help=
            'Set cross-region-restore feature state for a Recovery Services Vault. Default: False.'
        )

    # Identity
    with self.argument_context('backup vault identity assign') as c:
        c.argument('vault_name',
                   vault_name_type,
                   options_list=['--name', '-n'],
                   id_part='name')
        c.argument('system_assigned', system_assigned_type)
        c.argument('user_assigned', user_assigned_type)

    with self.argument_context('backup vault identity remove') as c:
        c.argument('vault_name',
                   vault_name_type,
                   options_list=['--name', '-n'],
                   id_part='name')
        c.argument('system_assigned', system_assigned_remove_type)
        c.argument('user_assigned', user_assigned_remove_type)

    with self.argument_context('backup vault identity show') as c:
        c.argument('vault_name',
                   vault_name_type,
                   options_list=['--name', '-n'],
                   id_part='name')

    # Encryption
    with self.argument_context('backup vault encryption') as c:
        c.argument('vault_name',
                   vault_name_type,
                   options_list=['--name', '-n'],
                   id_part='name')

    with self.argument_context('backup vault encryption update') as c:
        c.argument('encryption_key_id', encryption_key_id_type)
        c.argument('infrastructure_encryption', infrastructure_encryption_type)
        c.argument('mi_user_assigned', mi_user_assigned_type)
        c.argument('mi_system_assigned', mi_system_assigned_type)

    with self.argument_context('backup vault encryption show') as c:
        c.argument('vault_name',
                   vault_name_type,
                   options_list=['--name', '-n'],
                   id_part='name')

    # Container
    with self.argument_context('backup container') as c:
        c.argument('vault_name', vault_name_type, id_part='name')
        c.ignore('status')

    with self.argument_context('backup container show') as c:
        c.argument(
            'name',
            container_name_type,
            options_list=['--name', '-n'],
            help=
            'Name of the container. You can use the backup container list command to get the name of a container.',
            id_part='child_name_2')
        c.argument('backup_management_type', extended_backup_management_type)
        c.argument('use_secondary_region',
                   action='store_true',
                   help='Use this flag to show container in secondary region.')

    with self.argument_context('backup container list') as c:
        c.argument('vault_name', vault_name_type, id_part=None)
        c.argument('backup_management_type', extended_backup_management_type)
        c.argument(
            'use_secondary_region',
            action='store_true',
            help='Use this flag to list containers in secondary region.')

    with self.argument_context('backup container unregister') as c:
        c.argument('backup_management_type', backup_management_type)
        c.argument('container_name',
                   container_name_type,
                   id_part='child_name_2')

    with self.argument_context('backup container re-register') as c:
        c.argument('backup_management_type', backup_management_type)
        c.argument('container_name',
                   container_name_type,
                   id_part='child_name_2')
        c.argument('workload_type', azure_workload_type)

    with self.argument_context('backup container register') as c:
        c.argument('vault_name', vault_name_type, id_part=None)
        c.argument('backup_management_type', backup_management_type)
        c.argument('resource_id', resource_id_type)
        c.argument('workload_type', azure_workload_type)

    # Item
    with self.argument_context('backup item') as c:
        c.argument('vault_name', vault_name_type, id_part='name')
        c.argument('container_name',
                   container_name_type,
                   id_part='child_name_2')

    with self.argument_context('backup item show') as c:
        c.argument(
            'name',
            item_name_type,
            options_list=['--name', '-n'],
            help=
            'Name of the backed up item. You can use the backup item list command to get the name of a backed up item.',
            id_part='child_name_3')
        c.argument('backup_management_type', extended_backup_management_type)
        c.argument('workload_type', workload_type)
        c.argument('use_secondary_region',
                   action='store_true',
                   help='Use this flag to show item in secondary region.')

    # TODO: Need to use item.id once https://github.com/Azure/msrestazure-for-python/issues/80 is fixed.
    with self.argument_context('backup item set-policy') as c:
        c.argument(
            'item_name',
            item_name_type,
            options_list=['--name', '-n'],
            help=
            'Name of the backed up item. You can use the backup item list command to get the name of a backed up item.',
            id_part='child_name_3')
        c.argument(
            'policy_name',
            policy_name_type,
            help=
            'Name of the Backup policy. You can use the backup policy list command to get the name of a backup policy.'
        )
        c.argument('backup_management_type', backup_management_type)
        c.argument('workload_type', workload_type)

    with self.argument_context('backup item list') as c:
        c.argument('vault_name', vault_name_type, id_part=None)
        c.argument('backup_management_type', extended_backup_management_type)
        c.argument('workload_type', workload_type)
        c.argument('use_secondary_region',
                   action='store_true',
                   help='Use this flag to list items in secondary region.')

    # Policy
    with self.argument_context('backup policy') as c:
        c.argument('vault_name', vault_name_type, id_part='name')

    for command in ['show', 'delete', 'list-associated-items']:
        with self.argument_context('backup policy ' + command) as c:
            c.argument(
                'name',
                policy_name_type,
                options_list=['--name', '-n'],
                help=
                'Name of the backup policy. You can use the backup policy list command to get the name of a policy.',
                id_part='child_name_1')

    with self.argument_context('backup policy list-associated-items') as c:
        c.argument('backup_management_type', backup_management_type)

    with self.argument_context('backup policy set') as c:
        c.argument(
            'policy',
            type=file_type,
            help=
            'JSON encoded policy definition. Use the show command with JSON output to obtain a policy object. Modify the values using a file editor and pass the object.',
            completer=FilesCompleter())
        c.argument('name',
                   options_list=['--name', '-n'],
                   help='Name of the Policy.',
                   id_part='child_name_1')
        c.argument(
            'fix_for_inconsistent_items',
            arg_type=get_three_state_flag(),
            options_list=['--fix-for-inconsistent-items'],
            help=
            'Specify whether or not to retry Policy Update for failed items.')
        c.argument('backup_management_type', backup_management_type)

    with self.argument_context('backup policy create') as c:
        c.argument(
            'policy',
            type=file_type,
            help=
            'JSON encoded policy definition. Use the show command with JSON output to obtain a policy object. Modify the values using a file editor and pass the object.',
            completer=FilesCompleter())
        c.argument('name',
                   options_list=['--name', '-n'],
                   help='Name of the Policy.')
        c.argument('backup_management_type', backup_management_type)
        c.argument('workload_type', workload_type)

    with self.argument_context('backup policy list') as c:
        c.argument('vault_name', vault_name_type, id_part=None)
        c.argument('backup_management_type', backup_management_type)
        c.argument('workload_type', workload_type)

    with self.argument_context('backup policy get-default-for-vm') as c:
        c.argument('vault_name', vault_name_type, id_part=None)

    # Recovery Point
    # TODO: Need to use item.id once https://github.com/Azure/msrestazure-for-python/issues/80 is fixed.
    with self.argument_context('backup recoverypoint') as c:
        c.argument('vault_name', vault_name_type, id_part='name')
        c.argument('container_name',
                   container_name_type,
                   id_part='child_name_2')
        c.argument('item_name', item_name_type, id_part='child_name_3')

    with self.argument_context('backup recoverypoint list') as c:
        c.argument('vault_name', vault_name_type, id_part=None)
        c.argument('start_date',
                   type=datetime_type,
                   help='The start date of the range in UTC (d-m-Y).')
        c.argument('end_date',
                   type=datetime_type,
                   help='The end date of the range in UTC (d-m-Y).')
        c.argument('backup_management_type', backup_management_type)
        c.argument('container_name', container_name_type)
        c.argument('workload_type', workload_type)
        c.argument(
            'use_secondary_region',
            action='store_true',
            help='Use this flag to list recoverypoints in secondary region.')
        c.argument(
            'is_ready_for_move',
            arg_type=get_three_state_flag(),
            help=
            'Use this flag to retrieve the recoverypoints that are ready to be moved to destination-tier.'
        )
        c.argument('target_tier', target_tier_type)
        c.argument('tier', tier_type)
        c.argument(
            'recommended_for_archive',
            action="store_true",
            help=
            'Use this flag to retrieve recommended archivable recoverypoints.')

    with self.argument_context('backup recoverypoint move') as c:
        c.argument('vault_name', vault_name_type, id_part=None)
        c.argument('container_name', container_name_type)
        c.argument('rp_name',
                   rp_name_type,
                   options_list=['--name', '-n'],
                   id_part='child_name_4')
        c.argument('backup_management_type', backup_management_type)
        c.argument('workload_type', workload_type)
        c.argument(
            'source_tier',
            help=
            'The source tier from which a particular recovery point has to be moved.',
            arg_type=get_enum_type(['VaultStandard']),
            options_list=['--source-tier'])
        c.argument('destination_tier',
                   help=target_tier_help,
                   arg_type=get_enum_type(['VaultArchive']),
                   options_list=['--destination-tier'])

    with self.argument_context('backup recoverypoint show-log-chain') as c:
        c.argument('vault_name', vault_name_type, id_part=None)
        c.argument('start_date',
                   type=datetime_type,
                   help='The start date of the range in UTC (d-m-Y).')
        c.argument('end_date',
                   type=datetime_type,
                   help='The end date of the range in UTC (d-m-Y).')
        c.argument('backup_management_type', backup_management_type)
        c.argument('container_name', container_name_type)
        c.argument('workload_type', workload_type)
        c.argument(
            'use_secondary_region',
            action='store_true',
            help='Use this flag to list recoverypoints in secondary region.')

    with self.argument_context('backup recoverypoint show') as c:
        c.argument(
            'name',
            rp_name_type,
            options_list=['--name', '-n'],
            help=
            'Name of the recovery point. You can use the backup recovery point list command to get the name of a backed up item.',
            id_part='child_name_4')
        c.argument('backup_management_type', backup_management_type)
        c.argument('container_name', container_name_type)
        c.argument('workload_type', workload_type)
        c.argument(
            'use_secondary_region',
            action='store_true',
            help='Use this flag to show recoverypoints in secondary region.')

    # Protection
    with self.argument_context('backup protection') as c:
        c.argument('vault_name', vault_name_type, id_part='name')
        c.argument('vm',
                   help='Name or ID of the Virtual Machine to be protected.')
        c.argument('policy_name', policy_name_type)

    # TODO: Need to use item.id once https://github.com/Azure/msrestazure-for-python/issues/80 is fixed.
    for command in [
            'backup-now', 'disable', 'auto-disable-for-azurewl', 'resume',
            'undelete', 'update-for-vm'
    ]:
        with self.argument_context('backup protection ' + command) as c:
            c.argument('container_name',
                       container_name_type,
                       id_part='child_name_2')
            c.argument('item_name', item_name_type, id_part='child_name_3')
            c.argument('backup_management_type', backup_management_type)
            c.argument('workload_type', workload_type)
            c.argument('enable_compression',
                       arg_type=get_three_state_flag(),
                       help='Option to enable compression')
            c.argument('backup_type',
                       help=backup_type_help,
                       options_list=['--backup-type'])

    with self.argument_context('backup protection backup-now') as c:
        c.argument('retain_until', type=datetime_type, help=retain_until_help)

    with self.argument_context('backup protection disable') as c:
        c.argument(
            'delete_backup_data',
            arg_type=get_three_state_flag(),
            help=
            'Option to delete existing backed up data in the Recovery services vault.'
        )
        c.argument('backup_management_type', backup_management_type)
        c.argument('workload_type', workload_type)

    with self.argument_context('backup protection check-vm') as c:
        c.argument(
            'vm_id',
            help='ID of the virtual machine to be checked for protection.',
            deprecate_info=c.deprecate(redirect='--vm', hide=True))

    with self.argument_context('backup protection enable-for-vm') as c:
        c.argument('vault_name', vault_name_type, id_part=None)
        c.argument('diskslist', diskslist_type)
        c.argument('disk_list_setting',
                   arg_type=get_enum_type(['include', 'exclude']),
                   options_list=['--disk-list-setting'],
                   help=disk_list_setting_help)
        c.argument('exclude_all_data_disks',
                   arg_type=get_three_state_flag(),
                   help='Option to specify to backup OS disk only.')

    with self.argument_context('backup protection update-for-vm') as c:
        c.argument('diskslist', diskslist_type)
        c.argument('disk_list_setting',
                   arg_type=get_enum_type(
                       ['include', 'exclude', 'resetexclusionsettings']),
                   options_list=['--disk-list-setting'],
                   help=disk_list_setting_help)
        c.argument('exclude_all_data_disks',
                   arg_type=get_three_state_flag(),
                   help='Option to specify to backup OS disk only.')

    with self.argument_context(
            'backup protection enable-for-azurefileshare') as c:
        c.argument('vault_name', vault_name_type, id_part=None)
        c.argument('azure_file_share',
                   options_list=['--azure-file-share'],
                   help='Name of the Azure FileShare.')
        c.argument('storage_account',
                   options_list=['--storage-account'],
                   help='Name of the Storage Account of the FileShare.')

    for command in ["enable-for-azurewl", "auto-enable-for-azurewl"]:
        with self.argument_context('backup protection ' + command) as c:
            c.argument('vault_name', vault_name_type, id_part=None)
            c.argument('protectable_item_type', protectable_item_type)
            c.argument('protectable_item_name', protectable_item_name_type)
            c.argument('server_name',
                       options_list=['--server-name'],
                       help='Parent Server name of the item.')
            c.argument('workload_type', workload_type)

    # Protectable-item
    with self.argument_context('backup protectable-item') as c:
        c.argument('vault_name', vault_name_type)
        c.argument('workload_type', azure_workload_type)
        c.argument('container_name', container_name_type)

    with self.argument_context('backup protectable-item show') as c:
        c.argument('vault_name', vault_name_type, id_part='name')
        c.argument('name',
                   options_list=['--name'],
                   help='Name of the protectable item.',
                   id_part='child_name_3')
        c.argument('server_name',
                   options_list=['--server-name'],
                   help='Parent Server name of the item.')
        c.argument('protectable_item_type', protectable_item_type)

    with self.argument_context('backup protectable-item list') as c:
        c.argument('server_name',
                   options_list=['--server-name'],
                   help='Parent Server name of the item.')
        c.argument('protectable_item_type', protectable_item_type)
        c.argument('backup_management_type', backup_management_type)

    # Restore
    # TODO: Need to use recovery_point.id once https://github.com/Azure/msrestazure-for-python/issues/80 is fixed.
    with self.argument_context('backup restore') as c:
        c.argument('vault_name', vault_name_type, id_part='name')
        c.argument('container_name',
                   container_name_type,
                   id_part='child_name_2')
        c.argument('item_name', item_name_type, id_part='child_name_3')
        c.argument('rp_name', rp_name_type, id_part='child_name_4')

    with self.argument_context('backup restore restore-disks') as c:
        c.argument(
            'storage_account',
            help=
            'Name or ID of the staging storage account. The VM configuration will be restored to this storage account. See the help for --restore-to-staging-storage-account parameter for more info.'
        )
        c.argument(
            'restore_to_staging_storage_account',
            arg_type=get_three_state_flag(),
            help=
            'Use this flag when you want disks to be restored to the staging storage account using the --storage-account parameter. When not specified, disks will be restored to their original storage accounts. Default: false.'
        )
        c.argument(
            'target_resource_group',
            options_list=['--target-resource-group', '-t'],
            help=
            'Use this to specify the target resource group in which the restored disks will be saved'
        )
        c.argument('diskslist', diskslist_type)
        c.argument(
            'restore_only_osdisk',
            arg_type=get_three_state_flag(),
            help='Use this flag to restore only OS disks of a backed up VM.')
        c.argument(
            'restore_as_unmanaged_disks',
            arg_type=get_three_state_flag(),
            help='Use this flag to specify to restore as unmanaged disks')
        c.argument(
            'use_secondary_region',
            action='store_true',
            help=
            'Use this flag to restore from a recoverypoint in secondary region.'
        )
        c.argument(
            'rehydration_duration',
            type=int,
            help=
            'Set the maximum time, in days (between 10-30, both inclusive) for which the recovery point stays in hydrated state.'
        )
        c.argument('rehydration_priority', rehyd_priority_type)
        c.argument(
            'disk_encryption_set_id',
            options_list=['--disk-encryption-set-id'],
            help=
            'The disk encryption set id is used for encrypting restored disks. Please ensure access to disk encryption set id that is specified here.'
        )
        c.argument(
            'mi_system_assigned',
            action='store_true',
            help=
            'Use this flag to specify whether a system-assigned managed identity should be used for the restore operation. MI option is not applicable for restoring unmanaged disks.'
        )
        c.argument(
            'mi_user_assigned',
            help=
            'ARM ID of the user-assigned managed identity to use for the restore operation. Specify a value for this parameter if you do not want to use a system-assigned MI for restoring the backup item.'
        )

    with self.argument_context('backup restore restore-azurefileshare') as c:
        c.argument('resolve_conflict', resolve_conflict_type)
        c.argument('restore_mode', restore_mode_type)
        c.argument(
            'target_file_share',
            options_list=['--target-file-share'],
            help='Destination file share to which content will be restored')
        c.argument(
            'target_folder',
            options_list=['--target-folder'],
            help=
            'Destination folder to which content will be restored. To restore content to root , leave the folder name empty'
        )
        c.argument(
            'target_storage_account',
            options_list=['--target-storage-account'],
            help='Destination storage account to which content will be restored'
        )

    with self.argument_context('backup restore restore-azurefiles') as c:
        c.argument('resolve_conflict', resolve_conflict_type)
        c.argument('restore_mode', restore_mode_type)
        c.argument(
            'target_file_share',
            options_list=['--target-file-share'],
            help='Destination file share to which content will be restored')
        c.argument(
            'target_folder',
            options_list=['--target-folder'],
            help=
            'Destination folder to which content will be restored. To restore content to root , leave the folder name empty'
        )
        c.argument(
            'target_storage_account',
            options_list=['--target-storage-account'],
            help='Destination storage account to which content will be restored'
        )
        c.argument('source_file_type',
                   arg_type=get_enum_type(['File', 'Directory']),
                   options_list=['--source-file-type'],
                   help='Specify the source file type to be selected')
        c.argument(
            'source_file_path',
            options_list=['--source-file-path'],
            nargs='+',
            help=
            """The absolute path of the file, to be restored within the file share, as a string. This path is the same path used in the 'az storage file download' or 'az storage file show' CLI commands."""
        )

    with self.argument_context('backup restore restore-azurewl') as c:
        c.argument('vault_name', vault_name_type, id_part=None)
        c.argument(
            'recovery_config',
            options_list=['--recovery-config'],
            help=
            """Specify the recovery configuration of a backed up item. The configuration object can be obtained from 'backup recoveryconfig show' command."""
        )
        c.argument(
            'rehydration_duration',
            type=int,
            help=
            'Set the maximum time, in days (between 10-30, both inclusive) for which the recovery point stays in hydrated state.'
        )
        c.argument('rehydration_priority', rehyd_priority_type)
        c.argument(
            'use_secondary_region',
            action='store_true',
            help=
            'Use this flag to restore from a recoverypoint in secondary region.'
        )

    # Recoveryconfig
    with self.argument_context('backup recoveryconfig show') as c:
        c.argument('container_name',
                   container_name_type,
                   id_part='child_name_2')
        c.argument('item_name', item_name_type, id_part='child_name_3')
        c.argument('restore_mode', restore_mode_workload_type)
        c.argument('vault_name', vault_name_type, id_part='name')
        c.argument(
            'log_point_in_time',
            options_list=['--log-point-in-time'],
            help="""Specify the point-in-time which will be restored.""")
        c.argument('rp_name', rp_name_type)
        c.argument(
            'target_item_name',
            options_list=['--target-item-name'],
            help="""Specify the target item name for the restore operation.""")
        c.argument('target_server_type', target_server_type)
        c.argument(
            'target_server_name',
            options_list=['--target-server-name'],
            help="""Specify the parent server name of the target item.""")
        c.argument('workload_type', azure_workload_type)
        c.argument('target_container_name', target_container_name_type)
        c.argument('from_full_rp_name', from_full_rp_type)
        c.argument('filepath', filepath_type)
        c.argument('backup_management_type', backup_management_type)
        c.argument(
            'target_resource_group',
            options_list=['--target-resource-group'],
            help=
            """Specify the resource group of target item for Cross Region Restore. Default value will be same as --resource-group if not specified."""
        )
        c.argument(
            'target_vault_name',
            options_list=['--target-vault-name'],
            help=
            """Specify the vault name of target item for Cross Region Restore. Default value will be same as --vault-name if not specified."""
        )

    # Job
    with self.argument_context('backup job') as c:
        c.argument('vault_name', vault_name_type, id_part='name')

    # TODO: Need to use job.id once https://github.com/Azure/msrestazure-for-python/issues/80 is fixed.
    for command in ['show', 'stop', 'wait']:
        with self.argument_context('backup job ' + command) as c:
            c.argument(
                'name',
                job_name_type,
                help=
                'Name of the job. You can use the backup job list command to get the name of a job.',
                id_part='child_name_1')
            c.argument(
                'use_secondary_region',
                action='store_true',
                help='Use this flag to show recoverypoints in secondary region.'
            )

    with self.argument_context('backup job list') as c:
        c.argument('vault_name', vault_name_type, id_part=None)
        c.argument('status',
                   arg_type=get_enum_type([
                       'Cancelled', 'Completed', 'CompletedWithWarnings',
                       'Failed', 'InProgress'
                   ]),
                   help='Status of the Job.')
        c.argument('operation',
                   arg_type=get_enum_type([
                       'Backup', 'ConfigureBackup', 'DeleteBackupData',
                       'DisableBackup', 'Restore'
                   ]),
                   help='User initiated operation.')
        c.argument('start_date',
                   type=datetime_type,
                   help='The start date of the range in UTC (d-m-Y).')
        c.argument('end_date',
                   type=datetime_type,
                   help='The end date of the range in UTC (d-m-Y).')
        c.argument('backup_management_type', extended_backup_management_type)
        c.argument(
            'use_secondary_region',
            action='store_true',
            help='Use this flag to show recoverypoints in secondary region.')

    with self.argument_context('backup job wait') as c:
        c.argument('timeout',
                   type=int,
                   help='Maximum time, in seconds, to wait before aborting.')
Пример #2
0
def load_arguments(self, _):

    # ACS command argument configuration
    with self.argument_context('acs') as c:
        c.argument(
            'resource_name',
            name_type,
            completer=get_resource_name_completion_list(
                'Microsoft.ContainerService/ContainerServices'),
            help=
            'Name of the container service. You can configure the default using `az configure --defaults acs=<name>`'
        )
        c.argument(
            'name',
            name_type,
            completer=get_resource_name_completion_list(
                'Microsoft.ContainerService/ContainerServices'),
            help=
            'Name of the container service. You can configure the default using `az configure --defaults acs=<name>`'
        )
        c.argument(
            'container_service_name',
            name_type,
            help=
            'Name of the container service. You can configure the default using `az configure --defaults acs=<name>`',
            completer=get_resource_name_completion_list(
                'Microsoft.ContainerService/ContainerServices'))
        c.argument('admin_username',
                   options_list=['--admin-username', '-u'],
                   default='azureuser')
        c.argument(
            'api_version',
            help=_get_feature_in_preview_message() +
            'Use API version of ACS to perform az acs operations. Available options: 2017-01-31, 2017-07-01. Default: the latest version for the location'
        )
        c.argument('dns_name_prefix', options_list=['--dns-prefix', '-d'])
        c.argument('orchestrator_type',
                   get_enum_type(orchestrator_types),
                   options_list=['--orchestrator-type', '-t'])
        c.argument('ssh_key_value',
                   required=False,
                   type=file_type,
                   default=os.path.join('~', '.ssh', 'id_rsa.pub'),
                   completer=FilesCompleter(),
                   validator=validate_ssh_key)
        c.argument('tags', tags_type)
        c.argument(
            'disable_browser',
            help=
            'Do not open browser after opening a proxy to the cluster web user interface'
        )

    with self.argument_context('acs create') as c:
        c.argument('ssh_key_value',
                   required=False,
                   type=file_type,
                   default=os.path.join('~', '.ssh', 'id_rsa.pub'),
                   completer=FilesCompleter(),
                   validator=validate_ssh_key)
        c.argument(
            'master_profile',
            options_list=['--master-profile', '-m'],
            type=validate_file_or_dict,
            help=_get_feature_in_preview_message() +
            'The file or dictionary representation of the master profile. Note it will override any master settings once set'
        )
        c.argument('master_vm_size',
                   completer=get_vm_size_completion_list,
                   help=_get_feature_in_preview_message())
        c.argument('agent_count', type=int)
        c.argument('generate_ssh_keys',
                   action='store_true',
                   validator=validate_create_parameters,
                   help='Generate SSH public and private key files if missing')
        c.argument(
            'master_osdisk_size',
            type=int,
            help=_get_feature_in_preview_message() +
            'The disk size for master pool vms. Unit in GB. Default: corresponding vmsize disk size'
        )
        c.argument(
            'master_vnet_subnet_id',
            type=str,
            help=_get_feature_in_preview_message() +
            'The custom vnet subnet id. Note agent need to used the same vnet if master set. Default: ""'
        )
        c.argument('master_first_consecutive_static_ip',
                   type=str,
                   help=_get_feature_in_preview_message() +
                   'The first consecutive ip used to specify static ip block.')
        c.argument('master_storage_profile',
                   get_enum_type(storage_profile_types),
                   help=_get_feature_in_preview_message() +
                   'Default: varies based on Orchestrator')
        c.argument(
            'agent_profiles',
            options_list=['--agent-profiles', '-a'],
            type=validate_file_or_dict,
            help=_get_feature_in_preview_message() +
            'The file or dictionary representation of the agent profiles. Note it will override any agent settings once set'
        )
        c.argument('agent_vm_size',
                   completer=get_vm_size_completion_list,
                   help='Set the default size for agent pools vms.')
        c.argument(
            'agent_osdisk_size',
            type=int,
            help=_get_feature_in_preview_message() +
            'Set the default disk size for agent pools vms. Unit in GB. Default: corresponding vmsize disk size'
        )
        c.argument(
            'agent_vnet_subnet_id',
            type=str,
            help=_get_feature_in_preview_message() +
            'Set the default custom vnet subnet id for agent pools. Note agent need to used the same vnet if master set. Default: ""'
        )
        c.argument(
            'agent_ports',
            type=validate_list_of_integers,
            help=_get_feature_in_preview_message() +
            'Set the default ports exposed on the agent pools. Only usable for non-Kubernetes. Default: 8080,4000,80'
        )
        c.argument(
            'agent_storage_profile',
            get_enum_type(storage_profile_types),
            help=_get_feature_in_preview_message() +
            'Set default storage profile for agent pools. Default: varies based on Orchestrator'
        )
        c.argument(
            'windows',
            action='store_true',
            help='If true, set the default osType of agent pools to be Windows.'
        )
        c.argument(
            'validate',
            action='store_true',
            help=
            'Generate and validate the ARM template without creating any resources'
        )
        c.argument(
            'orchestrator_version',
            help=_get_feature_in_preview_message() +
            'Use Orchestrator Version to specify the semantic version for your choice of orchestrator.'
        )

    with self.argument_context('acs scale') as c:
        c.argument('new_agent_count', type=int)

    with self.argument_context('acs dcos browse') as c:
        c.argument('ssh_key_file',
                   required=False,
                   type=file_type,
                   default=os.path.join('~', '.ssh', 'id_rsa'),
                   completer=FilesCompleter(),
                   help='Path to an SSH key file to use.')

    with self.argument_context('acs dcos install-cli') as c:
        c.argument('install_location',
                   default=_get_default_install_location('dcos'))

    with self.argument_context('acs kubernetes get-credentials') as c:
        c.argument('path', options_list=['--file', '-f'])

    with self.argument_context('acs kubernetes install-cli') as c:
        c.argument('install_location',
                   type=file_type,
                   completer=FilesCompleter(),
                   default=_get_default_install_location('kubectl'))
        c.argument('ssh_key_file',
                   required=False,
                   type=file_type,
                   default=os.path.join('~', '.ssh', 'id_rsa'),
                   completer=FilesCompleter(),
                   help='Path to an SSH key file to use.')

    # AKS command argument configuration
    with self.argument_context('aks') as c:
        c.argument('resource_name',
                   name_type,
                   help='Name of the managed cluster.',
                   completer=get_resource_name_completion_list(
                       'Microsoft.ContainerService/ManagedClusters'))
        c.argument('name',
                   name_type,
                   help='Name of the managed cluster.',
                   completer=get_resource_name_completion_list(
                       'Microsoft.ContainerService/ManagedClusters'))
        c.argument('kubernetes_version',
                   options_list=['--kubernetes-version', '-k'],
                   validator=validate_k8s_version)
        c.argument('node_count', options_list=['--node-count', '-c'], type=int)
        c.argument('tags', tags_type)

    with self.argument_context('aks create') as c:
        c.argument('name', validator=validate_linux_host_name)
        c.argument('kubernetes_version',
                   completer=get_k8s_versions_completion_list)
        c.argument('admin_username',
                   options_list=['--admin-username', '-u'],
                   default='azureuser')
        c.argument('dns_name_prefix', options_list=['--dns-name-prefix', '-p'])
        c.argument('generate_ssh_keys',
                   action='store_true',
                   validator=validate_create_parameters)
        c.argument('node_vm_size',
                   options_list=['--node-vm-size', '-s'],
                   completer=get_vm_size_completion_list)
        c.argument('ssh_key_value',
                   required=False,
                   type=file_type,
                   default=os.path.join('~', '.ssh', 'id_rsa.pub'),
                   completer=FilesCompleter(),
                   validator=validate_ssh_key)

    with self.argument_context('aks get-credentials') as c:
        c.argument('admin', options_list=['--admin', '-a'], default=False)
        c.argument('path',
                   options_list=['--file', '-f'],
                   type=file_type,
                   completer=FilesCompleter(),
                   default=os.path.join(os.path.expanduser('~'), '.kube',
                                        'config'))

    with self.argument_context('aks install-cli') as c:
        c.argument('client_version', validator=validate_k8s_client_version)
        c.argument('install_location',
                   default=_get_default_install_location('kubectl'))

    with self.argument_context('aks install-connector') as c:
        c.argument('chart_url',
                   default=aci_connector_chart_url,
                   help='URL to the chart')
        c.argument(
            'client_secret',
            help=
            'Client secret to use with the service principal for making calls to Azure APIs'
        )
        c.argument('connector_name',
                   help='The name for the ACI Connector',
                   validator=validate_connector_name)
        c.argument('os_type',
                   get_enum_type(aci_connector_os_type),
                   help='The OS type of the connector')
        c.argument(
            'service_principal',
            help=
            'Service principal for making calls into Azure APIs. If not set, auto generate a new service principal of Contributor role, and save it locally for reusing'
        )

    with self.argument_context('aks remove-connector') as c:
        c.argument('connector_name',
                   help='The name for the ACI Connector',
                   validator=validate_connector_name)
        c.argument(
            'graceful',
            action='store_true',
            help=
            'Mention if you want to drain/uncordon your aci-connector to move your applications'
        )
        c.argument('os_type',
                   get_enum_type(aci_connector_os_type),
                   help='The OS type of the connector')

    with self.argument_context('aks upgrade') as c:
        c.argument('kubernetes_version',
                   completer=get_k8s_upgrades_completion_list)
Пример #3
0
 def add_arguments(self, parser, cli_name):
     arg = parser.add_argument('POLICY_FILE_PATH',
                               help='path of the policy xml file')
     arg.completer = FilesCompleter(allowednames=('xml'), directories=False)
     add_strategy_node_arguments(parser)
Пример #4
0
def load_arguments(self, _):  # pylint: disable=too-many-locals, too-many-statements
    from argcomplete.completers import FilesCompleter
    from six import u as unicode_string

    from knack.arguments import ignore_type, CLIArgumentType

    from azure.cli.core.commands.parameters import get_resource_name_completion_list

    from .sdkutil import get_table_data_type
    from .completers import get_storage_name_completion_list, get_container_name_completions

    t_base_blob_service = self.get_sdk('blob.baseblobservice#BaseBlobService')
    t_file_service = self.get_sdk('file#FileService')
    t_queue_service = self.get_sdk('queue#QueueService')
    t_table_service = get_table_data_type(self.cli_ctx, 'table', 'TableService')

    acct_name_type = CLIArgumentType(options_list=['--account-name', '-n'], help='The storage account name.',
                                     id_part='name',
                                     completer=get_resource_name_completion_list('Microsoft.Storage/storageAccounts'))
    blob_name_type = CLIArgumentType(options_list=['--blob-name', '-b'], help='The blob name.',
                                     completer=get_storage_name_completion_list(t_base_blob_service, 'list_blobs',
                                                                                parent='container_name'))

    container_name_type = CLIArgumentType(options_list=['--container-name', '-c'], help='The container name.',
                                          completer=get_container_name_completions)
    directory_type = CLIArgumentType(options_list=['--directory-name', '-d'], help='The directory name.',
                                     completer=get_storage_name_completion_list(t_file_service,
                                                                                'list_directories_and_files',
                                                                                parent='share_name'))
    file_name_type = CLIArgumentType(options_list=['--file-name', '-f'],
                                     completer=get_storage_name_completion_list(t_file_service,
                                                                                'list_directories_and_files',
                                                                                parent='share_name'))
    share_name_type = CLIArgumentType(options_list=['--share-name', '-s'], help='The file share name.',
                                      completer=get_storage_name_completion_list(t_file_service, 'list_shares'))
    table_name_type = CLIArgumentType(options_list=['--table-name', '-t'],
                                      completer=get_storage_name_completion_list(t_table_service, 'list_tables'))
    queue_name_type = CLIArgumentType(options_list=['--queue-name', '-q'], help='The queue name.',
                                      completer=get_storage_name_completion_list(t_queue_service, 'list_queues'))
    progress_type = CLIArgumentType(help='Include this flag to disable progress reporting for the command.',
                                    action='store_true', validator=add_progress_callback)
    socket_timeout_type = CLIArgumentType(help='The socket timeout(secs), used by the service to regulate data flow.',
                                          type=int)

    sas_help = 'The permissions the SAS grants. Allowed values: {}. Do not use if a stored access policy is ' \
               'referenced with --id that specifies this value. Can be combined.'

    with self.argument_context('storage') as c:
        c.argument('container_name', container_name_type)
        c.argument('directory_name', directory_type)
        c.argument('share_name', share_name_type)
        c.argument('table_name', table_name_type)
        c.argument('retry_wait', options_list=('--retry-interval',))
        c.ignore('progress_callback')
        c.argument('metadata', nargs='+',
                   help='Metadata in space-separated key=value pairs. This overwrites any existing metadata.',
                   validator=validate_metadata)
        c.argument('timeout', help='Request timeout in seconds. Applies to each call to the service.', type=int)

    with self.argument_context('storage', arg_group='Precondition') as c:
        c.argument('if_modified_since', help='Alter only if modified since supplied UTC datetime (Y-m-d\'T\'H:M\'Z\')',
                   type=get_datetime_type(False))
        c.argument('if_unmodified_since',
                   help='Alter only if unmodified since supplied UTC datetime (Y-m-d\'T\'H:M\'Z\')',
                   type=get_datetime_type(False))
        c.argument('if_match')
        c.argument('if_none_match')

    for item in ['delete', 'show', 'update', 'show-connection-string', 'keys', 'network-rule']:
        with self.argument_context('storage account {}'.format(item)) as c:
            c.argument('account_name', acct_name_type, options_list=['--name', '-n'])
            c.argument('resource_group_name', required=False, validator=process_resource_group)

    with self.argument_context('storage account check-name') as c:
        c.argument('name', options_list=['--name', '-n'])

    with self.argument_context('storage account create') as c:
        t_account_type, t_sku_name, t_kind = self.get_models('AccountType', 'SkuName', 'Kind',
                                                             resource_type=CUSTOM_MGMT_STORAGE)
        c.register_common_storage_account_options()
        c.argument('hierarchical_namespace', help='Allows the blob service to exhibit filesystem semantics.',
                   arg_type=get_three_state_flag())
        c.argument('location', get_location_type(self.cli_ctx), validator=get_default_location_from_resource_group)
        c.argument('account_type', help='The storage account type', arg_type=get_enum_type(t_account_type))
        c.argument('account_name', acct_name_type, options_list=['--name', '-n'], completer=None)
        c.argument('kind', help='Indicates the type of storage account.',
                   arg_type=get_enum_type(t_kind, default='storage'))
        c.argument('tags', tags_type)
        c.argument('custom_domain', help='User domain assigned to the storage account. Name is the CNAME source.')
        c.argument('sku', help='The storage account SKU.', arg_type=get_enum_type(t_sku_name, default='standard_ragrs'))

    with self.argument_context('storage account update') as c:
        c.register_common_storage_account_options()
        c.argument('custom_domain',
                   help='User domain assigned to the storage account. Name is the CNAME source. Use "" to clear '
                        'existing value.',
                   validator=validate_custom_domain)
        c.argument('use_subdomain', help='Specify whether to use indirect CNAME validation.',
                   arg_type=get_enum_type(['true', 'false']))
        c.argument('tags', tags_type, default=None)

    with self.argument_context('storage account update', arg_group='Customer managed key', min_api='2017-06-01') as c:
        c.extra('encryption_key_name', help='The name of the KeyVault key', )
        c.extra('encryption_key_vault', help='The Uri of the KeyVault')
        c.extra('encryption_key_version', help='The version of the KeyVault key')
        c.argument('encryption_key_source',
                   arg_type=get_enum_type(['Microsoft.Storage', 'Microsoft.Keyvault'], 'Microsoft.Storage'),
                   help='The default encryption service',
                   validator=validate_encryption_source)
        c.ignore('encryption_key_vault_properties')

    for scope in ['storage account create', 'storage account update']:
        with self.argument_context(scope, resource_type=CUSTOM_MGMT_STORAGE, min_api='2017-06-01',
                                   arg_group='Network Rule') as c:
            t_bypass, t_default_action = self.get_models('Bypass', 'DefaultAction',
                                                         resource_type=CUSTOM_MGMT_STORAGE)

            c.argument('bypass', nargs='+', validator=validate_bypass, arg_type=get_enum_type(t_bypass),
                       help='Bypass traffic for space-separated uses.')
            c.argument('default_action', arg_type=get_enum_type(t_default_action),
                       help='Default action to apply when no rule matches.')

    with self.argument_context('storage account show-connection-string') as c:
        c.argument('protocol', help='The default endpoint protocol.', arg_type=get_enum_type(['http', 'https']))
        c.argument('key_name', options_list=['--key'], help='The key to use.',
                   arg_type=get_enum_type(list(storage_account_key_options.keys())))
        for item in ['blob', 'file', 'queue', 'table']:
            c.argument('{}_endpoint'.format(item), help='Custom endpoint for {}s.'.format(item))

    with self.argument_context('storage account keys renew') as c:
        c.argument('key_name', options_list=['--key'], help='The key to regenerate.', validator=validate_key,
                   arg_type=get_enum_type(list(storage_account_key_options.keys())))
        c.argument('account_name', acct_name_type, id_part=None)

    with self.argument_context('storage account keys list') as c:
        c.argument('account_name', acct_name_type, id_part=None)

    with self.argument_context('storage account network-rule') as c:
        from ._validators import validate_subnet
        c.argument('account_name', acct_name_type, id_part=None)
        c.argument('ip_address', help='IPv4 address or CIDR range.')
        c.argument('subnet', help='Name or ID of subnet. If name is supplied, `--vnet-name` must be supplied.')
        c.argument('vnet_name', help='Name of a virtual network.', validator=validate_subnet)
        c.argument('action', help='The action of virtual network rule.')

    with self.argument_context('storage account generate-sas') as c:
        t_account_permissions = self.get_sdk('common.models#AccountPermissions')
        c.register_sas_arguments()
        c.argument('services', type=services_type(self))
        c.argument('resource_types', type=resource_type_type(self))
        c.argument('expiry', type=get_datetime_type(True))
        c.argument('start', type=get_datetime_type(True))
        c.argument('account_name', acct_name_type, options_list=['--account-name'])
        c.argument('permission', options_list=('--permissions',),
                   help='The permissions the SAS grants. Allowed values: {}. Can be combined.'.format(
                       get_permission_help_string(t_account_permissions)),
                   validator=get_permission_validator(t_account_permissions))
        c.ignore('sas_token')

    with self.argument_context('storage account management-policy create') as c:
        c.argument('policy', type=file_type, completer=FilesCompleter(),
                   help='The Storage Account ManagementPolicies Rules, in JSON format. See more details in: '
                        'https://docs.microsoft.com/en-us/azure/storage/common/storage-lifecycle-managment-concepts.')
        c.argument('account_name', help='The name of the storage account within the specified resource group.')

    with self.argument_context('storage account management-policy update') as c:
        c.argument('account_name', help='The name of the storage account within the specified resource group.')

    with self.argument_context('storage logging show') as c:
        c.extra('services', validator=get_char_options_validator('bqt', 'services'), default='bqt')

    with self.argument_context('storage logging update') as c:
        c.extra('services', validator=get_char_options_validator('bqt', 'services'), options_list='--services',
                required=True)
        c.argument('log', validator=get_char_options_validator('rwd', 'log'))
        c.argument('retention', type=int)

    with self.argument_context('storage metrics show') as c:
        c.extra('services', validator=get_char_options_validator('bfqt', 'services'), default='bfqt')
        c.argument('interval', arg_type=get_enum_type(['hour', 'minute', 'both']))

    with self.argument_context('storage metrics update') as c:
        c.extra('services', validator=get_char_options_validator('bfqt', 'services'), options_list='--services',
                required=True)
        c.argument('hour', validator=process_metric_update_namespace, arg_type=get_enum_type(['true', 'false']))
        c.argument('minute', arg_type=get_enum_type(['true', 'false']))
        c.argument('api', arg_type=get_enum_type(['true', 'false']))
        c.argument('retention', type=int)

    with self.argument_context('storage blob') as c:
        c.argument('blob_name', options_list=('--name', '-n'), arg_type=blob_name_type)
        c.argument('destination_path', help='The destination path that will be appended to the blob name.')

    with self.argument_context('storage blob list') as c:
        c.argument('include', validator=validate_included_datasets)
        c.argument('num_results', type=int,
                   help='Specifies the maximum number of blobs to return. Must be in range [1,5000]. '
                        'If this parameter is not provided, all blobs will be returned.')
        c.ignore('marker')  # https://github.com/Azure/azure-cli/issues/3745

    with self.argument_context('storage blob generate-sas') as c:
        from .completers import get_storage_acl_name_completion_list

        t_blob_permissions = self.get_sdk('blob.models#BlobPermissions')
        c.register_sas_arguments()
        c.argument('id', options_list='--policy-name',
                   help='The name of a stored access policy within the container\'s ACL.',
                   completer=get_storage_acl_name_completion_list(t_base_blob_service, 'container_name',
                                                                  'get_container_acl'))
        c.argument('permission', options_list='--permissions',
                   help=sas_help.format(get_permission_help_string(t_blob_permissions)),
                   validator=get_permission_validator(t_blob_permissions))

    with self.argument_context('storage blob update') as c:
        t_blob_content_settings = self.get_sdk('blob.models#ContentSettings')
        c.register_content_settings_argument(t_blob_content_settings, update=True)

    with self.argument_context('storage blob exists') as c:
        c.argument('blob_name', required=True)

    with self.argument_context('storage blob url') as c:
        c.argument('protocol', arg_type=get_enum_type(['http', 'https'], 'https'), help='Protocol to use.')

    with self.argument_context('storage blob set-tier') as c:
        from ._validators import blob_tier_validator

        c.argument('blob_type', options_list=('--type', '-t'), arg_type=get_enum_type(('block', 'page')))
        c.argument('tier', validator=blob_tier_validator)
        c.argument('timeout', type=int)

    with self.argument_context('storage blob service-properties delete-policy update') as c:
        c.argument('enable', arg_type=get_enum_type(['true', 'false']), help='Enables/disables soft-delete.')
        c.argument('days_retained', type=int,
                   help='Number of days that soft-deleted blob will be retained. Must be in range [1,365].')

    with self.argument_context('storage blob service-properties update') as c:
        c.argument('delete_retention', arg_type=get_three_state_flag(), arg_group='Soft Delete',
                   help='Enables soft-delete.')
        c.argument('days_retained', type=int, arg_group='Soft Delete',
                   help='Number of days that soft-deleted blob will be retained. Must be in range [1,365].')
        c.argument('static_website', arg_group='Static Website', arg_type=get_three_state_flag(),
                   help='Enables static-website.')
        c.argument('index_document', help='Represents the name of the index document. This is commonly "index.html".',
                   arg_group='Static Website')
        c.argument('error_document_404_path', options_list=['--404-document'], arg_group='Static Website',
                   help='Represents the path to the error document that should be shown when an error 404 is issued,'
                        ' in other words, when a browser requests a page that does not exist.')

    with self.argument_context('storage blob upload') as c:
        from ._validators import page_blob_tier_validator
        from .sdkutil import get_blob_types, get_blob_tier_names

        t_blob_content_settings = self.get_sdk('blob.models#ContentSettings')
        c.register_content_settings_argument(t_blob_content_settings, update=False)

        c.argument('file_path', options_list=('--file', '-f'), type=file_type, completer=FilesCompleter())
        c.argument('max_connections', type=int)
        c.argument('blob_type', options_list=('--type', '-t'), validator=validate_blob_type,
                   arg_type=get_enum_type(get_blob_types()))
        c.argument('validate_content', action='store_true', min_api='2016-05-31')
        c.extra('no_progress', progress_type)
        c.extra('socket_timeout', socket_timeout_type)
        # TODO: Remove once #807 is complete. Smart Create Generation requires this parameter.
        # register_extra_cli_argument('storage blob upload', '_subscription_id', options_list=('--subscription',),
        #                              help=argparse.SUPPRESS)
        c.argument('tier', validator=page_blob_tier_validator,
                   arg_type=get_enum_type(get_blob_tier_names(self.cli_ctx, 'PremiumPageBlobTier')),
                   min_api='2017-04-17')

    with self.argument_context('storage blob upload-batch') as c:
        from .sdkutil import get_blob_types

        t_blob_content_settings = self.get_sdk('blob.models#ContentSettings')
        c.register_content_settings_argument(t_blob_content_settings, update=False, arg_group='Content Control')
        c.ignore('source_files', 'destination_container_name')

        c.argument('source', options_list=('--source', '-s'))
        c.argument('destination', options_list=('--destination', '-d'))
        c.argument('max_connections', type=int,
                   help='Maximum number of parallel connections to use when the blob size exceeds 64MB.')
        c.argument('maxsize_condition', arg_group='Content Control')
        c.argument('validate_content', action='store_true', min_api='2016-05-31', arg_group='Content Control')
        c.argument('blob_type', options_list=('--type', '-t'), arg_type=get_enum_type(get_blob_types()))
        c.extra('no_progress', progress_type)
        c.extra('socket_timeout', socket_timeout_type)

    with self.argument_context('storage blob download') as c:
        c.argument('file_path', options_list=('--file', '-f'), type=file_type, completer=FilesCompleter())
        c.argument('max_connections', type=int)
        c.argument('start_range', type=int)
        c.argument('end_range', type=int)
        c.argument('validate_content', action='store_true', min_api='2016-05-31')
        c.extra('no_progress', progress_type)
        c.extra('socket_timeout', socket_timeout_type)

    with self.argument_context('storage blob download-batch') as c:
        c.ignore('source_container_name')
        c.argument('destination', options_list=('--destination', '-d'))
        c.argument('source', options_list=('--source', '-s'))
        c.extra('no_progress', progress_type)
        c.extra('socket_timeout', socket_timeout_type)
        c.argument('max_connections', type=int,
                   help='Maximum number of parallel connections to use when the blob size exceeds 64MB.')

    with self.argument_context('storage blob delete') as c:
        from .sdkutil import get_delete_blob_snapshot_type_names
        c.argument('delete_snapshots', arg_type=get_enum_type(get_delete_blob_snapshot_type_names()))

    with self.argument_context('storage blob delete-batch') as c:
        c.ignore('source_container_name')
        c.argument('source', options_list=('--source', '-s'))
        c.argument('delete_snapshots', arg_type=get_enum_type(get_delete_blob_snapshot_type_names()),
                   help='Required if the blob has associated snapshots.')
        c.argument('lease_id', help='Required if the blob has an active lease.')

    with self.argument_context('storage blob lease') as c:
        c.argument('lease_duration', type=int)
        c.argument('lease_break_period', type=int)
        c.argument('blob_name', arg_type=blob_name_type)

    with self.argument_context('storage blob copy') as c:
        for item in ['destination', 'source']:
            c.argument('{}_if_modified_since'.format(item), arg_group='Pre-condition')
            c.argument('{}_if_unmodified_since'.format(item), arg_group='Pre-condition')
            c.argument('{}_if_match'.format(item), arg_group='Pre-condition')
            c.argument('{}_if_none_match'.format(item), arg_group='Pre-condition')
        c.argument('container_name', container_name_type, options_list=('--destination-container', '-c'))
        c.argument('blob_name', blob_name_type, options_list=('--destination-blob', '-b'),
                   help='Name of the destination blob. If the exists, it will be overwritten.')
        c.argument('source_lease_id', arg_group='Copy Source')

    with self.argument_context('storage blob copy start') as c:
        from ._validators import validate_source_uri

        c.register_source_uri_arguments(validator=validate_source_uri)

    with self.argument_context('storage blob copy start-batch', arg_group='Copy Source') as c:
        from ._validators import get_source_file_or_blob_service_client

        c.argument('source_client', ignore_type, validator=get_source_file_or_blob_service_client)

        c.extra('source_account_name')
        c.extra('source_account_key')
        c.extra('source_uri')
        c.argument('source_sas')
        c.argument('source_container')
        c.argument('source_share')

    with self.argument_context('storage blob incremental-copy start') as c:
        from ._validators import process_blob_source_uri

        c.register_source_uri_arguments(validator=process_blob_source_uri, blob_only=True)
        c.argument('destination_if_modified_since', arg_group='Pre-condition')
        c.argument('destination_if_unmodified_since', arg_group='Pre-condition')
        c.argument('destination_if_match', arg_group='Pre-condition')
        c.argument('destination_if_none_match', arg_group='Pre-condition')
        c.argument('container_name', container_name_type, options_list=('--destination-container', '-c'))
        c.argument('blob_name', blob_name_type, options_list=('--destination-blob', '-b'),
                   help='Name of the destination blob. If the exists, it will be overwritten.')
        c.argument('source_lease_id', arg_group='Copy Source')

    with self.argument_context('storage container') as c:
        from .sdkutil import get_container_access_type_names
        c.argument('container_name', container_name_type, options_list=('--name', '-n'))
        c.argument('public_access', validator=validate_container_public_access,
                   arg_type=get_enum_type(get_container_access_type_names()),
                   help='Specifies whether data in the container may be accessed publically. By default, container '
                        'data is private ("off") to the account owner. Use "blob" to allow public read access for '
                        'blobs. Use "container" to allow public read and list access to the entire container.')

    with self.argument_context('storage container create') as c:
        c.argument('container_name', container_name_type, options_list=('--name', '-n'), completer=None)
        c.argument('fail_on_exist', help='Throw an exception if the container already exists.')

    with self.argument_context('storage container delete') as c:
        c.argument('fail_not_exist', help='Throw an exception if the container does not exist.')

    with self.argument_context('storage container exists') as c:
        c.ignore('blob_name', 'snapshot')

    with self.argument_context('storage container set-permission') as c:
        c.ignore('signed_identifiers')

    with self.argument_context('storage container lease') as c:
        c.argument('container_name', container_name_type)

    with self.argument_context('storage container list') as c:
        c.ignore('marker')  # https://github.com/Azure/azure-cli/issues/3745

    with self.argument_context('storage container policy') as c:
        from .completers import get_storage_acl_name_completion_list
        t_container_permissions = self.get_sdk('blob.models#ContainerPermissions')

        c.argument('container_name', container_name_type)
        c.argument('policy_name', options_list=('--name', '-n'), help='The stored access policy name.',
                   completer=get_storage_acl_name_completion_list(t_base_blob_service, 'container_name',
                                                                  'get_container_acl'))
        help_str = 'Allowed values: {}. Can be combined'.format(get_permission_help_string(t_container_permissions))
        c.argument('permission', options_list='--permissions', help=help_str,
                   validator=get_permission_validator(t_container_permissions))

        c.argument('start', type=get_datetime_type(True),
                   help='start UTC datetime (Y-m-d\'T\'H:M:S\'Z\'). Defaults to time of request.')
        c.argument('expiry', type=get_datetime_type(True), help='expiration UTC datetime in (Y-m-d\'T\'H:M:S\'Z\')')

    for item in ['create', 'delete', 'list', 'show', 'update']:
        with self.argument_context('storage container policy {}'.format(item)) as c:
            c.extra('lease_id', options_list='--lease-id', help='The container lease ID.')

    with self.argument_context('storage container generate-sas') as c:
        from .completers import get_storage_acl_name_completion_list
        t_container_permissions = self.get_sdk('blob.models#ContainerPermissions')
        c.register_sas_arguments()
        c.argument('id', options_list='--policy-name',
                   help='The name of a stored access policy within the container\'s ACL.',
                   completer=get_storage_acl_name_completion_list(t_container_permissions, 'container_name',
                                                                  'get_container_acl'))
        c.argument('permission', options_list='--permissions',
                   help=sas_help.format(get_permission_help_string(t_container_permissions)),
                   validator=get_permission_validator(t_container_permissions))

    with self.argument_context('storage container lease') as c:
        c.argument('lease_duration', type=int)
        c.argument('lease_break_period', type=int)

    with self.argument_context('storage container immutability-policy') as c:
        c.argument('immutability_period_since_creation_in_days', options_list='--period')
        c.argument('container_name', container_name_type)
        c.argument('account_name', completer=get_resource_name_completion_list('Microsoft.Storage/storageAccounts'))

    with self.argument_context('storage container legal-hold') as c:
        c.argument('container_name', container_name_type)
        c.argument('account_name', completer=get_resource_name_completion_list('Microsoft.Storage/storageAccounts'))
        c.argument('tags', nargs='+', help='Each tag should be 3 to 23 alphanumeric characters and is '
                                           'normalized to lower case')

    with self.argument_context('storage share') as c:
        c.argument('share_name', share_name_type, options_list=('--name', '-n'))

    with self.argument_context('storage share list') as c:
        c.ignore('marker')  # https://github.com/Azure/azure-cli/issues/3745

    with self.argument_context('storage share exists') as c:
        c.ignore('directory_name', 'file_name')

    with self.argument_context('storage share policy') as c:
        from .completers import get_storage_acl_name_completion_list

        t_file_svc = self.get_sdk('file#FileService')
        t_share_permissions = self.get_sdk('file.models#SharePermissions')

        c.argument('container_name', share_name_type)
        c.argument('policy_name', options_list=('--name', '-n'), help='The stored access policy name.',
                   completer=get_storage_acl_name_completion_list(t_file_svc, 'container_name', 'get_share_acl'))

        help_str = 'Allowed values: {}. Can be combined'.format(get_permission_help_string(t_share_permissions))
        c.argument('permission', options_list='--permissions', help=help_str,
                   validator=get_permission_validator(t_share_permissions))

        c.argument('start', type=get_datetime_type(True),
                   help='start UTC datetime (Y-m-d\'T\'H:M:S\'Z\'). Defaults to time of request.')
        c.argument('expiry', type=get_datetime_type(True), help='expiration UTC datetime in (Y-m-d\'T\'H:M:S\'Z\')')

    with self.argument_context('storage share delete') as c:
        from .sdkutil import get_delete_file_snapshot_type_names
        c.argument('delete_snapshots', arg_type=get_enum_type(get_delete_file_snapshot_type_names()),
                   help='Specify the deletion strategy when the share has snapshots.')

    with self.argument_context('storage share generate-sas') as c:
        from .completers import get_storage_acl_name_completion_list

        t_share_permissions = self.get_sdk('file.models#SharePermissions')
        c.register_sas_arguments()
        c.argument('id', options_list='--policy-name',
                   help='The name of a stored access policy within the share\'s ACL.',
                   completer=get_storage_acl_name_completion_list(t_share_permissions, 'share_name', 'get_share_acl'))
        c.argument('permission', options_list='--permissions',
                   help=sas_help.format(get_permission_help_string(t_share_permissions)),
                   validator=get_permission_validator(t_share_permissions))

    with self.argument_context('storage directory') as c:
        c.argument('directory_name', directory_type, options_list=('--name', '-n'))

    with self.argument_context('storage directory exists') as c:
        c.ignore('file_name')
        c.argument('directory_name', required=True)

    with self.argument_context('storage file') as c:
        c.argument('file_name', file_name_type, options_list=('--name', '-n'))
        c.argument('directory_name', directory_type, required=False)

    with self.argument_context('storage file copy') as c:
        c.argument('share_name', share_name_type, options_list=('--destination-share', '-s'),
                   help='Name of the destination share. The share must exist.')

    with self.argument_context('storage file copy start') as c:
        c.register_path_argument(options_list=('--destination-path', '-p'))

    with self.argument_context('storage file copy cancel') as c:
        c.register_path_argument(options_list=('--destination-path', '-p'))

    with self.argument_context('storage file delete') as c:
        c.register_path_argument()

    with self.argument_context('storage file download') as c:
        c.register_path_argument()
        c.argument('file_path', options_list=('--dest',), type=file_type, required=False,
                   help='Path of the file to write to. The source filename will be used if not specified.',
                   validator=process_file_download_namespace, completer=FilesCompleter())
        c.argument('path', validator=None)  # validator called manually from process_file_download_namespace
        c.extra('no_progress', progress_type)
        c.argument('max_connections', type=int)
        c.argument('start_range', type=int)
        c.argument('end_range', type=int)

    with self.argument_context('storage file exists') as c:
        c.register_path_argument()

    with self.argument_context('storage file generate-sas') as c:
        from .completers import get_storage_acl_name_completion_list

        c.register_path_argument()
        c.register_sas_arguments()

        t_file_svc = self.get_sdk('file.fileservice#FileService')
        t_file_permissions = self.get_sdk('file.models#FilePermissions')
        c.argument('id', options_list='--policy-name',
                   help='The name of a stored access policy within the container\'s ACL.',
                   completer=get_storage_acl_name_completion_list(t_file_svc, 'container_name', 'get_container_acl'))
        c.argument('permission', options_list='--permissions',
                   help=sas_help.format(get_permission_help_string(t_file_permissions)),
                   validator=get_permission_validator(t_file_permissions))

    with self.argument_context('storage file list') as c:
        from .completers import dir_path_completer
        c.argument('directory_name', options_list=('--path', '-p'), help='The directory path within the file share.',
                   completer=dir_path_completer)

    with self.argument_context('storage file metadata show') as c:
        c.register_path_argument()

    with self.argument_context('storage file metadata update') as c:
        c.register_path_argument()

    with self.argument_context('storage file resize') as c:
        c.register_path_argument()
        c.argument('content_length', options_list='--size')

    with self.argument_context('storage file show') as c:
        c.register_path_argument()

    with self.argument_context('storage file update') as c:
        t_file_content_settings = self.get_sdk('file.models#ContentSettings')

        c.register_path_argument()
        c.register_content_settings_argument(t_file_content_settings, update=True)

    with self.argument_context('storage file upload') as c:
        t_file_content_settings = self.get_sdk('file.models#ContentSettings')

        c.register_path_argument(default_file_param='local_file_path')
        c.register_content_settings_argument(t_file_content_settings, update=False, guess_from_file='local_file_path')
        c.argument('local_file_path', options_list='--source', type=file_type, completer=FilesCompleter())
        c.extra('no_progress', progress_type)
        c.argument('max_connections', type=int)

    with self.argument_context('storage file url') as c:
        c.register_path_argument()
        c.argument('protocol', arg_type=get_enum_type(['http', 'https'], 'https'), help='Protocol to use.')

    with self.argument_context('storage file upload-batch') as c:
        from ._validators import process_file_upload_batch_parameters
        c.argument('source', options_list=('--source', '-s'), validator=process_file_upload_batch_parameters)
        c.argument('destination', options_list=('--destination', '-d'))
        c.argument('max_connections', arg_group='Download Control', type=int)
        c.argument('validate_content', action='store_true', min_api='2016-05-31')
        c.register_content_settings_argument(t_file_content_settings, update=False, arg_group='Content Settings')
        c.extra('no_progress', progress_type)

    with self.argument_context('storage file download-batch') as c:
        from ._validators import process_file_download_batch_parameters
        c.argument('source', options_list=('--source', '-s'), validator=process_file_download_batch_parameters)
        c.argument('destination', options_list=('--destination', '-d'))
        c.argument('max_connections', arg_group='Download Control', type=int)
        c.argument('validate_content', action='store_true', min_api='2016-05-31')
        c.extra('no_progress', progress_type)

    with self.argument_context('storage file delete-batch') as c:
        from ._validators import process_file_batch_source_parameters
        c.argument('source', options_list=('--source', '-s'), validator=process_file_batch_source_parameters)

    with self.argument_context('storage file copy start') as c:
        from ._validators import validate_source_uri

        c.register_source_uri_arguments(validator=validate_source_uri)

    with self.argument_context('storage file copy start-batch', arg_group='Copy Source') as c:
        from ._validators import get_source_file_or_blob_service_client
        c.argument('source_client', ignore_type, validator=get_source_file_or_blob_service_client)
        c.extra('source_account_name')
        c.extra('source_account_key')
        c.extra('source_uri')
        c.argument('source_sas')
        c.argument('source_container')
        c.argument('source_share')

    with self.argument_context('storage cors list') as c:
        c.extra('services', validator=get_char_options_validator('bfqt', 'services'), default='bqft',
                options_list='--services', required=False)

    with self.argument_context('storage cors add') as c:
        c.extra('services', validator=get_char_options_validator('bfqt', 'services'), required=True,
                options_list='--services')
        c.argument('max_age')
        c.argument('origins', nargs='+')
        c.argument('methods', nargs='+',
                   arg_type=get_enum_type(['DELETE', 'GET', 'HEAD', 'MERGE', 'POST', 'OPTIONS', 'PUT']))
        c.argument('allowed_headers', nargs='+')
        c.argument('exposed_headers', nargs='+')

    with self.argument_context('storage cors clear') as c:
        c.extra('services', validator=get_char_options_validator('bfqt', 'services'), required=True,
                options_list='--services')

    with self.argument_context('storage queue generate-sas') as c:
        from .completers import get_storage_acl_name_completion_list

        t_queue_permissions = self.get_sdk('queue.models#QueuePermissions')

        c.register_sas_arguments()

        c.argument('id', options_list='--policy-name',
                   help='The name of a stored access policy within the share\'s ACL.',
                   completer=get_storage_acl_name_completion_list(t_queue_permissions, 'queue_name', 'get_queue_acl'))
        c.argument('permission', options_list='--permissions',
                   help=sas_help.format(get_permission_help_string(t_queue_permissions)),
                   validator=get_permission_validator(t_queue_permissions))

    with self.argument_context('storage queue') as c:
        c.argument('queue_name', queue_name_type, options_list=('--name', '-n'))

    with self.argument_context('storage queue create') as c:
        c.argument('queue_name', queue_name_type, options_list=('--name', '-n'), completer=None)

    with self.argument_context('storage queue policy') as c:
        from .completers import get_storage_acl_name_completion_list

        t_queue_permissions = self.get_sdk('queue.models#QueuePermissions')

        c.argument('container_name', queue_name_type)
        c.argument('policy_name', options_list=('--name', '-n'), help='The stored access policy name.',
                   completer=get_storage_acl_name_completion_list(t_queue_service, 'container_name', 'get_queue_acl'))

        help_str = 'Allowed values: {}. Can be combined'.format(get_permission_help_string(t_queue_permissions))
        c.argument('permission', options_list='--permissions', help=help_str,
                   validator=get_permission_validator(t_queue_permissions))

        c.argument('start', type=get_datetime_type(True),
                   help='start UTC datetime (Y-m-d\'T\'H:M:S\'Z\'). Defaults to time of request.')
        c.argument('expiry', type=get_datetime_type(True), help='expiration UTC datetime in (Y-m-d\'T\'H:M:S\'Z\')')

    with self.argument_context('storage message') as c:
        c.argument('queue_name', queue_name_type)
        c.argument('message_id', options_list='--id')
        c.argument('content', type=unicode_string, help='Message content, up to 64KB in size.')

    with self.argument_context('storage table') as c:
        c.argument('table_name', table_name_type, options_list=('--name', '-n'))

    with self.argument_context('storage table create') as c:
        c.argument('table_name', table_name_type, options_list=('--name', '-n'), completer=None)
        c.argument('fail_on_exist', help='Throw an exception if the table already exists.')

    with self.argument_context('storage table policy') as c:
        from ._validators import table_permission_validator
        from .completers import get_storage_acl_name_completion_list

        c.argument('container_name', table_name_type)
        c.argument('policy_name', options_list=('--name', '-n'), help='The stored access policy name.',
                   completer=get_storage_acl_name_completion_list(t_table_service, 'table_name', 'get_table_acl'))

        help_str = 'Allowed values: (r)ead/query (a)dd (u)pdate (d)elete. Can be combined.'
        c.argument('permission', options_list='--permissions', help=help_str, validator=table_permission_validator)

        c.argument('start', type=get_datetime_type(True),
                   help='start UTC datetime (Y-m-d\'T\'H:M:S\'Z\'). Defaults to time of request.')
        c.argument('expiry', type=get_datetime_type(True), help='expiration UTC datetime in (Y-m-d\'T\'H:M:S\'Z\')')

    with self.argument_context('storage table generate-sas') as c:
        from .completers import get_storage_acl_name_completion_list

        c.register_sas_arguments()
        c.argument('id', options_list='--policy-name',
                   help='The name of a stored access policy within the table\'s ACL.',
                   completer=get_storage_acl_name_completion_list(t_table_service, 'table_name', 'get_table_acl'))
        c.argument('permission', options_list='--permissions',
                   help=sas_help.format('(r)ead/query (a)dd (u)pdate (d)elete'),
                   validator=table_permission_validator)

    with self.argument_context('storage entity') as c:
        c.ignore('property_resolver')
        c.argument('entity', options_list=('--entity', '-e'), validator=validate_entity, nargs='+')
        c.argument('select', nargs='+', validator=validate_select,
                   help='Space-separated list of properties to return for each entity.')

    with self.argument_context('storage entity insert') as c:
        c.argument('if_exists', arg_type=get_enum_type(['fail', 'merge', 'replace']))

    with self.argument_context('storage entity query') as c:
        c.argument('accept', default='minimal', validator=validate_table_payload_format,
                   arg_type=get_enum_type(['none', 'minimal', 'full']),
                   help='Specifies how much metadata to include in the response payload.')
        c.argument('marker', validator=validate_marker, nargs='+')
Пример #5
0
def load_arguments(self, _):

    # pylint: disable=line-too-long
    # PARAMETER REGISTRATION
    name_arg_type = CLIArgumentType(options_list=['--name', '-n'],
                                    metavar='NAME')
    sku_arg_type = CLIArgumentType(
        help=
        'The pricing tiers, e.g., F1(Free), D1(Shared), B1(Basic Small), B2(Basic Medium), B3(Basic Large), S1(Standard Small), P1(Premium Small), P1V2(Premium V2 Small) etc',
        arg_type=get_enum_type([
            'F1', 'FREE', 'D1', 'SHARED', 'B1', 'B2', 'B3', 'S1', 'S2', 'S3',
            'P1', 'P2', 'P3', 'P1V2', 'P2V2', 'P3V2'
        ]))
    webapp_name_arg_type = CLIArgumentType(
        configured_default='web',
        options_list=['--name', '-n'],
        metavar='NAME',
        completer=get_resource_name_completion_list('Microsoft.Web/sites'),
        id_part='name',
        help=
        "name of the web. You can configure the default using 'az configure --defaults web=<name>'"
    )

    # use this hidden arg to give a command the right instance, that functionapp commands
    # work on function app and webapp ones work on web app
    with self.argument_context('webapp') as c:
        c.ignore('app_instance')
        c.argument('resource_group_name', arg_type=resource_group_name_type)
        c.argument('location', arg_type=get_location_type(self.cli_ctx))
        c.argument(
            'slot',
            options_list=['--slot', '-s'],
            help=
            "the name of the slot. Default to the productions slot if not specified"
        )
        c.argument(
            'name',
            configured_default='web',
            arg_type=name_arg_type,
            completer=get_resource_name_completion_list('Microsoft.Web/sites'),
            id_part='name',
            help=
            "name of the web. You can configure the default using 'az configure --defaults web=<name>'"
        )

    with self.argument_context('appservice') as c:
        c.argument('resource_group_name', arg_type=resource_group_name_type)
        c.argument('location', arg_type=get_location_type(self.cli_ctx))

    with self.argument_context('appservice list-locations') as c:
        c.argument(
            'linux_workers_enabled',
            action='store_true',
            help='get regions which support hosting webapps on Linux workers')
        c.argument('sku', arg_type=sku_arg_type)

    with self.argument_context('appservice plan') as c:
        c.argument('name',
                   arg_type=name_arg_type,
                   help='The name of the app service plan',
                   completer=get_resource_name_completion_list(
                       'Microsoft.Web/serverFarms'),
                   id_part='name')
        c.argument('number_of_workers',
                   help='Number of workers to be allocated.',
                   type=int,
                   default=1)
        c.argument('admin_site_name', help='The name of the admin web app.')

    with self.argument_context('appservice plan create') as c:
        c.argument('name',
                   options_list=['--name', '-n'],
                   help="Name of the new app service plan",
                   completer=None)
        c.argument('sku', arg_type=sku_arg_type)
        c.argument('is_linux',
                   action='store_true',
                   required=False,
                   help='host webapp on Linux worker')
    with self.argument_context('appservice plan update') as c:
        c.argument('sku', arg_type=sku_arg_type)
        c.ignore('allow_pending_state')

    with self.argument_context('webapp create') as c:
        c.argument('name',
                   options_list=['--name', '-n'],
                   help='name of the new webapp')
        c.argument('startup_file', help="Linux only. The web's startup file")
        c.argument(
            'runtime',
            options_list=['--runtime', '-r'],
            help=
            "canonicalized web runtime in the format of Framework|Version, e.g. \"PHP|5.6\". Use 'az webapp list-runtimes' for available list"
        )  # TODO ADD completer
        c.argument(
            'plan',
            options_list=['--plan', '-p'],
            completer=get_resource_name_completion_list(
                'Microsoft.Web/serverFarms'),
            help=
            "name or resource id of the app service plan. Use 'appservice plan create' to get one"
        )

    with self.argument_context('webapp show') as c:
        c.argument('name', arg_type=webapp_name_arg_type)

    with self.argument_context('webapp list-runtimes') as c:
        c.argument('linux',
                   action='store_true',
                   help='list runtime stacks for linux based webapps')

    with self.argument_context('webapp traffic-routing') as c:
        c.argument(
            'distribution',
            options_list=['--distribution', '-d'],
            nargs='+',
            help=
            'space separated slot routings in a format of <slot-name>=<percentage> e.g. staging=50. Unused traffic percentage will go to the Production slot'
        )

    with self.argument_context('webapp update') as c:
        c.argument('client_affinity_enabled',
                   help="Enables sending session affinity cookies.",
                   arg_type=get_three_state_flag(return_label=True))
    with self.argument_context('webapp browse') as c:
        c.argument(
            'logs',
            options_list=['--logs', '-l'],
            action='store_true',
            help=
            'Enable viewing the log stream immediately after launching the web app'
        )
    with self.argument_context('webapp delete') as c:
        c.argument('keep_empty_plan',
                   action='store_true',
                   help='keep empty app service plan')
        c.argument('keep_metrics',
                   action='store_true',
                   help='keep app metrics')
        c.argument('keep_dns_registration',
                   action='store_true',
                   help='keep DNS registration')

    for scope in ['webapp', 'functionapp']:
        with self.argument_context(scope + ' create') as c:
            c.argument(
                'deployment_container_image_name',
                options_list=['--deployment-container-image-name', '-i'],
                help=
                'Linux only. Container image name from Docker Hub, e.g. publisher/image-name:tag'
            )
            c.argument('deployment_local_git',
                       action='store_true',
                       options_list=['--deployment-local-git', '-l'],
                       help='enable local git')
            c.argument('deployment_zip',
                       options_list=['--deployment-zip', '-z'],
                       help='perform deployment using zip file')
            c.argument(
                'deployment_source_url',
                options_list=['--deployment-source-url', '-u'],
                help='Git repository URL to link with manual integration')
            c.argument('deployment_source_branch',
                       options_list=['--deployment-source-branch', '-b'],
                       help='the branch to deploy')
        with self.argument_context(scope + ' config ssl bind') as c:
            c.argument('ssl_type',
                       help='The ssl cert type',
                       arg_type=get_enum_type(['SNI', 'IP']))
        with self.argument_context(scope + ' config ssl upload') as c:
            c.argument('certificate_password', help='The ssl cert password')
            c.argument('certificate_file',
                       type=file_type,
                       help='The filepath for the .pfx file')
        with self.argument_context(scope + ' config ssl') as c:
            c.argument('certificate_thumbprint',
                       help='The ssl cert thumbprint')
        with self.argument_context(scope + ' config appsettings') as c:
            c.argument(
                'settings',
                nargs='+',
                help=
                "space separated app settings in a format of <name>=<value>")
            c.argument('setting_names',
                       nargs='+',
                       help="space separated app setting names")
        with self.argument_context(scope + ' config hostname') as c:
            c.argument(
                'hostname',
                completer=get_hostname_completion_list,
                help="hostname assigned to the site, such as custom domains",
                id_part='child_name_1')
        with self.argument_context(scope + ' deployment user') as c:
            c.argument('user_name', help='user name')
            c.argument('password',
                       help='password, will prompt if not specified')
        with self.argument_context(scope + ' deployment source') as c:
            c.argument(
                'manual_integration',
                action='store_true',
                help='disable automatic sync between source control and web')
            c.argument(
                'repo_url',
                options_list=['--repo-url', '-u'],
                help=
                'repository url to pull the latest source from, e.g. https://github.com/foo/foo-web'
            )
            c.argument('branch', help='the branch name of the repository')
            c.argument('private_repo_username',
                       arg_group='VSTS CD Provider',
                       help='Username for the private repository')
            c.argument('private_repo_password',
                       arg_group='VSTS CD Provider',
                       help='Password for the private repository')
            c.argument(
                'cd_app_type',
                arg_group='VSTS CD Provider',
                help=
                'Web application framework you used to develop your app. Default is AspNet.',
                arg_type=get_enum_type(
                    ['AspNet', 'AspNetCore', 'NodeJS', 'PHP', 'Python']))
            c.argument(
                'app_working_dir',
                arg_group='VSTS CD Provider',
                help=
                'Working directory of the application. Default will be root of the repo'
            )
            c.argument('nodejs_task_runner',
                       arg_group='VSTS CD Provider',
                       help='Task runner for nodejs. Default is None',
                       arg_type=get_enum_type(['None', 'Gulp', 'Grunt']))
            c.argument(
                'python_framework',
                arg_group='VSTS CD Provider',
                help='Framework used for Python application. Default is Django',
                arg_type=get_enum_type(['Bottle', 'Django', 'Flask']))
            c.argument(
                'python_version',
                arg_group='VSTS CD Provider',
                help=
                'Python version used for application. Default is Python 3.5.3 x86',
                arg_type=get_enum_type([
                    'Python 2.7.12 x64', 'Python 2.7.12 x86',
                    'Python 2.7.13 x64', 'Python 2.7.13 x86',
                    'Python 3.5.3 x64', 'Python 3.5.3 x86', 'Python 3.6.0 x64',
                    'Python 3.6.0 x86', 'Python 3.6.2 x64', 'Python 3.6.1 x86'
                ]))
            c.argument(
                'cd_project_url',
                arg_group='VSTS CD Provider',
                help=
                'URL of the Visual Studio Team Services (VSTS) project to use for continuous delivery. URL should be in format https://<accountname>.visualstudio.com/<projectname>'
            )
            c.argument(
                'cd_account_create',
                arg_group='VSTS CD Provider',
                help=
                "To create a new Visual Studio Team Services (VSTS) account if it doesn't exist already",
                action='store_true')
            c.argument(
                'test',
                arg_group='VSTS CD Provider',
                help=
                'Name of the web app to be used for load testing. If web app is not available, it will be created. Default: Disable'
            )
            c.argument(
                'slot_swap',
                arg_group='VSTS CD Provider',
                help=
                'Name of the slot to be used for deployment and later promote to production. If slot is not available, it will be created. Default: Not configured'
            )
            c.argument('repository_type',
                       help='repository type',
                       arg_type=get_enum_type([
                           'git', 'mercurial', 'vsts', 'github', 'externalgit',
                           'localgit'
                       ]))
            c.argument('git_token',
                       help='Git access token required for auto sync')
        with self.argument_context(scope + ' assign-identity') as c:
            c.argument('disable_msi',
                       action='store_true',
                       help='disable the identity')
            c.argument('scope',
                       help="The scope the managed identity has access to")
            c.argument(
                'role',
                help="Role name or id the managed identity will be assigned")

    with self.argument_context('webapp config hostname') as c:
        c.argument(
            'webapp_name',
            help=
            "webapp name. You can configure the default using 'az configure --defaults web=<name>'",
            configured_default='web',
            completer=get_resource_name_completion_list('Microsoft.Web/sites'),
            id_part='name')
    with self.argument_context('webapp config appsettings') as c:
        c.argument(
            'slot_settings',
            nargs='+',
            help=
            "space separated slot app settings in a format of <name>=<value>")
    with self.argument_context('webapp deployment container config') as c:
        c.argument('enable',
                   options_list=['--enable-cd', '-e'],
                   help='enable/disable continuous deployment',
                   arg_type=get_enum_type(['true', 'false']))
    with self.argument_context('webapp deployment slot') as c:
        c.argument('slot', help='the name of the slot')
        c.argument(
            'webapp',
            arg_type=name_arg_type,
            completer=get_resource_name_completion_list('Microsoft.Web/sites'),
            help='Name of the webapp',
            id_part='name')
        c.argument('auto_swap_slot',
                   help='target slot to auto swap',
                   default='production')
        c.argument('disable', help='disable auto swap', action='store_true')
        c.argument('target_slot',
                   help="target slot to swap, default to 'production'")
    with self.argument_context('webapp deployment slot create') as c:
        c.argument(
            'configuration_source',
            help=
            "source slot to clone configurations from. Use webapp's name to refer to the production slot"
        )
    with self.argument_context('webapp deployment slot swap') as c:
        c.argument(
            'action',
            help=
            "swap types. use 'preview' to apply target slot's settings on the source slot first; use 'swap' to complete it; use 'reset' to reset the swap",
            arg_type=get_enum_type(['swap', 'preview', 'reset']))
    with self.argument_context('webapp log config') as c:
        c.argument('application_logging',
                   help='configure application logging to file system',
                   arg_type=get_three_state_flag(return_label=True))
        c.argument('detailed_error_messages',
                   help='configure detailed error messages',
                   arg_type=get_three_state_flag(return_label=True))
        c.argument('failed_request_tracing',
                   help='configure failed request tracing',
                   arg_type=get_three_state_flag(return_label=True))
        c.argument('level',
                   help='logging level',
                   arg_type=get_enum_type(
                       ['error', 'warning', 'information', 'verbose']))
        c.argument('web_server_logging',
                   help='configure Web server logging',
                   arg_type=get_enum_type(['off', 'filesystem']))
        c.argument(
            'docker_container_logging',
            help='configure gathering STDOUT and STDERR output from container',
            arg_type=get_enum_type(['off', 'filesystem']))

    with self.argument_context('webapp log tail') as c:
        c.argument(
            'provider',
            help=
            "By default all live traces configured by 'az webapp log config' will be shown, but you can scope to certain providers/folders, e.g. 'application', 'http', etc. For details, check out https://github.com/projectkudu/kudu/wiki/Diagnostic-Log-Stream"
        )
    with self.argument_context('webapp log download') as c:
        c.argument('log_file',
                   default='webapp_logs.zip',
                   type=file_type,
                   completer=FilesCompleter(),
                   help='the downloaded zipped log file path')

    for scope in ['appsettings', 'connection-string']:
        with self.argument_context('webapp config ' + scope) as c:
            c.argument(
                'settings',
                nargs='+',
                help="space separated {} in a format of <name>=<value>".format(
                    scope))
            c.argument(
                'slot_settings',
                nargs='+',
                help="space separated slot {} in a format of <name>=<value>".
                format(scope))
            c.argument('setting_names',
                       nargs='+',
                       help="space separated {} names".format(scope))

    with self.argument_context('webapp config connection-string') as c:
        c.argument('connection_string_type',
                   options_list=['--connection-string-type', '-t'],
                   help='connection string type',
                   arg_type=get_enum_type(ConnectionStringType))

    with self.argument_context('webapp config container') as c:
        c.argument('docker_registry_server_url',
                   options_list=['--docker-registry-server-url', '-r'],
                   help='the container registry server url')
        c.argument(
            'docker_custom_image_name',
            options_list=['--docker-custom-image-name', '-c', '-i'],
            help='the container custom image name and optionally the tag name')
        c.argument('docker_registry_server_user',
                   options_list=['--docker-registry-server-user', '-u'],
                   help='the container registry server username')
        c.argument('docker_registry_server_password',
                   options_list=['--docker-registry-server-password', '-p'],
                   help='the container registry server password')
        c.argument('websites_enable_app_service_storage',
                   options_list=['--enable-app-service-storage', '-t'],
                   help='enables platform storage (custom container only)',
                   arg_type=get_three_state_flag(return_label=True))

    with self.argument_context('webapp config set') as c:
        c.argument('remote_debugging_enabled',
                   help='enable or disable remote debugging',
                   arg_type=get_three_state_flag(return_label=True))
        c.argument('web_sockets_enabled',
                   help='enable or disable web sockets',
                   arg_type=get_three_state_flag(return_label=True))
        c.argument(
            'always_on',
            help=
            'ensure webapp gets loaded all the time, rather unloaded after been idle. Recommended when you have continuous web jobs running',
            arg_type=get_three_state_flag(return_label=True))
        c.argument('auto_heal_enabled',
                   help='enable or disable auto heal',
                   arg_type=get_three_state_flag(return_label=True))
        c.argument('use32_bit_worker_process',
                   options_list=['--use-32bit-worker-process'],
                   help='use 32 bits worker process or not',
                   arg_type=get_three_state_flag(return_label=True))
        c.argument(
            'php_version',
            help=
            'The version used to run your web app if using PHP, e.g., 5.5, 5.6, 7.0'
        )
        c.argument(
            'python_version',
            help=
            'The version used to run your web app if using Python, e.g., 2.7, 3.4'
        )
        c.argument(
            'net_framework_version',
            help=
            "The version used to run your web app if using .NET Framework, e.g., 'v4.0' for .NET 4.6 and 'v3.0' for .NET 3.5"
        )
        c.argument(
            'linux_fx_version',
            help=
            "The runtime stack used for your linux-based webapp, e.g., \"RUBY|2.3\", \"NODE|6.6\", \"PHP|5.6\", \"DOTNETCORE|1.1.0\". See https://aka.ms/linux-stacks for more info."
        )
        c.argument(
            'java_version',
            help=
            "The version used to run your web app if using Java, e.g., '1.7' for Java 7, '1.8' for Java 8"
        )
        c.argument('java_container',
                   help="The java container, e.g., Tomcat, Jetty")
        c.argument(
            'java_container_version',
            help="The version of the java container, e.g., '8.0.23' for Tomcat"
        )
        c.argument(
            'app_command_line',
            options_list=['--startup-file'],
            help=
            "The startup file for linux hosted web apps, e.g. 'process.json' for Node.js web"
        )

    with self.argument_context('webapp config backup') as c:
        c.argument('storage_account_url',
                   help='URL with SAS token to the blob storage container',
                   options_list=['--container-url'])
        c.argument('webapp_name', help='The name of the webapp')
        c.argument('db_name',
                   help='Name of the database in the backup',
                   arg_group='Database')
        c.argument('db_connection_string',
                   help='Connection string for the database in the backup',
                   arg_group='Database')
        c.argument('db_type',
                   help='Type of database in the backup',
                   arg_group='Database',
                   arg_type=get_enum_type(DatabaseType))

    with self.argument_context('webapp config backup create') as c:
        c.argument(
            'backup_name',
            help=
            'Name of the backup. If unspecified, the backup will be named with the webapp name and a timestamp'
        )

    with self.argument_context('webapp config backup update') as c:
        c.argument(
            'frequency',
            help=
            'How often to backup. Use a number followed by d or h, e.g. 5d = 5 days, 2h = 2 hours'
        )
        c.argument('keep_at_least_one_backup',
                   help='Always keep one backup, regardless of how old it is',
                   options_list=['--retain-one'],
                   arg_type=get_three_state_flag(return_label=True))
        c.argument(
            'retention_period_in_days',
            help=
            'How many days to keep a backup before automatically deleting it. Set to 0 for indefinite retention',
            options_list=['--retention'])

    with self.argument_context('webapp config backup restore') as c:
        c.argument('backup_name', help='Name of the backup to restore')
        c.argument(
            'target_name',
            help=
            'The name to use for the restored webapp. If unspecified, will default to the name that was used when the backup was created'
        )
        c.argument(
            'overwrite',
            help=
            'Overwrite the source webapp, if --target-name is not specified',
            action='store_true')
        c.argument('ignore_hostname_conflict',
                   help='Ignores custom hostnames stored in the backup',
                   action='store_true')

    with self.argument_context('webapp auth update') as c:
        c.argument('enabled', arg_type=get_three_state_flag(return_label=True))
        c.argument('token_store_enabled',
                   options_list=['--token-store'],
                   arg_type=get_three_state_flag(return_label=True))
        c.argument('action', arg_type=get_enum_type(AUTH_TYPES))
        c.argument('token_refresh_extension_hours',
                   type=float,
                   help="Hours, must be formattable into a float")
        c.argument('allowed_external_redirect_urls',
                   nargs='+',
                   help="One or more urls (space delimited).")
        c.argument('client_id',
                   options_list=['--aad-client-id'],
                   arg_group='Azure Active Directory')
        c.argument('client_secret',
                   options_list=['--aad-client-secret'],
                   arg_group='Azure Active Directory')
        c.argument('allowed_audiences',
                   nargs='+',
                   options_list=['--aad-allowed-token-audiences'],
                   arg_group='Azure Active Directory',
                   help="One or more token audiences (space delimited).")
        c.argument(
            'issuer',
            options_list=['--aad-token-issuer-url'],
            help=
            'This url can be found in the JSON output returned from your active directory endpoint using your tenantID. The endpoint can be queried from \'az cloud show\' at \"endpoints.activeDirectory\". '
            'The tenantID can be found using \'az account show\'. Get the \"issuer\" from the JSON at <active directory endpoint>/<tenantId>/.well-known/openid-configuration.',
            arg_group='Azure Active Directory')
        c.argument('facebook_app_id', arg_group='Facebook')
        c.argument('facebook_app_secret', arg_group='Facebook')
        c.argument(
            'facebook_oauth_scopes',
            nargs='+',
            help=
            "One or more facebook authentication scopes (space delimited).",
            arg_group='Facebook')
        c.argument('twitter_consumer_key', arg_group='Twitter')
        c.argument('twitter_consumer_secret', arg_group='Twitter')
        c.argument('google_client_id', arg_group='Google')
        c.argument('google_client_secret', arg_group='Google')
        c.argument(
            'google_oauth_scopes',
            nargs='+',
            help="One or more Google authentication scopes (space delimited).",
            arg_group='Google')
        c.argument('microsoft_account_client_id', arg_group='Microsoft')
        c.argument('microsoft_account_client_secret', arg_group='Microsoft')
        c.argument(
            'microsoft_account_oauth_scopes',
            nargs='+',
            help=
            "One or more Microsoft authentification scopes (space delimited).",
            arg_group='Microsoft')

    with self.argument_context('functionapp') as c:
        c.ignore('app_instance', 'slot')
        c.argument('name',
                   arg_type=name_arg_type,
                   id_part='name',
                   help='name of the function app')
    with self.argument_context('functionapp config hostname') as c:
        c.argument('webapp_name',
                   arg_type=name_arg_type,
                   id_part='name',
                   help='name of the function app')
    with self.argument_context('functionapp create') as c:
        c.argument(
            'plan',
            options_list=['--plan', '-p'],
            completer=get_resource_name_completion_list(
                'Microsoft.Web/serverFarms'),
            help=
            "name or resource id of the function app service plan. Use 'appservice plan create' to get one"
        )
        c.argument('new_app_name',
                   options_list=['--name', '-n'],
                   help='name of the new function app')
        c.argument(
            'storage_account',
            options_list=['--storage-account', '-s'],
            help=
            'Provide a string value of a Storage Account in the provided Resource Group. Or Resource ID of a Storage Account in a different Resource Group'
        )
        c.argument(
            'consumption_plan_location',
            options_list=['--consumption-plan-location', '-c'],
            help=
            "Geographic location where Function App will be hosted. Use 'functionapp list-consumption-locations' to view available locations."
        )
    # For commands with shared impl between webapp and functionapp and has output, we apply type validation to avoid confusions
    with self.argument_context('functionapp show') as c:
        c.argument('name', arg_type=name_arg_type)
Пример #6
0
def load_arguments(self, _):

    acr_arg_type = CLIArgumentType(metavar='ACR_NAME_OR_RESOURCE_ID')

    # AKS command argument configuration
    with self.argument_context('aks') as c:
        c.argument('resource_name',
                   name_type,
                   help='Name of the managed cluster.',
                   completer=get_resource_name_completion_list(
                       'Microsoft.ContainerService/ManagedClusters'))
        c.argument('name',
                   name_type,
                   help='Name of the managed cluster.',
                   completer=get_resource_name_completion_list(
                       'Microsoft.ContainerService/ManagedClusters'))
        c.argument('kubernetes_version',
                   options_list=['--kubernetes-version', '-k'],
                   validator=validate_k8s_version)
        c.argument('node_count', options_list=['--node-count', '-c'], type=int)
        c.argument('tags', tags_type)

    with self.argument_context('aks create') as c:
        c.argument('name', validator=validate_linux_host_name)
        c.argument('kubernetes_version',
                   completer=get_k8s_versions_completion_list)
        c.argument('admin_username',
                   options_list=['--admin-username', '-u'],
                   default='azureuser')
        c.argument('windows_admin_username',
                   options_list=['--windows-admin-username'])
        c.argument('windows_admin_password',
                   options_list=['--windows-admin-password'])
        c.argument('enable_ahub', options_list=['--enable-ahub'])
        c.argument('dns_name_prefix', options_list=['--dns-name-prefix', '-p'])
        c.argument('generate_ssh_keys',
                   action='store_true',
                   validator=validate_create_parameters)
        c.argument('node_vm_size',
                   options_list=['--node-vm-size', '-s'],
                   completer=get_vm_size_completion_list)
        c.argument('nodepool_name',
                   type=str,
                   default='nodepool1',
                   help='Node pool name, upto 12 alphanumeric characters',
                   validator=validate_nodepool_name)
        c.argument(
            'nodepool_tags',
            nargs='*',
            validator=validate_nodepool_tags,
            help=
            'space-separated tags: key[=value] [key[=value] ...]. Use "" to clear existing tags.'
        )
        c.argument(
            'nodepool_labels',
            nargs='*',
            validator=validate_nodepool_labels,
            help=
            'space-separated labels: key[=value] [key[=value] ...]. You can not change the node labels through CLI after creation. See https://aka.ms/node-labels for syntax of labels.'
        )
        c.argument('ssh_key_value',
                   required=False,
                   type=file_type,
                   default=os.path.join('~', '.ssh', 'id_rsa.pub'),
                   completer=FilesCompleter(),
                   validator=validate_ssh_key)
        c.argument('aad_client_app_id')
        c.argument('aad_server_app_id')
        c.argument('aad_server_app_secret')
        c.argument('aad_tenant_id')
        c.argument('dns_service_ip')
        c.argument('docker_bridge_address')
        c.argument('load_balancer_sku',
                   type=str,
                   validator=validate_load_balancer_sku)
        c.argument('load_balancer_managed_outbound_ip_count', type=int)
        c.argument('load_balancer_outbound_ips',
                   type=str,
                   validator=validate_load_balancer_outbound_ips)
        c.argument('load_balancer_outbound_ip_prefixes',
                   type=str,
                   validator=validate_load_balancer_outbound_ip_prefixes)
        c.argument('load_balancer_outbound_ports',
                   type=int,
                   validator=validate_load_balancer_outbound_ports)
        c.argument('load_balancer_idle_timeout',
                   type=int,
                   validator=validate_load_balancer_idle_timeout)
        c.argument('outbound_type',
                   arg_type=get_enum_type([
                       CONST_OUTBOUND_TYPE_LOAD_BALANCER,
                       CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING
                   ]))
        c.argument('enable_addons',
                   options_list=['--enable-addons', '-a'],
                   validator=validate_addons)
        c.argument('disable_rbac', action='store_true')
        c.argument('enable_rbac',
                   action='store_true',
                   options_list=['--enable-rbac', '-r'],
                   deprecate_info=c.deprecate(redirect="--disable-rbac",
                                              hide="2.0.45"))
        c.argument('max_pods', type=int, options_list=['--max-pods', '-m'])
        c.argument('network_plugin',
                   arg_type=get_enum_type(['azure', 'kubenet']))
        c.argument('network_policy')
        c.argument('no_ssh_key', options_list=['--no-ssh-key', '-x'])
        c.argument('pod_cidr')
        c.argument('service_cidr')
        c.argument('vnet_subnet_id',
                   type=str,
                   validator=validate_vnet_subnet_id)
        c.argument('pod_subnet_id', type=str, validator=validate_pod_subnet_id)
        c.argument('ppg')
        c.argument('workspace_resource_id')
        c.argument('skip_subnet_role_assignment', action='store_true')
        c.argument('enable_cluster_autoscaler', action='store_true')
        c.argument('uptime_sla', action='store_true')
        c.argument('cluster_autoscaler_profile',
                   nargs='+',
                   validator=validate_cluster_autoscaler_profile)
        c.argument('min_count', type=int, validator=validate_nodes_count)
        c.argument('max_count', type=int, validator=validate_nodes_count)
        c.argument('enable_vmss',
                   action='store_true',
                   help='To be deprecated. Use vm_set_type instead.')
        c.argument('vm_set_type', type=str, validator=validate_vm_set_type)
        c.argument(
            'node_zones',
            zones_type,
            options_list=['--node-zones', '--zones', '-z'],
            help=
            '(--node-zones will be deprecated, use --zones) Space-separated list of availability zones where agent nodes will be placed.'
        )
        c.argument('enable_node_public_ip', action='store_true')
        c.argument('node_public_ip_prefix_id', type=str)
        c.argument('enable_pod_security_policy', action='store_true')
        c.argument('node_resource_group')
        c.argument('attach_acr', acr_arg_type)
        c.argument('api_server_authorized_ip_ranges',
                   type=str,
                   validator=validate_ip_ranges)
        c.argument('enable_ahub', options_list=['--enable-ahub'])
        c.argument('disable_ahub', options_list=['--disable-ahub'])
        c.argument('aks_custom_headers')
        c.argument('enable_private_cluster', action='store_true')
        c.argument('private_dns_zone')
        c.argument('fqdn_subdomain')
        c.argument('enable_managed_identity', action='store_true')
        c.argument('assign_identity',
                   type=str,
                   validator=validate_assign_identity)
        c.argument('enable_sgxquotehelper', action='store_true')
        c.argument('auto_upgrade_channel',
                   arg_type=get_enum_type([
                       CONST_RAPID_UPGRADE_CHANNEL,
                       CONST_STABLE_UPGRADE_CHANNEL,
                       CONST_PATCH_UPGRADE_CHANNEL,
                       CONST_NODE_IMAGE_UPGRADE_CHANNEL,
                       CONST_NONE_UPGRADE_CHANNEL
                   ]))
        c.argument('kubelet_config', type=str)
        c.argument('linux_os_config', type=str)
        c.argument('enable_pod_identity', action='store_true')
        c.argument('appgw_name',
                   options_list=['--appgw-name'],
                   arg_group='Application Gateway')
        c.argument('appgw_subnet_prefix',
                   options_list=['--appgw-subnet-prefix'],
                   arg_group='Application Gateway',
                   deprecate_info=c.deprecate(redirect='--appgw-subnet-cidr',
                                              hide=True))
        c.argument('appgw_subnet_cidr',
                   options_list=['--appgw-subnet-cidr'],
                   arg_group='Application Gateway')
        c.argument('appgw_id',
                   options_list=['--appgw-id'],
                   arg_group='Application Gateway')
        c.argument('appgw_subnet_id',
                   options_list=['--appgw-subnet-id'],
                   arg_group='Application Gateway')
        c.argument('appgw_watch_namespace',
                   options_list=['--appgw-watch-namespace'],
                   arg_group='Application Gateway')
        c.argument('aci_subnet_name', type=str)
        c.argument('enable_encryption_at_host',
                   arg_type=get_three_state_flag(),
                   help='Enable EncryptionAtHost.')
        c.argument('enable_secret_rotation', action='store_true')
        c.argument('yes',
                   options_list=['--yes', '-y'],
                   help='Do not prompt for confirmation.',
                   action='store_true')

    with self.argument_context('aks update') as c:
        c.argument('enable_cluster_autoscaler',
                   options_list=["--enable-cluster-autoscaler", "-e"],
                   action='store_true')
        c.argument('disable_cluster_autoscaler',
                   options_list=["--disable-cluster-autoscaler", "-d"],
                   action='store_true')
        c.argument('update_cluster_autoscaler',
                   options_list=["--update-cluster-autoscaler", "-u"],
                   action='store_true')
        c.argument('cluster_autoscaler_profile',
                   nargs='+',
                   validator=validate_cluster_autoscaler_profile)
        c.argument('min_count', type=int, validator=validate_nodes_count)
        c.argument('max_count', type=int, validator=validate_nodes_count)
        c.argument('uptime_sla', action='store_true')
        c.argument('no_uptime_sla', action='store_true')
        c.argument('load_balancer_managed_outbound_ip_count', type=int)
        c.argument('load_balancer_outbound_ips',
                   type=str,
                   validator=validate_load_balancer_outbound_ips)
        c.argument('load_balancer_outbound_ip_prefixes',
                   type=str,
                   validator=validate_load_balancer_outbound_ip_prefixes)
        c.argument('load_balancer_outbound_ports',
                   type=int,
                   validator=validate_load_balancer_outbound_ports)
        c.argument('load_balancer_idle_timeout',
                   type=int,
                   validator=validate_load_balancer_idle_timeout)
        c.argument('api_server_authorized_ip_ranges',
                   type=str,
                   validator=validate_ip_ranges)
        c.argument('enable_pod_security_policy', action='store_true')
        c.argument('disable_pod_security_policy', action='store_true')
        c.argument('attach_acr', acr_arg_type, validator=validate_acr)
        c.argument('detach_acr', acr_arg_type, validator=validate_acr)
        c.argument('aks_custom_headers')
        c.argument('auto_upgrade_channel',
                   arg_type=get_enum_type([
                       CONST_RAPID_UPGRADE_CHANNEL,
                       CONST_STABLE_UPGRADE_CHANNEL,
                       CONST_PATCH_UPGRADE_CHANNEL,
                       CONST_NODE_IMAGE_UPGRADE_CHANNEL,
                       CONST_NONE_UPGRADE_CHANNEL
                   ]))
        c.argument('enable_managed_identity', action='store_true')
        c.argument('assign_identity',
                   type=str,
                   validator=validate_assign_identity)
        c.argument('enable_pod_identity', action='store_true')
        c.argument('disable_pod_identity', action='store_true')
        c.argument('enable_secret_rotation', action='store_true')
        c.argument('disable_secret_rotation', action='store_true')
        c.argument('yes',
                   options_list=['--yes', '-y'],
                   help='Do not prompt for confirmation.',
                   action='store_true')

    with self.argument_context('aks scale') as c:
        c.argument('nodepool_name',
                   type=str,
                   help='Node pool name, upto 12 alphanumeric characters',
                   validator=validate_nodepool_name)

    with self.argument_context('aks upgrade') as c:
        c.argument('kubernetes_version',
                   completer=get_k8s_upgrades_completion_list)
        c.argument('yes',
                   options_list=['--yes', '-y'],
                   help='Do not prompt for confirmation.',
                   action='store_true')

    with self.argument_context('aks maintenanceconfiguration') as c:
        c.argument('cluster_name', type=str, help='The cluster name.')

    for scope in [
            'aks maintenanceconfiguration add',
            'aks maintenanceconfiguration update'
    ]:
        with self.argument_context(scope) as c:
            c.argument('config_name',
                       type=str,
                       options_list=['--name', '-n'],
                       help='The config name.')
            c.argument('config_file',
                       type=str,
                       options_list=['--config-file'],
                       help='The config json file.',
                       required=False)
            c.argument(
                'weekday',
                type=str,
                options_list=['--weekday'],
                help='weekday on which maintenance can happen. e.g. Monday',
                required=False)
            c.argument(
                'start_hour',
                type=int,
                options_list=['--start-hour'],
                help=
                'maintenance start hour of 1 hour window on the weekday. e.g. 1 means 1:00am - 2:00am',
                required=False)

    for scope in [
            'aks maintenanceconfiguration show',
            'aks maintenanceconfiguration delete'
    ]:
        with self.argument_context(scope) as c:
            c.argument('config_name',
                       type=str,
                       options_list=['--name', '-n'],
                       help='The config name.')

    with self.argument_context('aks nodepool') as c:
        c.argument('cluster_name', type=str, help='The cluster name.')

    with self.argument_context('aks command invoke') as c:
        c.argument('command_string',
                   type=str,
                   options_list=["--command", "-c"],
                   help='the command to run')
        c.argument(
            'command_files',
            options_list=["--file", "-f"],
            required=False,
            action="append",
            help=
            'attach any files the command may use, or use \'.\' to upload the current folder.'
        )

    with self.argument_context('aks command result') as c:
        c.argument('command_id',
                   type=str,
                   options_list=["--command-id", "-i"],
                   help='the command ID from "aks command invoke"')

    for scope in ['aks nodepool add']:
        with self.argument_context(scope) as c:
            c.argument('nodepool_name',
                       type=str,
                       options_list=['--name', '-n'],
                       validator=validate_nodepool_name,
                       help='The node pool name.')
            c.argument('tags', tags_type)
            c.argument(
                'node_zones',
                zones_type,
                options_list=['--node-zones', '--zones', '-z'],
                help=
                '(--node-zones will be deprecated) Space-separated list of availability zones where agent nodes will be placed.'
            )
            c.argument('enable_node_public_ip', action='store_true')
            c.argument('node_public_ip_prefix_id', type=str)
            c.argument('node_vm_size',
                       options_list=['--node-vm-size', '-s'],
                       completer=get_vm_size_completion_list)
            c.argument('max_pods', type=int, options_list=['--max-pods', '-m'])
            c.argument('os_type', type=str)
            c.argument('enable_cluster_autoscaler',
                       options_list=["--enable-cluster-autoscaler", "-e"],
                       action='store_true')
            c.argument('node_taints', type=str, validator=validate_taints)
            c.argument('priority',
                       arg_type=get_enum_type([
                           CONST_SCALE_SET_PRIORITY_REGULAR,
                           CONST_SCALE_SET_PRIORITY_SPOT
                       ]),
                       validator=validate_priority)
            c.argument('eviction_policy',
                       arg_type=get_enum_type([
                           CONST_SPOT_EVICTION_POLICY_DELETE,
                           CONST_SPOT_EVICTION_POLICY_DEALLOCATE
                       ]),
                       validator=validate_eviction_policy)
            c.argument('spot_max_price',
                       type=float,
                       validator=validate_spot_max_price)
            c.argument('labels', nargs='*', validator=validate_nodepool_labels)
            c.argument('mode',
                       arg_type=get_enum_type([
                           CONST_NODEPOOL_MODE_SYSTEM, CONST_NODEPOOL_MODE_USER
                       ]))
            c.argument('aks_custom_headers')
            c.argument('ppg')
            c.argument('max_surge', type=str, validator=validate_max_surge)
            c.argument('node_os_disk_type',
                       arg_type=get_enum_type([
                           CONST_OS_DISK_TYPE_MANAGED,
                           CONST_OS_DISK_TYPE_EPHEMERAL
                       ]))
            c.argument('vnet_subnet_id',
                       type=str,
                       validator=validate_vnet_subnet_id)
            c.argument('pod_subnet_id',
                       type=str,
                       validator=validate_pod_subnet_id)
            c.argument('kubelet_config', type=str)
            c.argument('linux_os_config', type=str)
            c.argument('enable_encryption_at_host',
                       options_list=['--enable-encryption-at-host'],
                       action='store_true')

    for scope in [
            'aks nodepool show', 'aks nodepool delete', 'aks nodepool scale',
            'aks nodepool upgrade', 'aks nodepool update'
    ]:
        with self.argument_context(scope) as c:
            c.argument('nodepool_name',
                       type=str,
                       options_list=['--name', '-n'],
                       validator=validate_nodepool_name,
                       help='The node pool name.')

    with self.argument_context('aks nodepool upgrade') as c:
        c.argument('max_surge', type=str, validator=validate_max_surge)

    with self.argument_context('aks nodepool update') as c:
        c.argument('enable_cluster_autoscaler',
                   options_list=["--enable-cluster-autoscaler", "-e"],
                   action='store_true')
        c.argument('disable_cluster_autoscaler',
                   options_list=["--disable-cluster-autoscaler", "-d"],
                   action='store_true')
        c.argument('update_cluster_autoscaler',
                   options_list=["--update-cluster-autoscaler", "-u"],
                   action='store_true')
        c.argument('tags', tags_type)
        c.argument('mode',
                   arg_type=get_enum_type(
                       [CONST_NODEPOOL_MODE_SYSTEM, CONST_NODEPOOL_MODE_USER]))
        c.argument('max_surge', type=str, validator=validate_max_surge)

    with self.argument_context('aks disable-addons') as c:
        c.argument('addons',
                   options_list=['--addons', '-a'],
                   validator=validate_addons)

    with self.argument_context('aks enable-addons') as c:
        c.argument('addons',
                   options_list=['--addons', '-a'],
                   validator=validate_addons)
        c.argument('subnet_name', options_list=['--subnet-name', '-s'])
        c.argument('enable_sgxquotehelper', action='store_true')
        c.argument('osm_mesh_name', options_list=['--osm-mesh-name'])
        c.argument('appgw_name',
                   options_list=['--appgw-name'],
                   arg_group='Application Gateway')
        c.argument('appgw_subnet_prefix',
                   options_list=['--appgw-subnet-prefix'],
                   arg_group='Application Gateway',
                   deprecate_info=c.deprecate(redirect='--appgw-subnet-cidr',
                                              hide=True))
        c.argument('appgw_subnet_cidr',
                   options_list=['--appgw-subnet-cidr'],
                   arg_group='Application Gateway')
        c.argument('appgw_id',
                   options_list=['--appgw-id'],
                   arg_group='Application Gateway')
        c.argument('appgw_subnet_id',
                   options_list=['--appgw-subnet-id'],
                   arg_group='Application Gateway')
        c.argument('appgw_watch_namespace',
                   options_list=['--appgw-watch-namespace'],
                   arg_group='Application Gateway')
        c.argument('enable_secret_rotation', action='store_true')

    with self.argument_context('aks get-credentials') as c:
        c.argument('admin', options_list=['--admin', '-a'], default=False)
        c.argument('context_name',
                   options_list=['--context'],
                   help='If specified, overwrite the default context name.')
        c.argument('user',
                   options_list=['--user', '-u'],
                   default='clusterUser',
                   validator=validate_user)
        c.argument('path',
                   options_list=['--file', '-f'],
                   type=file_type,
                   completer=FilesCompleter(),
                   default=os.path.join(os.path.expanduser('~'), '.kube',
                                        'config'))

    with self.argument_context('aks pod-identity') as c:
        c.argument('cluster_name', type=str, help='The cluster name.')

    with self.argument_context('aks pod-identity add') as c:
        c.argument('identity_name',
                   type=str,
                   options_list=['--name', '-n'],
                   default=None,
                   required=False,
                   help='The pod identity name. Generate if not specified.',
                   validator=validate_pod_identity_resource_name(
                       'identity_name', required=False))
        c.argument('identity_namespace',
                   type=str,
                   options_list=['--namespace'],
                   help='The pod identity namespace.')
        c.argument('identity_resource_id',
                   type=str,
                   options_list=['--identity-resource-id'],
                   help='Resource id of the identity to use.')

    with self.argument_context('aks pod-identity delete') as c:
        c.argument('identity_name',
                   type=str,
                   options_list=['--name', '-n'],
                   default=None,
                   required=True,
                   help='The pod identity name.',
                   validator=validate_pod_identity_resource_name(
                       'identity_name', required=True))
        c.argument('identity_namespace',
                   type=str,
                   options_list=['--namespace'],
                   help='The pod identity namespace.')

    with self.argument_context('aks pod-identity exception add') as c:
        c.argument(
            'exc_name',
            type=str,
            options_list=['--name', '-n'],
            default=None,
            required=False,
            help='The pod identity exception name. Generate if not specified.',
            validator=validate_pod_identity_resource_name('exc_name',
                                                          required=False))
        c.argument('exc_namespace',
                   type=str,
                   options_list=['--namespace'],
                   required=True,
                   help='The pod identity exception namespace.',
                   validator=validate_pod_identity_resource_namespace)
        c.argument('pod_labels',
                   nargs='*',
                   required=True,
                   help='space-separated labels: key=value [key=value ...].',
                   validator=validate_pod_identity_pod_labels)

    with self.argument_context('aks pod-identity exception delete') as c:
        c.argument('exc_name',
                   type=str,
                   options_list=['--name', '-n'],
                   required=True,
                   help='The pod identity exception name to remove.',
                   validator=validate_pod_identity_resource_name(
                       'exc_name', required=True))
        c.argument('exc_namespace',
                   type=str,
                   options_list=['--namespace'],
                   required=True,
                   help='The pod identity exception namespace to remove.',
                   validator=validate_pod_identity_resource_namespace)

    with self.argument_context('aks pod-identity exception update') as c:
        c.argument('exc_name',
                   type=str,
                   options_list=['--name', '-n'],
                   required=True,
                   help='The pod identity exception name to remove.',
                   validator=validate_pod_identity_resource_name(
                       'exc_name', required=True))
        c.argument('exc_namespace',
                   type=str,
                   options_list=['--namespace'],
                   required=True,
                   help='The pod identity exception namespace to remove.',
                   validator=validate_pod_identity_resource_namespace)
        c.argument('pod_labels',
                   nargs='*',
                   required=True,
                   help='pod labels in key=value [key=value ...].',
                   validator=validate_pod_identity_pod_labels)
Пример #7
0
def load_arguments(self, _):  # pylint: disable=too-many-statements
    SkuName, PasswordName, OsType, DefaultAction, PolicyStatus, WebhookAction, WebhookStatus, TaskStatus, BaseImageTriggerType, RunStatus = self.get_models(
        'SkuName', 'PasswordName', 'OsType', 'DefaultAction', 'PolicyStatus',
        'WebhookAction', 'WebhookStatus', 'TaskStatus', 'BaseImageTriggerType',
        'RunStatus')
    with self.argument_context('acr') as c:
        c.argument('tags', arg_type=tags_type)
        c.argument(
            'registry_name',
            options_list=['--name', '-n'],
            help=
            'The name of the container registry. You can configure the default registry name using `az configure --defaults acr=<registry name>`',
            completer=get_resource_name_completion_list(
                REGISTRY_RESOURCE_TYPE),
            configured_default='acr')
        c.argument(
            'tenant_suffix',
            options_list=['--suffix'],
            help=
            "The tenant suffix in registry login server. You may specify '--suffix tenant' if your registry login server is in the format 'registry-tenant.azurecr.io'. Applicable if you\'re accessing the registry from a different subscription or you have permission to access images but not the permission to manage the registry resource."
        )
        c.argument(
            'storage_account_name',
            help=
            'Provide the name of an existing storage account if you\'re recreating a container registry over a previous registry created storage account. Only applicable to Classic SKU.',
            completer=get_resource_name_completion_list(STORAGE_RESOURCE_TYPE))
        c.argument('sku',
                   help='The SKU of the container registry',
                   arg_type=get_enum_type(SkuName))
        c.argument('admin_enabled',
                   help='Indicates whether the admin user is enabled',
                   arg_type=get_three_state_flag())
        c.argument('password_name',
                   help='The name of password to regenerate',
                   arg_type=get_enum_type(PasswordName))
        c.argument('username',
                   options_list=['--username', '-u'],
                   help='The username used to log into a container registry')
        c.argument('password',
                   options_list=['--password', '-p'],
                   help='The password used to log into a container registry')
        c.argument('yes',
                   options_list=['--yes', '-y'],
                   help='Do not prompt for confirmation.',
                   action='store_true')
        c.argument('image_names', arg_type=image_by_tag_type, action='append')
        c.argument('timeout', type=int, help='The timeout in seconds.')
        c.argument(
            'docker_file_path',
            options_list=['--file', '-f'],
            help=
            "The relative path of the the docker file to the source code root folder. Default to 'Dockerfile'."
        )
        c.argument(
            'no_logs',
            help="Do not show logs after successfully queuing the build.",
            action='store_true')
        c.argument(
            'no_wait',
            help=
            "Do not wait for the run to complete and return immediately after queuing the run.",
            action='store_true')
        c.argument(
            'no_format',
            help="Indicates whether the logs should be displayed in raw format",
            action='store_true')
        c.argument('os_type',
                   options_list=['--os'],
                   help='The operating system type required for the build.',
                   arg_type=get_enum_type(OsType),
                   deprecate_info=c.deprecate(redirect='platform', hide=True))
        c.argument(
            'platform',
            help=
            "The platform where build/task is run, Eg, 'windows' and 'linux'. When it's used in build commands, it also can be specified in 'os/arch/variant' format for the resulting image. Eg, linux/arm/v7. The 'arch' and 'variant' parts are optional."
        )
        c.argument('target', help='The name of the target build stage.')

    for scope in ['acr create', 'acr update']:
        with self.argument_context(scope, arg_group='Network Rule') as c:
            c.argument(
                'default_action',
                arg_type=get_enum_type(DefaultAction),
                help=
                'Default action to apply when no rule matches. Only applicable to Premium SKU.'
            )

    with self.argument_context('acr import') as c:
        c.argument(
            'source',
            help=
            "The source identifier in the format '[registry.azurecr.io/]repository[:tag]' or '[registry.azurecr.io/]repository@digest'."
        )
        c.argument(
            'source_registry',
            options_list=['--registry', '-r'],
            help=
            'The source container registry can be name, login server or resource ID of the source registry.'
        )
        c.argument('source_registry_username',
                   options_list=['--username', '-u'],
                   help='The username of source container registry')
        c.argument('source_registry_password',
                   options_list=['--password', '-p'],
                   help='The password of source container registry')
        c.argument('target_tags', arg_type=image_by_tag_type, action='append')
        c.argument(
            'repository',
            help='The repository name to do a manifest-only copy for images.',
            action='append')
        c.argument(
            'force',
            help='Overwrite the existing tag of the image to be imported.',
            action='store_true')

    with self.argument_context('acr config content-trust') as c:
        c.argument(
            'status',
            help="Indicates whether content-trust is enabled or disabled.",
            arg_type=get_enum_type(PolicyStatus))

    with self.argument_context('acr login') as c:
        c.argument('resource_group_name',
                   deprecate_info=c.deprecate(hide=True))

    with self.argument_context('acr repository') as c:
        c.argument('resource_group_name',
                   deprecate_info=c.deprecate(hide=True))
        c.argument('repository', help="The name of the repository.")
        c.argument('image', arg_type=image_by_tag_or_digest_type)
        c.argument('top',
                   type=int,
                   help='Limit the number of items in the results.')
        c.argument(
            'orderby',
            help=
            'Order the items in the results. Default to alphabetical order of names.',
            arg_type=get_enum_type(['time_asc', 'time_desc']))
        c.argument('detail',
                   help='Show detailed information.',
                   action='store_true')
        c.argument('delete_enabled',
                   help='Indicates whether delete operation is allowed.',
                   arg_type=get_three_state_flag())
        c.argument(
            'list_enabled',
            help='Indicates whether this item shows in list operation results.',
            arg_type=get_three_state_flag())
        c.argument('read_enabled',
                   help='Indicates whether read operation is allowed.',
                   arg_type=get_three_state_flag())
        c.argument(
            'write_enabled',
            help='Indicates whether write or delete operation is allowed.',
            arg_type=get_three_state_flag())

    with self.argument_context('acr repository untag') as c:
        c.argument('image', arg_type=image_by_tag_type)

    with self.argument_context('acr create') as c:
        c.argument('registry_name', completer=None)
        c.argument('deployment_name', validator=None)
        c.argument('location',
                   validator=get_default_location_from_resource_group)

    with self.argument_context('acr check-name') as c:
        c.argument('registry_name', completer=None)

    with self.argument_context('acr webhook') as c:
        c.argument('registry_name', options_list=['--registry', '-r'])
        c.argument(
            'webhook_name',
            options_list=['--name', '-n'],
            help='The name of the webhook',
            completer=get_resource_name_completion_list(WEBHOOK_RESOURCE_TYPE))
        c.argument(
            'uri',
            help='The service URI for the webhook to post notifications.')
        c.argument(
            'headers',
            nargs='+',
            help=
            "Space-separated custom headers in 'key[=value]' format that will be added to the webhook notifications. Use {} to clear existing headers."
            .format(quotes),
            validator=validate_headers)
        c.argument(
            'actions',
            nargs='+',
            help=
            'Space-separated list of actions that trigger the webhook to post notifications.',
            arg_type=get_enum_type(WebhookAction))
        c.argument('status',
                   help='Indicates whether the webhook is enabled.',
                   arg_type=get_enum_type(WebhookStatus))
        c.argument(
            'scope',
            help=
            "The scope of repositories where the event can be triggered. For example, 'foo:*' means events for all tags under repository 'foo'. 'foo:bar' means events for 'foo:bar' only. 'foo' is equivalent to 'foo:latest'. Empty means events for all repositories."
        )

    with self.argument_context('acr webhook create') as c:
        c.argument('webhook_name', completer=None)

    with self.argument_context('acr replication') as c:
        c.argument('registry_name', options_list=['--registry', '-r'])
        c.argument('replication_name',
                   options_list=['--name', '-n'],
                   help='The name of the replication.',
                   completer=get_resource_name_completion_list(
                       REPLICATION_RESOURCE_TYPE))

    with self.argument_context('acr replication create') as c:
        c.argument(
            'replication_name',
            help='The name of the replication. Default to the location name.',
            completer=None)

    with self.argument_context('acr run') as c:
        c.argument('registry_name', options_list=['--registry', '-r'])
        c.positional(
            'source_location',
            help=
            "The local source code directory path (e.g., './src') or the URL to a git repository (e.g., 'https://github.com/Azure-Samples/acr-build-helloworld-node.git') or a remote tarball (e.g., 'http://server/context.tar.gz').",
            completer=FilesCompleter())
        c.argument(
            'file',
            options_list=['--file', '-f'],
            help=
            "The task template/definition file path relative to the source context."
        )
        c.argument(
            'values',
            help="The task values file path relative to the source context.")
        c.argument('set_value',
                   options_list=['--set'],
                   help="Value in 'name[=value]' format.",
                   action='append',
                   validator=validate_set)
        c.argument('set_secret',
                   help="Secret value in 'name[=value]' format.",
                   action='append',
                   validator=validate_set_secret)

    with self.argument_context('acr build') as c:
        c.argument('registry_name', options_list=['--registry', '-r'])
        c.positional(
            'source_location',
            help=
            "The local source code directory path (e.g., './src') or the URL to a git repository (e.g., 'https://github.com/Azure-Samples/acr-build-helloworld-node.git') or a remote tarball (e.g., 'http://server/context.tar.gz').",
            completer=FilesCompleter())
        c.argument(
            'no_push',
            help=
            "Indicates whether the image built should be pushed to the registry.",
            action='store_true')
        c.argument('arg',
                   options_list=['--build-arg'],
                   help="Build argument in 'name[=value]' format.",
                   action='append',
                   validator=validate_arg)
        c.argument('secret_arg',
                   options_list=['--secret-build-arg'],
                   help="Secret build argument in 'name[=value]' format.",
                   action='append',
                   validator=validate_secret_arg)

    with self.argument_context('acr task') as c:
        c.argument('registry_name', options_list=['--registry', '-r'])
        c.argument(
            'task_name',
            options_list=['--name', '-n'],
            help='The name of the task.',
            completer=get_resource_name_completion_list(TASK_RESOURCE_TYPE))
        c.argument('status',
                   help='The current status of task.',
                   arg_type=get_enum_type(TaskStatus))
        c.argument(
            'with_secure_properties',
            help=
            "Indicates whether the secure properties of a task should be returned.",
            action='store_true')

        # DockerBuildStep, FileTaskStep parameters
        c.argument(
            'file',
            options_list=['--file', '-f'],
            help=
            "The relative path of the the task/docker file to the source code root folder. Task files must be suffixed with '.yaml'."
        )
        c.argument('image', arg_type=image_by_tag_or_digest_type)
        c.argument(
            'no_push',
            help=
            "Indicates whether the image built should be pushed to the registry.",
            arg_type=get_three_state_flag())
        c.argument('no_cache',
                   help='Indicates whether the image cache is enabled.',
                   arg_type=get_three_state_flag())
        c.argument(
            'values',
            help=
            "The task values/parameters file path relative to the source context."
        )

        # common to DockerBuildStep, FileTaskStep and RunTaskStep
        c.argument(
            'context_path',
            options_list=['--context', '-c'],
            help=
            "The full URL to the source code repository (Requires '.git' suffix for a github repo)."
        )
        c.argument('arg',
                   help="Build argument in 'name[=value]' format.",
                   action='append',
                   validator=validate_arg)
        c.argument('secret_arg',
                   help="Secret build argument in 'name[=value]' format.",
                   action='append',
                   validator=validate_secret_arg)
        c.argument('set_value',
                   options_list=['--set'],
                   help="Task value in 'name[=value]' format.",
                   action='append',
                   validator=validate_set)
        c.argument('set_secret',
                   help="Secret task value in 'name[=value]' format.",
                   action='append',
                   validator=validate_set_secret)

        # Source Trigger parameters
        c.argument('source_trigger_name',
                   help="The name of the source trigger.")
        c.argument(
            'commit_trigger_enabled',
            help=
            "Indicates whether the source control commit trigger is enabled.",
            arg_type=get_three_state_flag())
        c.argument(
            'pull_request_trigger_enabled',
            help=
            "Indicates whether the source control pull request trigger is enabled.",
            arg_type=get_three_state_flag())
        c.argument(
            'git_access_token',
            help="The access token used to access the source control provider."
        )
        c.argument('branch', help="The source control branch name.")
        c.argument('base_image_trigger_name',
                   help="The name of the base image trigger.")
        c.argument('base_image_trigger_enabled',
                   help="Indicates whether the base image trigger is enabled.",
                   arg_type=get_three_state_flag())
        c.argument(
            'base_image_trigger_type',
            help=
            "The type of the auto trigger for base image dependency updates.",
            arg_type=get_enum_type(BaseImageTriggerType))

        # Run related parameters
        c.argument('top',
                   help='Limit the number of latest runs in the results.')
        c.argument('run_id', help='The unique run identifier.')
        c.argument('run_status',
                   help='The current status of run.',
                   arg_type=get_enum_type(RunStatus))
        c.argument('no_archive',
                   help='Indicates whether the run should be archived.',
                   arg_type=get_three_state_flag())

        # Run agent parameters
        c.argument(
            'cpu',
            type=int,
            help=
            'The CPU configuration in terms of number of cores required for the run.'
        )

    with self.argument_context('acr task create') as c:
        c.argument('task_name', completer=None)

    with self.argument_context('acr helm') as c:
        c.argument('resource_group_name',
                   deprecate_info=c.deprecate(hide=True))
        c.argument('repository', help=argparse.SUPPRESS)
        c.argument('version', help='The helm chart version.')

    with self.argument_context('acr helm show') as c:
        c.positional('chart', help='The helm chart name.')

    with self.argument_context('acr helm delete') as c:
        c.positional('chart', help='The helm chart name.')
        c.argument('prov',
                   help='Only delete the provenance file.',
                   action='store_true')

    with self.argument_context('acr helm push') as c:
        c.positional('chart_package',
                     help="The helm chart package.",
                     completer=FilesCompleter())
        c.argument('force',
                   help='Overwrite the existing chart package.',
                   action='store_true')

    with self.argument_context('acr network-rule') as c:
        c.argument(
            'subnet',
            help=
            'Name or ID of subnet. If name is supplied, `--vnet-name` must be supplied.'
        )
        c.argument('vnet_name', help='Name of a virtual network.')
        c.argument('ip_address', help='IPv4 address or CIDR range.')
Пример #8
0
def load_arguments(self, _):
    from argcomplete.completers import FilesCompleter

    from azure.mgmt.resource.resources.models import DeploymentMode
    from azure.mgmt.resource.locks.models import LockLevel
    from azure.mgmt.resource.managedapplications.models import ApplicationLockLevel

    from azure.cli.core.api import get_subscription_id_list
    from azure.cli.core.commands.parameters import (
        resource_group_name_type, get_location_type, tag_type, tags_type,
        get_resource_group_completion_list, no_wait_type, file_type,
        get_enum_type, get_three_state_flag)
    from azure.cli.core.profiles import ResourceType

    from knack.arguments import ignore_type, CLIArgumentType

    from azure.cli.command_modules.resource._completers import (
        get_policy_completion_list, get_policy_set_completion_list,
        get_policy_assignment_completion_list,
        get_resource_types_completion_list, get_providers_completion_list)
    from azure.cli.command_modules.resource._validators import (
        validate_lock_parameters, validate_resource_lock, validate_group_lock,
        validate_subscription_lock, validate_metadata, RollbackAction,
        validate_msi)

    # BASIC PARAMETER CONFIGURATION

    resource_name_type = CLIArgumentType(options_list=['--name', '-n'],
                                         help='The resource name. (Ex: myC)')
    resource_type_type = CLIArgumentType(
        help=
        "The resource type (Ex: 'resC'). Can also accept namespace/type format (Ex: 'Microsoft.Provider/resC')"
    )
    resource_namespace_type = CLIArgumentType(
        options_list='--namespace',
        completer=get_providers_completion_list,
        help="Provider namespace (Ex: 'Microsoft.Provider')")
    resource_parent_type = CLIArgumentType(
        required=False,
        options_list=['--parent'],
        help="The parent path (Ex: 'resA/myA/resB/myB')")
    existing_policy_definition_name_type = CLIArgumentType(
        options_list=['--name', '-n'],
        completer=get_policy_completion_list,
        help='The policy definition name.')
    existing_policy_set_definition_name_type = CLIArgumentType(
        options_list=['--name', '-n'],
        completer=get_policy_set_completion_list,
        help='The policy set definition name.')
    subscription_type = CLIArgumentType(
        options_list='--subscription',
        FilesCompleter=get_subscription_id_list,
        help='The subscription id of the policy [set] definition.')
    management_group_name_type = CLIArgumentType(
        options_list='--management-group',
        help='The name of the management group of the policy [set] definition.'
    )
    identity_scope_type = CLIArgumentType(
        help="Scope that the system assigned identity can access")
    identity_role_type = CLIArgumentType(
        options_list=['--role'],
        help="Role name or id that will be assigned to the managed identity")

    _PROVIDER_HELP_TEXT = 'the resource namespace, aka \'provider\''

    with self.argument_context('resource') as c:
        c.argument('no_wait', no_wait_type)
        c.argument('resource_group_name',
                   resource_group_name_type,
                   arg_group='Resource Id')
        c.ignore('resource_id')
        c.argument('resource_name',
                   resource_name_type,
                   arg_group='Resource Id')
        c.argument('api_version',
                   help='The api version of the resource (omit for latest)',
                   required=False,
                   arg_group='Resource Id')
        c.argument('resource_provider_namespace',
                   resource_namespace_type,
                   arg_group='Resource Id')
        c.argument('resource_type',
                   arg_type=resource_type_type,
                   completer=get_resource_types_completion_list,
                   arg_group='Resource Id')
        c.argument('parent_resource_path',
                   resource_parent_type,
                   arg_group='Resource Id')
        c.argument('tag', tag_type)
        c.argument('tags', tags_type)
        c.argument(
            'resource_ids',
            nargs='+',
            options_list=['--ids'],
            help=
            'One or more resource IDs (space-delimited). If provided, no other "Resource Id" arguments should be specified.',
            arg_group='Resource Id')
        c.argument(
            'include_response_body',
            arg_type=get_three_state_flag(),
            help=
            'Use if the default command output doesn\'t capture all of the property data.'
        )

    with self.argument_context('resource list') as c:
        c.argument('name', resource_name_type)

    with self.argument_context('resource move') as c:
        c.argument('ids', nargs='+')

    with self.argument_context('resource invoke-action') as c:
        c.argument(
            'action',
            help='The action that will be invoked on the specified resource')
        c.argument(
            'request_body',
            help=
            'JSON encoded parameter arguments for the action that will be passed along in the post request body. Use @{file} to load from a file.'
        )

    with self.argument_context('resource create') as c:
        c.argument('resource_id',
                   options_list=['--id'],
                   help='Resource ID.',
                   action=None)
        c.argument(
            'properties',
            options_list=['--properties', '-p'],
            help='a JSON-formatted string containing resource properties')
        c.argument(
            'is_full_object',
            action='store_true',
            help=
            'Indicates that the properties object includes other options such as location, tags, sku, and/or plan.'
        )

    with self.argument_context('resource link') as c:
        c.argument(
            'target_id',
            options_list=[
                '--target',
                c.deprecate(target='--target-id',
                            redirect='--target',
                            hide=True)
            ],
            help='Fully-qualified resource ID of the resource link target.')
        c.argument('link_id',
                   options_list=[
                       '--link',
                       c.deprecate(target='--link-id',
                                   redirect='--link',
                                   hide=True)
                   ],
                   help='Fully-qualified resource ID of the resource link.')
        c.argument('notes', help='Notes for the link.')
        c.argument('scope', help='Fully-qualified scope for retrieving links.')
        c.argument('filter_string',
                   options_list=[
                       '--filter',
                       c.deprecate(target='--filter-string',
                                   redirect='--filter',
                                   hide=True)
                   ],
                   help='Filter string for limiting results.')

    with self.argument_context('provider') as c:
        c.ignore('top')
        c.argument('resource_provider_namespace',
                   options_list=['--namespace', '-n'],
                   completer=get_providers_completion_list,
                   help=_PROVIDER_HELP_TEXT)

    with self.argument_context('provider register') as c:
        c.argument('wait',
                   action='store_true',
                   help='wait for the registration to finish')

    with self.argument_context('provider unregister') as c:
        c.argument('wait',
                   action='store_true',
                   help='wait for unregistration to finish')

    with self.argument_context('provider operation') as c:
        c.argument(
            'api_version',
            help=
            "The api version of the 'Microsoft.Authorization/providerOperations' resource (omit for latest)"
        )

    with self.argument_context('feature') as c:
        c.argument('resource_provider_namespace',
                   options_list='--namespace',
                   required=True,
                   help=_PROVIDER_HELP_TEXT)
        c.argument('feature_name',
                   options_list=['--name', '-n'],
                   help='the feature name')

    with self.argument_context('feature list') as c:
        c.argument('resource_provider_namespace',
                   options_list='--namespace',
                   required=False,
                   help=_PROVIDER_HELP_TEXT)

    with self.argument_context('policy') as c:
        c.argument('resource_group_name',
                   arg_type=resource_group_name_type,
                   help='the resource group where the policy will be applied')

    with self.argument_context(
            'policy definition',
            resource_type=ResourceType.MGMT_RESOURCE_POLICY) as c:
        from azure.mgmt.resource.policy.models import PolicyMode
        c.argument('policy_definition_name',
                   arg_type=existing_policy_definition_name_type)
        c.argument(
            'rules',
            help='JSON formatted string or a path to a file with such content',
            type=file_type,
            completer=FilesCompleter())
        c.argument('display_name', help='Display name of policy definition.')
        c.argument('description', help='Description of policy definition.')
        c.argument(
            'params',
            help=
            'JSON formatted string or a path to a file or uri with parameter definitions.',
            type=file_type,
            completer=FilesCompleter(),
            min_api='2016-12-01')
        c.argument('metadata',
                   min_api='2017-06-01-preview',
                   nargs='+',
                   validator=validate_metadata,
                   help='Metadata in space-separated key=value pairs.')
        c.argument('subscription', arg_type=subscription_type)
        c.argument('management_group', arg_type=management_group_name_type)
        c.argument('mode',
                   arg_type=get_enum_type(PolicyMode),
                   options_list=['--mode', '-m'],
                   help='Mode of the policy definition.',
                   min_api='2016-12-01')

    with self.argument_context(
            'policy definition create',
            resource_type=ResourceType.MGMT_RESOURCE_POLICY) as c:
        c.argument('name',
                   options_list=['--name', '-n'],
                   help='Name of the new policy definition.')

    with self.argument_context(
            'policy assignment',
            resource_type=ResourceType.MGMT_RESOURCE_POLICY) as c:
        c.ignore('_subscription')
        c.argument('name',
                   options_list=['--name', '-n'],
                   completer=get_policy_assignment_completion_list,
                   help='Name of the policy assignment.')
        c.argument('scope',
                   help='Scope to which this policy assignment applies.')
        c.argument(
            'disable_scope_strict_match',
            action='store_true',
            help=
            'Include policy assignments either inherited from parent scope or at child scope.'
        )
        c.argument('display_name',
                   help='Display name of the policy assignment.')
        c.argument('policy',
                   help='Name or id of the policy definition.',
                   completer=get_policy_completion_list)

    with self.argument_context(
            'policy assignment create',
            resource_type=ResourceType.MGMT_RESOURCE_POLICY) as c:
        c.argument('name',
                   options_list=['--name', '-n'],
                   help='Name of the new policy assignment.')
        c.argument(
            'params',
            options_list=['--params', '-p'],
            help=
            'JSON formatted string or a path to a file or uri with parameter values of the policy rule.',
            type=file_type,
            completer=FilesCompleter(),
            min_api='2016-12-01')

    with self.argument_context('policy assignment create',
                               resource_type=ResourceType.MGMT_RESOURCE_POLICY,
                               min_api='2017-06-01-preview') as c:
        c.argument('policy_set_definition',
                   options_list=['--policy-set-definition', '-d'],
                   help='Name or id of the policy set definition.')
        c.argument('sku',
                   options_list=['--sku', '-s'],
                   help='policy sku.',
                   arg_type=get_enum_type(['free', 'standard']))
        c.argument('notscopes', options_list='--not-scopes', nargs='+')

    with self.argument_context('policy assignment create',
                               resource_type=ResourceType.MGMT_RESOURCE_POLICY,
                               min_api='2018-05-01') as c:
        c.argument('location', arg_type=get_location_type(self.cli_ctx))

    with self.argument_context('policy assignment create',
                               resource_type=ResourceType.MGMT_RESOURCE_POLICY,
                               arg_group='Managed Identity',
                               min_api='2018-05-01') as c:
        c.argument(
            'assign_identity',
            nargs='*',
            validator=validate_msi,
            help="Assigns a system assigned identity to the policy assignment."
        )
        c.argument('identity_scope', arg_type=identity_scope_type)
        c.argument('identity_role', arg_type=identity_role_type)

    with self.argument_context('policy assignment identity',
                               resource_type=ResourceType.MGMT_RESOURCE_POLICY,
                               min_api='2018-05-01') as c:
        c.argument('identity_scope', arg_type=identity_scope_type)
        c.argument('identity_role', arg_type=identity_role_type)

    with self.argument_context(
            'policy set-definition',
            min_api='2017-06-01-preview',
            resource_type=ResourceType.MGMT_RESOURCE_POLICY) as c:
        c.argument('policy_set_definition_name',
                   arg_type=existing_policy_set_definition_name_type)
        c.argument('display_name',
                   help='Display name of policy set definition.')
        c.argument('description', help='Description of policy set definition.')
        c.argument(
            'params',
            help=
            'JSON formatted string or a path to a file or uri with parameter definitions.',
            type=file_type,
            completer=FilesCompleter())
        c.argument(
            'definitions',
            help=
            'JSON formatted string or a path to a file or uri containing definitions.',
            type=file_type,
            completer=FilesCompleter())
        c.argument('subscription', arg_type=subscription_type)
        c.argument('management_group', arg_type=management_group_name_type)

    with self.argument_context(
            'policy set-definition create',
            min_api='2017-06-01-preview',
            resource_type=ResourceType.MGMT_RESOURCE_POLICY) as c:
        c.argument('name',
                   options_list=['--name', '-n'],
                   help='Name of the new policy set definition.')

    with self.argument_context('group') as c:
        c.argument('tag', tag_type)
        c.argument('tags', tags_type)
        c.argument('resource_group_name',
                   resource_group_name_type,
                   options_list=['--name', '-n', '--resource-group', '-g'])

    with self.argument_context('group deployment') as c:
        c.argument('resource_group_name',
                   arg_type=resource_group_name_type,
                   completer=get_resource_group_completion_list)
        c.argument('deployment_name',
                   options_list=['--name', '-n'],
                   required=True,
                   help='The deployment name.')
        c.argument('template_file',
                   completer=FilesCompleter(),
                   type=file_type,
                   help="a template file path in the file system")
        c.argument('template_uri', help='a uri to a remote template file')
        c.argument(
            'mode',
            arg_type=get_enum_type(DeploymentMode, default='incremental'),
            help=
            'Incremental (only add resources to resource group) or Complete (remove extra resources from resource group)'
        )
        c.argument('parameters',
                   action='append',
                   nargs='+',
                   completer=FilesCompleter())
        c.argument(
            'rollback_on_error',
            nargs='?',
            action=RollbackAction,
            help=
            'The name of a deployment to roll back to on error, or use as a flag to roll back to the last successful deployment.'
        )

    with self.argument_context('group deployment create') as c:
        c.argument(
            'deployment_name',
            options_list=['--name', '-n'],
            required=False,
            help='The deployment name. Default to template file base name')

    with self.argument_context('group deployment operation show') as c:
        c.argument('operation_ids',
                   nargs='+',
                   help='A list of operation ids to show')

    with self.argument_context('deployment') as c:
        c.argument('deployment_name',
                   options_list=['--name', '-n'],
                   required=True,
                   help='The deployment name.')
        c.argument('deployment_location',
                   arg_type=get_location_type(self.cli_ctx),
                   required=True)
        c.argument('template_file',
                   completer=FilesCompleter(),
                   type=file_type,
                   help="a template file path in the file system")
        c.argument('template_uri', help='a uri to a remote template file')
        c.argument('parameters',
                   action='append',
                   nargs='+',
                   completer=FilesCompleter())

    with self.argument_context('deployment create') as c:
        c.argument(
            'deployment_name',
            options_list=['--name', '-n'],
            required=False,
            help='The deployment name. Default to template file base name')

    with self.argument_context('deployment operation show') as c:
        c.argument('operation_ids',
                   nargs='+',
                   help='A list of operation ids to show')

    with self.argument_context('group export') as c:
        c.argument('include_comments', action='store_true')
        c.argument('include_parameter_default_value', action='store_true')

    with self.argument_context('group create') as c:
        c.argument('rg_name',
                   options_list=['--name', '--resource-group', '-n', '-g'],
                   help='name of the new resource group',
                   completer=None)

    with self.argument_context('tag') as c:
        c.argument('tag_name', options_list=['--name', '-n'])
        c.argument('tag_value', options_list='--value')

    with self.argument_context('lock') as c:
        c.argument('lock_name',
                   options_list=['--name', '-n'],
                   validator=validate_lock_parameters)
        c.argument('level',
                   arg_type=get_enum_type(LockLevel),
                   options_list=['--lock-type', '-t'],
                   help='The type of lock restriction.')
        c.argument('parent_resource_path', resource_parent_type)
        c.argument('resource_provider_namespace', resource_namespace_type)
        c.argument('resource_type',
                   arg_type=resource_type_type,
                   completer=get_resource_types_completion_list)
        c.argument(
            'resource_name',
            options_list=['--resource', '--resource-name'],
            help=
            'Name or ID of the resource being locked. If an ID is given, other resource arguments should not be given.'
        )
        c.argument(
            'ids',
            nargs='+',
            options_list='--ids',
            help=
            'One or more resource IDs (space-delimited). If provided, no other "Resource Id" arguments should be specified.'
        )
        c.argument('resource_group',
                   resource_group_name_type,
                   validator=validate_lock_parameters)

    with self.argument_context('resource lock') as c:
        c.argument('resource_group', resource_group_name_type)
        c.argument(
            'resource_name',
            options_list=['--resource', '--resource-name'],
            help=
            'If an ID is given, other resource arguments should not be given.',
            validator=validate_resource_lock)

    with self.argument_context('group lock') as c:
        c.argument('resource_group',
                   resource_group_name_type,
                   validator=validate_group_lock,
                   id_part=None)

    with self.argument_context('group lock create') as c:
        c.argument('resource_group', required=True)

    with self.argument_context('account lock') as c:
        c.argument('resource_group',
                   ignore_type,
                   validator=validate_subscription_lock)

    for scope in ['account', 'group']:
        with self.argument_context('{} lock'.format(scope)) as c:
            c.ignore('resource_provider_namespace', 'parent_resource_path',
                     'resource_type', 'resource_name')

    for scope in ['lock', 'account lock', 'group lock', 'resource lock']:
        with self.argument_context(scope) as c:
            c.argument('lock_name',
                       options_list=['--name', '-n'],
                       help='Name of the lock')
            c.argument('level',
                       options_list=['--lock-type', '-t'],
                       arg_type=get_enum_type(
                           [LockLevel.can_not_delete, LockLevel.read_only]),
                       help='The type of lock restriction.')
            c.argument(
                'ids',
                nargs='+',
                options_list='--ids',
                help=
                'One or more resource IDs (space-delimited). If provided, no other "Resource Id" arguments should be specified.'
            )
            c.argument('notes', help='Notes about this lock.')

    with self.argument_context('managedapp') as c:
        c.argument('resource_group_name',
                   arg_type=resource_group_name_type,
                   help='the resource group of the managed application',
                   id_part='resource_group')
        c.argument('application_name',
                   options_list=['--name', '-n'],
                   id_part='name')

    with self.argument_context('managedapp definition') as c:
        c.argument(
            'resource_group_name',
            arg_type=resource_group_name_type,
            help='the resource group of the managed application definition',
            id_part='resource_group')
        c.argument('application_definition_name',
                   options_list=['--name', '-n'],
                   id_part='name')

    with self.argument_context('managedapp create') as c:
        c.argument('name',
                   options_list=['--name', '-n'],
                   help='name of the new managed application',
                   completer=None)
        c.argument('location', help='the managed application location')
        c.argument('managedapp_definition_id',
                   options_list=['--managedapp-definition-id', '-d'],
                   help='the full qualified managed application definition id')
        c.argument(
            'managedby_resource_group_id',
            options_list=['--managed-rg-id', '-m'],
            help='the resource group managed by the managed application')
        c.argument(
            'parameters',
            help='JSON formatted string or a path to a file with such content',
            type=file_type)

    with self.argument_context('managedapp definition create') as c:
        c.argument('lock_level',
                   arg_type=get_enum_type(ApplicationLockLevel),
                   help='The type of lock restriction.')
        c.argument(
            'authorizations',
            options_list=['--authorizations', '-a'],
            nargs='+',
            help=
            "space-separated authorization pairs in a format of <principalId>:<roleDefinitionId>"
        )
        c.argument(
            'createUiDefinition',
            options_list=['--create-ui-definition', '-c'],
            help='JSON formatted string or a path to a file with such content',
            type=file_type)
        c.argument(
            'mainTemplate',
            options_list=['--main-template', '-t'],
            help='JSON formatted string or a path to a file with such content',
            type=file_type)

    with self.argument_context('account') as c:
        c.argument('subscription',
                   options_list=['--subscription', '-s'],
                   help='Name or ID of subscription.',
                   completer=get_subscription_id_list)

    with self.argument_context('account management-group') as c:
        c.argument('group_name', options_list=['--name', '-n'])
        c.ignore('_subscription')  # hide global subscription parameter

    with self.argument_context('account management-group show') as c:
        c.argument('expand',
                   options_list=['--expand', '-e'],
                   action='store_true')
        c.argument('recurse',
                   options_list=['--recurse', '-r'],
                   action='store_true')

    with self.argument_context('account management-group create') as c:
        c.argument('display_name', options_list=['--display-name', '-d'])
        c.argument('parent', options_list=['--parent', '-p'])

    with self.argument_context('account management-group update') as c:
        c.argument('display_name', options_list=['--display-name', '-d'])
        c.argument('parent_id', options_list=['--parent', '-p'])

    with self.argument_context('rest') as c:
        c.argument(
            'method',
            options_list=['--method', '-m'],
            arg_type=get_enum_type(
                ['head', 'get', 'put', 'post', 'delete', 'options', 'patch'],
                default='get'),
            help='HTTP request method')
        c.argument(
            'uri',
            options_list=['--uri', '-u'],
            help=
            'request uri. For uri without host, CLI will assume "https://management.azure.com/".'
            ' Common tokens will also be replaced with real values including "{subscriptionId}"'
        )
        c.argument(
            'headers',
            nargs='+',
            help=
            "Space-separated headers in KEY=VALUE format or JSON string. Use @{file} to load from a file"
        )
        c.argument(
            'uri_parameters',
            nargs='+',
            help=
            'Space-separated queries in KEY=VALUE format or JSON string. Use @{file} to load from a file'
        )
        c.argument('skip_authorization_header',
                   action='store_true',
                   help='do not auto append "Authorization" header')
        c.argument('body', options_list=['--body', '-b'], help='request body')
        c.argument('output_file', help='save response payload to a file')
        c.argument(
            'resource',
            help=
            'Resource url for which CLI should acquire a token in order to access '
            'the service. The token will be placed in the "Authorization" header. By default, '
            'CLI can figure this out based on "--url" argument, unless you use ones not in the list '
            'of "az cloud show --query endpoints"')
Пример #9
0
def UUIDFileCompleter(prefix, **kwargs):
    from argcomplete.completers import FilesCompleter
    completion = UUIDCompleter(prefix)
    if not completion:
        return FilesCompleter()(prefix)
    return completion
Пример #10
0
def load_arguments(self, _):
    from argcomplete.completers import FilesCompleter

    from azure.mgmt.resource.resources.models import DeploymentMode
    from azure.mgmt.resource.locks.models import LockLevel
    from azure.mgmt.resource.managedapplications.models import ApplicationLockLevel

    from azure.cli.core.commands.parameters import (
        resource_group_name_type, tag_type, tags_type, get_resource_group_completion_list, no_wait_type, file_type,
        get_enum_type, get_three_state_flag)
    from azure.cli.core.profiles import ResourceType

    from knack.arguments import ignore_type, CLIArgumentType

    from azure.cli.command_modules.resource._completers import (
        get_policy_completion_list, get_policy_set_completion_list, get_policy_assignment_completion_list,
        get_resource_types_completion_list, get_providers_completion_list)
    from azure.cli.command_modules.resource._validators import (
        validate_lock_parameters, validate_resource_lock, validate_group_lock, validate_subscription_lock)

    # BASIC PARAMETER CONFIGURATION

    resource_name_type = CLIArgumentType(options_list=('--name', '-n'), help='The resource name. (Ex: myC)')
    resource_type_type = CLIArgumentType(help="The resource type (Ex: 'resC'). Can also accept namespace/type format (Ex: 'Microsoft.Provider/resC')")
    resource_namespace_type = CLIArgumentType(options_list=('--namespace',), completer=get_providers_completion_list, help="Provider namespace (Ex: 'Microsoft.Provider')")
    resource_parent_type = CLIArgumentType(required=False, options_list=['--parent'], help="The parent path (Ex: 'resA/myA/resB/myB')")
    existing_policy_definition_name_type = CLIArgumentType(options_list=('--name', '-n'), completer=get_policy_completion_list, help='The policy definition name')
    existing_policy_set_definition_name_type = CLIArgumentType(options_list=('--name', '-n'), completer=get_policy_set_completion_list, help='The policy set definition name')
    _PROVIDER_HELP_TEXT = 'the resource namespace, aka \'provider\''

    with self.argument_context('resource') as c:
        c.argument('no_wait', no_wait_type)
        c.argument('resource_group_name', resource_group_name_type, arg_group='Resource Id')
        c.ignore('resource_id')
        c.argument('resource_name', resource_name_type, arg_group='Resource Id')
        c.argument('api_version', help='The api version of the resource (omit for latest)', required=False, arg_group='Resource Id')
        c.argument('resource_provider_namespace', resource_namespace_type, arg_group='Resource Id')
        c.argument('resource_type', arg_type=resource_type_type, completer=get_resource_types_completion_list, arg_group='Resource Id')
        c.argument('parent_resource_path', resource_parent_type, arg_group='Resource Id')
        c.argument('tag', tag_type)
        c.argument('tags', tags_type)
        c.argument('resource_ids', nargs='+', options_list=['--ids'], help='One or more resource IDs (space-delimited). If provided, no other "Resource Id" arguments should be specified.', arg_group='Resource Id')
        c.argument('include_response_body', arg_type=get_three_state_flag(), help='Use if the default command output doesn\'t capture all of the property data.')

    with self.argument_context('resource list') as c:
        c.argument('name', resource_name_type)

    with self.argument_context('resource move') as c:
        c.argument('ids', nargs='+')

    with self.argument_context('resource invoke-action') as c:
        c.argument('action', help='The action that will be invoked on the specified resource')
        c.argument('request_body', help='JSON encoded parameter arguments for the action that will be passed along in the post request body. Use @{file} to load from a file.')

    with self.argument_context('resource create') as c:
        c.argument('resource_id', options_list=['--id'], help='Resource ID.', action=None)
        c.argument('properties', options_list=('--properties', '-p'), help='a JSON-formatted string containing resource properties')
        c.argument('is_full_object', action='store_true', help='Indicates that the properties object includes other options such as location, tags, sku, and/or plan.')

    with self.argument_context('provider') as c:
        c.ignore('top')
        c.argument('resource_provider_namespace', options_list=('--namespace', '-n'), completer=get_providers_completion_list, help=_PROVIDER_HELP_TEXT)

    with self.argument_context('provider register') as c:
        c.argument('wait', action='store_true', help='wait for the registration to finish')

    with self.argument_context('provider unregister') as c:
        c.argument('wait', action='store_true', help='wait for unregistration to finish')

    with self.argument_context('provider operation') as c:
        c.argument('api_version', help="The api version of the 'Microsoft.Authorization/providerOperations' resource (omit for latest)")

    with self.argument_context('feature') as c:
        c.argument('resource_provider_namespace', options_list=('--namespace',), required=True, help=_PROVIDER_HELP_TEXT)
        c.argument('feature_name', options_list=('--name', '-n'), help='the feature name')

    with self.argument_context('feature list') as c:
        c.argument('resource_provider_namespace', options_list=('--namespace',), required=False, help=_PROVIDER_HELP_TEXT)

    with self.argument_context('policy') as c:
        c.argument('resource_group_name', arg_type=resource_group_name_type, help='the resource group where the policy will be applied')

    with self.argument_context('policy definition', resource_type=ResourceType.MGMT_RESOURCE_POLICY) as c:
        c.argument('policy_definition_name', arg_type=existing_policy_definition_name_type)
        c.argument('rules', help='JSON formatted string or a path to a file with such content', type=file_type, completer=FilesCompleter())
        c.argument('display_name', help='display name of policy definition')
        c.argument('description', help='description of policy definition')
        c.argument('params', help='JSON formatted string or a path to a file or uri with parameter definitions', type=file_type, completer=FilesCompleter(), min_api='2016-12-01')

    with self.argument_context('policy definition create', resource_type=ResourceType.MGMT_RESOURCE_POLICY) as c:
        from azure.mgmt.resource.policy.models import PolicyMode
        c.argument('name', options_list=('--name', '-n'), help='name of the new policy definition')
        c.argument('mode', arg_type=get_enum_type(PolicyMode), options_list=('--mode', '-m'), help='mode of the new policy definition.', min_api='2016-12-01')

    with self.argument_context('policy assignment', resource_type=ResourceType.MGMT_RESOURCE_POLICY) as c:
        c.argument('name', options_list=('--name', '-n'), completer=get_policy_assignment_completion_list, help='name of the assignment')
        c.argument('scope', help='scope at which this policy assignment applies to, e.g., /subscriptions/0b1f6471-1bf0-4dda-aec3-111122223333, /subscriptions/0b1f6471-1bf0-4dda-aec3-111122223333/resourceGroups/myGroup, or /subscriptions/0b1f6471-1bf0-4dda-aec3-111122223333/resourceGroups/myGroup/providers/Microsoft.Compute/virtualMachines/myVM')
        c.argument('disable_scope_strict_match', action='store_true', help='include assignment either inherited from parent scope or at child scope')
        c.argument('display_name', help='display name of the assignment')
        c.argument('policy', help='name or id of the policy definition.', completer=get_policy_completion_list)

    with self.argument_context('policy assignment create') as c:
        c.argument('name', options_list=('--name', '-n'), help='name of the new assignment')
        c.argument('params', options_list=('--params', '-p'), help='JSON formatted string or path to file with parameter values of policy rule', min_api='2016-12-01')

    with self.argument_context('policy assignment create', resource_type=ResourceType.MGMT_RESOURCE_POLICY, min_api='2017-06-01-preview') as c:
        c.argument('policy_set_definition', options_list=('--policy-set-definition', '-d'), help='name or id of the policy set definition.')
        c.argument('sku', options_list=('--sku', '-s'), help='policy sku.', arg_type=get_enum_type(['free', 'standard']))
        c.argument('notscopes', options_list=('--not-scopes'), nargs='+')

    with self.argument_context('policy set-definition', min_api='2017-06-01-preview', resource_type=ResourceType.MGMT_RESOURCE_POLICY) as c:
        c.argument('policy_set_definition_name', arg_type=existing_policy_set_definition_name_type)
        c.argument('name', options_list=('--name', '-n'), help='name of the new policy set definition')
        c.argument('display_name', help='display name of policy set definition')
        c.argument('description', help='description of policy set definition')
        c.argument('params', help='JSON formatted string or a path to a file or uri with parameter definitions', type=file_type, completer=FilesCompleter())
        c.argument('definitions', help='JSON formatted string or a path to a file or uri with such content', type=file_type, completer=FilesCompleter())

    with self.argument_context('group') as c:
        c.argument('tag', tag_type)
        c.argument('tags', tags_type)
        c.argument('resource_group_name', resource_group_name_type, options_list=['--name', '-n', '--resource-group', '-g'])

    with self.argument_context('group deployment') as c:
        c.argument('resource_group_name', arg_type=resource_group_name_type, completer=get_resource_group_completion_list)
        c.argument('deployment_name', options_list=('--name', '-n'), required=True, help='The deployment name.')
        c.argument('template_file', completer=FilesCompleter(), type=file_type, help="a template file path in the file system")
        c.argument('template_uri', help='a uri to a remote template file')
        c.argument('mode', arg_type=get_enum_type(DeploymentMode, default='incremental'), help='Incremental (only add resources to resource group) or Complete (remove extra resources from resource group)')
        c.argument('parameters', action='append', nargs='+', completer=FilesCompleter())

    with self.argument_context('group deployment create') as c:
        c.argument('deployment_name', options_list=('--name', '-n'), required=False,
                   help='The deployment name. Default to template file base name')

    with self.argument_context('group deployment operation show') as c:
        c.argument('operation_ids', nargs='+', help='A list of operation ids to show')

    with self.argument_context('group export') as c:
        c.argument('include_comments', action='store_true')
        c.argument('include_parameter_default_value', action='store_true')

    with self.argument_context('group create') as c:
        c.argument('rg_name', options_list=['--name', '--resource-group', '-n', '-g'], help='name of the new resource group', completer=None)

    with self.argument_context('tag') as c:
        c.argument('tag_name', options_list=('--name', '-n'))
        c.argument('tag_value', options_list=('--value',))

    with self.argument_context('lock') as c:
        c.argument('lock_name', options_list=('--name', '-n'), validator=validate_lock_parameters)
        c.argument('level', arg_type=get_enum_type(LockLevel), options_list=('--lock-type', '-t'))
        c.argument('parent_resource_path', resource_parent_type)
        c.argument('resource_provider_namespace', resource_namespace_type)
        c.argument('resource_type', arg_type=resource_type_type, completer=get_resource_types_completion_list)
        c.argument('resource_name', options_list=['--resource', '--resource-name'], help='Name or ID of the resource being locked. If an ID is given, other resource arguments should not be given.')
        c.argument('ids', nargs='+', options_list=('--ids'), help='One or more resource IDs (space-delimited). If provided, no other "Resource Id" arguments should be specified.')
        c.argument('resource_group', resource_group_name_type, validator=validate_lock_parameters)

    with self.argument_context('resource lock') as c:
        c.argument('resource_group', resource_group_name_type)
        c.argument('resource_name', options_list=['--resource', '--resource-name'], help='If an ID is given, other resource arguments should not be given.', validator=validate_resource_lock)

    with self.argument_context('group lock') as c:
        c.argument('resource_group', resource_group_name_type, validator=validate_group_lock, id_part=None)

    with self.argument_context('group lock create') as c:
        c.argument('resource_group', required=True)

    with self.argument_context('account lock') as c:
        c.argument('resource_group', ignore_type, validator=validate_subscription_lock)

    for scope in ['account', 'group']:
        with self.argument_context('{} lock'.format(scope)) as c:
            c.ignore('resource_provider_namespace', 'parent_resource_path', 'resource_type', 'resource_name')

    for scope in ['lock', 'account lock', 'group lock', 'resource lock']:
        with self.argument_context(scope) as c:
            c.argument('lock_name', options_list=('--name', '-n'), help='Name of the lock')
            c.argument('level', options_list=('--lock-type', '-t'), arg_type=get_enum_type([LockLevel.can_not_delete, LockLevel.read_only]))
            c.argument('ids', nargs='+', options_list=('--ids'), help='One or more resource IDs (space-delimited). If provided, no other "Resource Id" arguments should be specified.')
            c.argument('notes', help='Notes about this lock.')

    with self.argument_context('managedapp') as c:
        c.argument('resource_group_name', arg_type=resource_group_name_type, help='the resource group of the managed application', id_part='resource_group')
        c.argument('application_name', options_list=('--name', '-n'), id_part='name')

    with self.argument_context('managedapp definition') as c:
        c.argument('resource_group_name', arg_type=resource_group_name_type, help='the resource group of the managed application definition', id_part='resource_group')
        c.argument('application_definition_name', options_list=('--name', '-n'), id_part='name')

    with self.argument_context('managedapp create') as c:
        c.argument('name', options_list=('--name', '-n'), help='name of the new managed application', completer=None)
        c.argument('location', help='the managed application location')
        c.argument('managedapp_definition_id', options_list=('--managedapp-definition-id', '-d'), help='the full qualified managed application definition id')
        c.argument('managedby_resource_group_id', options_list=('--managed-rg-id', '-m'), help='the resource group managed by the managed application')
        c.argument('parameters', help='JSON formatted string or a path to a file with such content', type=file_type)

    with self.argument_context('managedapp definition create') as c:
        c.argument('lock_level', arg_type=get_enum_type(ApplicationLockLevel))
        c.argument('authorizations', options_list=('--authorizations', '-a'), nargs='+', help="space-separated authorization pairs in a format of <principalId>:<roleDefinitionId>")
        c.argument('createUiDefinition', options_list=('--create-ui-definition', '-c'), help='JSON formatted string or a path to a file with such content', type=file_type)
        c.argument('mainTemplate', options_list=('--main-template', '-t'), help='JSON formatted string or a path to a file with such content', type=file_type)
Пример #11
0
                      **enum_choice_list(list(delete_snapshot_types.keys())))

register_cli_argument('storage blob exists', 'blob_name', required=True)

register_cli_argument(
    'storage blob list',
    'include',
    help=
    'Specifies additional datasets to include: (c)opy-info, (m)etadata, (s)napshots. Can be combined.',
    validator=validate_included_datasets)

for item in ['download', 'upload']:
    register_cli_argument('storage blob {}'.format(item),
                          'file_path',
                          options_list=('--file', '-f'),
                          completer=FilesCompleter())
    register_cli_argument('storage blob {}'.format(item),
                          'max_connections',
                          type=int)
    register_cli_argument('storage blob {}'.format(item),
                          'validate_content',
                          action='store_true')

for item in ['update', 'upload']:
    register_content_settings_argument('storage blob {}'.format(item),
                                       BlobContentSettings, item == 'update')

register_cli_argument(
    'storage blob upload',
    'blob_type',
    help="Defaults to 'page' for *.vhd files, or 'block' otherwise.",
Пример #12
0
def load_arguments(self, _):
    batch_name_type = CLIArgumentType(
        help='Name of the Batch account.',
        options_list=('--account-name', ),
        completer=get_resource_name_completion_list(
            'Microsoft.Batch/batchAccounts'),
        id_part=None)

    with self.argument_context('batch') as c:
        c.argument('resource_group_name',
                   resource_group_name_type,
                   help='Name of the resource group',
                   completer=None,
                   validator=None,
                   required=True)

    with self.argument_context('batch account') as c:
        c.argument('account_name',
                   batch_name_type,
                   options_list=('--name', '-n'))

    with self.argument_context('batch account show') as c:
        c.argument(
            'resource_group_name',
            resource_group_name_type,
            help=
            'Name of the resource group. If not specified will display currently set account.',
            required=False)
        c.argument(
            'account_name',
            batch_name_type,
            options_list=('--name', '-n'),
            help=
            'Name of the batch account to show. If not specified will display currently set account.',
            required=False)

    with self.argument_context('batch account list') as c:
        c.argument('resource_group_name',
                   resource_group_name_type,
                   help='Name of the resource group',
                   required=False)

    with self.argument_context('batch account create') as c:
        c.argument('location',
                   get_location_type(self.cli_ctx),
                   help='The region in which to create the account.')
        c.argument('tags',
                   tags_type,
                   help="Space-separated tags in 'key[=value]' format.")
        c.argument(
            'storage_account',
            help=
            'The storage account name or resource ID to be used for auto storage.',
            validator=storage_account_id)
        c.argument(
            'keyvault',
            help=
            'The KeyVault name or resource ID to be used for an account with a pool allocation mode of \'User Subscription\'.',
            validator=keyvault_id)
        c.ignore('keyvault_url')

    with self.argument_context('batch account set') as c:
        c.argument('tags', tags_type)
        c.argument(
            'storage_account',
            help=
            'The storage account name or resource ID to be used for auto storage.',
            validator=storage_account_id)

    with self.argument_context('batch account keys renew') as c:
        c.argument('key_name', arg_type=get_enum_type(AccountKeyType))

    with self.argument_context('batch account login') as c:
        c.argument(
            'shared_key_auth',
            action='store_true',
            help=
            'Using Shared Key authentication, if not specified, it will use Azure Active Directory authentication.'
        )
        c.argument(
            'show',
            action='store_true',
            help='Display the credential information for the Batch account.')

    with self.argument_context('batch application set') as c:
        c.argument('application_name',
                   options_list=('--application-name', ),
                   help="The name of the application.")
        c.argument(
            'allow_updates',
            options_list=('--allow-updates', ),
            help=
            "Specify to indicate whether packages within the application may be overwritten using the same version string. Specify either 'true' or 'false' to update the property."
        )

    with self.argument_context('batch application create') as c:
        c.argument(
            'allow_updates',
            options_list=('--allow-updates', ),
            action="store_true",
            help=
            "Specify to indicate whether packages within the application may be overwritten using the same version string. True if flag present."
        )

    with self.argument_context('batch application package create') as c:
        c.argument('package_file',
                   type=file_type,
                   help='The path of the application package in zip format',
                   completer=FilesCompleter())
        c.argument('application_name',
                   options_list=('--application-name', ),
                   help="The name of the application.")
        c.argument('version_name',
                   options_list=('--version-name', ),
                   help="The version name of the application.")

    with self.argument_context('batch location quotas show') as c:
        c.argument(
            'location_name',
            get_location_type(self.cli_ctx),
            help='The region from which to display the Batch service quotas.')

    for command in ['list', 'show', 'create', 'set', 'delete', 'package']:
        with self.argument_context(
                'batch application {}'.format(command)) as c:
            c.argument('account_name',
                       batch_name_type,
                       options_list=('--name', '-n'),
                       validator=application_enabled)

    # TODO: Refactor so the help text can be extracted automatically
    with self.argument_context('batch pool resize') as c:
        c.argument(
            'if_modified_since',
            help=
            'The operation will be performed only if the resource has been modified since the specified timestamp.',
            type=datetime_format,
            arg_group='Pre-condition and Query')
        c.argument(
            'if_unmodified_since',
            help=
            'The operation will not be performed only if the resource has been modified since the specified timestamp.',
            type=datetime_format,
            arg_group='Pre-condition and Query')
        c.argument(
            'if_match',
            help=
            'The operation will be performed only if the resource\'s current ETag exactly matches the specified value.',
            arg_group='Pre-condition and Query')
        c.argument(
            'if_none_match',
            help=
            'The operation will not be performed only if the resource\'s current ETag exactly matches the specified value.',
            arg_group='Pre-condition and Query')
        c.argument('pool_id', help='The ID of the pool.')
        c.argument('abort',
                   action='store_true',
                   help='Stop the pool resize operation.',
                   validator=validate_pool_resize_parameters)
        c.argument(
            'node_deallocation_option',
            options_list=('--node-deallocation-option', ),
            help=
            'When nodes may be removed from the pool, if the pool size is decreasing.',
            arg_type=get_enum_type(ComputeNodeDeallocationOption))

    # TODO: Refactor so the help text can be extracted automatically
    with self.argument_context('batch pool reset') as c:
        c.argument(
            'json_file',
            type=file_type,
            help=
            'The file containing pool update properties parameter specification in JSON(formatted to match REST API request body). If this parameter is specified, all \'Pool Update Properties Parameter Arguments\' are ignored.',
            validator=validate_json_file,
            completer=FilesCompleter())
        c.argument('pool_id', help='The ID of the pool to update.')
        c.argument('application_package_references',
                   nargs='+',
                   type=application_package_reference_format,
                   arg_group='Pool')
        c.argument('certificate_references',
                   nargs='+',
                   type=certificate_reference_format,
                   arg_group='Pool')
        c.argument('metadata',
                   nargs='+',
                   type=metadata_item_format,
                   arg_group='Pool')
        c.argument(
            'start_task_command_line',
            arg_group='Pool: Start Task',
            help=
            'The command line of the start task. The command line does not run under a shell, and therefore cannot take advantage of shell features such as environment variable expansion. If you want to take advantage of such features, you should invoke the shell in the command line, for example using "cmd /c MyCommand" in Windows or "/bin/sh -c MyCommand" in Linux.'
        )
        c.argument(
            'start_task_wait_for_success',
            action='store_true',
            arg_group='Pool: Start Task',
            help=
            'Whether the Batch service should wait for the start task to complete successfully (that is, to exit with exit code 0) before scheduling any tasks on the compute node. True if flag present, otherwise defaults to False.'
        )
        c.argument('start_task_max_task_retry_count',
                   arg_group='Pool: Start Task',
                   help='The maximum number of times the task may be retried.')
        c.argument(
            'start_task_environment_settings',
            nargs='+',
            type=environment_setting_format,
            arg_group='Pool: Start Task',
            help=
            'A list of environment variable settings for the start task. Space-separated values in \'key=value\' format.'
        )

    with self.argument_context('batch job list') as c:
        c.argument('filter',
                   help=' An OData $filter clause.',
                   arg_group='Pre-condition and Query')
        c.argument('select',
                   help=' An OData $select clause.',
                   arg_group='Pre-condition and Query')
        c.argument('expand',
                   help=' An OData $expand clause.',
                   arg_group='Pre-condition and Query')
        c.argument(
            'job_schedule_id',
            help=
            'The ID of the job schedule from which you want to get a list of jobs. If omitted, lists all jobs in the account.'
        )

    for command in [
            'job create', 'job set', 'job reset', 'job-schedule create',
            'job-schedule set', 'job-schedule reset'
    ]:
        with self.argument_context('batch {}'.format(command)) as c:
            c.argument(
                'pool_id',
                options_list=('--pool-id', ),
                help=
                'The id of an existing pool. All the tasks of the job will run on the specified pool.'
            )

    with self.argument_context('batch pool create') as c:
        c.argument('os_family',
                   arg_type=get_enum_type(['2', '3', '4', '5', '6']))
        c.argument(
            'auto_scale_formula',
            help=
            'A formula for the desired number of compute nodes in the pool. The formula is checked for validity before the pool is created. If the formula is not valid, the Batch service rejects the request with detailed error information. For more information about specifying this formula, see https://azure.microsoft.com/documentation/articles/batch-automatic-scaling/.'
        )
        c.extra(
            'disk_encryption_targets',
            arg_group="Pool: Virtual Machine Configuration",
            help=
            'A space seperated list of DiskEncryptionTargets. current possible values include OsDisk and TemporaryDisk.',
            type=disk_encryption_configuration_format)
        c.extra(
            'image',
            completer=load_supported_images,
            arg_group="Pool: Virtual Machine Configuration",
            help=
            "OS image reference. This can be either 'publisher:offer:sku[:version]' format, or a fully qualified ARM image id of the form '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/images/{imageName}'. If 'publisher:offer:sku[:version]' format, version is optional and if omitted latest will be used. Valid values can be retrieved via 'az batch pool supported-images list'. For example: 'MicrosoftWindowsServer:WindowsServer:2012-R2-Datacenter:latest'"
        )

    with self.argument_context('batch certificate') as c:
        c.argument('thumbprint', help='The certificate thumbprint.')
        c.argument(
            'password',
            help='The password to access the certificate\'s private key.')
        c.argument('certificate_file',
                   type=file_type,
                   help='The certificate file: cer file or pfx file.',
                   validator=validate_cert_file,
                   completer=FilesCompleter())
        c.argument('abort',
                   action='store_true',
                   help='Cancel the failed certificate deletion operation.')

    with self.argument_context('batch certificate show') as c:
        c.argument('thumbprint',
                   help='The certificate thumbprint.',
                   validator=validate_cert_settings)

    with self.argument_context('batch task create') as c:
        c.argument(
            'json_file',
            type=file_type,
            help=
            'The file containing the task(s) to create in JSON(formatted to match REST API request body). When submitting multiple tasks, accepts either an array of tasks or a TaskAddCollectionParamater. If this parameter is specified, all other parameters are ignored.',
            validator=validate_json_file,
            completer=FilesCompleter())
        c.argument(
            'application_package_references',
            nargs='+',
            help=
            'The space-separated list of IDs specifying the application packages to be installed. Space-separated application IDs with optional version in \'id[#version]\' format.',
            type=application_package_reference_format)
        c.argument('job_id', help='The ID of the job containing the task.')
        c.argument('task_id', help='The ID of the task.')
        c.argument(
            'command_line',
            help=
            'The command line of the task. The command line does not run under a shell, and therefore cannot take advantage of shell features such as environment variable expansion. If you want to take advantage of such features, you should invoke the shell in the command line, for example using "cmd /c MyCommand" in Windows or "/bin/sh -c MyCommand" in Linux.'
        )
        c.argument(
            'environment_settings',
            nargs='+',
            help=
            'A list of environment variable settings for the task. Space-separated values in \'key=value\' format.',
            type=environment_setting_format)
        c.argument(
            'resource_files',
            nargs='+',
            help=
            'A list of files that the Batch service will download to the compute node before running the command line. Space-separated resource references in filename=httpurl format, with httpurl being any HTTP url with public access or a SAS url with read access.',
            type=resource_file_format)

    for item in [
            'batch certificate delete', 'batch certificate create',
            'batch pool resize', 'batch pool reset', 'batch job list',
            'batch task create'
    ]:
        with self.argument_context(item) as c:
            c.extra(
                'account_name',
                arg_group='Batch Account',
                validator=validate_client_parameters,
                help=
                'The Batch account name. Alternatively, set by environment variable: AZURE_BATCH_ACCOUNT'
            )
            c.extra(
                'account_key',
                arg_group='Batch Account',
                help=
                'The Batch account key. Alternatively, set by environment variable: AZURE_BATCH_ACCESS_KEY'
            )
            c.extra(
                'account_endpoint',
                arg_group='Batch Account',
                help=
                'Batch service endpoint. Alternatively, set by environment variable: AZURE_BATCH_ENDPOINT'
            )
Пример #13
0
def load_arguments(self, _):

    # pylint: disable=line-too-long
    # PARAMETER REGISTRATION
    name_arg_type = CLIArgumentType(options_list=['--name', '-n'], metavar='NAME')
    sku_arg_type = CLIArgumentType(help='The pricing tiers, e.g., F1(Free), D1(Shared), B1(Basic Small), B2(Basic Medium), B3(Basic Large), S1(Standard Small), P1V2(Premium V2 Small), PC2 (Premium Container Small), PC3 (Premium Container Medium), PC4 (Premium Container Large)',
                                   arg_type=get_enum_type(['F1', 'FREE', 'D1', 'SHARED', 'B1', 'B2', 'B3', 'S1', 'S2', 'S3', 'P1V2', 'P2V2', 'P3V2', 'PC2', 'PC3', 'PC4']))
    webapp_name_arg_type = CLIArgumentType(configured_default='web', options_list=['--name', '-n'], metavar='NAME',
                                           completer=get_resource_name_completion_list('Microsoft.Web/sites'), id_part='name',
                                           help="name of the web app. You can configure the default using 'az configure --defaults web=<name>'")

    # use this hidden arg to give a command the right instance, that functionapp commands
    # work on function app and webapp ones work on web app
    with self.argument_context('webapp') as c:
        c.ignore('app_instance')
        c.argument('resource_group_name', arg_type=resource_group_name_type)
        c.argument('location', arg_type=get_location_type(self.cli_ctx))
        c.argument('slot', options_list=['--slot', '-s'], help="the name of the slot. Default to the productions slot if not specified")
        c.argument('name', configured_default='web', arg_type=name_arg_type,
                   completer=get_resource_name_completion_list('Microsoft.Web/sites'), id_part='name',
                   help="name of the web app. You can configure the default using 'az configure --defaults web=<name>'")

    with self.argument_context('appservice') as c:
        c.argument('resource_group_name', arg_type=resource_group_name_type)
        c.argument('location', arg_type=get_location_type(self.cli_ctx))

    with self.argument_context('appservice list-locations') as c:
        c.argument('linux_workers_enabled', action='store_true', help='get regions which support hosting web apps on Linux workers')
        c.argument('sku', arg_type=sku_arg_type)

    with self.argument_context('appservice plan') as c:
        c.argument('name', arg_type=name_arg_type, help='The name of the app service plan',
                   completer=get_resource_name_completion_list('Microsoft.Web/serverFarms'),
                   configured_default='appserviceplan', id_part='name')
        c.argument('number_of_workers', help='Number of workers to be allocated.', type=int, default=1)
        c.argument('admin_site_name', help='The name of the admin web app.', deprecate_info=c.deprecate(expiration='0.2.17'))
        c.ignore('max_burst')

    with self.argument_context('appservice plan create') as c:
        c.argument('name', options_list=['--name', '-n'], help="Name of the new app service plan", completer=None,
                   validator=validate_asp_create)
        c.argument('sku', arg_type=sku_arg_type)
        c.argument('is_linux', action='store_true', required=False, help='host web app on Linux worker')
        c.argument('hyper_v', action='store_true', required=False, help='Host web app on Windows container', is_preview=True)
        c.argument('tags', arg_type=tags_type)

    with self.argument_context('appservice plan update') as c:
        c.argument('sku', arg_type=sku_arg_type)
        c.ignore('allow_pending_state')

    with self.argument_context('webapp create') as c:
        c.argument('name', options_list=['--name', '-n'], help='name of the new web app', validator=validate_site_create)
        c.argument('startup_file', help="Linux only. The web's startup file")
        c.argument('multicontainer_config_type', options_list=['--multicontainer-config-type'], help="Linux only.", arg_type=get_enum_type(MULTI_CONTAINER_TYPES))
        c.argument('multicontainer_config_file', options_list=['--multicontainer-config-file'], help="Linux only. Config file for multicontainer apps. (local or remote)")
        c.argument('runtime', options_list=['--runtime', '-r'], help="canonicalized web runtime in the format of Framework|Version, e.g. \"PHP|5.6\". Use 'az webapp list-runtimes' for available list")  # TODO ADD completer
        c.argument('plan', options_list=['--plan', '-p'], configured_default='appserviceplan',
                   completer=get_resource_name_completion_list('Microsoft.Web/serverFarms'),
                   help="name or resource id of the app service plan. Use 'appservice plan create' to get one")

    with self.argument_context('webapp show') as c:
        c.argument('name', arg_type=webapp_name_arg_type)

    with self.argument_context('webapp list-runtimes') as c:
        c.argument('linux', action='store_true', help='list runtime stacks for linux based web apps')

    with self.argument_context('webapp deleted list') as c:
        c.argument('name', arg_type=webapp_name_arg_type, id_part=None)
        c.argument('slot', options_list=['--slot', '-s'], help='Name of the deleted web app slot.')

    with self.argument_context('webapp deleted restore') as c:
        c.argument('deleted_id', options_list=['--deleted-id'], help='Resource ID of the deleted web app')
        c.argument('name', options_list=['--name', '-n'], help='name of the web app to restore the deleted content to')
        c.argument('slot', options_list=['--slot', '-s'], help='slot to restore the deleted content to')
        c.argument('restore_content_only', action='store_true', help='restore only deleted files without web app settings')

    with self.argument_context('webapp traffic-routing') as c:
        c.argument('distribution', options_list=['--distribution', '-d'], nargs='+', help='space-separated slot routings in a format of <slot-name>=<percentage> e.g. staging=50. Unused traffic percentage will go to the Production slot')

    with self.argument_context('webapp update') as c:
        c.argument('client_affinity_enabled', help="Enables sending session affinity cookies.", arg_type=get_three_state_flag(return_label=True))
        c.argument('https_only', help="Redirect all traffic made to an app using HTTP to HTTPS.", arg_type=get_three_state_flag(return_label=True))
        c.argument('force_dns_registration', help="If true, web app hostname is force registered with DNS", arg_type=get_three_state_flag(return_label=True))
        c.argument('skip_custom_domain_verification', help="If true, custom (non *.azurewebsites.net) domains associated with web app are not verified", arg_type=get_three_state_flag(return_label=True))
        c.argument('ttl_in_seconds', help="Time to live in seconds for web app's default domain name", arg_type=get_three_state_flag(return_label=True))
        c.argument('skip_dns_registration', help="If true web app hostname is not registered with DNS on creation", arg_type=get_three_state_flag(return_label=True))

    with self.argument_context('webapp browse') as c:
        c.argument('logs', options_list=['--logs', '-l'], action='store_true', help='Enable viewing the log stream immediately after launching the web app')
    with self.argument_context('webapp delete') as c:
        c.argument('keep_empty_plan', action='store_true', help='keep empty app service plan')
        c.argument('keep_metrics', action='store_true', help='keep app metrics')
        c.argument('keep_dns_registration', action='store_true', help='keep DNS registration')

    with self.argument_context('webapp webjob') as c:
        c.argument('webjob_name', help='The name of the webjob', options_list=['--webjob-name', '-w'])
    with self.argument_context('webapp webjob continuous list') as c:
        c.argument('name', arg_type=webapp_name_arg_type, id_part=None)
    with self.argument_context('webapp webjob triggered list') as c:
        c.argument('name', arg_type=webapp_name_arg_type, id_part=None)

    for scope in ['webapp', 'functionapp']:
        with self.argument_context(scope + ' create') as c:
            c.argument('deployment_container_image_name', options_list=['--deployment-container-image-name', '-i'], help='Linux only. Container image name from Docker Hub, e.g. publisher/image-name:tag')
            c.argument('deployment_local_git', action='store_true', options_list=['--deployment-local-git', '-l'], help='enable local git')
            c.argument('deployment_zip', options_list=['--deployment-zip', '-z'], help='perform deployment using zip file')
            c.argument('deployment_source_url', options_list=['--deployment-source-url', '-u'], help='Git repository URL to link with manual integration')
            c.argument('deployment_source_branch', options_list=['--deployment-source-branch', '-b'], help='the branch to deploy')
            c.argument('tags', arg_type=tags_type)

        with self.argument_context(scope + ' config ssl bind') as c:
            c.argument('ssl_type', help='The ssl cert type', arg_type=get_enum_type(['SNI', 'IP']))
        with self.argument_context(scope + ' config ssl upload') as c:
            c.argument('certificate_password', help='The ssl cert password')
            c.argument('certificate_file', type=file_type, help='The filepath for the .pfx file')
        with self.argument_context(scope + ' config ssl') as c:
            c.argument('certificate_thumbprint', help='The ssl cert thumbprint')
        with self.argument_context(scope + ' config appsettings') as c:
            c.argument('settings', nargs='+', help="space-separated app settings in a format of <name>=<value>")
            c.argument('setting_names', nargs='+', help="space-separated app setting names")

        with self.argument_context(scope + ' config hostname') as c:
            c.argument('hostname', completer=get_hostname_completion_list, help="hostname assigned to the site, such as custom domains", id_part='child_name_1')
        with self.argument_context(scope + ' deployment user') as c:
            c.argument('user_name', help='user name')
            c.argument('password', help='password, will prompt if not specified')
        with self.argument_context(scope + ' deployment source') as c:
            c.argument('manual_integration', action='store_true', help='disable automatic sync between source control and web')
            c.argument('repo_url', options_list=['--repo-url', '-u'], help='repository url to pull the latest source from, e.g. https://github.com/foo/foo-web')
            c.argument('branch', help='the branch name of the repository')
            c.argument('private_repo_username', arg_group='VSTS CD Provider', help='Username for the private repository')
            c.argument('private_repo_password', arg_group='VSTS CD Provider', help='Password for the private repository')
            c.argument('cd_app_type', arg_group='VSTS CD Provider', help='Web application framework you used to develop your app. Default is AspNet.', arg_type=get_enum_type(['AspNet', 'AspNetCore', 'NodeJS', 'PHP', 'Python']))
            c.argument('app_working_dir', arg_group='VSTS CD Provider', help='Working directory of the application. Default will be root of the repo')
            c.argument('nodejs_task_runner', arg_group='VSTS CD Provider', help='Task runner for nodejs. Default is None', arg_type=get_enum_type(['None', 'Gulp', 'Grunt']))
            c.argument('python_framework', arg_group='VSTS CD Provider', help='Framework used for Python application. Default is Django', arg_type=get_enum_type(['Bottle', 'Django', 'Flask']))
            c.argument('python_version', arg_group='VSTS CD Provider', help='Python version used for application. Default is Python 3.5.3 x86', arg_type=get_enum_type(['Python 2.7.12 x64', 'Python 2.7.12 x86', 'Python 2.7.13 x64', 'Python 2.7.13 x86', 'Python 3.5.3 x64', 'Python 3.5.3 x86', 'Python 3.6.0 x64', 'Python 3.6.0 x86', 'Python 3.6.2 x64', 'Python 3.6.1 x86']))
            c.argument('cd_project_url', arg_group='VSTS CD Provider', help='URL of the Visual Studio Team Services (VSTS) project to use for continuous delivery. URL should be in format https://<accountname>.visualstudio.com/<projectname>')
            c.argument('cd_account_create', arg_group='VSTS CD Provider', help="To create a new Visual Studio Team Services (VSTS) account if it doesn't exist already", action='store_true')
            c.argument('test', arg_group='VSTS CD Provider', help='Name of the web app to be used for load testing. If web app is not available, it will be created. Default: Disable')
            c.argument('slot_swap', arg_group='VSTS CD Provider', help='Name of the slot to be used for deployment and later promote to production. If slot is not available, it will be created. Default: Not configured')
            c.argument('repository_type', help='repository type', arg_type=get_enum_type(['git', 'mercurial', 'vsts', 'github', 'externalgit', 'localgit']))
            c.argument('git_token', help='Git access token required for auto sync')
        with self.argument_context(scope + ' identity') as c:
            c.argument('scope', help="The scope the managed identity has access to")
            c.argument('role', help="Role name or id the managed identity will be assigned")

        with self.argument_context(scope + ' deployment source config-zip') as c:
            c.argument('src', help='a zip file path for deployment')
            c.argument('timeout', type=int, options_list=['--timeout', '-t'], help='Configurable timeout in seconds for checking the status of deployment', validator=validate_timeout_value)

        with self.argument_context(scope + ' config appsettings list') as c:
            c.argument('name', arg_type=webapp_name_arg_type, id_part=None)

        with self.argument_context(scope + ' config hostname list') as c:
            c.argument('webapp_name', arg_type=webapp_name_arg_type, id_part=None, options_list='--webapp-name')

        with self.argument_context(scope + ' cors') as c:
            c.argument('allowed_origins', options_list=['--allowed-origins', '-a'], nargs='*', help='space separated origins that should be allowed to make cross-origin calls (for example: http://example.com:12345). To allow all, use "*" and remove all other origins from the list')

        with self.argument_context(scope + ' config set') as c:
            c.argument('remote_debugging_enabled', help='enable or disable remote debugging', arg_type=get_three_state_flag(return_label=True))
            c.argument('web_sockets_enabled', help='enable or disable web sockets', arg_type=get_three_state_flag(return_label=True))
            c.argument('always_on', help='ensure web app gets loaded all the time, rather unloaded after been idle. Recommended when you have continuous web jobs running', arg_type=get_three_state_flag(return_label=True))
            c.argument('auto_heal_enabled', help='enable or disable auto heal', arg_type=get_three_state_flag(return_label=True))
            c.argument('use32_bit_worker_process', options_list=['--use-32bit-worker-process'], help='use 32 bits worker process or not', arg_type=get_three_state_flag(return_label=True))
            c.argument('php_version', help='The version used to run your web app if using PHP, e.g., 5.5, 5.6, 7.0')
            c.argument('python_version', help='The version used to run your web app if using Python, e.g., 2.7, 3.4')
            c.argument('net_framework_version', help="The version used to run your web app if using .NET Framework, e.g., 'v4.0' for .NET 4.6 and 'v3.0' for .NET 3.5")
            c.argument('linux_fx_version', help="The runtime stack used for your linux-based webapp, e.g., \"RUBY|2.3\", \"NODE|6.6\", \"PHP|5.6\", \"DOTNETCORE|1.1.0\". See https://aka.ms/linux-stacks for more info.")
            c.argument('windows_fx_version', help="A docker image name used for your windows container web app, e.g., microsoft/nanoserver:ltsc2016", is_preview=True)
            if scope == 'functionapp':
                c.ignore('windows_fx_version')
            c.argument('reserved_instance_count', options_list=['--prewarmed-instance-count'], help="Number of pre-warmed instances a function app has")
            if scope == 'webapp':
                c.ignore('reserved_instance_count')
            c.argument('java_version', help="The version used to run your web app if using Java, e.g., '1.7' for Java 7, '1.8' for Java 8")
            c.argument('java_container', help="The java container, e.g., Tomcat, Jetty")
            c.argument('java_container_version', help="The version of the java container, e.g., '8.0.23' for Tomcat")
            c.argument('min_tls_version', help="The minimum version of TLS required for SSL requests, e.g., '1.0', '1.1', '1.2'")
            c.argument('http20_enabled', help="configures a web site to allow clients to connect over http2.0.", arg_type=get_three_state_flag(return_label=True))
            c.argument('app_command_line', options_list=['--startup-file'], help="The startup file for linux hosted web apps, e.g. 'process.json' for Node.js web")
            c.argument('ftps_state', help="Set the Ftps state value for an app. Default value is 'AllAllowed'.", arg_type=get_enum_type(FTPS_STATE_TYPES))
            c.argument('generic_configurations', nargs='+',
                       help='provide site configuration list in a format of either "key=value" pair or "@<json_file>"')

        with self.argument_context(scope + ' config container') as c:
            c.argument('docker_registry_server_url', options_list=['--docker-registry-server-url', '-r'],
                       help='the container registry server url')
            c.argument('docker_custom_image_name', options_list=['--docker-custom-image-name', '-c', '-i'],
                       help='the container custom image name and optionally the tag name')
            c.argument('docker_registry_server_user', options_list=['--docker-registry-server-user', '-u'],
                       help='the container registry server username')
            c.argument('docker_registry_server_password', options_list=['--docker-registry-server-password', '-p'],
                       help='the container registry server password')
            c.argument('websites_enable_app_service_storage', options_list=['--enable-app-service-storage', '-t'],
                       help='enables platform storage (custom container only)',
                       arg_type=get_three_state_flag(return_label=True))
            c.argument('multicontainer_config_type', options_list=['--multicontainer-config-type'], help='config type',
                       arg_type=get_enum_type(MULTI_CONTAINER_TYPES))
            c.argument('multicontainer_config_file', options_list=['--multicontainer-config-file'],
                       help="config file for multicontainer apps")
            c.argument('show_multicontainer_config', action='store_true',
                       help='shows decoded config if a multicontainer config is set')

        with self.argument_context(scope + ' deployment container config') as c:
            c.argument('enable', options_list=['--enable-cd', '-e'], help='enable/disable continuous deployment',
                       arg_type=get_three_state_flag(return_label=True))

    with self.argument_context('webapp config connection-string list') as c:
        c.argument('name', arg_type=webapp_name_arg_type, id_part=None)

    with self.argument_context('webapp config storage-account list') as c:
        c.argument('name', arg_type=webapp_name_arg_type, id_part=None)

    with self.argument_context('webapp config hostname') as c:
        c.argument('webapp_name', help="webapp name. You can configure the default using 'az configure --defaults web=<name>'", configured_default='web',
                   completer=get_resource_name_completion_list('Microsoft.Web/sites'), id_part='name')
    with self.argument_context('webapp deployment slot') as c:
        c.argument('slot', help='the name of the slot')
        c.argument('webapp', arg_type=name_arg_type, completer=get_resource_name_completion_list('Microsoft.Web/sites'),
                   help='Name of the webapp', id_part='name')
        c.argument('auto_swap_slot', help='target slot to auto swap', default='production')
        c.argument('disable', help='disable auto swap', action='store_true')
        c.argument('target_slot', help="target slot to swap, default to 'production'")
    with self.argument_context('webapp deployment slot create') as c:
        c.argument('configuration_source', help="source slot to clone configurations from. Use web app's name to refer to the production slot")
    with self.argument_context('webapp deployment slot swap') as c:
        c.argument('action', help="swap types. use 'preview' to apply target slot's settings on the source slot first; use 'swap' to complete it; use 'reset' to reset the swap",
                   arg_type=get_enum_type(['swap', 'preview', 'reset']))
    with self.argument_context('webapp log config') as c:
        c.argument('application_logging', help='configure application logging to file system', arg_type=get_three_state_flag(return_label=True))
        c.argument('detailed_error_messages', help='configure detailed error messages', arg_type=get_three_state_flag(return_label=True))
        c.argument('failed_request_tracing', help='configure failed request tracing', arg_type=get_three_state_flag(return_label=True))
        c.argument('level', help='logging level', arg_type=get_enum_type(['error', 'warning', 'information', 'verbose']))
        c.argument('web_server_logging', help='configure Web server logging', arg_type=get_enum_type(['off', 'filesystem']))
        c.argument('docker_container_logging', help='configure gathering STDOUT and STDERR output from container', arg_type=get_enum_type(['off', 'filesystem']))

    with self.argument_context('webapp log tail') as c:
        c.argument('provider', help="By default all live traces configured by 'az webapp log config' will be shown, but you can scope to certain providers/folders, e.g. 'application', 'http', etc. For details, check out https://github.com/projectkudu/kudu/wiki/Diagnostic-Log-Stream")

    with self.argument_context('webapp log download') as c:
        c.argument('log_file', default='webapp_logs.zip', type=file_type, completer=FilesCompleter(), help='the downloaded zipped log file path')

    for scope in ['appsettings', 'connection-string']:
        with self.argument_context('webapp config ' + scope) as c:
            c.argument('settings', nargs='+', help="space-separated {} in a format of <name>=<value>".format(scope))
            c.argument('slot_settings', nargs='+', help="space-separated slot {} in a format of either <name>=<value> or @<json_file>".format(scope))
            c.argument('setting_names', nargs='+', help="space-separated {} names".format(scope))

    with self.argument_context('webapp config connection-string') as c:
        c.argument('connection_string_type', options_list=['--connection-string-type', '-t'], help='connection string type', arg_type=get_enum_type(ConnectionStringType))

    with self.argument_context('webapp config storage-account') as c:
        c.argument('custom_id', options_list=['--custom-id', '-i'], help='custom identifier')
        c.argument('storage_type', options_list=['--storage-type', '-t'], help='storage type', arg_type=get_enum_type(AzureStorageType))
        c.argument('account_name', options_list=['--account-name', '-a'], help='storage account name')
        c.argument('share_name', options_list=['--share-name', '--sn'], help='share name (Azure Files) or container name (Azure Blob Storage)')
        c.argument('access_key', options_list=['--access-key', '-k'], help='storage account access key')
        c.argument('mount_path', options_list=['--mount-path', '-m'], help='path to mount storage volume within web app')
        c.argument('slot', options_list=['--slot', '-s'], help="the name of the slot. Default to the productions slot if not specified")
    with self.argument_context('webapp config storage-account add') as c:
        c.argument('slot_setting', options_list=['--slot-setting'], help="slot setting")
    with self.argument_context('webapp config storage-account update') as c:
        c.argument('slot_setting', options_list=['--slot-setting'], help="slot setting")

    with self.argument_context('webapp config backup') as c:
        c.argument('storage_account_url', help='URL with SAS token to the blob storage container', options_list=['--container-url'])
        c.argument('webapp_name', help='The name of the web app')
        c.argument('db_name', help='Name of the database in the backup', arg_group='Database')
        c.argument('db_connection_string', help='Connection string for the database in the backup', arg_group='Database')
        c.argument('db_type', help='Type of database in the backup', arg_group='Database', arg_type=get_enum_type(DatabaseType))

    with self.argument_context('webapp config backup create') as c:
        c.argument('backup_name', help='Name of the backup. If unspecified, the backup will be named with the web app name and a timestamp')

    with self.argument_context('webapp config backup update') as c:
        c.argument('backup_name', help='Name of the backup. If unspecified, the backup will be named with the web app name and a timestamp')
        c.argument('frequency', help='How often to backup. Use a number followed by d or h, e.g. 5d = 5 days, 2h = 2 hours')
        c.argument('keep_at_least_one_backup', help='Always keep one backup, regardless of how old it is', options_list=['--retain-one'], arg_type=get_three_state_flag(return_label=True))
        c.argument('retention_period_in_days', help='How many days to keep a backup before automatically deleting it. Set to 0 for indefinite retention', options_list=['--retention'])

    with self.argument_context('webapp config backup restore') as c:
        c.argument('backup_name', help='Name of the backup to restore')
        c.argument('target_name', help='The name to use for the restored web app. If unspecified, will default to the name that was used when the backup was created')
        c.argument('overwrite', help='Overwrite the source web app, if --target-name is not specified', action='store_true')
        c.argument('ignore_hostname_conflict', help='Ignores custom hostnames stored in the backup', action='store_true')

    with self.argument_context('webapp config snapshot') as c:
        c.argument('name', arg_type=webapp_name_arg_type)
        c.argument('slot', options_list=['--slot', '-s'], help='The name of the slot.')

    with self.argument_context('webapp config snapshot list') as c:
        c.argument('name', arg_type=webapp_name_arg_type, id_part=None)

    with self.argument_context('webapp config snapshot restore') as c:
        c.argument('time', help='Timestamp of the snapshot to restore.')
        c.argument('restore_content_only', help='Restore the web app files without restoring the settings.')
        c.argument('source_resource_group', help='Name of the resource group to retrieve snapshot from.')
        c.argument('source_name', help='Name of the web app to retrieve snapshot from.')
        c.argument('source_slot', help='Name of the web app slot to retrieve snapshot from.')

    with self.argument_context('webapp auth update') as c:
        c.argument('enabled', arg_type=get_three_state_flag(return_label=True))
        c.argument('token_store_enabled', options_list=['--token-store'], arg_type=get_three_state_flag(return_label=True), help='use App Service Token Store')
        c.argument('action', arg_type=get_enum_type(AUTH_TYPES))
        c.argument('runtime_version', help='Runtime version of the Authentication/Authorization feature in use for the current app')
        c.argument('token_refresh_extension_hours', type=float, help="Hours, must be formattable into a float")
        c.argument('allowed_external_redirect_urls', nargs='+', help="One or more urls (space-delimited).")
        c.argument('client_id', options_list=['--aad-client-id'], arg_group='Azure Active Directory', help='Application ID to integrate AAD organization account Sign-in into your web app')
        c.argument('client_secret', options_list=['--aad-client-secret'], arg_group='Azure Active Directory', help='AAD application secret')
        c.argument('allowed_audiences', nargs='+', options_list=['--aad-allowed-token-audiences'], arg_group='Azure Active Directory', help="One or more token audiences (space-delimited).")
        c.argument('issuer', options_list=['--aad-token-issuer-url'],
                   help='This url can be found in the JSON output returned from your active directory endpoint using your tenantID. The endpoint can be queried from \'az cloud show\' at \"endpoints.activeDirectory\". '
                        'The tenantID can be found using \'az account show\'. Get the \"issuer\" from the JSON at <active directory endpoint>/<tenantId>/.well-known/openid-configuration.', arg_group='Azure Active Directory')
        c.argument('facebook_app_id', arg_group='Facebook', help="Application ID to integrate Facebook Sign-in into your web app")
        c.argument('facebook_app_secret', arg_group='Facebook', help='Facebook Application client secret')
        c.argument('facebook_oauth_scopes', nargs='+', help="One or more facebook authentication scopes (space-delimited).", arg_group='Facebook')
        c.argument('twitter_consumer_key', arg_group='Twitter', help='Application ID to integrate Twitter Sign-in into your web app')
        c.argument('twitter_consumer_secret', arg_group='Twitter', help='Twitter Application client secret')
        c.argument('google_client_id', arg_group='Google', help='Application ID to integrate Google Sign-in into your web app')
        c.argument('google_client_secret', arg_group='Google', help='Google Application client secret')
        c.argument('google_oauth_scopes', nargs='+', help="One or more Google authentication scopes (space-delimited).", arg_group='Google')
        c.argument('microsoft_account_client_id', arg_group='Microsoft', help="AAD V2 Application ID to integrate Microsoft account Sign-in into your web app")
        c.argument('microsoft_account_client_secret', arg_group='Microsoft', help='AAD V2 Application client secret')
        c.argument('microsoft_account_oauth_scopes', nargs='+', help="One or more Microsoft authentification scopes (space-delimited).", arg_group='Microsoft')

    with self.argument_context('webapp up') as c:
        c.argument('name', arg_type=webapp_name_arg_type)
        c.argument('resource_group_name', arg_type=resource_group_name_type)
        c.argument('plan', options_list=['--plan', '-p'], configured_default='appserviceplan',
                   completer=get_resource_name_completion_list('Microsoft.Web/serverFarms'),
                   help="name of the appserviceplan associated with the webapp")
        c.argument('sku', arg_type=sku_arg_type)
        c.argument('dryrun', help="show summary of the create and deploy operation instead of executing it", default=False, action='store_true')
        c.argument('location', arg_type=get_location_type(self.cli_ctx))
        c.argument('launch_browser', help="Launch the created app using the default browser", default=False, action='store_true', options_list=['--launch-browser', '-b'])
        c.argument('logs', help="Configure default logging required to enable viewing log stream immediately after launching the webapp", default=False, action='store_true')

    with self.argument_context('webapp ssh') as c:
        c.argument('port', options_list=['--port', '-p'],
                   help='Port for the remote connection. Default: Random available port', type=int)
        c.argument('timeout', options_list=['--timeout', '-t'], help='timeout in seconds. Defaults to none', type=int)

    with self.argument_context('webapp create-remote-connection') as c:
        c.argument('port', options_list=['--port', '-p'],
                   help='Port for the remote connection. Default: Random available port', type=int)
        c.argument('timeout', options_list=['--timeout', '-t'], help='timeout in seconds. Defaults to none', type=int)

    with self.argument_context('functionapp') as c:
        c.ignore('app_instance')
        c.argument('name', arg_type=name_arg_type, id_part='name', help='name of the function app')
        c.argument('slot', options_list=['--slot', '-s'],
                   help="the name of the slot. Default to the productions slot if not specified")
    with self.argument_context('functionapp config hostname') as c:
        c.argument('webapp_name', arg_type=name_arg_type, id_part='name', help='name of the function app')
    with self.argument_context('functionapp create') as c:
        c.argument('plan', options_list=['--plan', '-p'], configured_default='appserviceplan',
                   completer=get_resource_name_completion_list('Microsoft.Web/serverFarms'),
                   help="name or resource id of the function app service plan. Use 'appservice plan create' to get one")
        c.argument('new_app_name', options_list=['--name', '-n'], help='name of the new function app')
        c.argument('storage_account', options_list=['--storage-account', '-s'],
                   help='Provide a string value of a Storage Account in the provided Resource Group. Or Resource ID of a Storage Account in a different Resource Group')
        c.argument('consumption_plan_location', options_list=['--consumption-plan-location', '-c'],
                   help="Geographic location where Function App will be hosted. Use 'functionapp list-consumption-locations' to view available locations.")
        c.argument('runtime', help='The functions runtime stack.', arg_type=get_enum_type(set(LINUX_RUNTIMES).union(set(WINDOWS_RUNTIMES))))
        c.argument('os_type', arg_type=get_enum_type(OS_TYPES), help="Set the OS type for the app to be created.")
        c.argument('app_insights_key', help="Instrumentation key of App Insights to be added.")
        c.argument('app_insights', help="Name of the existing App Insights project to be added to the Function app. Must be in the same resource group.")

    # For commands with shared impl between web app and function app and has output, we apply type validation to avoid confusions
    with self.argument_context('functionapp show') as c:
        c.argument('name', arg_type=name_arg_type)
    with self.argument_context('functionapp config appsettings') as c:
        c.argument('slot_settings', nargs='+', help="space-separated slot app settings in a format of <name>=<value>")

    with self.argument_context('functionapp plan') as c:
        c.argument('name', arg_type=name_arg_type, help='The name of the app service plan',
                   completer=get_resource_name_completion_list('Microsoft.Web/serverFarms'),
                   configured_default='appserviceplan', id_part='name')
        c.argument('is_linux', arg_type=get_three_state_flag(return_label=True), required=False, help='host function app on Linux worker')
        c.argument('number_of_workers', options_list=['--number-of-workers', '--min-instances'],
                   help='The number of workers for the app service plan.')
        c.argument('max_burst',
                   help='The maximum number of elastic workers for the plan.')
        c.argument('tags', arg_type=tags_type)

    with self.argument_context('functionapp update') as c:
        c.argument('plan', required=False, help='The name or resource id of the plan to update the functionapp with.')

    with self.argument_context('functionapp plan create') as c:
        c.argument('sku', required=True, help='The SKU of the app service plan.')

    with self.argument_context('functionapp plan update') as c:
        c.argument('sku', required=False, help='The SKU of the app service plan.')

    with self.argument_context('functionapp devops-build create') as c:
        c.argument('functionapp_name', help="Name of the Azure function app that you want to use", required=False)
        c.argument('organization_name', help="Name of the Azure DevOps organization that you want to use", required=False)
        c.argument('project_name', help="Name of the Azure DevOps project that you want to use", required=False)
        c.argument('repository_name', help="Name of the Azure DevOps repository that you want to use", required=False)
        c.argument('overwrite_yaml', help="If you have an existing yaml, should it be overwritten?", arg_type=get_three_state_flag(return_label=True), required=False)
        c.argument('allow_force_push', help="If Azure DevOps repository is not clean, should it overwrite remote content?", arg_type=get_three_state_flag(return_label=True), required=False)
        c.argument('github_pat', help="Github personal access token for creating pipeline from Github repository", required=False)
        c.argument('github_repository', help="Fullname of your Github repository (e.g. Azure/azure-cli)", required=False)

    with self.argument_context('functionapp devops-pipeline create') as c:
        c.argument('functionapp_name', help="Name of the Azure function app that you want to use", required=False)
        c.argument('organization_name', help="Name of the Azure DevOps organization that you want to use", required=False)
        c.argument('project_name', help="Name of the Azure DevOps project that you want to use", required=False)
        c.argument('repository_name', help="Name of the Azure DevOps repository that you want to use", required=False)
        c.argument('overwrite_yaml', help="If you have an existing yaml, should it be overwritten?", arg_type=get_three_state_flag(return_label=True), required=False)
        c.argument('allow_force_push', help="If Azure DevOps repository is not clean, should it overwrite remote content?", arg_type=get_three_state_flag(return_label=True), required=False)
        c.argument('github_pat', help="Github personal access token for creating pipeline from Github repository", required=False)
        c.argument('github_repository', help="Fullname of your Github repository (e.g. Azure/azure-cli)", required=False)

    with self.argument_context('functionapp deployment slot') as c:
        c.argument('slot', help='the name of the slot')
        # This is set to webapp to simply reuse webapp functions, without rewriting same functions for function apps.
        # The help will still show "-n or --name", so it should not be a problem to do it this way
        c.argument('webapp', arg_type=name_arg_type, completer=get_resource_name_completion_list('Microsoft.Web/sites'),
                   help='Name of the function app', id_part='name')
        c.argument('auto_swap_slot', help='target slot to auto swap', default='production')
        c.argument('disable', help='disable auto swap', action='store_true')
        c.argument('target_slot', help="target slot to swap, default to 'production'")
    with self.argument_context('functionapp deployment slot create') as c:
        c.argument('configuration_source', help="source slot to clone configurations from. Use function app's name to refer to the production slot")
    with self.argument_context('functionapp deployment slot swap') as c:
        c.argument('action', help="swap types. use 'preview' to apply target slot's settings on the source slot first; use 'swap' to complete it; use 'reset' to reset the swap",
                   arg_type=get_enum_type(['swap', 'preview', 'reset']))
Пример #14
0
def load_arguments(self, _):

    acr_arg_type = CLIArgumentType(metavar='ACR_NAME_OR_RESOURCE_ID')

    # AKS command argument configuration
    with self.argument_context('aks') as c:
        c.argument('resource_name',
                   name_type,
                   help='Name of the managed cluster.',
                   completer=get_resource_name_completion_list(
                       'Microsoft.ContainerService/ManagedClusters'))
        c.argument('name',
                   name_type,
                   help='Name of the managed cluster.',
                   completer=get_resource_name_completion_list(
                       'Microsoft.ContainerService/ManagedClusters'))
        c.argument('kubernetes_version',
                   options_list=['--kubernetes-version', '-k'],
                   validator=validate_k8s_version)
        c.argument('node_count', options_list=['--node-count', '-c'], type=int)
        c.argument('tags', tags_type)

    with self.argument_context('aks create') as c:
        # managed cluster paramerters
        c.argument('name', validator=validate_linux_host_name)
        c.argument('kubernetes_version',
                   completer=get_k8s_versions_completion_list)
        c.argument('dns_name_prefix', options_list=['--dns-name-prefix', '-p'])
        c.argument('node_osdisk_diskencryptionset_id',
                   options_list=['--node-osdisk-diskencryptionset-id', '-d'])
        c.argument('disable_local_accounts', action='store_true')
        c.argument('disable_rbac', action='store_true')
        c.argument('enable_rbac',
                   action='store_true',
                   options_list=['--enable-rbac', '-r'],
                   deprecate_info=c.deprecate(redirect="--disable-rbac",
                                              hide="2.0.45"))
        c.argument('edge_zone', edge_zone_type)
        c.argument('admin_username',
                   options_list=['--admin-username', '-u'],
                   default='azureuser')
        c.argument('generate_ssh_keys',
                   action='store_true',
                   validator=validate_create_parameters)
        c.argument('ssh_key_value',
                   required=False,
                   type=file_type,
                   default=os.path.join('~', '.ssh', 'id_rsa.pub'),
                   completer=FilesCompleter(),
                   validator=validate_ssh_key)
        c.argument('no_ssh_key', options_list=['--no-ssh-key', '-x'])
        c.argument('dns_service_ip')
        c.argument('docker_bridge_address')
        c.argument('pod_cidrs')
        c.argument('service_cidrs')
        c.argument('load_balancer_sku',
                   arg_type=get_enum_type(load_balancer_skus),
                   validator=validate_load_balancer_sku)
        c.argument('load_balancer_managed_outbound_ip_count', type=int)
        c.argument('load_balancer_managed_outbound_ipv6_count', type=int)
        c.argument('load_balancer_outbound_ips',
                   validator=validate_load_balancer_outbound_ips)
        c.argument('load_balancer_outbound_ip_prefixes',
                   validator=validate_load_balancer_outbound_ip_prefixes)
        c.argument('load_balancer_outbound_ports',
                   type=int,
                   validator=validate_load_balancer_outbound_ports)
        c.argument('load_balancer_idle_timeout',
                   type=int,
                   validator=validate_load_balancer_idle_timeout)
        c.argument('nat_gateway_managed_outbound_ip_count',
                   type=int,
                   validator=validate_nat_gateway_managed_outbound_ip_count)
        c.argument('nat_gateway_idle_timeout',
                   type=int,
                   validator=validate_nat_gateway_idle_timeout)
        c.argument('outbound_type', arg_type=get_enum_type(outbound_types))
        c.argument('network_plugin', arg_type=get_enum_type(network_plugins))
        c.argument('network_policy')
        c.argument('auto_upgrade_channel',
                   arg_type=get_enum_type(auto_upgrade_channels))
        c.argument('cluster_autoscaler_profile', nargs='+')
        c.argument('uptime_sla', action='store_true')
        c.argument('fqdn_subdomain')
        c.argument('api_server_authorized_ip_ranges',
                   validator=validate_ip_ranges)
        c.argument('enable_private_cluster', action='store_true')
        c.argument('private_dns_zone')
        c.argument('disable_public_fqdn', action='store_true')
        c.argument('service_principal')
        c.argument('client_secret')
        c.argument('enable_managed_identity', action='store_true')
        c.argument('assign_identity', validator=validate_assign_identity)
        c.argument('assign_kubelet_identity',
                   validator=validate_assign_kubelet_identity)
        c.argument('enable_aad', action='store_true')
        c.argument('enable_azure_rbac', action='store_true')
        c.argument('aad_client_app_id')
        c.argument('aad_server_app_id')
        c.argument('aad_server_app_secret')
        c.argument('aad_tenant_id')
        c.argument('aad_admin_group_object_ids')
        c.argument('windows_admin_username')
        c.argument('windows_admin_password')
        c.argument('enable_ahub')
        c.argument('disable_ahub')
        c.argument('gmsa_dns_server')
        c.argument('gmsa_root_domain_name')
        c.argument('attach_acr', acr_arg_type)
        c.argument('skip_subnet_role_assignment', action='store_true')
        # addons
        c.argument('enable_addons',
                   options_list=['--enable-addons', '-a'],
                   validator=validate_addons)
        c.argument('workspace_resource_id')
        c.argument('enable_msi_auth_for_monitoring',
                   arg_type=get_three_state_flag(),
                   is_preview=True)
        c.argument('aci_subnet_name')
        c.argument('appgw_name', arg_group='Application Gateway')
        c.argument('appgw_subnet_prefix',
                   arg_group='Application Gateway',
                   deprecate_info=c.deprecate(redirect='--appgw-subnet-cidr',
                                              hide=True))
        c.argument('appgw_subnet_cidr', arg_group='Application Gateway')
        c.argument('appgw_id', arg_group='Application Gateway')
        c.argument('appgw_subnet_id', arg_group='Application Gateway')
        c.argument('appgw_watch_namespace', arg_group='Application Gateway')
        c.argument('enable_secret_rotation', action='store_true')
        c.argument('rotation_poll_interval')
        c.argument('enable_sgxquotehelper', action='store_true')
        # nodepool paramerters
        c.argument('nodepool_name',
                   default='nodepool1',
                   help='Node pool name, upto 12 alphanumeric characters',
                   validator=validate_nodepool_name)
        c.argument('node_vm_size',
                   options_list=['--node-vm-size', '-s'],
                   completer=get_vm_size_completion_list)
        c.argument('os_sku', completer=get_ossku_completion_list)
        c.argument('vnet_subnet_id', validator=validate_vnet_subnet_id)
        c.argument('pod_subnet_id', validator=validate_pod_subnet_id)
        c.argument('enable_node_public_ip', action='store_true')
        c.argument('node_public_ip_prefix_id')
        c.argument('enable_cluster_autoscaler', action='store_true')
        c.argument('min_count', type=int, validator=validate_nodes_count)
        c.argument('max_count', type=int, validator=validate_nodes_count)
        c.argument(
            'nodepool_tags',
            nargs='*',
            validator=validate_nodepool_tags,
            help=
            'space-separated tags: key[=value] [key[=value] ...]. Use "" to clear existing tags.'
        )
        c.argument(
            'nodepool_labels',
            nargs='*',
            validator=validate_nodepool_labels,
            help=
            'space-separated labels: key[=value] [key[=value] ...]. See https://aka.ms/node-labels for syntax of labels.'
        )
        c.argument('node_osdisk_type',
                   arg_type=get_enum_type(node_os_disk_types))
        c.argument('node_osdisk_size', type=int)
        c.argument('max_pods', type=int, options_list=['--max-pods', '-m'])
        c.argument('vm_set_type', validator=validate_vm_set_type)
        c.argument('enable_vmss',
                   action='store_true',
                   help='To be deprecated. Use vm_set_type instead.',
                   deprecate_info=c.deprecate(redirect='--vm-set-type',
                                              hide=True))
        c.argument(
            'node_zones',
            zones_type,
            options_list=['--node-zones'],
            help=
            '(--node-zones will be deprecated) Space-separated list of availability zones where agent nodes will be placed.',
            deprecate_info=c.deprecate(redirect='--zones', hide='2.37.0'))
        c.argument(
            'zones',
            zones_type,
            options_list=['--zones', '-z'],
            help=
            'Space-separated list of availability zones where agent nodes will be placed.'
        )
        c.argument('ppg')
        c.argument('enable_encryption_at_host',
                   arg_type=get_three_state_flag(),
                   help='Enable EncryptionAtHost.')
        c.argument('enable_ultra_ssd', action='store_true')
        c.argument('enable_fips_image', action='store_true')
        c.argument('snapshot_id', validator=validate_snapshot_id)
        c.argument('kubelet_config')
        c.argument('linux_os_config')
        c.argument('disable_disk_driver', arg_type=get_three_state_flag())
        c.argument('disable_file_driver', arg_type=get_three_state_flag())
        c.argument('disable_snapshot_controller',
                   arg_type=get_three_state_flag())
        c.argument('yes',
                   options_list=['--yes', '-y'],
                   help='Do not prompt for confirmation.',
                   action='store_true')
        c.argument('aks_custom_headers')
        # extensions
        # managed cluster
        c.argument('node_resource_group')
        c.argument('ip_families')
        c.argument('http_proxy_config')
        c.argument('enable_pod_security_policy', action='store_true')
        c.argument('enable_pod_identity', action='store_true')
        c.argument('enable_workload_identity',
                   arg_type=get_three_state_flag(),
                   is_preview=True)
        c.argument('enable_oidc_issuer', action='store_true', is_preview=True)
        c.argument('enable_azure_keyvault_kms',
                   action='store_true',
                   is_preview=True)
        c.argument('azure_keyvault_kms_key_id',
                   validator=validate_azure_keyvault_kms_key_id,
                   is_preview=True)
        c.argument('cluster_snapshot_id',
                   validator=validate_cluster_snapshot_id,
                   is_preview=True)
        # nodepool
        c.argument('host_group_id',
                   validator=validate_host_group_id,
                   is_preview=True)
        c.argument('crg_id', validator=validate_crg_id, is_preview=True)
        # no validation for aks create because it already only supports Linux.
        c.argument('message_of_the_day')
        c.argument('gpu_instance_profile',
                   arg_type=get_enum_type(gpu_instance_profiles))
        c.argument('workload_runtime',
                   arg_type=get_enum_type(workload_runtimes),
                   default=CONST_WORKLOAD_RUNTIME_OCI_CONTAINER)

    with self.argument_context('aks update') as c:
        # managed cluster paramerters
        c.argument('disable_local_accounts', action='store_true')
        c.argument('enable_local_accounts', action='store_true')
        c.argument('load_balancer_managed_outbound_ip_count', type=int)
        c.argument('load_balancer_managed_outbound_ipv6_count', type=int)
        c.argument('load_balancer_outbound_ips',
                   validator=validate_load_balancer_outbound_ips)
        c.argument('load_balancer_outbound_ip_prefixes',
                   validator=validate_load_balancer_outbound_ip_prefixes)
        c.argument('load_balancer_outbound_ports',
                   type=int,
                   validator=validate_load_balancer_outbound_ports)
        c.argument('load_balancer_idle_timeout',
                   type=int,
                   validator=validate_load_balancer_idle_timeout)
        c.argument('nat_gateway_managed_outbound_ip_count',
                   type=int,
                   validator=validate_nat_gateway_managed_outbound_ip_count)
        c.argument('nat_gateway_idle_timeout',
                   type=int,
                   validator=validate_nat_gateway_idle_timeout)
        c.argument('auto_upgrade_channel',
                   arg_type=get_enum_type(auto_upgrade_channels))
        c.argument('cluster_autoscaler_profile', nargs='+')
        c.argument('uptime_sla', action='store_true')
        c.argument('no_uptime_sla', action='store_true')
        c.argument('api_server_authorized_ip_ranges',
                   validator=validate_ip_ranges)
        c.argument('enable_public_fqdn', action='store_true')
        c.argument('disable_public_fqdn', action='store_true')
        c.argument('enable_managed_identity', action='store_true')
        c.argument('assign_identity', validator=validate_assign_identity)
        c.argument('assign_kubelet_identity',
                   validator=validate_assign_kubelet_identity)
        c.argument('enable_aad', action='store_true')
        c.argument('enable_azure_rbac', action='store_true')
        c.argument('disable_azure_rbac', action='store_true')
        c.argument('aad_tenant_id')
        c.argument('aad_admin_group_object_ids')
        c.argument('windows_admin_password')
        c.argument('enable_ahub')
        c.argument('disable_ahub')
        c.argument('enable_windows_gmsa', action='store_true')
        c.argument('gmsa_dns_server')
        c.argument('gmsa_root_domain_name')
        c.argument('enable_disk_driver', arg_type=get_three_state_flag())
        c.argument('disable_disk_driver', arg_type=get_three_state_flag())
        c.argument('enable_file_driver', arg_type=get_three_state_flag())
        c.argument('disable_file_driver', arg_type=get_three_state_flag())
        c.argument('enable_snapshot_controller',
                   arg_type=get_three_state_flag())
        c.argument('disable_snapshot_controller',
                   arg_type=get_three_state_flag())
        c.argument('attach_acr', acr_arg_type, validator=validate_acr)
        c.argument('detach_acr', acr_arg_type, validator=validate_acr)
        # addons
        c.argument('enable_secret_rotation', action='store_true')
        c.argument('disable_secret_rotation', action='store_true')
        c.argument('rotation_poll_interval')
        # nodepool paramerters
        c.argument('enable_cluster_autoscaler',
                   options_list=["--enable-cluster-autoscaler", "-e"],
                   action='store_true')
        c.argument('disable_cluster_autoscaler',
                   options_list=["--disable-cluster-autoscaler", "-d"],
                   action='store_true')
        c.argument('update_cluster_autoscaler',
                   options_list=["--update-cluster-autoscaler", "-u"],
                   action='store_true')
        c.argument('min_count', type=int, validator=validate_nodes_count)
        c.argument('max_count', type=int, validator=validate_nodes_count)
        c.argument(
            'nodepool_labels',
            nargs='*',
            validator=validate_nodepool_labels,
            help=
            'space-separated labels: key[=value] [key[=value] ...]. See https://aka.ms/node-labels for syntax of labels.'
        )
        c.argument('yes',
                   options_list=['--yes', '-y'],
                   help='Do not prompt for confirmation.',
                   action='store_true')
        c.argument('aks_custom_headers')
        # extensions
        # managed cluster
        c.argument('http_proxy_config')
        c.argument('enable_pod_security_policy', action='store_true')
        c.argument('disable_pod_security_policy', action='store_true')
        c.argument('enable_pod_identity', action='store_true')
        c.argument('disable_pod_identity', action='store_true')
        c.argument('enable_workload_identity',
                   arg_type=get_three_state_flag(),
                   is_preview=True)
        c.argument('disable_workload_identity',
                   arg_type=get_three_state_flag(),
                   is_preview=True)
        c.argument('enable_oidc_issuer', action='store_true', is_preview=True)
        c.argument('enable_azure_keyvault_kms',
                   action='store_true',
                   is_preview=True)
        c.argument('azure_keyvault_kms_key_id',
                   validator=validate_azure_keyvault_kms_key_id,
                   is_preview=True)

    with self.argument_context('aks scale') as c:
        c.argument('nodepool_name',
                   help='Node pool name, upto 12 alphanumeric characters',
                   validator=validate_nodepool_name)

    with self.argument_context('aks upgrade') as c:
        c.argument('kubernetes_version',
                   completer=get_k8s_upgrades_completion_list)
        c.argument('yes',
                   options_list=['--yes', '-y'],
                   help='Do not prompt for confirmation.',
                   action='store_true')

    with self.argument_context('aks maintenanceconfiguration') as c:
        c.argument('cluster_name', help='The cluster name.')

    for scope in [
            'aks maintenanceconfiguration add',
            'aks maintenanceconfiguration update'
    ]:
        with self.argument_context(scope) as c:
            c.argument('config_name',
                       options_list=['--name', '-n'],
                       help='The config name.')
            c.argument('config_file',
                       options_list=['--config-file'],
                       help='The config json file.',
                       required=False)
            c.argument(
                'weekday',
                options_list=['--weekday'],
                help='weekday on which maintenance can happen. e.g. Monday',
                required=False)
            c.argument(
                'start_hour',
                type=int,
                options_list=['--start-hour'],
                help=
                'maintenance start hour of 1 hour window on the weekday. e.g. 1 means 1:00am - 2:00am',
                required=False)

    for scope in [
            'aks maintenanceconfiguration show',
            'aks maintenanceconfiguration delete'
    ]:
        with self.argument_context(scope) as c:
            c.argument('config_name',
                       options_list=['--name', '-n'],
                       help='The config name.')

    with self.argument_context('aks nodepool') as c:
        c.argument('cluster_name', help='The cluster name.')

    for scope in ['aks nodepool add']:
        with self.argument_context(scope) as c:
            c.argument('nodepool_name',
                       options_list=['--name', '-n'],
                       validator=validate_nodepool_name,
                       help='The node pool name.')
            c.argument('node_vm_size',
                       options_list=['--node-vm-size', '-s'],
                       completer=get_vm_size_completion_list)
            c.argument('os_type')
            c.argument('os_sku',
                       options_list=['--os-sku'],
                       completer=get_ossku_completion_list)
            c.argument('vnet_subnet_id', validator=validate_vnet_subnet_id)
            c.argument('pod_subnet_id', validator=validate_pod_subnet_id)
            c.argument('enable_node_public_ip', action='store_true')
            c.argument('node_public_ip_prefix_id')
            c.argument('enable_cluster_autoscaler',
                       options_list=["--enable-cluster-autoscaler", "-e"],
                       action='store_true')
            c.argument('min_count', type=int, validator=validate_nodes_count)
            c.argument('max_count', type=int, validator=validate_nodes_count)
            c.argument('priority',
                       arg_type=get_enum_type(node_priorities),
                       validator=validate_priority)
            c.argument('eviction_policy',
                       arg_type=get_enum_type(node_eviction_policies),
                       validator=validate_eviction_policy)
            c.argument('spot_max_price',
                       type=float,
                       validator=validate_spot_max_price)
            c.argument('labels', nargs='*', validator=validate_nodepool_labels)
            c.argument('tags', tags_type)
            c.argument('node_taints', validator=validate_taints)
            c.argument('node_osdisk_type',
                       arg_type=get_enum_type(node_os_disk_types))
            c.argument('node_osdisk_size', type=int)
            c.argument('mode', arg_type=get_enum_type(node_mode_types))
            c.argument('scale_down_mode',
                       arg_type=get_enum_type(scale_down_modes))
            c.argument('max_surge', validator=validate_max_surge)
            c.argument('max_pods', type=int, options_list=['--max-pods', '-m'])
            c.argument(
                'node_zones',
                zones_type,
                options_list=['--node-zones'],
                help=
                '(--node-zones will be deprecated) Space-separated list of availability zones where agent nodes will be placed.',
                deprecate_info=c.deprecate(redirect='--zones', hide='2.37.0'))
            c.argument(
                'zones',
                zones_type,
                options_list=['--zones', '-z'],
                help=
                'Space-separated list of availability zones where agent nodes will be placed.'
            )
            c.argument('ppg')
            c.argument('enable_encryption_at_host',
                       options_list=['--enable-encryption-at-host'],
                       action='store_true')
            c.argument('enable_ultra_ssd', action='store_true')
            c.argument('enable_fips_image', action='store_true')
            c.argument('snapshot_id', validator=validate_snapshot_id)
            c.argument('kubelet_config')
            c.argument('linux_os_config')
            c.argument('aks_custom_headers')
            # extensions
            c.argument('host_group_id',
                       validator=validate_host_group_id,
                       is_preview=True)
            c.argument('crg_id', validator=validate_crg_id, is_preview=True)
            c.argument('message_of_the_day',
                       validator=validate_message_of_the_day)
            c.argument('workload_runtime',
                       arg_type=get_enum_type(workload_runtimes),
                       default=CONST_WORKLOAD_RUNTIME_OCI_CONTAINER)
            c.argument('gpu_instance_profile',
                       arg_type=get_enum_type(gpu_instance_profiles))

    for scope in [
            'aks nodepool show', 'aks nodepool scale', 'aks nodepool upgrade',
            'aks nodepool update'
    ]:
        with self.argument_context(scope) as c:
            c.argument('nodepool_name',
                       options_list=['--name', '-n'],
                       validator=validate_nodepool_name,
                       help='The node pool name.')

    with self.argument_context('aks nodepool delete') as c:
        c.argument('nodepool_name',
                   options_list=['--name', '-n'],
                   validator=validate_nodepool_name,
                   help='The node pool name.')
        c.argument(
            'ignore_pod_disruption_budget',
            options_list=["--ignore-pod-disruption-budget", "-i"],
            action=get_three_state_flag(),
            is_preview=True,
            help=
            'delete an AKS nodepool by ignoring PodDisruptionBudget setting')

    with self.argument_context('aks nodepool upgrade') as c:
        c.argument('max_surge', validator=validate_max_surge)
        c.argument('aks_custom_headers')
        c.argument('snapshot_id', validator=validate_snapshot_id)

    with self.argument_context('aks nodepool update') as c:
        c.argument('enable_cluster_autoscaler',
                   options_list=["--enable-cluster-autoscaler", "-e"],
                   action='store_true')
        c.argument('disable_cluster_autoscaler',
                   options_list=["--disable-cluster-autoscaler", "-d"],
                   action='store_true')
        c.argument('update_cluster_autoscaler',
                   options_list=["--update-cluster-autoscaler", "-u"],
                   action='store_true')
        c.argument('min_count', type=int, validator=validate_nodes_count)
        c.argument('max_count', type=int, validator=validate_nodes_count)
        c.argument('labels', nargs='*', validator=validate_nodepool_labels)
        c.argument('tags', tags_type)
        c.argument('node_taints', validator=validate_taints)
        c.argument('mode', arg_type=get_enum_type(node_mode_types))
        c.argument('scale_down_mode', arg_type=get_enum_type(scale_down_modes))
        c.argument('max_surge', validator=validate_max_surge)

    with self.argument_context('aks addon show') as c:
        c.argument('addon',
                   options_list=['--addon', '-a'],
                   validator=validate_addon)

    with self.argument_context('aks addon enable') as c:
        c.argument('addon',
                   options_list=['--addon', '-a'],
                   validator=validate_addon)
        c.argument('subnet_name', options_list=['--subnet-name', '-s'])
        c.argument('enable_sgxquotehelper', action='store_true')
        c.argument('osm_mesh_name', options_list=['--osm-mesh-name'])
        c.argument('appgw_name',
                   options_list=['--appgw-name'],
                   arg_group='Application Gateway')
        c.argument('appgw_subnet_prefix',
                   options_list=['--appgw-subnet-prefix'],
                   arg_group='Application Gateway',
                   deprecate_info=c.deprecate(redirect='--appgw-subnet-cidr',
                                              hide=True))
        c.argument('appgw_subnet_cidr',
                   options_list=['--appgw-subnet-cidr'],
                   arg_group='Application Gateway')
        c.argument('appgw_id',
                   options_list=['--appgw-id'],
                   arg_group='Application Gateway')
        c.argument('appgw_subnet_id',
                   options_list=['--appgw-subnet-id'],
                   arg_group='Application Gateway')
        c.argument('appgw_watch_namespace',
                   options_list=['--appgw-watch-namespace'],
                   arg_group='Application Gateway')
        c.argument('enable_secret_rotation', action='store_true')
        c.argument('rotation_poll_interval')
        c.argument('workspace_resource_id')
        c.argument('enable_msi_auth_for_monitoring',
                   arg_type=get_three_state_flag(),
                   is_preview=True)

    with self.argument_context('aks addon disable') as c:
        c.argument('addon',
                   options_list=['--addon', '-a'],
                   validator=validate_addon)

    with self.argument_context('aks addon update') as c:
        c.argument('addon',
                   options_list=['--addon', '-a'],
                   validator=validate_addon)
        c.argument('subnet_name', options_list=['--subnet-name', '-s'])
        c.argument('enable_sgxquotehelper', action='store_true')
        c.argument('osm_mesh_name', options_list=['--osm-mesh-name'])
        c.argument('appgw_name',
                   options_list=['--appgw-name'],
                   arg_group='Application Gateway')
        c.argument('appgw_subnet_prefix',
                   options_list=['--appgw-subnet-prefix'],
                   arg_group='Application Gateway',
                   deprecate_info=c.deprecate(redirect='--appgw-subnet-cidr',
                                              hide=True))
        c.argument('appgw_subnet_cidr',
                   options_list=['--appgw-subnet-cidr'],
                   arg_group='Application Gateway')
        c.argument('appgw_id',
                   options_list=['--appgw-id'],
                   arg_group='Application Gateway')
        c.argument('appgw_subnet_id',
                   options_list=['--appgw-subnet-id'],
                   arg_group='Application Gateway')
        c.argument('appgw_watch_namespace',
                   options_list=['--appgw-watch-namespace'],
                   arg_group='Application Gateway')
        c.argument('enable_secret_rotation', action='store_true')
        c.argument('rotation_poll_interval')
        c.argument('workspace_resource_id')
        c.argument('enable_msi_auth_for_monitoring',
                   arg_type=get_three_state_flag(),
                   is_preview=True)

    with self.argument_context('aks disable-addons') as c:
        c.argument('addons',
                   options_list=['--addons', '-a'],
                   validator=validate_addons)

    with self.argument_context('aks enable-addons') as c:
        c.argument('addons',
                   options_list=['--addons', '-a'],
                   validator=validate_addons)
        c.argument('subnet_name', options_list=['--subnet-name', '-s'])
        c.argument('enable_sgxquotehelper', action='store_true')
        c.argument('osm_mesh_name', options_list=['--osm-mesh-name'])
        c.argument('appgw_name',
                   options_list=['--appgw-name'],
                   arg_group='Application Gateway')
        c.argument('appgw_subnet_prefix',
                   options_list=['--appgw-subnet-prefix'],
                   arg_group='Application Gateway',
                   deprecate_info=c.deprecate(redirect='--appgw-subnet-cidr',
                                              hide=True))
        c.argument('appgw_subnet_cidr',
                   options_list=['--appgw-subnet-cidr'],
                   arg_group='Application Gateway')
        c.argument('appgw_id',
                   options_list=['--appgw-id'],
                   arg_group='Application Gateway')
        c.argument('appgw_subnet_id',
                   options_list=['--appgw-subnet-id'],
                   arg_group='Application Gateway')
        c.argument('appgw_watch_namespace',
                   options_list=['--appgw-watch-namespace'],
                   arg_group='Application Gateway')
        c.argument('enable_secret_rotation', action='store_true')
        c.argument('rotation_poll_interval')
        c.argument('workspace_resource_id')
        c.argument('enable_msi_auth_for_monitoring',
                   arg_type=get_three_state_flag(),
                   is_preview=True)

    with self.argument_context('aks get-credentials') as c:
        c.argument('admin', options_list=['--admin', '-a'], default=False)
        c.argument('context_name',
                   options_list=['--context'],
                   help='If specified, overwrite the default context name.')
        c.argument('user',
                   options_list=['--user', '-u'],
                   default='clusterUser',
                   validator=validate_user)
        c.argument('path',
                   options_list=['--file', '-f'],
                   type=file_type,
                   completer=FilesCompleter(),
                   default=os.path.join(os.path.expanduser('~'), '.kube',
                                        'config'))
        c.argument('public_fqdn', default=False, action='store_true')
        c.argument('credential_format',
                   options_list=['--format'],
                   arg_type=get_enum_type(credential_formats))

    with self.argument_context('aks pod-identity') as c:
        c.argument('cluster_name', help='The cluster name.')

    with self.argument_context('aks pod-identity add') as c:
        c.argument('identity_name',
                   options_list=['--name', '-n'],
                   default=None,
                   required=False,
                   help='The pod identity name. Generate if not specified.',
                   validator=validate_pod_identity_resource_name(
                       'identity_name', required=False))
        c.argument('identity_namespace',
                   options_list=['--namespace'],
                   help='The pod identity namespace.')
        c.argument('identity_resource_id',
                   options_list=['--identity-resource-id'],
                   help='Resource id of the identity to use.')
        c.argument('binding_selector',
                   options_list=['--binding-selector'],
                   help='Optional binding selector to use.')

    with self.argument_context('aks pod-identity delete') as c:
        c.argument('identity_name',
                   options_list=['--name', '-n'],
                   default=None,
                   required=True,
                   help='The pod identity name.',
                   validator=validate_pod_identity_resource_name(
                       'identity_name', required=True))
        c.argument('identity_namespace',
                   options_list=['--namespace'],
                   help='The pod identity namespace.')

    with self.argument_context('aks pod-identity exception add') as c:
        c.argument(
            'exc_name',
            options_list=['--name', '-n'],
            default=None,
            required=False,
            help='The pod identity exception name. Generate if not specified.',
            validator=validate_pod_identity_resource_name('exc_name',
                                                          required=False))
        c.argument('exc_namespace',
                   options_list=['--namespace'],
                   required=True,
                   help='The pod identity exception namespace.',
                   validator=validate_pod_identity_resource_namespace)
        c.argument('pod_labels',
                   nargs='*',
                   required=True,
                   help='space-separated labels: key=value [key=value ...].',
                   validator=validate_pod_identity_pod_labels)

    with self.argument_context('aks pod-identity exception delete') as c:
        c.argument('exc_name',
                   options_list=['--name', '-n'],
                   required=True,
                   help='The pod identity exception name to remove.',
                   validator=validate_pod_identity_resource_name(
                       'exc_name', required=True))
        c.argument('exc_namespace',
                   options_list=['--namespace'],
                   required=True,
                   help='The pod identity exception namespace to remove.',
                   validator=validate_pod_identity_resource_namespace)

    with self.argument_context('aks pod-identity exception update') as c:
        c.argument('exc_name',
                   options_list=['--name', '-n'],
                   required=True,
                   help='The pod identity exception name to remove.',
                   validator=validate_pod_identity_resource_name(
                       'exc_name', required=True))
        c.argument('exc_namespace',
                   options_list=['--namespace'],
                   required=True,
                   help='The pod identity exception namespace to remove.',
                   validator=validate_pod_identity_resource_namespace)
        c.argument('pod_labels',
                   nargs='*',
                   required=True,
                   help='pod labels in key=value [key=value ...].',
                   validator=validate_pod_identity_pod_labels)

    for scope in ['aks nodepool snapshot create']:
        with self.argument_context(scope) as c:
            c.argument('snapshot_name',
                       options_list=['--name', '-n'],
                       required=True,
                       help='The nodepool snapshot name.',
                       validator=validate_snapshot_name)
            c.argument('tags', tags_type)
            c.argument('nodepool_id',
                       required=True,
                       help='The nodepool id.',
                       validator=validate_nodepool_id)
            c.argument('aks_custom_headers')

    for scope in [
            'aks nodepool snapshot show', 'aks nodepool snapshot delete'
    ]:
        with self.argument_context(scope) as c:
            c.argument('snapshot_name',
                       options_list=['--name', '-n'],
                       required=True,
                       help='The nodepool snapshot name.',
                       validator=validate_snapshot_name)
            c.argument('yes',
                       options_list=['--yes', '-y'],
                       help='Do not prompt for confirmation.',
                       action='store_true')

    for scope in ['aks snapshot create']:
        with self.argument_context(scope) as c:
            c.argument('snapshot_name',
                       options_list=['--name', '-n'],
                       required=True,
                       help='The cluster snapshot name.',
                       validator=validate_snapshot_name)
            c.argument('tags', tags_type)
            c.argument('cluster_id',
                       required=True,
                       validator=validate_cluster_id,
                       help='The cluster id.')
            c.argument('aks_custom_headers')

    for scope in ['aks snapshot show', 'aks snapshot delete']:
        with self.argument_context(scope) as c:
            c.argument('snapshot_name',
                       options_list=['--name', '-n'],
                       required=True,
                       help='The cluster snapshot name.',
                       validator=validate_snapshot_name)
            c.argument('yes',
                       options_list=['--yes', '-y'],
                       help='Do not prompt for confirmation.',
                       action='store_true')
Пример #15
0
        help='Expiration UTC datetime  (Y-m-d\'T\'H:M:S\'Z\').',
        type=datetime_type)
    register_cli_argument(
        'keyvault key {}'.format(item),
        'not_before',
        default=None,
        help=
        'Key not usable before the provided UTC datetime  (Y-m-d\'T\'H:M:S\'Z\').',
        type=datetime_type)

register_cli_argument('keyvault key import',
                      'pem_file',
                      type=file_type,
                      help='PEM file containing the key to be imported.',
                      arg_group='Key Source',
                      completer=FilesCompleter(),
                      validator=validate_key_import_source)
register_cli_argument('keyvault key import',
                      'pem_password',
                      help='Password of PEM file.',
                      arg_group='Key Source')
register_cli_argument(
    'keyvault key import',
    'byok_file',
    type=file_type,
    help=
    'BYOK file containing the key to be imported. Must not be password protected.',
    completer=FilesCompleter(),
    arg_group='Key Source')

register_cli_argument('keyvault key backup',
Пример #16
0
def load_arguments(self, _):

    # ACS command argument configuration
    with self.argument_context('acs') as c:
        c.argument('resource_name', name_type,
                   completer=get_resource_name_completion_list('Microsoft.ContainerService/ContainerServices'),
                   help='Name of the container service. You can configure the default using `az configure --defaults acs=<name>`')
        c.argument('name', name_type,
                   completer=get_resource_name_completion_list('Microsoft.ContainerService/ContainerServices'),
                   help='Name of the container service. You can configure the default using `az configure --defaults acs=<name>`')
        c.argument('container_service_name', name_type, help='Name of the container service. You can configure the default using `az configure --defaults acs=<name>`',
                   completer=get_resource_name_completion_list('Microsoft.ContainerService/ContainerServices'))
        c.argument('admin_username', options_list=['--admin-username', '-u'], default='azureuser')
        c.argument('api_version',
                   help=_get_feature_in_preview_message() + 'Use API version of ACS to perform az acs operations. Available options: 2017-01-31, 2017-07-01. Default: the latest version for the location')
        c.argument('dns_name_prefix', options_list=['--dns-prefix', '-d'])
        c.argument('orchestrator_type', get_enum_type(orchestrator_types), options_list=['--orchestrator-type', '-t'])
        c.argument('ssh_key_value', required=False, type=file_type, default=os.path.join('~', '.ssh', 'id_rsa.pub'),
                   completer=FilesCompleter(), validator=validate_ssh_key)
        c.argument('tags', tags_type)
        c.argument('disable_browser', help='Do not open browser after opening a proxy to the cluster web user interface')

    with self.argument_context('acs create') as c:
        c.argument('ssh_key_value', required=False, type=file_type, default=os.path.join('~', '.ssh', 'id_rsa.pub'),
                   completer=FilesCompleter(), validator=validate_ssh_key)
        c.argument('master_profile', options_list=['--master-profile', '-m'], type=validate_file_or_dict,
                   help=_get_feature_in_preview_message() + 'The file or dictionary representation of the master profile. Note it will override any master settings once set')
        c.argument('master_vm_size', completer=get_vm_size_completion_list,
                   help=_get_feature_in_preview_message())
        c.argument('agent_count', type=int)
        c.argument('generate_ssh_keys', action='store_true', validator=validate_create_parameters,
                   help='Generate SSH public and private key files if missing')
        c.argument('master_osdisk_size', type=int,
                   help=_get_feature_in_preview_message() + 'The disk size for master pool vms. Unit in GB. Default: corresponding vmsize disk size')
        c.argument('master_vnet_subnet_id', type=str,
                   help=_get_feature_in_preview_message() + 'The custom vnet subnet id. Note agent need to used the same vnet if master set. Default: ""')
        c.argument('master_first_consecutive_static_ip', type=str,
                   help=_get_feature_in_preview_message() + 'The first consecutive ip used to specify static ip block.')
        c.argument('master_storage_profile', get_enum_type(storage_profile_types),
                   help=_get_feature_in_preview_message() + 'Default: varies based on Orchestrator')
        c.argument('agent_profiles', options_list=['--agent-profiles', '-a'], type=validate_file_or_dict,
                   help=_get_feature_in_preview_message() + 'The file or dictionary representation of the agent profiles. Note it will override any agent settings once set')
        c.argument('agent_vm_size', completer=get_vm_size_completion_list,
                   help='Set the default size for agent pools vms.')
        c.argument('agent_osdisk_size', type=int,
                   help=_get_feature_in_preview_message() + 'Set the default disk size for agent pools vms. Unit in GB. Default: corresponding vmsize disk size')
        c.argument('agent_vnet_subnet_id', type=str,
                   help=_get_feature_in_preview_message() + 'Set the default custom vnet subnet id for agent pools. Note agent need to used the same vnet if master set. Default: ""')
        c.argument('agent_ports', type=validate_list_of_integers,
                   help=_get_feature_in_preview_message() + 'Set the default ports exposed on the agent pools. Only usable for non-Kubernetes. Default: 8080,4000,80')
        c.argument('agent_storage_profile', get_enum_type(storage_profile_types),
                   help=_get_feature_in_preview_message() + 'Set default storage profile for agent pools. Default: varies based on Orchestrator')
        c.argument('windows', action='store_true',
                   help='If true, set the default osType of agent pools to be Windows.')
        c.argument('validate', action='store_true',
                   help='Generate and validate the ARM template without creating any resources')
        c.argument('orchestrator_version', help=_get_feature_in_preview_message() + 'Use Orchestrator Version to specify the semantic version for your choice of orchestrator.')

    with self.argument_context('acs scale') as c:
        c.argument('new_agent_count', type=int)

    for scope in ['dcos', 'kubernetes']:
        with self.argument_context('acs {} browse'.format(scope)) as c:
            c.argument('ssh_key_file', required=False, type=file_type, default=os.path.join('~', '.ssh', 'id_rsa'),
                       completer=FilesCompleter(), help='Path to an SSH key file to use.')

    with self.argument_context('acs dcos install-cli') as c:
        c.argument('install_location', default=_get_default_install_location('dcos'))

    with self.argument_context('acs kubernetes get-credentials') as c:
        c.argument('path', options_list=['--file', '-f'])
        c.argument('overwrite_existing', action='store_true', help='If specified, overwrite any existing credentials.')

    with self.argument_context('acs kubernetes install-cli') as c:
        c.argument('install_location', type=file_type, completer=FilesCompleter(),
                   default=_get_default_install_location('kubectl'))
        c.argument('ssh_key_file', required=False, type=file_type, default=os.path.join('~', '.ssh', 'id_rsa'),
                   completer=FilesCompleter(), help='Path to an SSH key file to use.')

    # AKS command argument configuration
    with self.argument_context('aks') as c:
        c.argument('resource_name', name_type, help='Name of the managed cluster.',
                   completer=get_resource_name_completion_list('Microsoft.ContainerService/ManagedClusters'))
        c.argument('name', name_type, help='Name of the managed cluster.',
                   completer=get_resource_name_completion_list('Microsoft.ContainerService/ManagedClusters'))
        c.argument('kubernetes_version', options_list=['--kubernetes-version', '-k'], validator=validate_k8s_version)
        c.argument('node_count', options_list=['--node-count', '-c'], type=int)
        c.argument('tags', tags_type)

    with self.argument_context('aks create') as c:
        c.argument('name', validator=validate_linux_host_name)
        c.argument('kubernetes_version', completer=get_k8s_versions_completion_list)
        c.argument('admin_username', options_list=['--admin-username', '-u'], default='azureuser')
        c.argument('dns_name_prefix', options_list=['--dns-name-prefix', '-p'])
        c.argument('generate_ssh_keys', action='store_true', validator=validate_create_parameters)
        c.argument('node_vm_size', options_list=['--node-vm-size', '-s'], completer=get_vm_size_completion_list)
        c.argument('nodepool_name', type=str, default='nodepool1',
                   help='Node pool name, upto 12 alphanumeric characters', validator=validate_nodepool_name)
        c.argument('ssh_key_value', required=False, type=file_type, default=os.path.join('~', '.ssh', 'id_rsa.pub'),
                   completer=FilesCompleter(), validator=validate_ssh_key)
        c.argument('aad_client_app_id')
        c.argument('aad_server_app_id')
        c.argument('aad_server_app_secret')
        c.argument('aad_tenant_id')
        c.argument('dns_service_ip')
        c.argument('docker_bridge_address')
        c.argument('enable_addons', options_list=['--enable-addons', '-a'])
        c.argument('disable_rbac', action='store_true')
        c.argument('enable_rbac', action='store_true', options_list=['--enable-rbac', '-r'],
                   deprecate_info=c.deprecate(redirect="--disable-rbac", hide="2.0.45"))
        c.argument('max_pods', type=int, options_list=['--max-pods', '-m'], validator=validate_max_pods)
        c.argument('network_plugin')
        c.argument('network_policy')
        c.argument('no_ssh_key', options_list=['--no-ssh-key', '-x'])
        c.argument('pod_cidr')
        c.argument('service_cidr')
        c.argument('vnet_subnet_id')
        c.argument('workspace_resource_id')
        c.argument('skip_subnet_role_assignment', action='store_true')

    with self.argument_context('aks disable-addons') as c:
        c.argument('addons', options_list=['--addons', '-a'])

    with self.argument_context('aks enable-addons') as c:
        c.argument('addons', options_list=['--addons', '-a'])
        c.argument('subnet_name', options_list=['--subnet-name', '-s'], help='Name of an existing subnet to use with the virtual-node add-on.')

    with self.argument_context('aks get-credentials') as c:
        c.argument('admin', options_list=['--admin', '-a'], default=False)
        c.argument('context_name', options_list=['--context'],
                   help='If specified, overwrite the default context name.')
        c.argument('path', options_list=['--file', '-f'], type=file_type, completer=FilesCompleter(),
                   default=os.path.join(os.path.expanduser('~'), '.kube', 'config'))

    for scope in ['aks', 'acs kubernetes', 'acs dcos']:
        with self.argument_context('{} install-cli'.format(scope)) as c:
            c.argument('client_version', validator=validate_k8s_client_version, help='Version of the client to install.')
            c.argument('install_location', default=_get_default_install_location('kubectl'), help='Path at which to install DC/OS.')

    with self.argument_context('aks install-connector') as c:
        c.argument('aci_resource_group', help='The resource group to create the ACI container groups')
        c.argument('chart_url', default=aci_connector_chart_url, help='URL to the chart')
        c.argument('client_secret', help='Client secret to use with the service principal for making calls to Azure APIs')
        c.argument('connector_name', default='aci-connector', help='The name for the ACI Connector', validator=validate_connector_name)
        c.argument('image_tag', help='The image tag of the virtual kubelet')
        c.argument('location', help='The location to create the ACI container groups')
        c.argument('os_type', get_enum_type(aci_connector_os_type), help='The OS type of the connector')
        c.argument('service_principal',
                   help='Service principal for making calls into Azure APIs. If not set, auto generate a new service principal of Contributor role, and save it locally for reusing')

    with self.argument_context('aks remove-connector') as c:
        c.argument('connector_name', default='aci-connector',
                   help='The name for the ACI Connector', validator=validate_connector_name)
        c.argument('graceful', action='store_true',
                   help='Mention if you want to drain/uncordon your aci-connector to move your applications')
        c.argument('os_type', get_enum_type(aci_connector_os_type),
                   help='The OS type of the connector')

    with self.argument_context('aks update-credentials', arg_group='Service Principal') as c:
        c.argument('reset_service_principal', action='store_true')
        c.argument('service_principal')
        c.argument('client_secret')

    with self.argument_context('aks update-credentials', arg_group='AAD') as c:
        c.argument('reset_aad', action='store_true')
        c.argument('aad_client_app_id')
        c.argument('aad_server_app_id')
        c.argument('aad_server_app_secret')
        c.argument('aad_tenant_id')

    with self.argument_context('aks upgrade') as c:
        c.argument('kubernetes_version', completer=get_k8s_upgrades_completion_list)

    with self.argument_context('aks scale') as c:
        c.argument('nodepool_name', type=str,
                   help='Node pool name, upto 12 alphanumeric characters', validator=validate_nodepool_name)

    with self.argument_context('aks upgrade-connector') as c:
        c.argument('aci_resource_group')
        c.argument('chart_url', default=aci_connector_chart_url)
        c.argument('client_secret')
        c.argument('connector_name', default='aci-connector', validator=validate_connector_name)
        c.argument('image_tag')
        c.argument('location')
        c.argument('os_type', get_enum_type(aci_connector_os_type))
        c.argument('service_principal')

    with self.argument_context('aks use-dev-spaces') as c:
        c.argument('update', options_list=['--update'], action='store_true')
        c.argument('space_name', options_list=['--space', '-s'])
        c.argument('prompt', options_list=['--yes', '-y'], action='store_true', help='Do not prompt for confirmation. Requires --space.')

    with self.argument_context('aks remove-dev-spaces') as c:
        c.argument('prompt', options_list=['--yes', '-y'], action='store_true', help='Do not prompt for confirmation')

    # OpenShift command argument configuration
    with self.argument_context('openshift') as c:
        c.argument('resource_name', name_type, help='Name of the managed OpenShift cluster.',
                   completer=get_resource_name_completion_list('Microsoft.ContainerService/OpenShiftManagedClusters'))
        c.argument('name', name_type, help='Name of the managed OpenShift cluster.',
                   completer=get_resource_name_completion_list('Microsoft.ContainerService/OpenShiftManagedClusters'))
        c.argument('compute_count', options_list=['--compute-count', '-c'], type=int, default=4)
        c.argument('tags', tags_type)

    with self.argument_context('openshift create') as c:
        c.argument('name', validator=validate_linux_host_name)
        c.argument('compute_vm_size', options_list=['--compute-vm-size', '-s'])
        c.argument('customer_admin_group_id', options_list=['--customer-admin-group-id'])
Пример #17
0
def load_arguments(self, _):

    with self.argument_context('backup') as c:
        c.ignore('container_type', 'item_type')
        c.argument('force',
                   action='store_true',
                   help='Force completion of the requested action.')

    # Vault
    with self.argument_context('backup vault') as c:
        c.argument('vault_name',
                   vault_name_type,
                   options_list=['--name', '-n'],
                   id_part='name')
        c.argument('location',
                   validator=get_default_location_from_resource_group)

    with self.argument_context('backup vault backup-properties set') as c:
        c.argument(
            'backup_storage_redundancy',
            arg_type=get_enum_type(['GeoRedundant', 'LocallyRedundant']),
            help='Sets backup storage properties for a Recovery Services vault.'
        )

    # Container
    with self.argument_context('backup container') as c:
        c.argument('vault_name', vault_name_type, id_part='name')
        c.ignore('status')

    with self.argument_context('backup container show') as c:
        c.argument(
            'name',
            container_name_type,
            options_list=['--name', '-n'],
            help=
            'Name of the container. You can use the backup container list command to get the name of a container.'
        )

    with self.argument_context('backup container list') as c:
        c.argument('vault_name', vault_name_type, id_part=None)

    # Item
    with self.argument_context('backup item') as c:
        c.argument('vault_name', vault_name_type, id_part='name')
        c.argument('container_name', container_name_type)

    with self.argument_context('backup item show') as c:
        c.argument(
            'name',
            item_name_type,
            options_list=['--name', '-n'],
            help=
            'Name of the backed up item. You can use the backup item list command to get the name of a backed up item.'
        )

    # TODO: Need to use item.id once https://github.com/Azure/msrestazure-for-python/issues/80 is fixed.
    with self.argument_context('backup item set-policy') as c:
        c.argument(
            'item_name',
            item_name_type,
            options_list=['--name', '-n'],
            id_part='name',
            help=
            'Name of the backed up item. You can use the backup item list command to get the name of a backed up item.'
        )
        c.argument(
            'policy_name',
            policy_name_type,
            help=
            'Name of the Backup policy. You can use the backup policy list command to get the name of a backup policy.'
        )

    with self.argument_context('backup item list') as c:
        c.argument('vault_name', vault_name_type, id_part=None)

    # Policy
    with self.argument_context('backup policy') as c:
        c.argument('vault_name', vault_name_type, id_part='name')

    for command in ['show', 'delete', 'list-associated-items']:
        with self.argument_context('backup policy ' + command) as c:
            c.argument(
                'name',
                policy_name_type,
                options_list=['--name', '-n'],
                help=
                'Name of the backup policy. You can use the backup policy list command to get the name of a policy.'
            )

    with self.argument_context('backup policy set') as c:
        c.argument(
            'policy',
            type=file_type,
            help=
            'JSON encoded policy definition. Use the show command with JSON output to obtain a policy object. Modify the values using a file editor and pass the object.',
            completer=FilesCompleter())

    with self.argument_context('backup policy list') as c:
        c.argument('vault_name', vault_name_type, id_part=None)

    # Recovery Point
    # TODO: Need to use item.id once https://github.com/Azure/msrestazure-for-python/issues/80 is fixed.
    with self.argument_context('backup recoverypoint') as c:
        c.argument('vault_name', vault_name_type, id_part='name')
        c.argument('container_name', container_name_type)
        c.argument('item_name', item_name_type)

    with self.argument_context('backup recoverypoint list') as c:
        c.argument('vault_name', vault_name_type, id_part=None)
        c.argument('start_date',
                   type=datetime_type,
                   help='The start date of the range in UTC (d-m-Y).')
        c.argument('end_date',
                   type=datetime_type,
                   help='The end date of the range in UTC (d-m-Y).')

    with self.argument_context('backup recoverypoint show') as c:
        c.argument(
            'name',
            rp_name_type,
            options_list=['--name', '-n'],
            help=
            'Name of the recovery point. You can use the backup recovery point list command to get the name of a backed up item.'
        )

    # Protection
    with self.argument_context('backup protection') as c:
        c.argument('vault_name', vault_name_type, id_part='name')
        c.argument('vm',
                   help='Name or ID of the Virtual Machine to be protected.')
        c.argument('policy_name', policy_name_type)

    # TODO: Need to use item.id once https://github.com/Azure/msrestazure-for-python/issues/80 is fixed.
    for command in ['backup-now', 'disable']:
        with self.argument_context('backup protection ' + command) as c:
            c.argument('container_name', container_name_type)
            c.argument('item_name', item_name_type)

    with self.argument_context('backup protection backup-now') as c:
        c.argument(
            'retain_until',
            type=datetime_type,
            help=
            'The date until which this backed up copy will be available for retrieval, in UTC (d-m-Y).'
        )

    with self.argument_context('backup protection disable') as c:
        c.argument(
            'delete_backup_data',
            arg_type=get_three_state_flag(),
            help=
            'Option to delete existing backed up data in the Recovery services vault.'
        )

    with self.argument_context('backup protection check-vm') as c:
        c.argument(
            'vm_id',
            help='ID of the virtual machine to be checked for protection.')

    # Restore
    # TODO: Need to use recovery_point.id once https://github.com/Azure/msrestazure-for-python/issues/80 is fixed.
    with self.argument_context('backup restore') as c:
        c.argument('vault_name', vault_name_type, id_part='name')
        c.argument('container_name', container_name_type)
        c.argument('item_name', item_name_type)
        c.argument('rp_name', rp_name_type)

    with self.argument_context('backup restore restore-disks') as c:
        c.argument(
            'storage_account',
            help=
            'Name or ID of the staging storage account. The VM configuration will be restored to this storage account. See the help for --restore-to-staging-storage-account parameter for more info.'
        )
        c.argument(
            'restore_to_staging_storage_account',
            arg_type=get_three_state_flag(),
            help=
            'Use this flag when you want disks to be restored to the staging storage account using the --storage-account parameter. When not specified, disks will be restored to their original storage accounts. Default: false.'
        )
        c.argument(
            'target_resource_group',
            options_list=['--target-resource-group', '-t'],
            help=
            'Use this to specify the target resource group in which the restored disks will be saved'
        )

    # Job
    with self.argument_context('backup job') as c:
        c.argument('vault_name', vault_name_type, id_part='name')

    # TODO: Need to use job.id once https://github.com/Azure/msrestazure-for-python/issues/80 is fixed.
    for command in ['show', 'stop', 'wait']:
        with self.argument_context('backup job ' + command) as c:
            c.argument(
                'name',
                job_name_type,
                help=
                'Name of the job. You can use the backup job list command to get the name of a job.'
            )

    with self.argument_context('backup job list') as c:
        c.argument('vault_name', vault_name_type, id_part=None)
        c.argument('status',
                   arg_type=get_enum_type([
                       'Cancelled', 'Completed', 'CompletedWithWarnings',
                       'Failed', 'InProgress'
                   ]),
                   help='Status of the Job.')
        c.argument('operation',
                   arg_type=get_enum_type([
                       'Backup', 'ConfigureBackup', 'DeleteBackupData',
                       'DisableBackup', 'Restore'
                   ]),
                   help='User initiated operation.')
        c.argument('start_date',
                   type=datetime_type,
                   help='The start date of the range in UTC (d-m-Y).')
        c.argument('end_date',
                   type=datetime_type,
                   help='The end date of the range in UTC (d-m-Y).')

    with self.argument_context('backup job wait') as c:
        c.argument('timeout',
                   type=int,
                   help='Maximum time, in seconds, to wait before aborting.')
Пример #18
0
 def __init__(self):
     # This is only safe to import if argcomplete is present in the install
     # (which happens for Cloud SDK installs), so import on usage, not on load.
     # pylint: disable=g-import-not-at-top
     from argcomplete.completers import FilesCompleter
     self.files_completer = FilesCompleter()
Пример #19
0
def load_arguments(self, _):  # pylint: disable=too-many-statements
    # Arguments for IoT DPS
    with self.argument_context('iot dps') as c:
        c.argument('dps_name',
                   dps_name_type,
                   options_list=['--name', '-n'],
                   id_part='name')

    with self.argument_context('iot dps create') as c:
        c.argument(
            'location',
            get_location_type(self.cli_ctx),
            help=
            'Location of your IoT Provisioning Service. Default is the location of target resource group.'
        )
        c.argument('sku',
                   arg_type=get_enum_type(IotDpsSku),
                   help='Pricing tier for the IoT provisioning service.')
        c.argument('unit',
                   help='Units in your IoT Provisioning Service.',
                   type=int)

    for subgroup in ['access-policy', 'linked-hub', 'certificate']:
        with self.argument_context('iot dps {}'.format(subgroup)) as c:
            c.argument('dps_name', options_list=['--dps-name'], id_part=None)

    with self.argument_context('iot dps access-policy') as c:
        c.argument('access_policy_name',
                   options_list=['--access-policy-name', '--name', '-n'],
                   help='A friendly name for DPS access policy.')

    with self.argument_context('iot dps access-policy create') as c:
        c.argument(
            'rights',
            options_list=['--rights', '-r'],
            nargs='+',
            arg_type=get_enum_type(AccessRightsDescription),
            help=
            'Access rights for the IoT provisioning service. Use space separated list for multiple rights.'
        )
        c.argument('primary_key', help='Primary SAS key value.')
        c.argument('secondary_key', help='Secondary SAS key value.')

    with self.argument_context('iot dps access-policy update') as c:
        c.argument(
            'rights',
            options_list=['--rights', '-r'],
            nargs='+',
            arg_type=get_enum_type(AccessRightsDescription),
            help=
            'Access rights for the IoT provisioning service. Use space separated list for multiple rights.'
        )
        c.argument('primary_key', help='Primary SAS key value.')
        c.argument('secondary_key', help='Secondary SAS key value.')

    with self.argument_context('iot dps linked-hub') as c:
        c.argument('linked_hub',
                   options_list=['--linked-hub'],
                   help='Host name of linked IoT Hub.')

    with self.argument_context('iot dps linked-hub create') as c:
        c.argument('connection_string',
                   help='Connection string of the IoT hub.')
        c.argument('location',
                   get_location_type(self.cli_ctx),
                   help='Location of the IoT hub.')
        c.argument(
            'apply_allocation_policy',
            help=
            'A boolean indicating whether to apply allocation policy to the IoT hub.',
            arg_type=get_three_state_flag())
        c.argument('allocation_weight',
                   help='Allocation weight of the IoT hub.')

    with self.argument_context('iot dps linked-hub update') as c:
        c.argument(
            'apply_allocation_policy',
            help=
            'A boolean indicating whether to apply allocation policy to the Iot hub.',
            arg_type=get_three_state_flag())
        c.argument('allocation_weight',
                   help='Allocation weight of the IoT hub.')

    with self.argument_context('iot dps allocation-policy update') as c:
        c.argument('allocation_policy',
                   options_list=['--policy', '-p'],
                   arg_type=get_enum_type(AllocationPolicy),
                   help='Allocation policy for the IoT provisioning service.')

    with self.argument_context('iot dps certificate') as c:
        c.argument('certificate_path',
                   options_list=['--path', '-p'],
                   type=file_type,
                   completer=FilesCompleter([".cer", ".pem"]),
                   help='The path to the file containing the certificate.')
        c.argument('certificate_name',
                   options_list=['--certificate-name', '--name', '-n'],
                   help='A friendly name for the certificate.')
        c.argument('etag',
                   options_list=['--etag', '-e'],
                   help='Entity Tag (etag) of the object.')

    # Arguments for IoT Hub
    with self.argument_context('iot') as c:
        c.argument('device_id',
                   options_list=['--device-id', '-d'],
                   help='Device Id.',
                   completer=get_device_id_completion_list)

    with self.argument_context('iot hub') as c:
        c.argument('hub_name',
                   hub_name_type,
                   options_list=['--name', '-n'],
                   id_part='name')
        c.argument('etag',
                   options_list=['--etag', '-e'],
                   help='Entity Tag (etag) of the object.')

    for subgroup in ['consumer-group', 'policy', 'job', 'certificate']:
        with self.argument_context('iot hub {}'.format(subgroup)) as c:
            c.argument('hub_name', options_list=['--hub-name'])

    with self.argument_context('iot device') as c:
        c.argument('hub_name', hub_name_type)

    with self.argument_context('iot hub certificate') as c:
        c.argument('certificate_path',
                   options_list=['--path', '-p'],
                   type=file_type,
                   completer=FilesCompleter([".cer", ".pem"]),
                   help='The path to the file containing the certificate.')
        c.argument('certificate_name',
                   options_list=['--name', '-n'],
                   help='A friendly name for the certificate.')

    with self.argument_context('iot hub consumer-group') as c:
        c.argument('consumer_group_name',
                   options_list=['--name', '-n'],
                   id_part='child_name_2',
                   help='Event hub consumer group name.')
        c.argument('event_hub_name',
                   id_part='child_name_1',
                   help='Event hub endpoint name.')

    with self.argument_context('iot hub policy') as c:
        c.argument('policy_name',
                   options_list=['--name', '-n'],
                   id_part='child_name_1',
                   help='Shared access policy name.')
        permission_values = ', '.join([x.value for x in SimpleAccessRights])
        c.argument(
            'permissions',
            nargs='*',
            validator=validate_policy_permissions,
            type=str.lower,
            help=
            'Permissions of shared access policy. Use space separated list for multiple permissions. '
            'Possible values: {}'.format(permission_values))

    with self.argument_context('iot hub job') as c:
        c.argument('job_id', id_part='child_name_1', help='Job Id.')

    with self.argument_context('iot hub create') as c:
        c.argument('hub_name', completer=None)
        c.argument(
            'location',
            get_location_type(self.cli_ctx),
            help=
            'Location of your IoT Hub. Default is the location of target resource group.'
        )
        c.argument(
            'sku',
            arg_type=get_enum_type(IotHubSku),
            help=
            'Pricing tier for Azure IoT Hub. Default value is F1, which is free. '
            'Note that only one free IoT hub instance is allowed in each '
            'subscription. Exception will be thrown if free instances exceed one.'
        )
        c.argument('unit', help='Units in your IoT Hub.', type=int)

    with self.argument_context('iot hub show-connection-string') as c:
        c.argument('policy_name', help='Shared access policy to use.')
        c.argument('key_type',
                   arg_type=get_enum_type(KeyType),
                   options_list=['--key'],
                   help='The key to use.')

    with self.argument_context('iot device create') as c:
        c.argument('device_id', completer=None)

    with self.argument_context('iot device create',
                               arg_group='X.509 Certificate') as c:
        c.argument('x509',
                   action='store_true',
                   help='Use X.509 certificate for device authentication.')
        c.argument(
            'primary_thumbprint',
            help='Primary X.509 certificate thumbprint to authenticate device.'
        )
        c.argument(
            'secondary_thumbprint',
            help=
            'Secondary X.509 certificate thumbprint to authenticate device.')
        c.argument(
            'valid_days',
            type=int,
            help=
            'Number of days the generated self-signed X.509 certificate should be '
            'valid for. Default validity is 365 days.')
        c.argument(
            'output_dir',
            help='Output directory for generated self-signed X.509 certificate. '
            'Default is current working directory.')

    with self.argument_context('iot device list') as c:
        c.argument('top',
                   help='Maximum number of device identities to return.',
                   type=int)

    with self.argument_context('iot device delete') as c:
        c.argument(
            'etag',
            help=
            'ETag of the target device. It is used for the purpose of optimistic '
            'concurrency. Delete operation will be performed only if the specified '
            'ETag matches the value maintained by the server, indicating that the '
            'device identity has not been modified since it was retrieved. Default '
            'value is set to wildcard character (*) to force an unconditional '
            'delete.')

    with self.argument_context('iot device show-connection-string') as c:
        c.argument('top',
                   type=int,
                   help='Maximum number of connection strings to return.')
        c.argument('key_type',
                   arg_type=get_enum_type(KeyType),
                   options_list=['--key'],
                   help='The key to use.')

    with self.argument_context('iot device message') as c:
        c.argument('lock_token', help='Message lock token.')

    with self.argument_context('iot device message send',
                               arg_group='Messaging') as c:
        c.argument('data', help='Device-to-cloud message body.')
        c.argument('message_id', help='Device-to-cloud message Id.')
        c.argument('correlation_id',
                   help='Device-to-cloud message correlation Id.')
        c.argument('user_id', help='Device-to-cloud message user Id.')

    with self.argument_context('iot device message receive') as c:
        c.argument(
            'lock_timeout',
            type=int,
            help=
            'In case a message returned to this call, this specifies the amount of '
            'time in seconds, the message will be invisible to other receive calls.'
        )

    with self.argument_context('iot device export') as c:
        c.argument(
            'blob_container_uri',
            help=
            'Blob Shared Access Signature URI with write access to a blob container.'
            'This is used to output the status of the job and the results.')
        c.argument(
            'include_keys',
            action='store_true',
            help=
            'If set, keys are exported normally. Otherwise, keys are set to null in '
            'export output.')

    with self.argument_context('iot device import') as c:
        c.argument(
            'input_blob_container_uri',
            help=
            'Blob Shared Access Signature URI with read access to a blob container.'
            'This blob contains the operations to be performed on the identity '
            'registry ')
        c.argument(
            'output_blob_container_uri',
            help=
            'Blob Shared Access Signature URI with write access to a blob container.'
            'This is used to output the status of the job and the results.')
Пример #20
0
def load_arguments(self, _):

    acr_arg_type = CLIArgumentType(metavar='ACR_NAME_OR_RESOURCE_ID')

    # AKS command argument configuration
    with self.argument_context('aks') as c:
        c.argument('resource_name',
                   name_type,
                   help='Name of the managed cluster.',
                   completer=get_resource_name_completion_list(
                       'Microsoft.ContainerService/ManagedClusters'))
        c.argument('name',
                   name_type,
                   help='Name of the managed cluster.',
                   completer=get_resource_name_completion_list(
                       'Microsoft.ContainerService/ManagedClusters'))
        c.argument('kubernetes_version',
                   options_list=['--kubernetes-version', '-k'],
                   validator=validate_k8s_version)
        c.argument('node_count', options_list=['--node-count', '-c'], type=int)
        c.argument('tags', tags_type)

    with self.argument_context('aks create') as c:
        c.argument('name', validator=validate_linux_host_name)
        c.argument('kubernetes_version',
                   completer=get_k8s_versions_completion_list)
        c.argument('admin_username',
                   options_list=['--admin-username', '-u'],
                   default='azureuser')
        c.argument('windows_admin_username',
                   options_list=['--windows-admin-username'])
        c.argument('windows_admin_password',
                   options_list=['--windows-admin-password'])
        c.argument('dns_name_prefix', options_list=['--dns-name-prefix', '-p'])
        c.argument('generate_ssh_keys',
                   action='store_true',
                   validator=validate_create_parameters)
        c.argument('node_vm_size',
                   options_list=['--node-vm-size', '-s'],
                   completer=get_vm_size_completion_list)
        c.argument('nodepool_name',
                   type=str,
                   default='nodepool1',
                   help='Node pool name, upto 12 alphanumeric characters',
                   validator=validate_nodepool_name)
        c.argument(
            'nodepool_tags',
            nargs='*',
            validator=validate_nodepool_tags,
            help=
            'space-separated tags: key[=value] [key[=value] ...]. Use "" to clear existing tags.'
        )
        c.argument(
            'nodepool_labels',
            nargs='*',
            validator=validate_nodepool_labels,
            help=
            'space-separated labels: key[=value] [key[=value] ...]. You can not change the node labels through CLI after creation. See https://aka.ms/node-labels for syntax of labels.'
        )
        c.argument('ssh_key_value',
                   required=False,
                   type=file_type,
                   default=os.path.join('~', '.ssh', 'id_rsa.pub'),
                   completer=FilesCompleter(),
                   validator=validate_ssh_key)
        c.argument('aad_client_app_id')
        c.argument('aad_server_app_id')
        c.argument('aad_server_app_secret')
        c.argument('aad_tenant_id')
        c.argument('dns_service_ip')
        c.argument('docker_bridge_address')
        c.argument('load_balancer_sku',
                   type=str,
                   validator=validate_load_balancer_sku)
        c.argument('load_balancer_managed_outbound_ip_count', type=int)
        c.argument('load_balancer_outbound_ips',
                   type=str,
                   validator=validate_load_balancer_outbound_ips)
        c.argument('load_balancer_outbound_ip_prefixes',
                   type=str,
                   validator=validate_load_balancer_outbound_ip_prefixes)
        c.argument('load_balancer_outbound_ports',
                   type=int,
                   validator=validate_load_balancer_outbound_ports)
        c.argument('load_balancer_idle_timeout',
                   type=int,
                   validator=validate_load_balancer_idle_timeout)
        c.argument('outbound_type',
                   arg_type=get_enum_type([
                       CONST_OUTBOUND_TYPE_LOAD_BALANCER,
                       CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING
                   ]))
        c.argument('enable_addons', options_list=['--enable-addons', '-a'])
        c.argument('disable_rbac', action='store_true')
        c.argument('enable_rbac',
                   action='store_true',
                   options_list=['--enable-rbac', '-r'],
                   deprecate_info=c.deprecate(redirect="--disable-rbac",
                                              hide="2.0.45"))
        c.argument('max_pods',
                   type=int,
                   options_list=['--max-pods', '-m'],
                   validator=validate_max_pods)
        c.argument('network_plugin',
                   arg_type=get_enum_type(['azure', 'kubenet']))
        c.argument('network_policy')
        c.argument('no_ssh_key', options_list=['--no-ssh-key', '-x'])
        c.argument('pod_cidr')
        c.argument('service_cidr')
        c.argument('vnet_subnet_id',
                   type=str,
                   validator=validate_vnet_subnet_id)
        c.argument('workspace_resource_id')
        c.argument('skip_subnet_role_assignment', action='store_true')
        c.argument('enable_cluster_autoscaler', action='store_true')
        c.argument('uptime_sla', action='store_true')
        c.argument('cluster_autoscaler_profile',
                   nargs='+',
                   validator=validate_cluster_autoscaler_profile)
        c.argument('min_count', type=int, validator=validate_nodes_count)
        c.argument('max_count', type=int, validator=validate_nodes_count)
        c.argument('enable_vmss',
                   action='store_true',
                   help='To be deprecated. Use vm_set_type instead.')
        c.argument('vm_set_type', type=str, validator=validate_vm_set_type)
        c.argument(
            'node_zones',
            zones_type,
            options_list=['--node-zones', '--zones', '-z'],
            help=
            '(--node-zones will be deprecated, use --zones) Space-separated list of availability zones where agent nodes will be placed.'
        )
        c.argument('enable_node_public_ip',
                   action='store_true',
                   is_preview=True)
        c.argument('enable_pod_security_policy', action='store_true')
        c.argument('node_resource_group')
        c.argument('attach_acr', acr_arg_type)
        c.argument('api_server_authorized_ip_ranges',
                   type=str,
                   validator=validate_ip_ranges)
        c.argument('aks_custom_headers')
        c.argument('enable_private_cluster', action='store_true')
        c.argument('enable_managed_identity', action='store_true')

    with self.argument_context('aks update') as c:
        c.argument('enable_cluster_autoscaler',
                   options_list=["--enable-cluster-autoscaler", "-e"],
                   action='store_true')
        c.argument('disable_cluster_autoscaler',
                   options_list=["--disable-cluster-autoscaler", "-d"],
                   action='store_true')
        c.argument('update_cluster_autoscaler',
                   options_list=["--update-cluster-autoscaler", "-u"],
                   action='store_true')
        c.argument('cluster_autoscaler_profile',
                   nargs='+',
                   validator=validate_cluster_autoscaler_profile)
        c.argument('min_count', type=int, validator=validate_nodes_count)
        c.argument('max_count', type=int, validator=validate_nodes_count)
        c.argument('load_balancer_managed_outbound_ip_count', type=int)
        c.argument('load_balancer_outbound_ips',
                   type=str,
                   validator=validate_load_balancer_outbound_ips)
        c.argument('load_balancer_outbound_ip_prefixes',
                   type=str,
                   validator=validate_load_balancer_outbound_ip_prefixes)
        c.argument('load_balancer_outbound_ports',
                   type=int,
                   validator=validate_load_balancer_outbound_ports)
        c.argument('load_balancer_idle_timeout',
                   type=int,
                   validator=validate_load_balancer_idle_timeout)
        c.argument('api_server_authorized_ip_ranges',
                   type=str,
                   validator=validate_ip_ranges)
        c.argument('enable_pod_security_policy', action='store_true')
        c.argument('disable_pod_security_policy', action='store_true')
        c.argument('attach_acr', acr_arg_type, validator=validate_acr)
        c.argument('detach_acr', acr_arg_type, validator=validate_acr)
        c.argument('aks_custom_headers')

    with self.argument_context('aks scale') as c:
        c.argument('nodepool_name',
                   type=str,
                   help='Node pool name, upto 12 alphanumeric characters',
                   validator=validate_nodepool_name)

    with self.argument_context('aks upgrade') as c:
        c.argument('kubernetes_version',
                   completer=get_k8s_upgrades_completion_list)

    with self.argument_context('aks nodepool') as c:
        c.argument('cluster_name', type=str, help='The cluster name.')

    for scope in ['aks nodepool add']:
        with self.argument_context(scope) as c:
            c.argument('nodepool_name',
                       type=str,
                       options_list=['--name', '-n'],
                       validator=validate_nodepool_name,
                       help='The node pool name.')
            c.argument('tags', tags_type)
            c.argument(
                'node_zones',
                zones_type,
                options_list=['--node-zones', '--zones', '-z'],
                help=
                '(--node-zones will be deprecated) Space-separated list of availability zones where agent nodes will be placed.'
            )
            c.argument('enable_node_public_ip',
                       action='store_true',
                       is_preview=True)
            c.argument('node_vm_size',
                       options_list=['--node-vm-size', '-s'],
                       completer=get_vm_size_completion_list)
            c.argument('max_pods',
                       type=int,
                       options_list=['--max-pods', '-m'],
                       validator=validate_max_pods)
            c.argument('os_type', type=str)
            c.argument('enable_cluster_autoscaler',
                       options_list=["--enable-cluster-autoscaler", "-e"],
                       action='store_true')
            c.argument('node_taints', type=str, validator=validate_taints)
            c.argument('priority',
                       arg_type=get_enum_type([
                           CONST_SCALE_SET_PRIORITY_REGULAR,
                           CONST_SCALE_SET_PRIORITY_SPOT
                       ]),
                       validator=validate_priority)
            c.argument('eviction_policy',
                       arg_type=get_enum_type([
                           CONST_SPOT_EVICTION_POLICY_DELETE,
                           CONST_SPOT_EVICTION_POLICY_DEALLOCATE
                       ]),
                       validator=validate_eviction_policy)
            c.argument('spot_max_price',
                       type=float,
                       validator=validate_spot_max_price)
            c.argument('labels', nargs='*', validator=validate_nodepool_labels)
            c.argument('mode',
                       arg_type=get_enum_type([
                           CONST_NODEPOOL_MODE_SYSTEM, CONST_NODEPOOL_MODE_USER
                       ]))
            c.argument('aks_custom_headers')

    for scope in [
            'aks nodepool show', 'aks nodepool delete', 'aks nodepool scale',
            'aks nodepool upgrade', 'aks nodepool update'
    ]:
        with self.argument_context(scope) as c:
            c.argument('nodepool_name',
                       type=str,
                       options_list=['--name', '-n'],
                       validator=validate_nodepool_name,
                       help='The node pool name.')

    with self.argument_context('aks nodepool update') as c:
        c.argument('enable_cluster_autoscaler',
                   options_list=["--enable-cluster-autoscaler", "-e"],
                   action='store_true')
        c.argument('disable_cluster_autoscaler',
                   options_list=["--disable-cluster-autoscaler", "-d"],
                   action='store_true')
        c.argument('update_cluster_autoscaler',
                   options_list=["--update-cluster-autoscaler", "-u"],
                   action='store_true')
        c.argument('tags', tags_type)
        c.argument('mode',
                   arg_type=get_enum_type(
                       [CONST_NODEPOOL_MODE_SYSTEM, CONST_NODEPOOL_MODE_USER]))

    with self.argument_context('aks disable-addons') as c:
        c.argument('addons', options_list=['--addons', '-a'])

    with self.argument_context('aks enable-addons') as c:
        c.argument('addons', options_list=['--addons', '-a'])
        c.argument('subnet_name', options_list=['--subnet-name', '-s'])

    with self.argument_context('aks get-credentials') as c:
        c.argument('admin', options_list=['--admin', '-a'], default=False)
        c.argument('context_name',
                   options_list=['--context'],
                   help='If specified, overwrite the default context name.')
        c.argument('user',
                   options_list=['--user', '-u'],
                   default='clusterUser',
                   validator=validate_user)
        c.argument('path',
                   options_list=['--file', '-f'],
                   type=file_type,
                   completer=FilesCompleter(),
                   default=os.path.join(os.path.expanduser('~'), '.kube',
                                        'config'))
Пример #21
0
def load_arguments(self, _):  # pylint: disable=too-many-statements
    SkuName, PasswordName, DefaultAction, PolicyStatus, WebhookAction, WebhookStatus, TaskStatus, \
        BaseImageTriggerType, RunStatus, SourceRegistryLoginMode, UpdateTriggerPayloadType, TokenStatus = self.get_models(
            'SkuName', 'PasswordName', 'DefaultAction', 'PolicyStatus', 'WebhookAction', 'WebhookStatus',
            'TaskStatus', 'BaseImageTriggerType', 'RunStatus', 'SourceRegistryLoginMode', 'UpdateTriggerPayloadType',
            'TokenStatus')

    with self.argument_context('acr') as c:
        c.argument('tags', arg_type=tags_type)
        c.argument('registry_name', options_list=['--name', '-n'], help='The name of the container registry. You can configure the default registry name using `az configure --defaults acr=<registry name>`', completer=get_resource_name_completion_list(REGISTRY_RESOURCE_TYPE), configured_default='acr')
        c.argument('tenant_suffix', options_list=['--suffix'], help="The tenant suffix in registry login server. You may specify '--suffix tenant' if your registry login server is in the format 'registry-tenant.azurecr.io'. Applicable if you\'re accessing the registry from a different subscription or you have permission to access images but not the permission to manage the registry resource.")
        c.argument('sku', help='The SKU of the container registry', arg_type=get_enum_type(SkuName))
        c.argument('admin_enabled', help='Indicates whether the admin user is enabled', arg_type=get_three_state_flag())
        c.argument('password_name', help='The name of password to regenerate', arg_type=get_enum_type(PasswordName))
        c.argument('username', options_list=['--username', '-u'], help='The username used to log into a container registry')
        c.argument('password', options_list=['--password', '-p'], help='The password used to log into a container registry')
        c.argument('yes', options_list=['--yes', '-y'], help='Do not prompt for confirmation.', action='store_true')
        c.argument('image_names', options_list=['--image', '-t'], help="The name and tag of the image using the format: '-t repo/image:tag'. Multiple tags are supported by passing -t multiple times.", action='append')
        c.argument('timeout', type=int, help='The timeout in seconds.')
        c.argument('docker_file_path', options_list=['--file', '-f'], help="The relative path of the the docker file to the source code root folder. Default to 'Dockerfile'.")
        c.argument('no_logs', help="Do not show logs after successfully queuing the build.", action='store_true')
        c.argument('no_wait', help="Do not wait for the run to complete and return immediately after queuing the run.", action='store_true')
        c.argument('no_format', help="Indicates whether the logs should be displayed in raw format", action='store_true')
        c.argument('platform', help="The platform where build/task is run, Eg, 'windows' and 'linux'. When it's used in build commands, it also can be specified in 'os/arch/variant' format for the resulting image. Eg, linux/arm/v7. The 'arch' and 'variant' parts are optional.")
        c.argument('target', help='The name of the target build stage.')
        c.argument('auth_mode', help='Auth mode of the source registry.', arg_type=get_enum_type(SourceRegistryLoginMode))
        # Overwrite default shorthand of cmd to make availability for acr usage
        c.argument('cmd', options_list=['--__cmd__'])
        c.argument('cmd_value', help="Commands to execute.", options_list=['--cmd'])

    for scope in ['acr create', 'acr update']:
        with self.argument_context(scope, arg_group='Network Rule') as c:
            c.argument('default_action', arg_type=get_enum_type(DefaultAction),
                       help='Default action to apply when no rule matches. Only applicable to Premium SKU.')

    with self.argument_context('acr create', arg_group="Customer managed key", is_preview=True) as c:
        c.argument('identity', help="Use assigned managed identity resource id or name if in the same resource group")
        c.argument('key_encryption_key', help="key vault key uri")

    with self.argument_context('acr import') as c:
        c.argument('source_image', options_list=['--source'], help="The source identifier will be either a source image name or a fully qualified source.")
        c.argument('source_registry', options_list=['--registry', '-r'], help='The source container registry can be name, login server or resource ID of the source registry.')
        c.argument('source_registry_username', options_list=['--username', '-u'], help='The username of source container registry')
        c.argument('source_registry_password', options_list=['--password', '-p'], help='The password of source container registry')
        c.argument('target_tags', options_list=['--image', '-t'], help="The name and tag of the image using the format: '-t repo/image:tag'. Multiple tags are supported by passing -t multiple times.", action='append')
        c.argument('repository', help='The repository name for a manifest-only copy of images. Multiple copies supported by passing --repository multiple times.', action='append')
        c.argument('force', help='Overwrite the existing tag of the image to be imported.', action='store_true')

    with self.argument_context('acr config content-trust') as c:
        c.argument('registry_name', options_list=['--registry', '-r', c.deprecate(target='-n', redirect='-r', hide=True), c.deprecate(target='--name', redirect='--registry', hide=True)])
        c.argument('status', help="Indicates whether content-trust is enabled.", arg_type=get_enum_type(PolicyStatus))

    with self.argument_context('acr config retention') as c:
        c.argument('status', help="Indicates whether retention policy is enabled.", arg_type=get_enum_type(PolicyStatus))
        c.argument('registry_name', options_list=['--registry', '-r'])
        c.argument('days', type=int, help='The number of days to retain an untagged manifest after which it gets purged (Range: 0 to 365). Value "0" will delete untagged manifests immediately.', validator=validate_retention_days, default=7)
        c.argument('policy_type', options_list=['--type'], help='The type of retention policy.', arg_type=get_enum_type(RetentionType))

    with self.argument_context('acr login') as c:
        c.argument('resource_group_name', deprecate_info=c.deprecate(hide=True))
        c.argument('expose_token', options_list=['--expose-token', '-t'], help='Expose access token instead of automatically logging in through Docker CLI', action='store_true', is_preview=True)

    with self.argument_context('acr repository') as c:
        c.argument('resource_group_name', deprecate_info=c.deprecate(hide=True))
        c.argument('repository', help="The name of the repository.")
        c.argument('image', arg_type=image_by_tag_or_digest_type)
        c.argument('top', type=int, help='Limit the number of items in the results.')
        c.argument('orderby', help='Order the items in the results. Default to alphabetical order of names.', arg_type=get_enum_type(['time_asc', 'time_desc']))
        c.argument('detail', help='Show detailed information.', action='store_true')
        c.argument('delete_enabled', help='Indicates whether delete operation is allowed.', arg_type=get_three_state_flag())
        c.argument('list_enabled', help='Indicates whether this item shows in list operation results.', arg_type=get_three_state_flag())
        c.argument('read_enabled', help='Indicates whether read operation is allowed.', arg_type=get_three_state_flag())
        c.argument('write_enabled', help='Indicates whether write or delete operation is allowed.', arg_type=get_three_state_flag())

    with self.argument_context('acr repository untag') as c:
        c.argument('image', options_list=['--image', '-t'], help="The name of the image. May include a tag in the format 'name:tag'.")

    with self.argument_context('acr create') as c:
        c.argument('registry_name', completer=None)
        c.argument('deployment_name', validator=None)
        c.argument('location', validator=get_default_location_from_resource_group)
        c.argument('workspace', is_preview=True,
                   help='Name or ID of the Log Analytics workspace to send registry diagnostic logs to. All events will be enabled. You can use "az monitor log-analytics workspace create" to create one. Extra billing may apply.')

    with self.argument_context('acr check-name') as c:
        c.argument('registry_name', completer=None)

    with self.argument_context('acr webhook') as c:
        c.argument('registry_name', options_list=['--registry', '-r'])
        c.argument('webhook_name', options_list=['--name', '-n'], help='The name of the webhook', completer=get_resource_name_completion_list(WEBHOOK_RESOURCE_TYPE))
        c.argument('uri', help='The service URI for the webhook to post notifications.')
        c.argument('headers', nargs='+', help="Space-separated custom headers in 'key[=value]' format that will be added to the webhook notifications. Use {} to clear existing headers.".format(quotes), validator=validate_headers)
        c.argument('actions', nargs='+', help='Space-separated list of actions that trigger the webhook to post notifications.', arg_type=get_enum_type(WebhookAction))
        c.argument('status', help='Indicates whether the webhook is enabled.', arg_type=get_enum_type(WebhookStatus))
        c.argument('scope', help="The scope of repositories where the event can be triggered. For example, 'foo:*' means events for all tags under repository 'foo'. 'foo:bar' means events for 'foo:bar' only. 'foo' is equivalent to 'foo:latest'. Empty means events for all repositories.")

    with self.argument_context('acr webhook create') as c:
        c.argument('webhook_name', completer=None)

    with self.argument_context('acr replication') as c:
        c.argument('registry_name', options_list=['--registry', '-r'])
        c.argument('replication_name', options_list=['--name', '-n'], help='The name of the replication.', completer=get_resource_name_completion_list(REPLICATION_RESOURCE_TYPE))

    with self.argument_context('acr replication create') as c:
        c.argument('replication_name', help='The name of the replication. Default to the location name.', completer=None)

    with self.argument_context('acr run') as c:
        c.argument('registry_name', options_list=['--registry', '-r'])
        c.positional('source_location', help="The local source code directory path (e.g., './src') or the URL to a git repository (e.g., 'https://github.com/Azure-Samples/acr-build-helloworld-node.git') or a remote tarball (e.g., 'http://server/context.tar.gz'). If '/dev/null' is specified, the value will be set to None and ignored.", completer=FilesCompleter())
        c.argument('file', options_list=['--file', '-f'], help="The task template/definition file path relative to the source context. It can be '-' to pipe a file from the standard input.")
        c.argument('values', help="The task values file path relative to the source context.")
        c.argument('set_value', options_list=['--set'], help="Value in 'name[=value]' format. Multiples supported by passing --set multiple times.", action='append', validator=validate_set)
        c.argument('set_secret', help="Secret value in '--set name[=value]' format. Multiples supported by passing --set multiple times.", action='append', validator=validate_set_secret)

    with self.argument_context('acr pack build') as c:
        c.argument('registry_name', options_list=['--registry', '-r'])
        c.argument('image_name', options_list=['--image', '-t'], help="The name and tag of the image using the format: '-t repo/image:tag'.")
        c.argument('builder', options_list=['--builder', '-b'], help="The name and tag of a Buildpack builder image.")
        c.argument('pack_image_tag', options_list=['--pack-image-tag'], help="The tag of the 'pack' runner image ('mcr.microsoft.com/oryx/pack').", is_preview=True)
        c.argument('pull', options_list=['--pull'], help="Pull the latest builder and run images before use.", action='store_true')
        c.positional('source_location', help="The local source code directory path (e.g., './src') or the URL to a git repository (e.g., 'https://github.com/Azure-Samples/acr-build-helloworld-node.git') or a remote tarball (e.g., 'http://server/context.tar.gz').", completer=FilesCompleter())

    with self.argument_context('acr build') as c:
        c.argument('registry_name', options_list=['--registry', '-r'])
        c.positional('source_location', help="The local source code directory path (e.g., './src') or the URL to a git repository (e.g., 'https://github.com/Azure-Samples/acr-build-helloworld-node.git') or a remote tarball (e.g., 'http://server/context.tar.gz').", completer=FilesCompleter())
        c.argument('no_push', help="Indicates whether the image built should be pushed to the registry.", action='store_true')
        c.argument('no_wait', help="Do not wait for the build to complete and return immediately after queuing the build.", action='store_true')
        c.argument('arg', options_list=['--build-arg'], help="Build argument in '--build-arg name[=value]' format. Multiples supported by passing --build-arg multiple times.", action='append', validator=validate_arg)
        c.argument('secret_arg', options_list=['--secret-build-arg'], help="Secret build argument in '--secret-build-arg name[=value]' format. Multiples supported by passing '--secret-build-arg name[=value]' multiple times.", action='append', validator=validate_secret_arg)

    with self.argument_context('acr task') as c:
        c.argument('registry_name', options_list=['--registry', '-r'])
        c.argument('task_name', options_list=['--name', '-n'], help='The name of the task.', completer=get_resource_name_completion_list(TASK_RESOURCE_TYPE))
        c.argument('status', help='The current status of task.', arg_type=get_enum_type(TaskStatus))
        c.argument('with_secure_properties', help="Indicates whether the secure properties of a task should be returned.", action='store_true')

        # DockerBuildStep, FileTaskStep parameters
        c.argument('file', options_list=['--file', '-f'], help="Relative path of the the task/docker file to the source code root folder. Task files must be suffixed with '.yaml' or piped from the standard input using '-'.")
        c.argument('image', arg_type=image_by_tag_or_digest_type)
        c.argument('no_push', help="Indicates whether the image built should be pushed to the registry.", arg_type=get_three_state_flag())
        c.argument('no_cache', help='Indicates whether the image cache is enabled.', arg_type=get_three_state_flag())
        c.argument('values', help="The task values/parameters file path relative to the source context.")

        # common to DockerBuildStep, FileTaskStep and RunTaskStep
        c.argument('context_path', options_list=['--context', '-c'], help="The full URL to the source code repository (Requires '.git' suffix for a github repo). If '/dev/null' is specified, the value will be set to None and ignored.")
        c.argument('arg', help="Build argument in '--arg name[=value]' format. Multiples supported by passing '--arg` multiple times.", action='append', validator=validate_arg)
        c.argument('secret_arg', help="Secret build argument in '--secret-arg name[=value]' format. Multiples supported by passing --secret-arg multiple times.", action='append', validator=validate_secret_arg)
        c.argument('set_value', options_list=['--set'], help="Task value in '--set name[=value]' format. Multiples supported by passing --set multiple times.", action='append', validator=validate_set)
        c.argument('set_secret', help="Secret task value in '--set-secret name[=value]' format. Multiples supported by passing --set-secret multiple times.", action='append', validator=validate_set_secret)

        # Trigger parameters
        c.argument('source_trigger_name', arg_group='Trigger', help="The name of the source trigger.")
        c.argument('commit_trigger_enabled', arg_group='Trigger', help="Indicates whether the source control commit trigger is enabled.", arg_type=get_three_state_flag())
        c.argument('pull_request_trigger_enabled', arg_group='Trigger', help="Indicates whether the source control pull request trigger is enabled. The trigger is disabled by default.", arg_type=get_three_state_flag())
        c.argument('schedule', arg_group='Trigger', help="Schedule for a timer trigger represented as a cron expression. An optional trigger name can be specified using `--schedule name:schedule` format. Multiples supported by passing --schedule multiple times.", action='append')
        c.argument('git_access_token', arg_group='Trigger', help="The access token used to access the source control provider.")
        c.argument('branch', arg_group='Trigger', deprecate_info=c.deprecate(hide=True), help="The source control branch name. Please specify your source branch in the context parameter e.g. https://github.com/Azure-Samples/acr-build-helloworld-node.git#mybranch")
        c.argument('base_image_trigger_name', arg_group='Trigger', help="The name of the base image trigger.")
        c.argument('base_image_trigger_enabled', arg_group='Trigger', help="Indicates whether the base image trigger is enabled.", arg_type=get_three_state_flag())
        c.argument('base_image_trigger_type', arg_group='Trigger', help="The type of the auto trigger for base image dependency updates.", arg_type=get_enum_type(BaseImageTriggerType))
        c.argument('update_trigger_endpoint', arg_group='Trigger', help="The full URL of the endpoint to receive base image update trigger notifications.", is_preview=True)
        c.argument('update_trigger_payload_type', arg_group='Trigger', help="Indicates whether to include metadata about the base image trigger in the payload alongwith the update trigger token, when a notification is sent.", arg_type=get_enum_type(UpdateTriggerPayloadType), is_preview=True)

        # Run related parameters
        c.argument('run_id', help='The unique run identifier.')

        # Run agent parameters
        c.argument('cpu', type=int, help='The CPU configuration in terms of number of cores required for the run.')

        # MSI parameter
        c.argument('assign_identity', nargs='*', help="Assigns managed identities to the task. Use '[system]' to refer to the system-assigned identity or a resource ID to refer to a user-assigned identity. Please see https://aka.ms/acr/tasks/task-create-managed-identity for more information.")

    with self.argument_context('acr task create') as c:
        c.argument('task_name', completer=None)

    with self.argument_context('acr task identity') as c:
        c.argument('identities', options_list=['--identities'], nargs='*', help="Assigns managed identities to the task. Use '[system]' to refer to the system-assigned identity or a resource ID to refer to a user-assigned identity.")

    with self.argument_context('acr task credential') as c:
        # Custom registry credentials
        c.argument('login_server', help="The login server of the custom registry. For instance, 'myregistry.azurecr.io'.", required=True)

    with self.argument_context('acr task run') as c:
        # Update trigger token parameters
        c.argument('update_trigger_token', help="The payload that will be passed back alongwith the base image trigger notification.", is_preview=True)

    with self.argument_context('acr task list-runs') as c:
        c.argument('run_status', help='The current status of run.', arg_type=get_enum_type(RunStatus))
        c.argument('top', help='Limit the number of latest runs in the results.')

    with self.argument_context('acr task update-run') as c:
        c.argument('no_archive', help='Indicates whether the run should be archived.', arg_type=get_three_state_flag())

    for scope in ['acr task credential add', 'acr task credential update']:
        with self.argument_context(scope) as c:
            c.argument('username', options_list=['--username', '-u'], help="The username to login to the custom registry. This can be plain text or a key vault secret URI.")
            c.argument('password', options_list=['--password', '-p'], help="The password to login to the custom registry. This can be plain text or a key vault secret URI.")
            c.argument('use_identity', help="The task managed identity used for the credential. Use '[system]' to refer to the system-assigned identity or a client id to refer to a user-assigned identity. Please see https://aka.ms/acr/tasks/cross-registry-authentication for more information.")

    with self.argument_context('acr task timer') as c:
        # Timer trigger parameters
        c.argument('timer_name', help="The name of the timer trigger.", required=True)
        c.argument('timer_schedule', options_list=['--schedule'], help="The schedule of the timer trigger represented as a cron expression.")
        c.argument('enabled', help="Indicates whether the timer trigger is enabled.", arg_type=get_three_state_flag())

    with self.argument_context('acr taskrun') as c:
        c.argument('registry_name', options_list=['--registry', '-r'])
        c.argument('taskrun_name', options_list=['--name', '-n'], help='The name of the taskrun.', completer=get_resource_name_completion_list(TASKRUN_RESOURCE_TYPE))

    with self.argument_context('acr helm') as c:
        c.argument('resource_group_name', deprecate_info=c.deprecate(hide=True))
        c.argument('repository', help=argparse.SUPPRESS)
        c.argument('version', help='The helm chart version.')

    with self.argument_context('acr helm show') as c:
        c.positional('chart', help='The helm chart name.')

    with self.argument_context('acr helm delete') as c:
        c.positional('chart', help='The helm chart name.')
        c.argument('prov', help='Only delete the provenance file.', action='store_true')

    with self.argument_context('acr helm push') as c:
        c.positional('chart_package', help="The helm chart package.", completer=FilesCompleter())
        c.argument('force', help='Overwrite the existing chart package.', action='store_true')

    with self.argument_context('acr helm install-cli') as c:
        c.argument('client_version', help='The target Helm CLI version. (Attention: Currently, Helm 3 does not work with "az acr helm" commands) ')
        c.argument('install_location', help='Path at which to install Helm CLI (Existing one at the same path will be overwritten)', default=_get_helm_default_install_location())
        c.argument('yes', help='Agree to the license of Helm, and do not prompt for confirmation.')

    with self.argument_context('acr network-rule') as c:
        c.argument('subnet', help='Name or ID of subnet. If name is supplied, `--vnet-name` must be supplied.')
        c.argument('vnet_name', help='Name of a virtual network.')
        c.argument('ip_address', help='IPv4 address or CIDR range.')

    with self.argument_context('acr check-health') as c:
        c.argument('ignore_errors', options_list=['--ignore-errors'], help='Provide all health checks, even if errors are found', action='store_true', required=False)

    with self.argument_context('acr scope-map') as c:
        c.argument('registry_name', options_list=['--registry', '-r'])
        c.argument('description', options_list=['--description'], help='Description for the scope map. Maximum 256 characters are allowed.', required=False)
        c.argument('scope_map_name', options_list=['--name', '-n'], help='The name of the scope map.', required=True)

    valid_actions = "Valid actions are {}".format({action.value for action in ScopeMapActions})
    with self.argument_context('acr scope-map update') as c:
        c.argument('add_repository', options_list=['--add'], nargs='+', action='append', required=False,
                   help='repository permissions to be added. Use the format "--add REPO [ACTION1 ACTION2 ...]" per flag. ' + valid_actions)
        c.argument('remove_repository', options_list=['--remove'], nargs='+', action='append', required=False,
                   help='respsitory permissions to be removed. Use the format "--remove REPO [ACTION1 ACTION2 ...]" per flag. ' + valid_actions)

    with self.argument_context('acr scope-map create') as c:
        c.argument('repository_actions_list', options_list=['--repository'], nargs='+', action='append', required=True,
                   help='repository permissions. Use the format "--repository REPO [ACTION1 ACTION2 ...]" per flag. ' + valid_actions)

    with self.argument_context('acr token') as c:
        c.argument('registry_name', options_list=['--registry', '-r'])
        c.argument('token_name', options_list=['--name', '-n'], help='The name of the token.', required=True)
        c.argument('scope_map_name', options_list=['--scope-map'], help='The name of the scope map associated with the token', required=False)
        c.argument('status', options_list=['--status'], arg_type=get_enum_type(TokenStatus),
                   help='The status of the token', required=False, default="enabled")

    with self.argument_context('acr token create') as c:
        c.argument('scope_map_name', options_list=['--scope-map'],
                   help='The name of the scope map with pre-configured repository permissions. Use "--repository" if you would like CLI to configure one for you')
        c.argument('repository_actions_list', options_list=['--repository'], nargs='+', action='append',
                   help='repository permissions. Use the format "--repository REPO [ACTION1 ACTION2 ...]" per flag. ' + valid_actions)
        c.argument('no_passwords', arg_type=get_three_state_flag(), help='Do not generate passwords, instead use "az acr token credential generate"')

    with self.argument_context('acr token update') as c:
        c.argument('scope_map_name', options_list=['--scope-map'], help='The name of the scope map associated with the token. If not specified, running this command will disassociate the current scope map related to the token.', required=False)

    with self.argument_context('acr token credential generate') as c:
        c.argument('password1', options_list=['--password1'], help='Flag indicating if password1 should be generated.', action='store_true', required=False)
        c.argument('password2', options_list=['--password2'], help='Flag indicating if password2 should be generated.', action='store_true', required=False)
        c.argument('days', options_list=['--days'], help='Number of days for which the credentials will be valid. If not specified, the expiration will default to the max value "9999-12-31T23:59:59.999999+00:00"', type=int, required=False)

    with self.argument_context('acr token credential delete') as c:
        c.argument('password1', options_list=['--password1'], help='Flag indicating if first password should be deleted', action='store_true', required=False)
        c.argument('password2', options_list=['--password2'], help='Flag indicating if second password should be deleted.', action='store_true', required=False)

    with self.argument_context('acr private-endpoint-connection') as c:
        # to match private_endpoint_connection_command_guideline.md guidelines
        c.argument('registry_name', options_list=['--registry-name', '-r'], help='The name of the container registry. You can configure the default registry name using `az configure --defaults acr=<registry name>`', completer=get_resource_name_completion_list(REGISTRY_RESOURCE_TYPE), configured_default='acr')
        c.argument('private_endpoint_connection_name', options_list=['--name', '-n'], help='The name of the private endpoint connection')

        c.argument('approval_description', options_list=['--description'], help='Approval description. For example, the reason for approval.')
        c.argument('rejection_description', options_list=['--description'], help='Rejection description. For example, the reason for rejection.')

    with self.argument_context('acr identity') as c:
        c.argument('identities', nargs='+', help="Space-separated identities. Use '[system]' to refer to the system assigned identity")

    with self.argument_context('acr encryption') as c:
        c.argument('key_encryption_key', help="key vault key uri")
        c.argument('identity', help="client id of managed identity, resource name or id of user assigned identity. Use '[system]' to refer to the system assigned identity")
Пример #22
0
existing_policy_definition_name_type = CliArgumentType(options_list=('--name', '-n'), completer=get_policy_completion_list, help='The policy definition name')
register_cli_argument('resource policy', 'resource_group_name', arg_type=resource_group_name_type, help='the resource group where the policy will be applied')
register_cli_argument('resource policy definition', 'policy_definition_name', arg_type=existing_policy_definition_name_type)
register_cli_argument('resource policy definition create', 'name', options_list=('--name', '-n'), help='name of the new policy definition')
register_cli_argument('resource policy definition', 'rules', help='JSON formatted string or a path to a file with such content')
register_cli_argument('resource policy definition', 'display_name', help='display name of policy definition')
register_cli_argument('resource policy definition', 'description', help='description of policy definition')
register_cli_argument('resource policy assignment', 'name', options_list=('--name', '-n'), completer=get_policy_assignment_completion_list, help='name of the assignment')
register_cli_argument('resource policy assignment create', 'name', options_list=('--name', '-n'), help='name of the new assignment')
register_cli_argument('resource policy assignment', 'scope', help='scope at which this policy assignment applies to, e.g., /subscriptions/0b1f6471-1bf0-4dda-aec3-111122223333, /subscriptions/0b1f6471-1bf0-4dda-aec3-111122223333/resourceGroups/myGroup, or /subscriptions/0b1f6471-1bf0-4dda-aec3-111122223333/resourceGroups/myGroup/providers/Microsoft.Compute/virtualMachines/myVM')
register_cli_argument('resource policy assignment', 'disable_scope_strict_match', action='store_true', help='include assignment either inhertied from parent scope or at child scope')
register_cli_argument('resource policy assignment', 'display_name', help='display name of the assignment')
register_cli_argument('resource policy assignment', 'policy', help='policy name or fully qualified id', completer=get_policy_completion_list)

register_cli_argument('resource group', 'resource_group_name', resource_group_name_type, options_list=('--name', '-n'))
register_cli_argument('resource group deployment', 'resource_group_name', arg_type=resource_group_name_type, completer=get_resource_group_completion_list)
register_cli_argument('resource group deployment', 'deployment_name', options_list=('--name', '-n'), required=True, help='The deployment name.')
register_cli_argument('resource group deployment', 'parameters', completer=FilesCompleter(), help="provide deployment parameter values, either json string, or use '@<file path>' to load from a file")
register_cli_argument('resource group deployment', 'template_file', completer=FilesCompleter(), help="a template file path in the file system")
register_cli_argument('resource group deployment', 'template_uri', completer=FilesCompleter(), help='a uri to a remote template file')
register_cli_argument('resource group deployment', 'mode', help='Incremental (only add resources to resource group) or Complete (remove extra resources from resource group)', **enum_choice_list(DeploymentMode))
register_cli_argument('resource group deployment create', 'deployment_name', options_list=('--name', '-n'), required=False,
                      validator=validate_deployment_name, help='The deployment name. Default to template file base name')
register_cli_argument('resource group export', 'include_comments', action='store_true')
register_cli_argument('resource group export', 'include_parameter_default_value', action='store_true')
register_cli_argument('resource group create', 'resource_group_name', completer=None)

register_cli_argument('tag', 'tag_name', options_list=('--name', '-n'))
register_cli_argument('tag', 'tag_value', options_list=('--value',))
Пример #23
0
    def _get_arg_parser(self, doc_parser=False):
        description = textwrap.dedent(__doc__)

        examples = textwrap.dedent('''
            mdt-math-img fiso.nii ficvf.nii '(1-input[0]) * i[1]' -o Wic.w.nii.gz
            mdt-math-img fiso.nii ficvf.nii '(1-a) * b' -o Wic.w.nii.gz
            mdt-math-img *.nii.gz 'np.mean(np.concatenate(i, axis=3), axis=3)' -o output.nii.gz
            mdt-math-img FA.nii.gz 'np.mean(a)'
            mdt-math-img FA.nii white_matter_mask.nii 'np.mean(mdt.create_roi(a, b))'
            mdt-math-img images*.nii.gz mask.nii 'list(map(lambda f: np.mean(mdt.create_roi(f, i[-1])), i[0:-1]))'
            mdt-math-img FA.nii.gz
            mdt-math-img timeseries.nii '[a[..., ind] for ind in range(a.shape[-1])]' -o split.nii
           ''')
        epilog = self._format_examples(doc_parser, examples)

        parser = argparse.ArgumentParser(
            description=description,
            epilog=epilog,
            formatter_class=argparse.RawTextHelpFormatter)

        parser.add_argument('input_files',
                            metavar='input_files',
                            nargs="+",
                            type=str,
                            help="The input images to use")

        parser.add_argument('expr',
                            metavar='expr',
                            type=str,
                            help="The expression/statement to evaluate.")

        parser.add_argument(
            '-e',
            '--as-expression',
            dest='as_expression',
            action='store_true',
            help="Evaluates the given string as an expression (default).")
        parser.add_argument('-s',
                            '--as-statement',
                            dest='as_expression',
                            action='store_false',
                            help="Evaluates the given string as an statement.")
        parser.set_defaults(as_expression=True)

        parser.add_argument('-o', '--output-file',
                            help='the output file, if not set nothing is written').completer = \
            FilesCompleter(['nii', 'gz', 'hdr', 'img'], directories=False)

        parser.add_argument(
            '-4d',
            '--input-4d',
            action='store_true',
            help=
            'Add a singleton dimension to all input 3d maps to make them 4d, this prevents '
            'some broadcast issues.')

        parser.add_argument('--verbose',
                            '-v',
                            action='store_true',
                            help="Verbose, prints runtime information")

        return parser
Пример #24
0
def load_arguments(self, _):  # pylint: disable=too-many-statements
    # Arguments for IoT DPS
    with self.argument_context('iot dps') as c:
        c.argument('dps_name',
                   dps_name_type,
                   options_list=['--name', '-n'],
                   id_part='name')

    with self.argument_context('iot dps create') as c:
        c.argument(
            'location',
            get_location_type(self.cli_ctx),
            help=
            'Location of your IoT Provisioning Service. Default is the location of target resource group.'
        )
        c.argument('sku',
                   arg_type=get_enum_type(IotDpsSku),
                   help='Pricing tier for the IoT provisioning service.')
        c.argument('unit',
                   help='Units in your IoT Provisioning Service.',
                   type=int)

    for subgroup in ['access-policy', 'linked-hub', 'certificate']:
        with self.argument_context('iot dps {}'.format(subgroup)) as c:
            c.argument('dps_name', options_list=['--dps-name'], id_part=None)

    with self.argument_context('iot dps access-policy') as c:
        c.argument('access_policy_name',
                   options_list=['--access-policy-name', '--name', '-n'],
                   help='A friendly name for DPS access policy.')

    with self.argument_context('iot dps access-policy create') as c:
        c.argument(
            'rights',
            options_list=['--rights', '-r'],
            nargs='+',
            arg_type=get_enum_type(AccessRightsDescription),
            help=
            'Access rights for the IoT provisioning service. Use space-separated list for multiple rights.'
        )
        c.argument('primary_key', help='Primary SAS key value.')
        c.argument('secondary_key', help='Secondary SAS key value.')

    with self.argument_context('iot dps access-policy update') as c:
        c.argument(
            'rights',
            options_list=['--rights', '-r'],
            nargs='+',
            arg_type=get_enum_type(AccessRightsDescription),
            help=
            'Access rights for the IoT provisioning service. Use space-separated list for multiple rights.'
        )
        c.argument('primary_key', help='Primary SAS key value.')
        c.argument('secondary_key', help='Secondary SAS key value.')

    with self.argument_context('iot dps linked-hub') as c:
        c.argument('linked_hub',
                   options_list=['--linked-hub'],
                   help='Host name of linked IoT Hub.')

    with self.argument_context('iot dps linked-hub create') as c:
        c.argument('connection_string',
                   help='Connection string of the IoT hub.')
        c.argument('location',
                   get_location_type(self.cli_ctx),
                   help='Location of the IoT hub.')
        c.argument(
            'apply_allocation_policy',
            help=
            'A boolean indicating whether to apply allocation policy to the IoT hub.',
            arg_type=get_three_state_flag())
        c.argument('allocation_weight',
                   help='Allocation weight of the IoT hub.')

    with self.argument_context('iot dps linked-hub update') as c:
        c.argument(
            'apply_allocation_policy',
            help=
            'A boolean indicating whether to apply allocation policy to the Iot hub.',
            arg_type=get_three_state_flag())
        c.argument('allocation_weight',
                   help='Allocation weight of the IoT hub.')

    with self.argument_context('iot dps allocation-policy update') as c:
        c.argument('allocation_policy',
                   options_list=['--policy', '-p'],
                   arg_type=get_enum_type(AllocationPolicy),
                   help='Allocation policy for the IoT provisioning service.')

    with self.argument_context('iot dps certificate') as c:
        c.argument('certificate_path',
                   options_list=['--path', '-p'],
                   type=file_type,
                   completer=FilesCompleter([".cer", ".pem"]),
                   help='The path to the file containing the certificate.')
        c.argument('certificate_name',
                   options_list=['--certificate-name', '--name', '-n'],
                   help='A friendly name for the certificate.')
        c.argument('etag',
                   options_list=['--etag', '-e'],
                   help='Entity Tag (etag) of the object.')

    # Arguments for IoT Hub
    with self.argument_context('iot hub') as c:
        c.argument('hub_name',
                   hub_name_type,
                   options_list=['--name', '-n'],
                   id_part='name')
        c.argument('etag',
                   options_list=['--etag', '-e'],
                   help='Entity Tag (etag) of the object.')

    for subgroup in [
            'consumer-group', 'policy', 'job', 'certificate',
            'routing-endpoint', 'route'
    ]:
        with self.argument_context('iot hub {}'.format(subgroup)) as c:
            c.argument('hub_name', options_list=['--hub-name'])

    with self.argument_context('iot hub route') as c:
        c.argument('route_name',
                   options_list=['--route-name', '--name', '-n'],
                   help='Name of the Route.')
        c.argument('endpoint_name',
                   options_list=['--endpoint-name', '--endpoint', '--en'],
                   help='Name of the routing endpoint.')
        c.argument(
            'condition',
            options_list=['--condition', '-c'],
            help='Condition that is evaluated to apply the routing rule.')
        c.argument(
            'enabled',
            options_list=['--enabled', '-e'],
            arg_type=get_three_state_flag(),
            help='A boolean indicating whether to enable route to the Iot hub.'
        )
        c.argument('source_type',
                   arg_type=get_enum_type(RouteSourceType),
                   options_list=['--source-type', '--type', '--source', '-s'],
                   help='Source of the route.')

    with self.argument_context('iot hub route test') as c:
        c.argument('body',
                   options_list=['--body', '-b'],
                   help='Body of the route message.')
        c.argument('app_properties',
                   options_list=['--app-properties', '--ap'],
                   help='App properties of the route message.')
        c.argument('system_properties',
                   options_list=['--system-properties', '--sp'],
                   help='System properties of the route message.')

    with self.argument_context('iot hub routing-endpoint') as c:
        c.argument('endpoint_name',
                   options_list=['--endpoint-name', '--name', '-n'],
                   help='Name of the Routing Endpoint.')
        c.argument('endpoint_resource_group',
                   options_list=['--endpoint-resource-group', '--erg', '-r'],
                   help='Resource group of the Endpoint resoure.')
        c.argument('endpoint_subscription_id',
                   options_list=['--endpoint-subscription-id', '-s'],
                   help='SubscriptionId of the Endpoint resource.')
        c.argument('connection_string',
                   options_list=['--connection-string', '-c'],
                   help='Connection string of the Routing Endpoint.')
        c.argument('container_name',
                   options_list=['--container-name', '--container'],
                   help='Name of the storage container.')
        c.argument('endpoint_type',
                   arg_type=get_enum_type(EndpointType),
                   options_list=['--endpoint-type', '--type', '-t'],
                   help='Type of the Routing Endpoint.')
        c.argument(
            'encoding',
            options_list=['--encoding'],
            arg_type=get_enum_type(EncodingFormat),
            help='Encoding format for the container. The default is AVRO. '
            'Note that this field is applicable only for blob container endpoints.'
        )

    with self.argument_context('iot hub certificate') as c:
        c.argument('certificate_path',
                   options_list=['--path', '-p'],
                   type=file_type,
                   completer=FilesCompleter([".cer", ".pem"]),
                   help='The path to the file containing the certificate.')
        c.argument('certificate_name',
                   options_list=['--name', '-n'],
                   help='A friendly name for the certificate.')

    with self.argument_context('iot hub consumer-group') as c:
        c.argument('consumer_group_name',
                   options_list=['--name', '-n'],
                   id_part='child_name_2',
                   help='Event hub consumer group name.')
        c.argument('event_hub_name',
                   id_part='child_name_1',
                   help='Event hub endpoint name.')

    with self.argument_context('iot hub policy') as c:
        c.argument('policy_name',
                   options_list=['--name', '-n'],
                   id_part='child_name_1',
                   help='Shared access policy name.')
        permission_values = ', '.join([x.value for x in SimpleAccessRights])
        c.argument(
            'permissions',
            nargs='*',
            validator=validate_policy_permissions,
            type=str.lower,
            help=
            'Permissions of shared access policy. Use space-separated list for multiple permissions. '
            'Possible values: {}'.format(permission_values))

    with self.argument_context('iot hub job') as c:
        c.argument('job_id', id_part='child_name_1', help='Job Id.')

    with self.argument_context('iot hub create') as c:
        c.argument('hub_name', completer=None)
        c.argument(
            'location',
            get_location_type(self.cli_ctx),
            help=
            'Location of your IoT Hub. Default is the location of target resource group.'
        )
        c.argument(
            'sku',
            arg_type=get_enum_type(IotHubSku),
            help=
            'Pricing tier for Azure IoT Hub. Default value is F1, which is free. '
            'Note that only one free IoT hub instance is allowed in each '
            'subscription. Exception will be thrown if free instances exceed one.'
        )
        c.argument('unit', help='Units in your IoT Hub.', type=int)
        c.argument(
            'partition_count',
            help=
            'The number of partitions of the backing Event Hub for device-to-cloud messages.',
            type=int)

    with self.argument_context('iot hub show-connection-string') as c:
        c.argument('policy_name', help='Shared access policy to use.')
        c.argument('key_type',
                   arg_type=get_enum_type(KeyType),
                   options_list=['--key'],
                   help='The key to use.')
Пример #25
0
def load_arguments(self, _):  # pylint: disable=too-many-statements
    with self.argument_context('acr') as c:
        c.argument('resource_group_name', arg_type=resource_group_name_type)
        c.argument('location', arg_type=get_location_type(self.cli_ctx))
        c.argument('tags', arg_type=tags_type)
        c.argument(
            'registry_name',
            options_list=['--name', '-n'],
            help=
            'The name of the container registry. You can configure the default registry name using `az configure --defaults acr=<registry name>`',
            completer=get_resource_name_completion_list(
                REGISTRY_RESOURCE_TYPE),
            configured_default='acr')
        c.argument(
            'storage_account_name',
            help=
            'Provide the name of an existing storage account if you\'re recreating a container registry over a previous registry created storage account. Only applicable to Classic SKU.',
            completer=get_resource_name_completion_list(STORAGE_RESOURCE_TYPE))
        c.argument('sku',
                   help='The SKU of the container registry',
                   arg_type=get_enum_type(MANAGED_REGISTRY_SKU +
                                          CLASSIC_REGISTRY_SKU))
        c.argument('admin_enabled',
                   help='Indicates whether the admin user is enabled',
                   arg_type=get_three_state_flag())
        c.argument('password_name',
                   help='The name of password to regenerate',
                   arg_type=get_enum_type(PasswordName))
        c.argument('username',
                   options_list=['--username', '-u'],
                   help='The username used to log into a container registry')
        c.argument('password',
                   options_list=['--password', '-p'],
                   help='The password used to log into a container registry')
        c.argument('image_names', arg_type=image_by_tag_type, action='append')
        c.argument('timeout', type=int, help='The build timeout in seconds.')
        c.argument(
            'docker_file_path',
            options_list=['--file', '-f'],
            help=
            "The relative path of the the docker file to the source code root folder."
        )
        c.argument('build_arg',
                   help="Build argument in 'name[=value]' format.",
                   action='append',
                   validator=validate_build_arg)
        c.argument('secret_build_arg',
                   help="Secret build argument in 'name[=value]' format.",
                   action='append',
                   validator=validate_secret_build_arg)
        c.argument(
            'no_logs',
            help="Do not show logs after successfully queuing the build.",
            action='store_true')
        c.argument('os_type',
                   options_list=['--os'],
                   help='The operating system type required for the build.',
                   arg_type=get_enum_type(OsType))

    with self.argument_context('acr import') as c:
        c.argument(
            'source',
            help=
            "The source identifier in the format '[registry.azurecr.io/]repository[:tag]' or '[registry.azurecr.io/]repository@digest'."
        )
        c.argument(
            'source_registry',
            options_list=['--registry', '-r'],
            help=
            'The source container registry can be name, login server or resource ID of the source registry.'
        )
        c.argument('target_tags', arg_type=image_by_tag_type, action='append')
        c.argument(
            'repository',
            help='The repository name to do a manifest-only copy for images.',
            action='append')
        c.argument(
            'force',
            help='Overwrite the existing tag of the image to be imported.',
            action='store_true')

    with self.argument_context('acr config content-trust') as c:
        c.argument(
            'status',
            help="Indicates whether content-trust is enabled or disabled.",
            arg_type=get_enum_type(PolicyStatus))

    with self.argument_context('acr repository') as c:
        c.argument('repository', help="The name of the repository.")
        c.argument('image', arg_type=image_by_tag_or_digest_type)
        c.argument('yes',
                   options_list=['--yes', '-y'],
                   help='Do not prompt for confirmation.',
                   action='store_true')
        c.argument('top',
                   type=int,
                   help='Limit the number of items in the results.')
        c.argument(
            'orderby',
            help=
            'Order the items in the results. Default to alphabetical order of names.',
            arg_type=get_enum_type(['time_asc', 'time_desc']))
        c.argument('detail',
                   help='Show detailed information.',
                   action='store_true')
        c.argument('delete_enabled',
                   help='Indicates whether delete operation is allowed.',
                   arg_type=get_three_state_flag())
        c.argument(
            'list_enabled',
            help='Indicates whether this item shows in list operation results.',
            arg_type=get_three_state_flag())
        c.argument('read_enabled',
                   help='Indicates whether read operation is allowed.',
                   arg_type=get_three_state_flag())
        c.argument(
            'write_enabled',
            help='Indicates whether write or delete operation is allowed.',
            arg_type=get_three_state_flag())

    with self.argument_context('acr repository delete') as c:
        c.argument('manifest',
                   nargs='?',
                   required=False,
                   const='',
                   default=None,
                   help=argparse.SUPPRESS)
        c.argument('tag', help=argparse.SUPPRESS)

    with self.argument_context('acr repository untag') as c:
        c.argument('image', arg_type=image_by_tag_type)

    with self.argument_context('acr create') as c:
        c.argument('registry_name',
                   completer=None,
                   validator=validate_registry_name)
        c.argument('deployment_name',
                   arg_type=deployment_name_type,
                   validator=None)
        c.argument('location',
                   arg_type=get_location_type(self.cli_ctx),
                   validator=get_default_location_from_resource_group)

    with self.argument_context('acr check-name') as c:
        c.argument('registry_name', completer=None)

    with self.argument_context('acr webhook') as c:
        c.argument('registry_name', options_list=['--registry', '-r'])
        c.argument(
            'webhook_name',
            options_list=['--name', '-n'],
            help='The name of the webhook',
            completer=get_resource_name_completion_list(WEBHOOK_RESOURCE_TYPE))
        c.argument(
            'uri',
            help='The service URI for the webhook to post notifications.')
        c.argument(
            'headers',
            nargs='+',
            help=
            "Space-separated custom headers in 'key[=value]' format that will be added to the webhook notifications. Use {} to clear existing headers."
            .format(quotes),
            validator=validate_headers)
        c.argument(
            'actions',
            nargs='+',
            help=
            'Space-separated list of actions that trigger the webhook to post notifications.',
            arg_type=get_enum_type(WebhookAction))
        c.argument('status',
                   help='Indicates whether the webhook is enabled.',
                   arg_type=get_enum_type(WebhookStatus))
        c.argument(
            'scope',
            help=
            "The scope of repositories where the event can be triggered. For example, 'foo:*' means events for all tags under repository 'foo'. 'foo:bar' means events for 'foo:bar' only. 'foo' is equivalent to 'foo:latest'. Empty means events for all repositories."
        )

    with self.argument_context('acr webhook create') as c:
        c.argument('webhook_name', completer=None)

    with self.argument_context('acr replication') as c:
        c.argument('registry_name', options_list=['--registry', '-r'])
        c.argument('replication_name',
                   options_list=['--name', '-n'],
                   help='The name of the replication.',
                   completer=get_resource_name_completion_list(
                       REPLICATION_RESOURCE_TYPE))

    with self.argument_context('acr replication create') as c:
        c.argument(
            'replication_name',
            help='The name of the replication. Default to the location name.',
            completer=None)

    with self.argument_context('acr build') as c:
        c.argument('registry_name', options_list=['--registry', '-r'])
        c.positional(
            'source_location',
            help=
            "The local source code directory path (e.g., './src') or the URL to a git repository (e.g., 'https://github.com/Azure-Samples/acr-build-helloworld-node.git') or a remote tarball (e.g., 'http://server/context.tar.gz').",
            completer=FilesCompleter())
        c.argument(
            'no_push',
            help=
            "Indicates whether the image built should be pushed to the registry.",
            action='store_true')

    with self.argument_context('acr build-task') as c:
        c.argument('registry_name', options_list=['--registry', '-r'])
        # build task parameters
        c.argument('build_task_name',
                   options_list=['--name', '-n'],
                   help='The name of the build task.',
                   completer=get_resource_name_completion_list(
                       BUILD_TASK_RESOURCE_TYPE))
        c.argument(
            'alias',
            help=
            'The alternative name for build task. Default to the build task name.'
        )
        c.argument('status',
                   help='The current status of build task.',
                   arg_type=get_enum_type(BuildTaskStatus))
        c.argument(
            'cpu',
            type=int,
            help=
            'The CPU configuration in terms of number of cores required for the build.'
        )
        c.argument('repository_url',
                   options_list=['--context', '-c'],
                   help="The full URL to the source code respository.")
        c.argument(
            'commit_trigger_enabled',
            help=
            "Indicates whether the source control commit trigger is enabled.",
            arg_type=get_three_state_flag())
        c.argument(
            'git_access_token',
            help="The access token used to access the source control provider."
        )
        c.argument(
            'with_secure_properties',
            help=
            "Indicates whether the secure properties of a build task should be returned.",
            action='store_true')
        # build step parameters
        c.argument('step_name',
                   help='The name of the build step.',
                   completer=get_resource_name_completion_list(
                       BUILD_STEP_RESOURCE_TYPE))
        c.argument('branch', help="The source control branch name.")
        c.argument(
            'no_push',
            help=
            "Indicates whether the image built should be pushed to the registry.",
            arg_type=get_three_state_flag())
        c.argument('no_cache',
                   help='Indicates whether the image cache is enabled.',
                   arg_type=get_three_state_flag())
        c.argument(
            'base_image_trigger',
            help=
            "The type of the auto trigger for base image dependency updates.",
            arg_type=get_enum_type(BaseImageTriggerType))
        # build parameters
        c.argument('top',
                   help='Limit the number of latest builds in the results.')
        c.argument('build_id', help='The unique build identifier.')
        c.argument('build_status',
                   help='The current status of build.',
                   arg_type=get_enum_type(BuildStatus))
        c.argument('image', arg_type=image_by_tag_or_digest_type)
        c.argument('no_archive',
                   help='Indicates whether the build should be archived.',
                   arg_type=get_three_state_flag())

    with self.argument_context('acr build-task create') as c:
        c.argument('build_task_name', completer=None)
Пример #26
0
def load_arguments(self, _):  # pylint: disable=too-many-locals, too-many-statements
    from argcomplete.completers import FilesCompleter
    from knack.arguments import CLIArgumentType

    from azure.cli.core.commands.parameters import get_resource_name_completion_list

    from .sdkutil import get_table_data_type
    from .completers import get_storage_name_completion_list, get_container_name_completions

    t_file_service = self.get_sdk('file#FileService')
    t_table_service = get_table_data_type(self.cli_ctx, 'table',
                                          'TableService')

    acct_name_type = CLIArgumentType(
        options_list=['--account-name', '-n'],
        help='The storage account name.',
        id_part='name',
        completer=get_resource_name_completion_list(
            'Microsoft.Storage/storageAccounts'))
    container_name_type = CLIArgumentType(
        options_list=['--container-name', '-c'],
        help='The container name.',
        completer=get_container_name_completions)
    directory_type = CLIArgumentType(
        options_list=['--directory-name', '-d'],
        help='The directory name.',
        completer=get_storage_name_completion_list(
            t_file_service, 'list_directories_and_files', parent='share_name'))
    share_name_type = CLIArgumentType(
        options_list=['--share-name', '-s'],
        help='The file share name.',
        completer=get_storage_name_completion_list(t_file_service,
                                                   'list_shares'))
    table_name_type = CLIArgumentType(
        options_list=['--table-name', '-t'],
        completer=get_storage_name_completion_list(t_table_service,
                                                   'list_tables'))

    with self.argument_context('storage') as c:
        c.argument('container_name', container_name_type)
        c.argument('directory_name', directory_type)
        c.argument('share_name', share_name_type)
        c.argument('table_name', table_name_type)
        c.argument('retry_wait', options_list=('--retry-interval', ))
        c.ignore('progress_callback')
        c.argument(
            'metadata',
            nargs='+',
            help=
            'Metadata in space-separated key=value pairs. This overwrites any existing metadata.',
            validator=validate_metadata)
        c.argument(
            'timeout',
            help=
            'Request timeout in seconds. Applies to each call to the service.',
            type=int)

    with self.argument_context('storage', arg_group='Precondition') as c:
        c.argument(
            'if_modified_since',
            help=
            'Alter only if modified since supplied UTC datetime (Y-m-d\'T\'H:M\'Z\')',
            type=get_datetime_type(False))
        c.argument(
            'if_unmodified_since',
            help=
            'Alter only if unmodified since supplied UTC datetime (Y-m-d\'T\'H:M\'Z\')',
            type=get_datetime_type(False))
        c.argument('if_match')
        c.argument('if_none_match')

    for item in [
            'delete', 'show', 'update', 'show-connection-string', 'keys',
            'network-rule', 'failover'
    ]:
        with self.argument_context('storage account {}'.format(item)) as c:
            c.argument('account_name',
                       acct_name_type,
                       options_list=['--name', '-n'])
            c.argument('resource_group_name',
                       required=False,
                       validator=process_resource_group)

    with self.argument_context('storage account check-name') as c:
        c.argument('name', options_list=['--name', '-n'])

    with self.argument_context('storage account create') as c:
        t_account_type, t_sku_name, t_kind = self.get_models(
            'AccountType',
            'SkuName',
            'Kind',
            resource_type=CUSTOM_MGMT_STORAGE)
        c.register_common_storage_account_options()
        c.argument(
            'hierarchical_namespace',
            help='Allows the blob service to exhibit filesystem semantics.',
            arg_type=get_three_state_flag())
        c.argument('location',
                   get_location_type(self.cli_ctx),
                   validator=get_default_location_from_resource_group)
        c.argument('account_type',
                   help='The storage account type',
                   arg_type=get_enum_type(t_account_type))
        c.argument('account_name',
                   acct_name_type,
                   options_list=['--name', '-n'],
                   completer=None)
        c.argument('kind',
                   help='Indicates the type of storage account.',
                   arg_type=get_enum_type(t_kind, default='storage'))
        c.argument('tags', tags_type)
        c.argument(
            'custom_domain',
            help=
            'User domain assigned to the storage account. Name is the CNAME source.'
        )
        c.argument('sku',
                   help='The storage account SKU.',
                   arg_type=get_enum_type(t_sku_name,
                                          default='standard_ragrs'))

    with self.argument_context('storage account update') as c:
        c.register_common_storage_account_options()
        c.argument(
            'custom_domain',
            help=
            'User domain assigned to the storage account. Name is the CNAME source. Use "" to clear '
            'existing value.',
            validator=validate_custom_domain)
        c.argument('use_subdomain',
                   help='Specify whether to use indirect CNAME validation.',
                   arg_type=get_enum_type(['true', 'false']))
        c.argument('tags', tags_type, default=None)

    with self.argument_context('storage account update',
                               arg_group='Customer managed key',
                               min_api='2017-06-01') as c:
        c.extra(
            'encryption_key_name',
            help='The name of the KeyVault key',
        )
        c.extra('encryption_key_vault', help='The Uri of the KeyVault')
        c.extra('encryption_key_version',
                help='The version of the KeyVault key')
        c.argument(
            'encryption_key_source',
            arg_type=get_enum_type(['Microsoft.Storage', 'Microsoft.Keyvault'],
                                   'Microsoft.Storage'),
            help='The default encryption service',
            validator=validate_encryption_source)
        c.ignore('encryption_key_vault_properties')

    for scope in ['storage account create', 'storage account update']:
        with self.argument_context(scope,
                                   resource_type=CUSTOM_MGMT_STORAGE,
                                   min_api='2017-06-01',
                                   arg_group='Network Rule') as c:
            t_bypass, t_default_action = self.get_models(
                'Bypass', 'DefaultAction', resource_type=CUSTOM_MGMT_STORAGE)

            c.argument('bypass',
                       nargs='+',
                       validator=validate_bypass,
                       arg_type=get_enum_type(t_bypass),
                       help='Bypass traffic for space-separated uses.')
            c.argument('default_action',
                       arg_type=get_enum_type(t_default_action),
                       help='Default action to apply when no rule matches.')

    with self.argument_context('storage account show') as c:
        c.argument('expand',
                   arg_type=get_enum_type(
                       self.get_models('StorageAccountExpand',
                                       resource_type=CUSTOM_MGMT_STORAGE)))

    with self.argument_context('storage account show-connection-string') as c:
        c.argument('protocol',
                   help='The default endpoint protocol.',
                   arg_type=get_enum_type(['http', 'https']))
        c.argument('key_name',
                   options_list=['--key'],
                   help='The key to use.',
                   arg_type=get_enum_type(
                       list(storage_account_key_options.keys())))
        for item in ['blob', 'file', 'queue', 'table']:
            c.argument('{}_endpoint'.format(item),
                       help='Custom endpoint for {}s.'.format(item))

    with self.argument_context('storage account keys renew') as c:
        c.argument('key_name',
                   options_list=['--key'],
                   help='The key to regenerate.',
                   validator=validate_key,
                   arg_type=get_enum_type(
                       list(storage_account_key_options.keys())))
        c.argument('account_name', acct_name_type, id_part=None)

    with self.argument_context('storage account keys list') as c:
        c.argument('account_name', acct_name_type, id_part=None)

    with self.argument_context('storage account network-rule') as c:
        from ._validators import validate_subnet
        c.argument('account_name', acct_name_type, id_part=None)
        c.argument('ip_address', help='IPv4 address or CIDR range.')
        c.argument(
            'subnet',
            help=
            'Name or ID of subnet. If name is supplied, `--vnet-name` must be supplied.'
        )
        c.argument('vnet_name',
                   help='Name of a virtual network.',
                   validator=validate_subnet)
        c.argument('action', help='The action of virtual network rule.')

    with self.argument_context(
            'storage account management-policy create') as c:
        c.argument(
            'policy',
            type=file_type,
            completer=FilesCompleter(),
            help=
            'The Storage Account ManagementPolicies Rules, in JSON format. See more details in: '
            'https://docs.microsoft.com/en-us/azure/storage/common/storage-lifecycle-managment-concepts.'
        )
        c.argument(
            'account_name',
            help=
            'The name of the storage account within the specified resource group.'
        )

    with self.argument_context(
            'storage account management-policy update') as c:
        c.argument(
            'account_name',
            help=
            'The name of the storage account within the specified resource group.'
        )

    with self.argument_context('storage blob service-properties update') as c:
        c.argument('delete_retention',
                   arg_type=get_three_state_flag(),
                   arg_group='Soft Delete',
                   help='Enables soft-delete.')
        c.argument(
            'days_retained',
            type=int,
            arg_group='Soft Delete',
            help=
            'Number of days that soft-deleted blob will be retained. Must be in range [1,365].'
        )
        c.argument('static_website',
                   arg_group='Static Website',
                   arg_type=get_three_state_flag(),
                   help='Enables static-website.')
        c.argument(
            'index_document',
            help=
            'Represents the name of the index document. This is commonly "index.html".',
            arg_group='Static Website')
        c.argument(
            'error_document_404_path',
            options_list=['--404-document'],
            arg_group='Static Website',
            help=
            'Represents the path to the error document that should be shown when an error 404 is issued,'
            ' in other words, when a browser requests a page that does not exist.'
        )
Пример #27
0
You can compile a keymap already in the repo or using a QMK Configurator export.
"""
from subprocess import DEVNULL

from argcomplete.completers import FilesCompleter
from milc import cli

import qmk.path
from qmk.decorators import automagic_keyboard, automagic_keymap
from qmk.commands import compile_configurator_json, create_make_command, parse_configurator_json
from qmk.keyboard import keyboard_completer, keyboard_folder
from qmk.keymap import keymap_completer


@cli.argument('filename', nargs='?', arg_only=True, type=qmk.path.FileType('r'), completer=FilesCompleter('.json'), help='The configurator export to compile')
@cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='The keyboard to build a firmware for. Ignored when a configurator export is supplied.')
@cli.argument('-km', '--keymap', completer=keymap_completer, help='The keymap to build a firmware for. Ignored when a configurator export is supplied.')
@cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't actually build, just show the make command to be run.")
@cli.argument('-j', '--parallel', type=int, default=1, help="Set the number of parallel make jobs to run.")
@cli.argument('-e', '--env', arg_only=True, action='append', default=[], help="Set a variable to be passed to make. May be passed multiple times.")
@cli.argument('-c', '--clean', arg_only=True, action='store_true', help="Remove object files before compiling.")
@cli.subcommand('Compile a QMK Firmware.')
@automagic_keyboard
@automagic_keymap
def compile(cli):
    """Compile a QMK Firmware.

    If a Configurator export is supplied this command will create a new keymap, overwriting an existing keymap if one exists.

    If a keyboard and keymap are provided this command will build a firmware based on that.
Пример #28
0
 def _populate_matches(self, prefix):
     from argcomplete.completers import FilesCompleter
     completer = FilesCompleter()
     self.matches = completer(prefix)
Пример #29
0
register_cli_argument('vmss diagnostics', 'vmss_name', id_part=None, help='Scale set name')

register_cli_argument('vmss extension image', 'publisher_name', options_list=('--publisher', '-p'), help='Image publisher name')
register_cli_argument('vmss extension image', 'type', options_list=('--name', '-n'), help='Extension name')
register_cli_argument('vmss extension image', 'latest', action='store_true')
register_cli_argument('vmss extension image', 'image_name', help='Image name')
register_cli_argument('vmss extension image', 'orderby', help='The sort to apply on the operation')
register_cli_argument('vmss extension image', 'top', help='Return top number of records')
register_cli_argument('vmss extension image', 'version', help='Extension version')

register_cli_argument('vmss extension', 'settings', type=validate_file_or_dict)
register_cli_argument('vmss extension', 'protected_settings', type=validate_file_or_dict)

for scope in ['vm diagnostics', 'vmss diagnostics']:
    register_cli_argument(scope, 'version', help='version of the diagnostics extension. Will use the latest if not specfied')
    register_cli_argument(scope, 'settings', help='json string or a file path, which defines data to be collected.', type=file_type, completer=FilesCompleter())
    register_cli_argument(scope, 'protected_settings', help='json string or a file path containing private configurations such as storage account keys, etc.', type=file_type, completer=FilesCompleter())

for scope in ['vm', 'vmss']:
    register_cli_argument(scope, 'no_auto_upgrade', action='store_true', help='by doing this, extension system will not pick the highest minor version for the specified version number, and will not auto update to the latest build/revision number on any scale set updates in future.')
    register_cli_argument('{} create'.format(scope), 'generate_ssh_keys', action='store_true', help='Generate SSH public and private key files if missing', arg_group='Authentication')


register_cli_argument('vm image list', 'image_location', location_type)
register_cli_argument('vm image', 'publisher_name', options_list=('--publisher', '-p'))
register_cli_argument('vm image', 'offer', options_list=('--offer', '-f'))
register_cli_argument('vm image', 'sku', options_list=('--sku', '-s'))
# overriding skus from the sdk operation to be a single sku
register_cli_argument('vm image show', 'skus', options_list=('--sku', '-s'))

register_cli_argument('vm open-port', 'vm_name', name_arg_type, help='The name of the virtual machine to open inbound traffic on.')
Пример #30
0
def load_arguments(self, _):
    StorageAccountTypes, UpgradeMode, CachingTypes = self.get_models('StorageAccountTypes', 'UpgradeMode', 'CachingTypes')
    OperatingSystemTypes = self.get_models('OperatingSystemTypes')

    # REUSABLE ARGUMENT DEFINITIONS
    name_arg_type = CLIArgumentType(options_list=['--name', '-n'], metavar='NAME')
    multi_ids_type = CLIArgumentType(nargs='+')
    existing_vm_name = CLIArgumentType(overrides=name_arg_type,
                                       configured_default='vm',
                                       help="The name of the Virtual Machine. You can configure the default using `az configure --defaults vm=<name>`",
                                       completer=get_resource_name_completion_list('Microsoft.Compute/virtualMachines'), id_part='name')
    existing_disk_name = CLIArgumentType(overrides=name_arg_type, help='The name of the managed disk', completer=get_resource_name_completion_list('Microsoft.Compute/disks'), id_part='name')
    existing_snapshot_name = CLIArgumentType(overrides=name_arg_type, help='The name of the snapshot', completer=get_resource_name_completion_list('Microsoft.Compute/snapshots'), id_part='name')
    vmss_name_type = CLIArgumentType(name_arg_type,
                                     configured_default='vmss',
                                     completer=get_resource_name_completion_list('Microsoft.Compute/virtualMachineScaleSets'),
                                     help="Scale set name. You can configure the default using `az configure --defaults vmss=<name>`",
                                     id_part='name')

    extension_instance_name_type = CLIArgumentType(help="Name of the vm's instance of the extension. Default: name of the extension.")

    if StorageAccountTypes:
        disk_sku = CLIArgumentType(arg_type=get_enum_type(StorageAccountTypes))
    else:
        # StorageAccountTypes introduced in api version 2016_04_30_preview of Resource.MGMT.Compute package..
        # However, 2017-03-09-profile targets version 2016-03-30 of compute package.
        disk_sku = CLIArgumentType(arg_type=get_enum_type(['Premium_LRS', 'Standard_LRS']))

    # special case for `network nic scale-set list` command alias
    with self.argument_context('network nic scale-set list') as c:
        c.argument('virtual_machine_scale_set_name', options_list=['--vmss-name'], completer=get_resource_name_completion_list('Microsoft.Compute/virtualMachineScaleSets'), id_part='name')

    # region MixedScopes
    for scope in ['vm', 'disk', 'snapshot', 'image', 'sig']:
        with self.argument_context(scope) as c:
            c.argument('tags', tags_type)

    for scope in ['disk', 'snapshot']:
        with self.argument_context(scope) as c:
            c.ignore('source_blob_uri', 'source_disk', 'source_snapshot')
            c.argument('source_storage_account_id', help='used when source blob is in a different subscription')
            c.argument('size_gb', options_list=['--size-gb', '-z'], help='size in GB. Max size: 4095 GB (certain preview disks can be larger).', type=int)
            c.argument('duration_in_seconds', help='Time duration in seconds until the SAS access expires', type=int)

    for scope in ['disk create', 'snapshot create']:
        with self.argument_context(scope) as c:
            c.argument('source', help='source to create the disk/snapshot from, including unmanaged blob uri, managed disk id or name, or snapshot id or name')
    # endregion

    # region Disks
    with self.argument_context('disk') as c:
        c.argument('zone', zone_type, min_api='2017-03-30', options_list=['--zone'])  # TODO: --size-gb currently has claimed -z. We can do a breaking change later if we want to.
        c.argument('disk_name', existing_disk_name, completer=get_resource_name_completion_list('Microsoft.Compute/disks'))
        c.argument('name', arg_type=name_arg_type)
        c.argument('sku', arg_type=disk_sku, help='Underlying storage SKU')
        c.argument('os_type', arg_type=get_enum_type(OperatingSystemTypes), help='The Operating System type of the Disk.')
        c.argument('disk_iops_read_write', type=int, min_api='2018-06-01', help='The number of IOPS allowed for this disk. Only settable for UltraSSD disks. One operation can transfer between 4k and 256k bytes')
        c.argument('disk_mbps_read_write', type=int, min_api='2018-06-01', help="The bandwidth allowed for this disk. Only settable for UltraSSD disks. MBps means millions of bytes per second with ISO notation of powers of 10")
    # endregion

    # region Snapshots
    with self.argument_context('snapshot', resource_type=ResourceType.MGMT_COMPUTE, operation_group='snapshots') as c:
        c.argument('snapshot_name', existing_snapshot_name, id_part='name', completer=get_resource_name_completion_list('Microsoft.Compute/snapshots'))
        c.argument('name', arg_type=name_arg_type)
        if self.supported_api_version(min_api='2018-04-01', operation_group='snapshots'):
            c.argument('sku', arg_type=get_enum_type(['Premium_LRS', 'Standard_LRS', 'Standard_ZRS']))
        else:
            c.argument('sku', arg_type=get_enum_type(['Premium_LRS', 'Standard_LRS']))
    # endregion

    # region Images
    with self.argument_context('image') as c:
        c.argument('os_type', arg_type=get_enum_type(['Windows', 'Linux']))
        c.argument('image_name', arg_type=name_arg_type, id_part='name', completer=get_resource_name_completion_list('Microsoft.Compute/images'))

    with self.argument_context('image create') as c:
        # here we collpase all difference image sources to under 2 common arguments --os-disk-source --data-disk-sources
        c.argument('name', arg_type=name_arg_type, help='new image name')
        c.argument('source', help='OS disk source from the same region, including a virtual machine ID or name, OS disk blob URI, managed OS disk ID or name, or OS snapshot ID or name')
        c.argument('data_disk_sources', nargs='+', help='Space-separated list of data disk sources, including unmanaged blob URI, managed disk ID or name, or snapshot ID or name')
        c.argument('zone_resilient', min_api='2017-12-01', arg_type=get_three_state_flag(), help='Specifies whether an image is zone resilient or not. '
                   'Default is false. Zone resilient images can be created only in regions that provide Zone Redundant Storage')
        c.argument('storage_sku', arg_type=disk_sku, help='The SKU of the storage account with which to create the VM image. Unused if source VM is specified.')
        c.argument('os_disk_caching', arg_type=get_enum_type(CachingTypes), help="Storage caching type for the image's OS disk.")
        c.ignore('source_virtual_machine', 'os_blob_uri', 'os_disk', 'os_snapshot', 'data_blob_uris', 'data_disks', 'data_snapshots')
    # endregion

    # region AvailabilitySets
    with self.argument_context('vm availability-set') as c:
        c.argument('availability_set_name', name_arg_type, id_part='name', completer=get_resource_name_completion_list('Microsoft.Compute/availabilitySets'), help='Name of the availability set')

    with self.argument_context('vm availability-set create') as c:
        c.argument('availability_set_name', name_arg_type, validator=get_default_location_from_resource_group, help='Name of the availability set')
        c.argument('platform_update_domain_count', type=int, help='Update Domain count. If unspecified, the server will pick the most optimal number like 5.')
        c.argument('platform_fault_domain_count', type=int, help='Fault Domain count.')
        c.argument('validate', help='Generate and validate the ARM template without creating any resources.', action='store_true')
        c.argument('unmanaged', action='store_true', min_api='2016-04-30-preview', help='contained VMs should use unmanaged disks')

    with self.argument_context('vm availability-set update') as c:
        if self.supported_api_version(max_api='2016-04-30-preview', operation_group='virtual_machines'):
            c.argument('name', name_arg_type, id_part='name', completer=get_resource_name_completion_list('Microsoft.Compute/availabilitySets'), help='Name of the availability set')
            c.argument('availability_set_name', options_list=['--availability-set-name'])
    # endregion

    # region VirtualMachines
    with self.argument_context('vm') as c:
        c.argument('vm_name', existing_vm_name)
        c.argument('size', completer=get_vm_size_completion_list)
        c.argument('name', arg_type=name_arg_type)
        c.argument('zone', zone_type, min_api='2017-03-30')
        c.argument('caching', help='Disk caching policy', arg_type=get_enum_type(CachingTypes))
        c.argument('nsg', help='The name to use when creating a new Network Security Group (default) or referencing an existing one. Can also reference an existing NSG by ID or specify "" for none.', arg_group='Network')
        c.argument('nsg_rule', help='NSG rule to create when creating a new NSG. Defaults to open ports for allowing RDP on Windows and allowing SSH on Linux.', arg_group='Network', arg_type=get_enum_type(['RDP', 'SSH']))
        c.argument('application_security_groups', min_api='2017-09-01', nargs='+', options_list=['--asgs'], help='Space-separated list of existing application security groups to associate with the VM.', arg_group='Network')

    with self.argument_context('vm capture') as c:
        c.argument('overwrite', action='store_true')

    with self.argument_context('vm update') as c:
        c.argument('os_disk', min_api='2017-12-01', help="Managed OS disk ID or name to swap to")
        c.argument('write_accelerator', nargs='*', min_api='2017-12-01',
                   help="enable/disable disk write accelerator. Use singular value 'true/false' to apply across, or specify individual disks, e.g.'os=true 1=true 2=true' for os disk and data disks with lun of 1 & 2")
        c.argument('disk_caching', nargs='*', help="Use singular value to apply across, or specify individual disks, e.g. 'os=ReadWrite 0=None 1=ReadOnly' should enable update os disk and 2 data disks")

    with self.argument_context('vm create') as c:
        c.argument('name', name_arg_type, validator=_resource_not_exists(self.cli_ctx, 'Microsoft.Compute/virtualMachines'))
        c.argument('vm_name', name_arg_type, id_part=None, help='Name of the virtual machine.', completer=None)
        c.argument('os_disk_size_gb', type=int, help='the size of the os disk in GB', arg_group='Storage')
        c.argument('attach_os_disk', help='Attach an existing OS disk to the VM. Can use the name or ID of a managed disk or the URI to an unmanaged disk VHD.')
        c.argument('attach_data_disks', nargs='+', help='Attach existing data disks to the VM. Can use the name or ID of a managed disk or the URI to an unmanaged disk VHD.')
        c.argument('availability_set', help='Name or ID of an existing availability set to add the VM to. None by default.')
        c.argument('nsg', help='The name to use when creating a new Network Security Group (default) or referencing an existing one. Can also reference an existing NSG by ID or specify "" for none.', arg_group='Network')
        c.argument('nsg_rule', help='NSG rule to create when creating a new NSG. Defaults to open ports for allowing RDP on Windows and allowing SSH on Linux.', arg_group='Network', arg_type=get_enum_type(['RDP', 'SSH']))
        c.argument('application_security_groups', resource_type=ResourceType.MGMT_NETWORK, min_api='2017-09-01', nargs='+', options_list=['--asgs'], help='Space-separated list of existing application security groups to associate with the VM.', arg_group='Network', validator=validate_asg_names_or_ids)
        c.argument('boot_diagnostics_storage',
                   help='pre-existing storage account name or its blob uri to capture boot diagnostics. Its sku should be one of Standard_GRS, Standard_LRS and Standard_RAGRS')
        c.argument('accelerated_networking', resource_type=ResourceType.MGMT_NETWORK, min_api='2016-09-01', arg_type=get_three_state_flag(), arg_group='Network',
                   help="enable accelerated networking. Unless specified, CLI will enable it based on machine image and size")

    with self.argument_context('vm open-port') as c:
        c.argument('vm_name', name_arg_type, help='The name of the virtual machine to open inbound traffic on.')
        c.argument('network_security_group_name', options_list=('--nsg-name',), help='The name of the network security group to create if one does not exist. Ignored if an NSG already exists.', validator=validate_nsg_name)
        c.argument('apply_to_subnet', help='Allow inbound traffic on the subnet instead of the NIC', action='store_true')
        c.argument('port', help="The port or port range (ex: 80-100) to open inbound traffic to. Use '*' to allow traffic to all ports.")
        c.argument('priority', help='Rule priority, between 100 (highest priority) and 4096 (lowest priority). Must be unique for each rule in the collection.', type=int)

    for scope in ['vm show', 'vm list']:
        with self.argument_context(scope) as c:
            c.argument('show_details', action='store_true', options_list=['--show-details', '-d'], help='show public ip address, FQDN, and power states. command will run slow')

    with self.argument_context('vm diagnostics') as c:
        c.argument('vm_name', arg_type=existing_vm_name, options_list=['--vm-name'])

    with self.argument_context('vm diagnostics set') as c:
        c.argument('storage_account', completer=get_resource_name_completion_list('Microsoft.Storage/storageAccounts'))

    with self.argument_context('vm disk') as c:
        c.argument('vm_name', options_list=['--vm-name'], id_part=None, completer=get_resource_name_completion_list('Microsoft.Compute/virtualMachines'))
        c.argument('new', action='store_true', help='create a new disk')
        c.argument('sku', arg_type=disk_sku, help='Underlying storage SKU')
        c.argument('size_gb', options_list=['--size-gb', '-z'], help='size in GB. Max size: 4095 GB (certain preview disks can be larger).', type=int)
        c.argument('lun', type=int, help='0-based logical unit number (LUN). Max value depends on the Virtual Machine size.')

    with self.argument_context('vm disk attach') as c:
        c.argument('enable_write_accelerator', min_api='2017-12-01', action='store_true', help='enable write accelerator')
        c.argument('disk', options_list=['--name', '-n', c.deprecate(target='--disk', redirect='--name', hide=True)],
                   help="The name or ID of the managed disk", validator=validate_vm_disk, id_part='name',
                   completer=get_resource_name_completion_list('Microsoft.Compute/disks'))

    with self.argument_context('vm disk detach') as c:
        c.argument('disk_name', arg_type=name_arg_type, help='The data disk name.')

    with self.argument_context('vm encryption enable') as c:
        c.argument('encrypt_format_all', action='store_true', help='Encrypts-formats data disks instead of encrypting them. Encrypt-formatting is a lot faster than in-place encryption but wipes out the partition getting encrypt-formatted.')

    with self.argument_context('vm extension') as c:
        c.argument('vm_extension_name', name_arg_type, completer=get_resource_name_completion_list('Microsoft.Compute/virtualMachines/extensions'), help='Name of the extension.', id_part='child_name_1')
        c.argument('vm_name', arg_type=existing_vm_name, options_list=['--vm-name'], id_part='name')
        c.argument('expand', deprecate_info=c.deprecate(expiration='2.1.0', hide=True))

    with self.argument_context('vm extension list') as c:
        c.argument('vm_name', arg_type=existing_vm_name, options_list=['--vm-name'], id_part=None)

    with self.argument_context('vm secret') as c:
        c.argument('secrets', multi_ids_type, options_list=['--secrets', '-s'], help='Space-separated list of key vault secret URIs. Perhaps, produced by \'az keyvault secret list-versions --vault-name vaultname -n cert1 --query "[?attributes.enabled].id" -o tsv\'')
        c.argument('keyvault', help='Name or ID of the key vault.', validator=validate_keyvault)
        c.argument('certificate', help='key vault certificate name or its full secret URL')
        c.argument('certificate_store', help='Windows certificate store names. Default: My')

    with self.argument_context('vm secret list') as c:
        c.argument('vm_name', arg_type=existing_vm_name, id_part=None)

    with self.argument_context('vm image') as c:
        c.argument('publisher_name', options_list=['--publisher', '-p'])
        c.argument('publisher', options_list=['--publisher', '-p'], help='image publisher')
        c.argument('offer', options_list=['--offer', '-f'], help='image offer')
        c.argument('plan', help='image billing plan')
        c.argument('sku', options_list=['--sku', '-s'], help='image sku')
        c.argument('version', help="image sku's version")
        c.argument('urn', help="URN, in format of 'publisher:offer:sku:version'. If specified, other argument values can be omitted")

    with self.argument_context('vm image list') as c:
        c.argument('image_location', get_location_type(self.cli_ctx))

    with self.argument_context('vm image show') as c:
        c.argument('skus', options_list=['--sku', '-s'])

    with self.argument_context('vm nic') as c:
        c.argument('vm_name', existing_vm_name, options_list=['--vm-name'], id_part=None)
        c.argument('nics', nargs='+', help='Names or IDs of NICs.', validator=validate_vm_nics)
        c.argument('primary_nic', help='Name or ID of the primary NIC. If missing, the first NIC in the list will be the primary.')

    with self.argument_context('vm nic show') as c:
        c.argument('nic', help='NIC name or ID.', validator=validate_vm_nic)

    with self.argument_context('vm unmanaged-disk') as c:
        c.argument('new', action='store_true', help='Create a new disk.')
        c.argument('lun', type=int, help='0-based logical unit number (LUN). Max value depends on the Virtual Machine size.')
        c.argument('vhd_uri', help="Virtual hard disk URI. For example: https://mystorage.blob.core.windows.net/vhds/d1.vhd")

    with self.argument_context('vm unmanaged-disk attach') as c:
        c.argument('disk_name', options_list=['--name', '-n'], help='The data disk name.')
        c.argument('size_gb', options_list=['--size-gb', '-z'], help='size in GB. Max size: 4095 GB (certain preview disks can be larger).', type=int)

    with self.argument_context('vm unmanaged-disk detach') as c:
        c.argument('disk_name', options_list=['--name', '-n'], help='The data disk name.')

    for scope in ['vm unmanaged-disk attach', 'vm unmanaged-disk detach']:
        with self.argument_context(scope) as c:
            c.argument('vm_name', arg_type=existing_vm_name, options_list=['--vm-name'], id_part=None)

    with self.argument_context('vm unmanaged-disk list') as c:
        c.argument('vm_name', options_list=['--vm-name', '--name', '-n'], arg_type=existing_vm_name, id_part=None)

    with self.argument_context('vm user') as c:
        c.argument('username', options_list=['--username', '-u'], help='The user name')
        c.argument('password', options_list=['--password', '-p'], help='The user password')

    with self.argument_context('vm list-skus') as c:
        c.argument('size', options_list=['--size', '-s'], help="size name, partial name is accepted")
        c.argument('zone', options_list=['--zone', '-z'], arg_type=get_three_state_flag(), help="show all vm size supporting availability zones")
        c.argument('show_all', options_list=['--all'], arg_type=get_three_state_flag(),
                   help="show all information including vm sizes not available under the current subscription")
        c.argument('resource_type', options_list=['--resource-type', '-r'], help='resource types e.g. "availabilitySets", "snapshots", "disk", etc')

    with self.argument_context('vm restart') as c:
        c.argument('force', action='store_true', help='Force the VM to restart by redeploying it. Use if the VM is unresponsive.')
    # endregion

    # region VMSS
    scaleset_name_aliases = ['vm_scale_set_name', 'virtual_machine_scale_set_name', 'name']

    with self.argument_context('vmss') as c:
        c.argument('zones', zones_type, min_api='2017-03-30')
        c.argument('instance_id', id_part='child_name_1')
        c.argument('instance_ids', multi_ids_type, help='Space-separated list of IDs (ex: 1 2 3 ...) or * for all instances. If not provided, the action will be applied on the scaleset itself')
        c.argument('tags', tags_type)
        c.argument('caching', help='Disk caching policy', arg_type=get_enum_type(CachingTypes))
        for dest in scaleset_name_aliases:
            c.argument(dest, vmss_name_type)

    for scope in ['vmss deallocate', 'vmss delete-instances', 'vmss restart', 'vmss start', 'vmss stop', 'vmss show', 'vmss update-instances']:
        with self.argument_context(scope) as c:
            for dest in scaleset_name_aliases:
                c.argument(dest, vmss_name_type, id_part=None)  # due to instance-ids parameter

    with self.argument_context('vmss create') as c:
        VMPriorityTypes = self.get_models('VirtualMachinePriorityTypes', resource_type=ResourceType.MGMT_COMPUTE)
        VirtualMachineEvictionPolicyTypes = self.get_models('VirtualMachineEvictionPolicyTypes', resource_type=ResourceType.MGMT_COMPUTE)
        c.argument('name', name_arg_type)
        c.argument('nat_backend_port', default=None, help='Backend port to open with NAT rules.  Defaults to 22 on Linux and 3389 on Windows.')
        c.argument('single_placement_group', arg_type=get_three_state_flag(), help="Enable replicate using fault domains within the same cluster. Default to 'false' for any zonals, or with 100+ instances"
                   " See https://docs.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-placement-groups for details")
        c.argument('platform_fault_domain_count', type=int, help='Fault Domain count for each placement group in the availability zone', min_api='2017-12-01')
        c.argument('vmss_name', name_arg_type, id_part=None, help='Name of the virtual machine scale set.')
        c.argument('instance_count', help='Number of VMs in the scale set.', type=int)
        c.argument('disable_overprovision', help='Overprovision option (see https://azure.microsoft.com/en-us/documentation/articles/virtual-machine-scale-sets-overview/ for details).', action='store_true')
        c.argument('upgrade_policy_mode', help=None, arg_type=get_enum_type(UpgradeMode))
        c.argument('health_probe', help='(Preview) probe name from the existing load balancer, mainly used for rolling upgrade')
        c.argument('vm_sku', help='Size of VMs in the scale set. Default to "Standard_DS1_v2". See https://azure.microsoft.com/en-us/pricing/details/virtual-machines/ for size info.')
        c.argument('nsg', help='Name or ID of an existing Network Security Group.', arg_group='Network')
        c.argument('priority', resource_type=ResourceType.MGMT_COMPUTE, min_api='2017-12-01', arg_type=get_enum_type(VMPriorityTypes, default=None),
                   help="Priority. Use 'Low' to run short-lived workloads in a cost-effective way")
        c.argument('eviction_policy', resource_type=ResourceType.MGMT_COMPUTE, min_api='2017-12-01', arg_type=get_enum_type(VirtualMachineEvictionPolicyTypes, default=None),
                   help="(PREVIEW) The eviction policy for virtual machines in a low priority scale set.")
        c.argument('application_security_groups', resource_type=ResourceType.MGMT_COMPUTE, min_api='2018-06-01', nargs='+', options_list=['--asgs'], help='Space-separated list of existing application security groups to associate with the VM.', arg_group='Network', validator=validate_asg_names_or_ids)

    with self.argument_context('vmss create', arg_group='Network Balancer') as c:
        LoadBalancerSkuName = self.get_models('LoadBalancerSkuName', resource_type=ResourceType.MGMT_NETWORK)
        c.argument('application_gateway', help='Name to use when creating a new application gateway (default) or referencing an existing one. Can also reference an existing application gateway by ID or specify "" for none.', options_list=['--app-gateway'])
        c.argument('app_gateway_capacity', help='The number of instances to use when creating a new application gateway.')
        c.argument('app_gateway_sku', help='SKU when creating a new application gateway.')
        c.argument('app_gateway_subnet_address_prefix', help='The subnet IP address prefix to use when creating a new application gateway in CIDR format.')
        c.argument('backend_pool_name', help='Name to use for the backend pool when creating a new load balancer or application gateway.')
        c.argument('backend_port', help='When creating a new load balancer, backend port to open with NAT rules (Defaults to 22 on Linux and 3389 on Windows). When creating an application gateway, the backend port to use for the backend HTTP settings.', type=int)
        c.argument('load_balancer', help='Name to use when creating a new load balancer (default) or referencing an existing one. Can also reference an existing load balancer by ID or specify "" for none.', options_list=['--load-balancer', '--lb'])
        c.argument('load_balancer_sku', resource_type=ResourceType.MGMT_NETWORK, min_api='2017-08-01', options_list=['--lb-sku'], arg_type=get_enum_type(LoadBalancerSkuName),
                   help="Sku of the Load Balancer to create. Default to 'Standard' when single placement group is turned off; otherwise, default to 'Basic'")
        c.argument('nat_pool_name', help='Name to use for the NAT pool when creating a new load balancer.', options_list=['--lb-nat-pool-name', '--nat-pool-name'])

    with self.argument_context('vmss create', min_api='2017-03-30', arg_group='Network') as c:
        c.argument('public_ip_per_vm', action='store_true', help="Each VM instance will have a public ip. For security, you can use '--nsg' to apply appropriate rules")
        c.argument('vm_domain_name', help="domain name of VM instances, once configured, the FQDN is 'vm<vm-index>.<vm-domain-name>.<..rest..>'")
        c.argument('dns_servers', nargs='+', help="space-separated IP addresses of DNS servers, e.g. 10.0.0.5 10.0.0.6")
        c.argument('accelerated_networking', arg_type=get_three_state_flag(),
                   help="enable accelerated networking. Unless specified, CLI will enable it based on machine image and size")

    for scope in ['vmss update-instances', 'vmss delete-instances']:
        with self.argument_context(scope) as c:
            c.argument('instance_ids', multi_ids_type, help='Space-separated list of IDs (ex: 1 2 3 ...) or * for all instances.')

    with self.argument_context('vmss diagnostics') as c:
        c.argument('vmss_name', id_part=None, help='Scale set name')

    with self.argument_context('vmss disk') as c:
        options_list = ['--vmss-name'] + [c.deprecate(target=opt, redirect='--vmss-name', hide=True)for opt in name_arg_type.settings['options_list']]
        new_vmss_name_type = CLIArgumentType(overrides=vmss_name_type, options_list=options_list)

        c.argument('lun', type=int, help='0-based logical unit number (LUN). Max value depends on the Virtual Machine instance size.')
        c.argument('size_gb', options_list=['--size-gb', '-z'], help='size in GB. Max size: 4095 GB (certain preview disks can be larger).', type=int)
        c.argument('vmss_name', new_vmss_name_type, completer=get_resource_name_completion_list('Microsoft.Compute/virtualMachineScaleSets'))
        c.argument('disk', validator=validate_vmss_disk, help='existing disk name or ID to attach or detach from VM instances',
                   min_api='2017-12-01', completer=get_resource_name_completion_list('Microsoft.Compute/disks'))
        c.argument('instance_id', help='Scale set VM instance id', min_api='2017-12-01')
        c.argument('sku', arg_type=disk_sku, help='Underlying storage SKU')

    with self.argument_context('vmss encryption') as c:
        c.argument('vmss_name', vmss_name_type, completer=get_resource_name_completion_list('Microsoft.Compute/virtualMachineScaleSets'))

    with self.argument_context('vmss extension') as c:
        c.argument('extension_name', name_arg_type, help='Name of the extension.')
        c.argument('vmss_name', vmss_name_type, options_list=['--vmss-name'], id_part=None)

    with self.argument_context('vmss nic') as c:
        c.argument('virtual_machine_scale_set_name', options_list=['--vmss-name'], help='Scale set name.', completer=get_resource_name_completion_list('Microsoft.Compute/virtualMachineScaleSets'), id_part='name')
        c.argument('virtualmachine_index', options_list=['--instance-id'], id_part='child_name_1')
        c.argument('network_interface_name', options_list=['--name', '-n'], metavar='NIC_NAME', help='The network interface (NIC).', completer=get_resource_name_completion_list('Microsoft.Network/networkInterfaces'), id_part='child_name_2')

    with self.argument_context('vmss nic list') as c:
        c.argument('virtual_machine_scale_set_name', arg_type=vmss_name_type, options_list=['--vmss-name'], id_part=None)
    # endregion

    # region VM & VMSS Shared
    for scope in ['vm', 'vmss']:
        with self.argument_context(scope) as c:
            c.argument('no_auto_upgrade', arg_type=get_three_state_flag(), help='If set, the extension service will not automatically pick or upgrade to the latest minor version, even if the extension is redeployed.')

        with self.argument_context('{} run-command'.format(scope)) as c:
            c.argument('command_id', completer=get_vm_run_command_completion_list, help="The command id. Use 'az {} run-command list' to get the list".format(scope))
            if scope == 'vmss':
                c.argument('vmss_name', vmss_name_type)

        with self.argument_context('{} run-command invoke'.format(scope)) as c:
            c.argument('parameters', nargs='+', help="space-separated parameters in the format of '[name=]value'")
            c.argument('scripts', nargs='+', help="script lines separated by whites spaces. Use @{file} to load from a file")

    for scope in ['vm identity assign', 'vmss identity assign']:
        with self.argument_context(scope) as c:
            c.argument('assign_identity', options_list=['--identities'], nargs='*', help="Space-separated identities to assign. Use '{0}' to refer to the system assigned identity. Default: '{0}'".format(MSI_LOCAL_ID))
            c.argument('vm_name', existing_vm_name)
            c.argument('vmss_name', vmss_name_type)

    for scope in ['vm identity remove', 'vmss identity remove']:
        with self.argument_context(scope) as c:
            c.argument('identities', nargs='+', help="Space-separated identities to remove. Use '{0}' to refer to the system assigned identity. Default: '{0}'".format(MSI_LOCAL_ID))
            c.argument('vm_name', existing_vm_name)
            c.argument('vmss_name', vmss_name_type)

    for scope in ['vm identity show', 'vmss identity show']:
        with self.argument_context(scope) as c:
            c.argument('vm_name', existing_vm_name)
            c.argument('vmss_name', vmss_name_type)

    for scope in ['vm create', 'vmss create']:
        with self.argument_context(scope) as c:
            c.argument('location', get_location_type(self.cli_ctx), help='Location in which to create VM and related resources. If default location is not configured, will default to the resource group\'s location')
            c.argument('tags', tags_type)
            c.argument('no_wait', help='Do not wait for the long-running operation to finish.')
            c.argument('validate', options_list=['--validate'], help='Generate and validate the ARM template without creating any resources.', action='store_true')
            c.argument('size', help='The VM size to be created. See https://azure.microsoft.com/en-us/pricing/details/virtual-machines/ for size info.')
            c.argument('image', completer=get_urn_aliases_completion_list)
            c.argument('custom_data', help='Custom init script file or text (cloud-init, cloud-config, etc..)', completer=FilesCompleter(), type=file_type)
            c.argument('secrets', multi_ids_type, help='One or many Key Vault secrets as JSON strings or files via `@{path}` containing `[{ "sourceVault": { "id": "value" }, "vaultCertificates": [{ "certificateUrl": "value", "certificateStore": "cert store name (only on windows)"}] }]`', type=file_type, completer=FilesCompleter())
            c.argument('assign_identity', nargs='*', arg_group='Managed Service Identity', help="accept system or user assigned identities separated by spaces. Use '[system]' to refer system assigned identity, or a resource id to refer user assigned identity. Check out help for more examples")
            c.ignore('aux_subscriptions')

        with self.argument_context(scope, arg_group='Authentication') as c:
            c.argument('generate_ssh_keys', action='store_true', help='Generate SSH public and private key files if missing. The keys will be stored in the ~/.ssh directory')
            c.argument('admin_username', help='Username for the VM.', default=get_default_admin_username())
            c.argument('admin_password', help="Password for the VM if authentication type is 'Password'.")
            c.argument('ssh_key_value', help='SSH public key or public key file path.', completer=FilesCompleter(), type=file_type)
            c.argument('ssh_dest_key_path', help='Destination file path on the VM for the SSH key.')
            c.argument('authentication_type', help='Type of authentication to use with the VM. Defaults to password for Windows and SSH public key for Linux. "all" enables both ssh and password authentication. ', arg_type=get_enum_type(['ssh', 'password', 'all']))

        with self.argument_context(scope, arg_group='Storage') as c:
            if StorageAccountTypes:
                allowed_values = ", ".join([sku.value for sku in StorageAccountTypes])
            else:
                allowed_values = ", ".join(['Premium_LRS', 'Standard_LRS'])

            usage = 'Usage: [--storage-sku SKU | --storage-sku ID=SKU ID=SKU ID=SKU...], where each ID is "os" or a 0-indexed lun.'
            allowed_values = 'Allowed values: {}.'.format(allowed_values)
            storage_sku_help = 'The SKU of the storage account with which to persist VM. Use a singular sku that would be applied across all disks, ' \
                               'or specify individual disks. {} {}'.format(usage, allowed_values)

            c.argument('os_disk_name', help='The name of the new VM OS disk.')
            c.argument('os_type', help='Type of OS installed on a custom VHD. Do not use when specifying an URN or URN alias.', arg_type=get_enum_type(['windows', 'linux']))
            c.argument('storage_account', help="Only applicable when used with `--use-unmanaged-disk`. The name to use when creating a new storage account or referencing an existing one. If omitted, an appropriate storage account in the same resource group and location will be used, or a new one will be created.")
            c.argument('storage_sku', nargs='+', help=storage_sku_help)
            c.argument('storage_container_name', help="Only applicable when used with `--use-unmanaged-disk`. Name of the storage container for the VM OS disk. Default: vhds")
            c.ignore('os_publisher', 'os_offer', 'os_sku', 'os_version', 'storage_profile')
            c.argument('use_unmanaged_disk', action='store_true', help='Do not use managed disk to persist VM')
            c.argument('data_disk_sizes_gb', nargs='+', type=int, help='space-separated empty managed data disk sizes in GB to create')
            c.ignore('disk_info', 'storage_account_type', 'public_ip_address_type', 'nsg_type', 'nic_type', 'vnet_type', 'load_balancer_type', 'app_gateway_type')
            c.argument('os_caching', options_list=[self.deprecate(target='--storage-caching', redirect='--os-disk-caching', hide=True), '--os-disk-caching'], help='Storage caching type for the VM OS disk. Default: ReadWrite', arg_type=get_enum_type(CachingTypes))
            c.argument('data_caching', options_list=['--data-disk-caching'], nargs='+',
                       help="storage caching type for data disk(s), including 'None', 'ReadOnly', 'ReadWrite', etc. Use a singular value to apply on all disks, or use '<lun>=<vaule1> <lun>=<value2>' to configure individual disk")
            c.argument('ultra_ssd_enabled', arg_type=get_three_state_flag(), min_api='2018-06-01',
                       help='(PREVIEW) Enables or disables the capability to have 1 or more managed data disks with UltraSSD_LRS storage account')
            c.argument('ephemeral_os_disk', arg_type=get_three_state_flag(), min_api='2018-06-01',
                       help='(Preview) Allows you to create an OS disk directly on the host node, providing local disk performance and faster VM/VMSS reimage time.')

        with self.argument_context(scope, arg_group='Network') as c:
            c.argument('vnet_name', help='Name of the virtual network when creating a new one or referencing an existing one.')
            c.argument('vnet_address_prefix', help='The IP address prefix to use when creating a new VNet in CIDR format.')
            c.argument('subnet', help='The name of the subnet when creating a new VNet or referencing an existing one. Can also reference an existing subnet by ID. If omitted, an appropriate VNet and subnet will be selected automatically, or a new one will be created.')
            c.argument('subnet_address_prefix', help='The subnet IP address prefix to use when creating a new VNet in CIDR format.')
            c.argument('nics', nargs='+', help='Names or IDs of existing NICs to attach to the VM. The first NIC will be designated as primary. If omitted, a new NIC will be created. If an existing NIC is specified, do not specify subnet, VNet, public IP or NSG.')
            c.argument('private_ip_address', help='Static private IP address (e.g. 10.0.0.5).')
            c.argument('public_ip_address', help='Name of the public IP address when creating one (default) or referencing an existing one. Can also reference an existing public IP by ID or specify "" for None.')
            c.argument('public_ip_address_allocation', help=None, default=None, arg_type=get_enum_type(['dynamic', 'static']))
            c.argument('public_ip_address_dns_name', help='Globally unique DNS name for a newly created public IP.')
            if self.supported_api_version(min_api='2017-08-01', resource_type=ResourceType.MGMT_NETWORK):
                PublicIPAddressSkuName = self.get_models('PublicIPAddressSkuName', resource_type=ResourceType.MGMT_NETWORK)
                c.argument('public_ip_sku', help='Sku', default=None, arg_type=get_enum_type(PublicIPAddressSkuName))

        with self.argument_context(scope, arg_group='Marketplace Image Plan') as c:
            c.argument('plan_name', help='plan name')
            c.argument('plan_product', help='plan product')
            c.argument('plan_publisher', help='plan publisher')
            c.argument('plan_promotion_code', help='plan promotion code')

    for scope in ['vm create', 'vmss create', 'vm identity assign', 'vmss identity assign']:
        with self.argument_context(scope) as c:
            arg_group = 'Managed Service Identity' if scope.split()[-1] == 'create' else None
            c.argument('identity_scope', options_list=['--scope'], arg_group=arg_group, help="Scope that the system assigned identity can access")
            c.argument('identity_role', options_list=['--role'], arg_group=arg_group, help="Role name or id the system assigned identity will have")
            c.ignore('identity_role_id')

    for scope in ['vm diagnostics', 'vmss diagnostics']:
        with self.argument_context(scope) as c:
            c.argument('version', help='version of the diagnostics extension. Will use the latest if not specfied')
            c.argument('settings', help='json string or a file path, which defines data to be collected.', type=validate_file_or_dict, completer=FilesCompleter())
            c.argument('protected_settings', help='json string or a file path containing private configurations such as storage account keys, etc.', type=validate_file_or_dict, completer=FilesCompleter())
            c.argument('is_windows_os', action='store_true', help='for Windows VMs')

    for scope in ['vm encryption', 'vmss encryption']:
        with self.argument_context(scope) as c:
            c.argument('volume_type', help='Type of volume that the encryption operation is performed on', arg_type=get_enum_type(['DATA', 'OS', 'ALL']))
            c.argument('force', action='store_true', help='continue by ignoring client side validation errors')
            c.argument('disk_encryption_keyvault', help='The key vault where the generated encryption key will be placed.')
            c.argument('key_encryption_key', help='Key vault key name or URL used to encrypt the disk encryption key.')
            c.argument('key_encryption_keyvault', help='The key vault containing the key encryption key used to encrypt the disk encryption key. If missing, CLI will use `--disk-encryption-keyvault`.')

    for scope in ['vm extension', 'vmss extension']:
        with self.argument_context(scope) as c:
            c.argument('publisher', help='The name of the extension publisher.')
            c.argument('settings', type=validate_file_or_dict, help='Extension settings in JSON format. A JSON file path is also accepted.')
            c.argument('protected_settings', type=validate_file_or_dict, help='Protected settings in JSON format for sensitive information like credentials. A JSON file path is also accepted.')
            c.argument('version', help='The version of the extension')

    with self.argument_context('vm extension set') as c:
        c.argument('force_update', action='store_true', help='force to update even if the extension configuration has not changed.')
        c.argument('extension_instance_name', extension_instance_name_type, arg_group='Resource Id')

    with self.argument_context('vmss extension set', min_api='2017-12-01') as c:
        c.argument('force_update', action='store_true', help='force to update even if the extension configuration has not changed.')
        c.argument('extension_instance_name', extension_instance_name_type)
        c.argument('provision_after_extensions', nargs='+', help='Space-separated list of extension names after which this extension should be provisioned. These extensions must already be set on the vm.')

    for scope in ['vm extension image', 'vmss extension image']:
        with self.argument_context(scope) as c:
            c.argument('image_location', options_list=['--location', '-l'], help='Image location.')
            c.argument('name', help='Image name', id_part=None)
            c.argument('publisher_name', options_list=['--publisher', '-p'], help='Image publisher name')
            c.argument('type', options_list=['--name', '-n'], help='Name of the extension')
            c.argument('latest', action='store_true', help='Show the latest version only.')
            c.argument('version', help='Extension version')
            c.argument('orderby', help="the $orderby odata query option")
            c.argument('top', help='the $top odata query option')

    for scope in ['vm create', 'vm update', 'vmss create', 'vmss update']:
        with self.argument_context(scope) as c:
            c.argument('license_type', help="license type if the Windows image or disk used was licensed on-premises", arg_type=get_enum_type(['Windows_Server', 'Windows_Client', 'None']))

    with self.argument_context('sig') as c:
        c.argument('gallery_name', options_list=['--gallery-name', '-r'], help='gallery name')
        c.argument('gallery_image_name', options_list=['--gallery-image-definition', '-i'], help='gallery image definition')
        c.argument('gallery_image_version', options_list=['--gallery-image-version', '-e'], help='gallery image version')

    for scope in ['sig show', 'sig image-definition show', 'sig image-definition delete']:
        with self.argument_context(scope) as c:
            c.argument('gallery_name', options_list=['--gallery-name', '-r'], id_part='name', help='gallery name')
            c.argument('gallery_image_name', options_list=['--gallery-image-definition', '-i'], id_part='child_name_1', help='gallery image definition')

    with self.argument_context('sig image-definition create') as c:
        c.argument('offer', options_list=['--offer', '-f'], help='image offer')
        c.argument('sku', options_list=['--sku', '-s'], help='image sku')
        c.argument('publisher', options_list=['--publisher', '-p'], help='image publisher')
        c.argument('os_type', arg_type=get_enum_type(['Windows', 'Linux']), help='the type of the OS that is included in the disk if creating a VM from user-image or a specialized VHD')
        c.ignore('os_state')  # service is not ready
        c.argument('minimum_cpu_core', type=int, arg_group='Recommendation', help='minimum cpu cores')
        c.argument('maximum_cpu_core', type=int, arg_group='Recommendation', help='maximum cpu cores')
        c.argument('minimum_memory', type=int, arg_group='Recommendation', help='minimum memory in MB')
        c.argument('maximum_memory', type=int, arg_group='Recommendation', help='maximum memory in MB')

        c.argument('plan_publisher', help='plan publisher', arg_group='Purchase plan')
        c.argument('plan_name', help='plan name', arg_group='Purchase plan')
        c.argument('plan_product', help='plan product', arg_group='Purchase plan')

        c.argument('eula', help='The Eula agreement for the gallery image')
        c.argument('privacy_statement_uri', help='The privacy statement uri')
        c.argument('release_note_uri', help='The release note uri')
        c.argument('end_of_life_date', help="the end of life date, e.g. '2020-12-31'")
        c.argument('disallowed_disk_types', nargs='*', help='disk types which would not work with the image, e.g., Standard_LRS')

    with self.argument_context('sig create') as c:
        c.argument('description', help='the description of the gallery')
    with self.argument_context('sig update') as c:
        c.ignore('gallery')
    with self.argument_context('sig image-definition create') as c:
        c.argument('description', help='the description of the gallery image definition')
    with self.argument_context('sig image-definition update') as c:
        c.ignore('gallery_image')

    with self.argument_context('sig image-version') as c:
        deprecated_option = c.deprecate(target='--gallery-image-version-name', redirect='--gallery-image-version', hide=True, expiration="2.1.0")
        c.argument('gallery_image_version_name', options_list=['--gallery-image-version', '-e', deprecated_option], )

    with self.argument_context('sig image-version create') as c:
        c.argument('gallery_image_version', options_list=['--gallery-image-version', '-e'],
                   help='Gallery image version in semantic version pattern. The allowed characters are digit and period. Digits must be within the range of a 32-bit integer, e.g. <MajorVersion>.<MinorVersion>.<Patch>')
        c.argument('description', help='the description of the gallery image version')
        c.argument('managed_image', help='image name(if in the same resource group) or resource id')
        c.argument('exclude_from_latest', arg_type=get_three_state_flag(), help='The flag means that if it is set to true, people deploying VMs with version omitted will not use this version.')
        c.argument('version', help='image version')
        c.argument('end_of_life_date', help="the end of life date, e.g. '2020-12-31'")

    with self.argument_context('sig image-version show') as c:
        c.argument('expand', help="The expand expression to apply on the operation, e.g. 'ReplicationStatus'")
    for scope in ['sig image-version create', 'sig image-version update']:
        with self.argument_context(scope) as c:
            c.argument('target_regions', nargs='*', validator=process_gallery_image_version_namespace,
                       help='Space-separated list of regions and their replica counts. Use "<region>=<replica count>" to set the replica count for each region. If only the region is specified, the default replica count will be used.')
            c.argument('replica_count', help='The default number of replicas to be created per region. To set regional replication counts, use --target-regions', type=int)