Skip to content

Commit

Permalink
Merge branch 'dev' into update-sdk-7
Browse files Browse the repository at this point in the history
  • Loading branch information
StrawnSC committed Jul 19, 2022
2 parents 230fbba + 5ce15ee commit ef73111
Show file tree
Hide file tree
Showing 51 changed files with 3,747 additions and 1,234 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/scripts/live_test @kairu-ms @wangzelin007
/src/azure-cli-testsdk/ @jsntcy @jiasli @kairu-ms @wangzelin007

/src/azure-cli-core/ @jiasli @evelyn-ys @jsntcy @kairu-ms @zhoxing-ms @calvinhzy
/src/azure-cli-core/ @jiasli @evelyn-ys @jsntcy @kairu-ms @zhoxing-ms @calvinhzy @necusjz
/src/azure-cli-core/azure/cli/core/_profile.py @jiasli @evelyn-ys @calvinhzy
/src/azure-cli-core/azure/cli/core/auth/ @jiasli @evelyn-ys @calvinhzy
/src/azure-cli-core/azure/cli/core/extension/ @jsntcy @kairu-ms
Expand Down
3 changes: 2 additions & 1 deletion src/azure-cli-core/azure/cli/core/aaz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from ._arg_fmt import AAZStrArgFormat, AAZIntArgFormat, AAZFloatArgFormat, AAZBoolArgFormat, AAZObjectArgFormat, \
AAZDictArgFormat, AAZListArgFormat, AAZResourceLocationArgFormat, AAZResourceIdArgFormat, AAZSubscriptionIdArgFormat
from ._base import AAZValuePatch, AAZUndefined
from ._command import AAZCommand, AAZCommandGroup, register_command, register_command_group, load_aaz_command_table
from ._command import AAZCommand, AAZWaitCommand, AAZCommandGroup, \
register_command, register_command_group, load_aaz_command_table
from ._field_type import AAZIntType, AAZFloatType, AAZStrType, AAZBoolType, AAZDictType, AAZListType, AAZObjectType
from ._operation import AAZHttpOperation, AAZJsonInstanceUpdateOperation, AAZGenericInstanceUpdateOperation
20 changes: 20 additions & 0 deletions src/azure-cli-core/azure/cli/core/aaz/_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,26 @@ def executor_wrapper(next_link):
return AAZPaged(executor=executor_wrapper, extract_result=extract_result)


class AAZWaitCommand(AAZCommand):
"""Support wait command"""

def __init__(self, loader):
from azure.cli.core.commands.command_operation import WaitCommandOperation
super().__init__(loader)

# add wait args in commands
for param_name, argtype in WaitCommandOperation.wait_args().items():
self.arguments[param_name] = argtype

def __call__(self, *args, **kwargs):
from azure.cli.core.commands.command_operation import WaitCommandOperation
return WaitCommandOperation.wait(
*args, **kwargs,
cli_ctx=self.cli_ctx,
getter=lambda **command_args: self._handler(command_args)
)


