diff --git a/src/azure-cli/azure/cli/command_modules/network/custom.py b/src/azure-cli/azure/cli/command_modules/network/custom.py index 2813ad8cd04..6f57364cffc 100644 --- a/src/azure-cli/azure/cli/command_modules/network/custom.py +++ b/src/azure-cli/azure/cli/command_modules/network/custom.py @@ -6756,3 +6756,19 @@ def create_ddos_custom_policy(cmd, ddos_custom_policy_name, resource_group_name, policy['no_wait'] = no_wait return DdosCustomPolicyCreate(cli_ctx=cmd.cli_ctx)(command_args=policy) + + +def get_vm(cli_ctx, resource_group_name, vm_name): + from ..vm.operations.vm import VMShow + return VMShow(cli_ctx=cli_ctx)(command_args={ + 'resource_group': resource_group_name, + 'vm_name': vm_name + }) + + +def get_vmss(cli_ctx, resource_group_name, vmss_name): + from ..vm.operations.vmss import VMSSShow + return VMSSShow(cli_ctx=cli_ctx)(command_args={ + 'resource_group': resource_group_name, + 'vm_scale_set_name': vmss_name + }) diff --git a/src/azure-cli/azure/cli/command_modules/network/operations/watcher.py b/src/azure-cli/azure/cli/command_modules/network/operations/watcher.py index d30644852ca..1b425687f7b 100644 --- a/src/azure-cli/azure/cli/command_modules/network/operations/watcher.py +++ b/src/azure-cli/azure/cli/command_modules/network/operations/watcher.py @@ -72,11 +72,11 @@ def get_network_watcher_from_location(cmd, watcher_name="watcher_name", rg_name= def get_network_watcher_from_vm(cmd): + from ..custom import get_vm args = cmd.ctx.args - compute_client = get_mgmt_service_client(cmd.cli_ctx, ResourceType.MGMT_COMPUTE).virtual_machines vm_name = parse_resource_id(args.vm.to_serialized_data())["name"] - vm = compute_client.get(args.resource_group_name, vm_name) - args.location = vm.location + vm = get_vm(cmd.cli_ctx, args.resource_group_name, vm_name) + args.location = vm.get('location') get_network_watcher_from_location(cmd) @@ -88,11 +88,11 @@ def get_network_watcher_from_resource(cmd): def get_network_watcher_from_vmss(cmd): + from ..custom import get_vmss args = cmd.ctx.args - compute_client = get_mgmt_service_client(cmd.cli_ctx, ResourceType.MGMT_COMPUTE).virtual_machine_scale_sets vmss_name = parse_resource_id(args.target.to_serialized_data())["name"] - vmss = compute_client.get(args.resource_group_name, vmss_name) - args.location = vmss.location + vmss = get_vmss(cmd.cli_ctx, args.resource_group_name, vmss_name) + args.location = vmss.get('location') get_network_watcher_from_location(cmd) @@ -387,16 +387,16 @@ def _build_arguments_schema(cls, *args, **kwargs): return args_schema def pre_operations(self): + from ..custom import get_vm args = self.ctx.args - compute_client = get_mgmt_service_client(self.cli_ctx, ResourceType.MGMT_COMPUTE).virtual_machines id_parts = parse_resource_id(args.source_resource.to_serialized_data()) vm_name = id_parts["name"] rg = args.resource_group_name or id_parts.get("resource_group", None) if not rg: raise ValidationError("usage error: --source-resource ID | --source-resource NAME --resource-group NAME") - vm = compute_client.get(rg, vm_name) - args.location = vm.location + vm = get_vm(self.cli_ctx, rg, vm_name) + args.location = vm.get('location') get_network_watcher_from_location(self) if has_value(args.source_resource) and not is_valid_resource_id(args.source_resource.to_serialized_data()):