def register_command_group(
name, is_preview=False, is_experimental=False, hide=False, redirect=None, expiration=None):
"""This decorator is used to register an AAZCommandGroup as a cli command group.
Expand Down
54 changes: 33 additions & 21 deletions src/azure-cli-core/azure/cli/core/commands/command_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,7 @@ def __init__(self, command_loader, op_path, **merged_kwargs):

def handler(self, command_args): # pylint: disable=too-many-statements, too-many-locals
""" Callback function of CLICommand handler """
from msrest.exceptions import ClientException
from azure.core.exceptions import HttpResponseError
from knack.util import CLIError
from azure.cli.core.commands.arm import EXCLUDED_NON_CLIENT_PARAMS, verify_property
from azure.cli.core.commands.progress import IndeterminateProgressBar

import time
from azure.cli.core.commands.arm import EXCLUDED_NON_CLIENT_PARAMS

op = self.get_op_handler(self.op_path)
getter_args = dict(extract_args_from_signature(op, excluded_params=EXCLUDED_NON_CLIENT_PARAMS))
Expand All @@ -405,6 +399,18 @@ def handler(self, command_args): # pylint: disable=too-many-statements, too-m

getter = self.get_op_handler(self.op_path) # Fetch op handler again after cmd property is set

return self.wait(command_args, cli_ctx=self.cli_ctx, getter=getter)

@classmethod
def wait(cls, command_args, cli_ctx, getter):
from msrest.exceptions import ClientException
from azure.core.exceptions import HttpResponseError
from knack.util import CLIError
from azure.cli.core.azclierror import InvalidArgumentValueError, AzureResponseError
from azure.cli.core.commands.arm import verify_property
from azure.cli.core.commands.progress import IndeterminateProgressBar
import time

timeout = command_args.pop('timeout')
interval = command_args.pop('interval')
wait_for_created = command_args.pop('created')
Expand All @@ -414,10 +420,10 @@ def handler(self, command_args): # pylint: disable=too-many-statements, too-m
custom_condition = command_args.pop('custom')
if not any([wait_for_created, wait_for_updated, wait_for_deleted,
wait_for_exists, custom_condition]):
raise CLIError(
raise InvalidArgumentValueError(
"incorrect usage: --created | --updated | --deleted | --exists | --custom JMESPATH")

progress_indicator = IndeterminateProgressBar(self.cli_ctx, message='Waiting')
progress_indicator = IndeterminateProgressBar(cli_ctx, message='Waiting')
progress_indicator.begin()
for _ in range(0, timeout, interval):
try:
Expand All @@ -426,13 +432,13 @@ def handler(self, command_args): # pylint: disable=too-many-statements, too-m
if wait_for_exists:
progress_indicator.end()
return None
provisioning_state = self._get_provisioning_state(instance)
provisioning_state = cls._get_provisioning_state(instance)
# until we have any needs to wait for 'Failed', let us bail out on this
if provisioning_state:
provisioning_state = provisioning_state.lower()
if provisioning_state == 'failed':
progress_indicator.stop()
raise CLIError('The operation failed')
raise AzureResponseError('The operation failed')
if ((wait_for_created or wait_for_updated) and provisioning_state == 'succeeded') or \
custom_condition and bool(verify_property(instance, custom_condition)):
progress_indicator.end()
Expand All @@ -457,26 +463,32 @@ def handler(self, command_args): # pylint: disable=too-many-statements, too-m

@staticmethod
def _get_provisioning_state(instance):
provisioning_state = getattr(instance, 'provisioning_state', None)
from knack.util import todict
result = todict(instance)
provisioning_state = result.get('provisioning_state', result.get('provisioningState', None))
if not provisioning_state:
# some SDK, like resource-group, has 'provisioning_state' under 'properties'
properties = getattr(instance, 'properties', None)
properties = result.get('properties', None)
if properties:
provisioning_state = getattr(properties, 'provisioning_state', None)
provisioning_state = properties.get('provisioning_state', properties.get('provisioningState', None))
# some SDK, like keyvault, has 'provisioningState' under 'properties.additional_properties'
if not provisioning_state:
additional_properties = getattr(properties, 'additional_properties', {})
provisioning_state = additional_properties.get('provisioningState')

# some SDK, like resource, has 'provisioningState' under 'properties' dict
if not provisioning_state:
provisioning_state = properties.get('provisioningState')
additional_properties = properties.get('additional_properties',
properties.get('additionalProperties', {}))
provisioning_state = additional_properties.get('provisioning_state',
additional_properties.get('provisioningState', None))
return provisioning_state

def arguments_loader(self):
""" Callback function of CLICommand arguments_loader """
cmd_args = self.load_getter_op_arguments(self.op_path)

cmd_args.update(self.wait_args())
return list(cmd_args.items())

@staticmethod
def wait_args():
cmd_args = {}
group_name = 'Wait Condition'
cmd_args['timeout'] = CLICommandArgument(
'timeout', options_list=['--timeout'], default=3600, arg_group=group_name, type=int,
Expand Down Expand Up @@ -508,7 +520,7 @@ def arguments_loader(self):
"provisioningState!='InProgress', "
"instanceView.statuses[?code=='PowerState/running']"
)
return list(cmd_args.items())
return cmd_args

def description_loader(self):
""" Callback function of CLICommand description_loader """
Expand Down
4 changes: 2 additions & 2 deletions src/azure-cli/azure/cli/command_modules/acs/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,10 +987,10 @@
short-summary: Public IP prefix ID used to assign public IPs to VMSS nodes.
- name: --vnet-subnet-id
type: string
short-summary: The ID of a subnet in an existing VNet into which to deploy the cluster.
short-summary: The Resource Id of a subnet in an existing VNet into which to deploy the cluster.
- name: --pod-subnet-id
type: string
short-summary: The ID of a subnet in an existing VNet into which to assign pods in the cluster (requires azure network-plugin).
short-summary: The Resource Id of a subnet in an existing VNet into which to assign pods in the cluster (requires azure network-plugin).
- name: --ppg
type: string
short-summary: The ID of a PPG.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ def _load_transformed_arguments(self, handler):
param = 'json_file'
docstring = f"A file containing the {arg[0].replace('_', ' ')} specification in JSON " \
"(formatted to match the respective REST API body). " \
"If this parameter is specified, all '{group_title(arg[0])} Arguments'" \
f"If this parameter is specified, all '{group_title(arg[0])} Arguments'" \
" are ignored."
args.append((param, CLICommandArgument(param,
options_list=[arg_name(param)],
Expand Down
97 changes: 97 additions & 0 deletions src/azure-cli/azure/cli/command_modules/batch/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,103 @@
long-summary: List the endpoints that a Batch Compute Node under this Batch Account may call as part of Batch service administration. If you are deploying a Pool inside of a virtual network that you specify, you must make sure your network allows outbound access to these endpoints. Failure to allow access to these endpoints may cause Batch to mark the affected nodes as unusable. For more information about creating a pool inside of a virtual network, see https://docs.microsoft.com/azure/batch/batch-virtual-network."
"""

helps['batch account identity'] = """
type: group
short-summary: Manage identities of a batch account.
"""

helps['batch account identity assign'] = """
type: command
short-summary: Add managed identities to an existing batch account.
examples:
- name: Add a system assigned managed identity to an existing batch account.
text: >
az batch account identity assign --name MyBatchAccount --resource-group MyResourceGroup --system-assigned
- name: Add a user assigned managed identity to an existing batch account.
text: >
az batch account identity assign --name MyBatchAccount --resource-group MyResourceGroup --user-assigned MyAssignedId
"""

helps['batch account identity remove'] = """
type: command
short-summary: Remove managed identities from an existing batch account.
examples:
- name: Remove a system assigned managed identity from an existing batch account.
text: >
az batch account identity remove --name MyBatchAccount --resource-group MyResourceGroup --system-assigned
- name: Remove a user assigned managed identity from an existing batch account.
text: >
az batch account identity remove --name MyBatchAccount --resource-group MyResourceGroup --user-assigned MyAssignedId
- name: Remove all user assigned managed identities from an existing batch account.
text: >
az batch account identity remove --name MyBatchAccount --resource-group MyResourceGroup --user-assigned
"""

helps['batch account identity show'] = """
type: command
short-summary: Display managed identities of a batch account.
examples:
- name: Display managed identities of a batch account.
text: |
az batch account identity show --name MyBatchAccount --resource-group MyResourceGroup
"""

helps['batch account network-profile'] = """
type: group
short-summary: Manage Batch account Network profiles.
"""

helps['batch account network-profile show'] = """
type: command
short-summary: Get information about the Network profile for Batch account.
examples:
- name: Show the network-profile for both BatchAccount and NodeManagement
text: >
az batch account network-profile show -g MyResourceGroup -n MyBatchAccount
"""

helps['batch account network-profile set'] = """
type: command
short-summary: Set the Network profile for Batch account.
examples:
- name: Set the BatchAccount network-profile to the Allow
text: >
az batch account network-profile set -g MyResourceGroup -n MyBatchAccount --profile BatchAccount --default-action Allow
"""

helps['batch account network-profile network-rule'] = """
type: group
short-summary: Manage Batch account Network rules in Network Profile.
"""

helps['batch account network-profile network-rule list'] = """
type: command
short-summary: List the Network rules from a Network Profile.
examples:
- name: List the Batch Accounts network profile
text: >
az batch account network-profile network-rule list -g MyResourceGroup -n MyBatchAccount
"""

helps['batch account network-profile network-rule add'] = """
type: command
short-summary: Add a Network rule from a Network Profile.
examples:
- name: Add ip address to BatchAccount network rule
text: >
az batch account network-profile network-rule add -g MyResourceGroup -n MyBatchAccount --profile BatchAccount --ip-address 1.2.3.4
"""

helps['batch account network-profile network-rule delete'] = """
type: command
short-summary: Delete a Network rule from a Network Profile.
examples:
- name: Delete ip address from BatchAccount network rule
text: >
az batch account network-profile network-rule delete -g MyResourceGroup -n MyBatchAccount --profile BatchAccount --ip-address 1.2.3.4
"""


helps['batch application'] = """
type: group
short-summary: Manage Batch applications.
Expand Down
Loading

0 comments on commit ef73111

Please sign in to comment.