From 5a78dc4ca1f7cbfcc9adfeb078d537846984bbc1 Mon Sep 17 00:00:00 2001 From: Oluwatosin Adewale Date: Tue, 26 Feb 2019 18:36:35 -0800 Subject: [PATCH 1/4] AzCliHelp now updates help loaders with applicable file contents before calling load. Update get_all_help in file_util. Improved efficiency. Updates to test. --- src/azure-cli-core/azure/cli/core/_help.py | 25 + .../azure/cli/core/_help_loaders.py | 103 +- .../azure/cli/core/file_util.py | 1 + .../azure/cli/core/tests/test_help_loaders.py | 123 +- .../azure/cli/command_modules/vm/help.yaml | 1347 +++++++++++++++++ 5 files changed, 1516 insertions(+), 83 deletions(-) create mode 100644 src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/help.yaml diff --git a/src/azure-cli-core/azure/cli/core/_help.py b/src/azure-cli-core/azure/cli/core/_help.py index d9da0df7bc1..e3f6552d5fe 100644 --- a/src/azure-cli-core/azure/cli/core/_help.py +++ b/src/azure-cli-core/azure/cli/core/_help.py @@ -138,6 +138,12 @@ def new_normalize_text(s): HelpObject._normalize_text = new_normalize_text # pylint: disable=protected-access self._register_help_loaders() + self._name_to_content = {} + + # override + def show_help(self, cli_name, nouns, parser, is_group): + self.update_loaders_with_help_file_contents(nouns) + super().show_help(cli_name, nouns, parser, is_group) def _register_help_loaders(self): import azure.cli.core._help_loaders as help_loaders @@ -157,6 +163,25 @@ def is_loader_cls(cls): self.versioned_loaders = versioned_loaders + def update_loaders_with_help_file_contents(self, nouns): + loader_file_names_dict = {} + file_name_set = set() + for ldr_cls_name, loader in self.versioned_loaders.items(): + new_file_names = loader.get_noun_help_file_names(nouns) or [] + loader_file_names_dict[ldr_cls_name] = new_file_names + file_name_set.update(new_file_names) + + for file_name in file_name_set: + if file_name not in self._name_to_content: + with open(file_name, 'r') as f: + self._name_to_content[file_name] = f.read() + + for ldr_cls_name, file_names in loader_file_names_dict.items(): + file_contents = {} + for name in file_names: + file_contents[name] = self._name_to_content[name] + self.versioned_loaders[ldr_cls_name].update_file_contents(file_contents) + class CliHelpFile(KnackHelpFile): diff --git a/src/azure-cli-core/azure/cli/core/_help_loaders.py b/src/azure-cli-core/azure/cli/core/_help_loaders.py index ebc9129b65d..7a36dea9069 100644 --- a/src/azure-cli-core/azure/cli/core/_help_loaders.py +++ b/src/azure-cli-core/azure/cli/core/_help_loaders.py @@ -20,14 +20,27 @@ class BaseHelpLoader(ABC): def __init__(self, help_ctx=None): self.help_ctx = help_ctx - self._data = None + self._entry_data = None + self._file_content_dict = {} def versioned_load(self, help_obj, parser): - self.load_raw_data(help_obj, parser) + if not self._file_content_dict: + return + self._entry_data = None + # Cycle through versioned_load helpers + self.load_entry_data(help_obj, parser) if self._data_is_applicable(): self.load_help_body(help_obj) self.load_help_parameters(help_obj) self.load_help_examples(help_obj) + self._entry_data = None + + def update_file_contents(self, file_contents): + self._file_content_dict.update(file_contents) + + @abc.abstractmethod + def get_noun_help_file_names(self, nouns): + pass @property @abc.abstractmethod @@ -35,10 +48,10 @@ def version(self): pass def _data_is_applicable(self): - return self._data and self.version == self._data.get('version') + return self._entry_data and self.version == self._entry_data.get('version') @abc.abstractmethod - def load_raw_data(self, help_obj, parser): + def load_entry_data(self, help_obj, parser): pass @abc.abstractmethod @@ -75,27 +88,16 @@ def _update_help_obj_params(help_obj, data_params, params_equal, attr_key_tups): loaded_params.append(param_obj) help_obj.parameters = loaded_params - # get the yaml help + +class YamlLoaderMixin(object): # pylint:disable=too-few-public-methods + """A class containing helper methods for Yaml Loaders.""" + + # get the list of yaml help file names for the command or group @staticmethod - def _get_yaml_help_for_nouns(nouns, cmd_loader_map_ref): + def _get_yaml_help_files_list(nouns, cmd_loader_map_ref): import inspect import os - def _parse_yaml_from_string(text, help_file_path): - import yaml - - dir_name, base_name = os.path.split(help_file_path) - - pretty_file_path = os.path.join(os.path.basename(dir_name), base_name) - - try: - data = yaml.load(text) - if not data: - raise CLIError("Error: Help file {} is empty".format(pretty_file_path)) - return data - except yaml.YAMLError as e: - raise CLIError("Error parsing {}:\n\n{}".format(pretty_file_path, e)) - command_nouns = " ".join(nouns) # if command in map, get the loader. Path of loader is path of helpfile. ldr_or_none = cmd_loader_map_ref.get(command_nouns, [None])[0] @@ -121,9 +123,32 @@ def _parse_yaml_from_string(text, help_file_path): for file in files: if file.endswith("help.yaml") or file.endswith("help.yml"): help_file_path = os.path.join(dir_name, file) - with open(help_file_path, "r") as f: - text = f.read() - results.append(_parse_yaml_from_string(text, help_file_path)) + results.append(help_file_path) + return results + + @staticmethod + def _load_yaml_content(file_names_list, file_content_dict): + import os + + def _parse_yaml_from_string(text, help_file_path): + import yaml + + dir_name, base_name = os.path.split(help_file_path) + pretty_file_path = os.path.join(os.path.basename(dir_name), base_name) + + if not text: + raise CLIError("No content passed for {}.".format(pretty_file_path)) + + try: + return yaml.load(text) + except yaml.YAMLError as e: + raise CLIError("Error parsing {}:\n\n{}".format(pretty_file_path, e)) + + results = [] + for file_name in file_names_list: + content = file_content_dict.get(file_name, '') + results.append(_parse_yaml_from_string(content, file_name)) + return results @@ -136,7 +161,10 @@ def version(self): def versioned_load(self, help_obj, parser): super(CliHelpFile, help_obj).load(parser) # pylint:disable=bad-super-call - def load_raw_data(self, help_obj, parser): + def get_noun_help_file_names(self, nouns): + pass + + def load_entry_data(self, help_obj, parser): pass def load_help_body(self, help_obj): @@ -149,7 +177,7 @@ def load_help_examples(self, help_obj): pass -class HelpLoaderV1(BaseHelpLoader): +class HelpLoaderV1(BaseHelpLoader, YamlLoaderMixin): core_attrs_to_keys = [("short_summary", "summary"), ("long_summary", "description")] body_attrs_to_keys = core_attrs_to_keys + [("links", "links")] param_attrs_to_keys = core_attrs_to_keys + [("value_sources", "value-sources")] @@ -158,16 +186,23 @@ class HelpLoaderV1(BaseHelpLoader): def version(self): return 1 - def load_raw_data(self, help_obj, parser): + def get_noun_help_file_names(self, nouns): + cmd_loader_map_ref = self.help_ctx.cli_ctx.invocation.commands_loader.cmd_to_loader_map + return self._get_yaml_help_files_list(nouns, cmd_loader_map_ref) + + def load_entry_data(self, help_obj, parser): prog = parser.prog if hasattr(parser, "prog") else parser._prog_prefix # pylint: disable=protected-access command_nouns = prog.split()[1:] cmd_loader_map_ref = self.help_ctx.cli_ctx.invocation.commands_loader.cmd_to_loader_map - data_list = self._get_yaml_help_for_nouns(command_nouns, cmd_loader_map_ref) - self._data = self._get_entry_data(help_obj.command, data_list) + + files_list = self._get_yaml_help_files_list(command_nouns, cmd_loader_map_ref) + data_list = self._load_yaml_content(files_list, self._file_content_dict) + + self._entry_data = self._get_entry_data(help_obj.command, data_list) def load_help_body(self, help_obj): help_obj.long_summary = "" # similar to knack... - self._update_obj_from_data_dict(help_obj, self._data, self.body_attrs_to_keys) + self._update_obj_from_data_dict(help_obj, self._entry_data, self.body_attrs_to_keys) def load_help_parameters(self, help_obj): def params_equal(param, param_dict): @@ -176,18 +211,18 @@ def params_equal(param, param_dict): # for positionals, help file must name must match param name shown when -h is run return param_dict['name'] == param.name - if help_obj.type == "command" and hasattr(help_obj, "parameters") and self._data.get("arguments"): + if help_obj.type == "command" and hasattr(help_obj, "parameters") and self._entry_data.get("arguments"): loaded_params = [] for param_obj in help_obj.parameters: - loaded_param = next((n for n in self._data["arguments"] if params_equal(param_obj, n)), None) + loaded_param = next((n for n in self._entry_data["arguments"] if params_equal(param_obj, n)), None) if loaded_param: self._update_obj_from_data_dict(param_obj, loaded_param, self.param_attrs_to_keys) loaded_params.append(param_obj) help_obj.parameters = loaded_params def load_help_examples(self, help_obj): - if help_obj.type == "command" and self._data.get("examples"): - help_obj.examples = [HelpExample(**ex) for ex in self._data["examples"] if help_obj._should_include_example(ex)] # pylint: disable=line-too-long, protected-access + if help_obj.type == "command" and self._entry_data.get("examples"): + help_obj.examples = [HelpExample(**ex) for ex in self._entry_data["examples"] if help_obj._should_include_example(ex)] # pylint: disable=line-too-long, protected-access @staticmethod def _get_entry_data(cmd_name, data_list): diff --git a/src/azure-cli-core/azure/cli/core/file_util.py b/src/azure-cli-core/azure/cli/core/file_util.py index de0c315a092..e869c979119 100644 --- a/src/azure-cli-core/azure/cli/core/file_util.py +++ b/src/azure-cli-core/azure/cli/core/file_util.py @@ -27,6 +27,7 @@ def get_all_help(cli_ctx): help_files = [] for cmd, parser in zip(sub_parser_keys, sub_parser_values): try: + help_ctx.update_loaders_with_help_file_contents(cmd.split()) help_file = CliGroupHelpFile(help_ctx, cmd, parser) if _is_group(parser) \ else CliCommandHelpFile(help_ctx, cmd, parser) help_file.load(parser) diff --git a/src/azure-cli-core/azure/cli/core/tests/test_help_loaders.py b/src/azure-cli-core/azure/cli/core/tests/test_help_loaders.py index c30417b0cba..2f48558e9d5 100644 --- a/src/azure-cli-core/azure/cli/core/tests/test_help_loaders.py +++ b/src/azure-cli-core/azure/cli/core/tests/test_help_loaders.py @@ -52,68 +52,93 @@ def dummy_handler(arg1, arg2=None, arg3=None, arg4=None): # region Test Help Loader -# test Help Loader, loads from help.json -class DummyHelpLoader(HelpLoaderV1): - # This loader has different keys in the data object. Except for "arguments" and "examples". - core_attrs_to_keys = [("short_summary", "short"), ("long_summary", "long")] - body_attrs_to_keys = core_attrs_to_keys + [("links", "hyper-links")] - param_attrs_to_keys = core_attrs_to_keys + [("value_sources", "sources")] +class JsonLoaderMixin(object): + """A class containing helper methods for Json Loaders.""" - @property - def version(self): - return 2 - - def load_raw_data(self, help_obj, parser): - prog = parser.prog if hasattr(parser, "prog") else parser._prog_prefix - command_nouns = prog.split()[1:] - cmd_loader_map_ref = self.help_ctx.cli_ctx.invocation.commands_loader.cmd_to_loader_map - all_data = self.get_json_help_for_nouns(command_nouns, cmd_loader_map_ref) - self._data = self._get_entry_data(help_obj.command, all_data) + # get the list of json help file names for the command or group + @staticmethod + def _get_json_help_files_list(nouns, cmd_loader_map_ref): + import inspect + import os - def load_help_body(self, help_obj): - self._update_obj_from_data_dict(help_obj, self._data, self.body_attrs_to_keys) + command_nouns = " ".join(nouns) + # if command in map, get the loader. Path of loader is path of helpfile. + ldr_or_none = cmd_loader_map_ref.get(command_nouns, [None])[0] + if ldr_or_none: + loaders = {ldr_or_none} + else: + loaders = set() + + # otherwise likely a group, try to find all command loaders under group as the group help could be defined + # in either. + if not loaders: + for cmd_name, cmd_ldr in cmd_loader_map_ref.items(): + # if first word in loader name is the group, this is a command in the command group + if cmd_name.startswith(command_nouns + " "): + loaders.add(cmd_ldr[0]) + + results = [] + if loaders: + for loader in loaders: + loader_file_path = inspect.getfile(loader.__class__) + dir_name = os.path.dirname(loader_file_path) + files = os.listdir(dir_name) + for file in files: + if file.endswith("help.json"): + help_file_path = os.path.join(dir_name, file) + results.append(help_file_path) + return results - # get the json help @staticmethod - def get_json_help_for_nouns(nouns, cmd_loader_map_ref): - import inspect + def _load_json_content(file_names_list, file_content_dict): import os def _parse_json_from_string(text, help_file_path): import json dir_name, base_name = os.path.split(help_file_path) - pretty_file_path = os.path.join(os.path.basename(dir_name), base_name) + if not text: + raise CLIError("No content passed for {}.".format(pretty_file_path)) + try: - data = json.loads(text) - if not data: - raise CLIError("Error: Help file {} is empty".format(pretty_file_path)) - return data + return json.loads(text) except ValueError as e: raise CLIError("Error parsing {}:\n\n{}".format(pretty_file_path, e)) - command_nouns = " ".join(nouns) - # if command in map, get the loader. Path of loader is path of helpfile. - loader = cmd_loader_map_ref.get(command_nouns, [None])[0] - - # otherwise likely a group, get the loader - if not loader: - for k, v in cmd_loader_map_ref.items(): - # if loader name starts with noun / group, this is a command in the command group - if k.startswith(command_nouns): - loader = v[0] - break - - if loader: - loader_file_path = inspect.getfile(loader.__class__) - dir_name = os.path.dirname(loader_file_path) - files = os.listdir(dir_name) - for file in files: - if file.endswith("help.json"): - help_file_path = os.path.join(dir_name, file) - with open(help_file_path, "r") as f: - text = f.read() - return [_parse_json_from_string(text, help_file_path)] - return None + results = [] + for file_name in file_names_list: + content = file_content_dict.get(file_name, '') + results.append(_parse_json_from_string(content, file_name)) + + return results + + +# test Help Loader, loads from help.json +class DummyHelpLoader(HelpLoaderV1, JsonLoaderMixin): + # This loader has different keys in the data object. Except for "arguments" and "examples". + core_attrs_to_keys = [("short_summary", "short"), ("long_summary", "long")] + body_attrs_to_keys = core_attrs_to_keys + [("links", "hyper-links")] + param_attrs_to_keys = core_attrs_to_keys + [("value_sources", "sources")] + + @property + def version(self): + return 2 + + def get_noun_help_file_names(self, nouns): + cmd_loader_map_ref = self.help_ctx.cli_ctx.invocation.commands_loader.cmd_to_loader_map + return self._get_json_help_files_list(nouns, cmd_loader_map_ref) + + def load_entry_data(self, help_obj, parser): + prog = parser.prog if hasattr(parser, "prog") else parser._prog_prefix # pylint: disable=protected-access + command_nouns = prog.split()[1:] + cmd_loader_map_ref = self.help_ctx.cli_ctx.invocation.commands_loader.cmd_to_loader_map + + files_list = self._get_json_help_files_list(command_nouns, cmd_loader_map_ref) + data_list = self._load_json_content(files_list, self._file_content_dict) + + self._entry_data = self._get_entry_data(help_obj.command, data_list) + + def load_help_body(self, help_obj): + self._update_obj_from_data_dict(help_obj, self._entry_data, self.body_attrs_to_keys) diff --git a/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/help.yaml b/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/help.yaml new file mode 100644 index 00000000000..444b96b1b4b --- /dev/null +++ b/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/help.yaml @@ -0,0 +1,1347 @@ +version: 1 +content: +- group: + name: vm secret + summary: Manage VM secrets. +- command: + name: vm secret add + summary: Add a secret to a VM. +- command: + name: vm secret list + summary: List secrets on a VM. +- command: + name: vm secret remove + summary: Remove a secret from a VM. +- command: + name: vm secret format + summary: Transform secrets into a form that can be used by VMs and VMSSes. + arguments: + - name: --secrets + description: > + The command will attempt to resolve the vault ID for each secret. If it is unable to do so, + specify the vault ID to use for *all* secrets using: --keyvault NAME --resource-group NAME | --keyvault ID. + examples: + - summary: Create a self-signed certificate with the default policy, and add it to a virtual machine. + command: > + az keyvault certificate create --vault-name vaultname -n cert1 \ + -p "$(az keyvault certificate get-default-policy)" + + secrets=$(az keyvault secret list-versions --vault-name vaultname \ + -n cert1 --query "[?attributes.enabled].id" -o tsv) + + vm_secrets=$(az vm secret format -s "$secrets") + + az vm create -g group-name -n vm-name --admin-username deploy \ + --image debian --secrets "$vm_secrets" +- command: + name: vm create + summary: Create an Azure Virtual Machine. + description: For an end-to-end tutorial, see https://docs.microsoft.com/azure/virtual-machines/virtual-machines-linux-quick-create-cli. + arguments: + - name: --image + summary: > + The name of the operating system image as a URN alias, URN, custom image name or ID, or VHD blob URI. + This parameter is required unless using `--attach-os-disk.` Valid URN format: "Publisher:Offer:Sku:Version". + value-sources: + - link: + command: az vm image list + - link: + command: az vm image show + - name: --ssh-key-value + summary: The SSH public key or public key file path. + examples: + - summary: Create a default Ubuntu VM with automatic SSH authentication. + command: > + az vm create -n MyVm -g MyResourceGroup --image UbuntuLTS + - summary: Create a default RedHat VM with automatic SSH authentication using an image URN. + command: > + az vm create -n MyVm -g MyResourceGroup --image RedHat:RHEL:7-RAW:7.4.2018010506 + - summary: Create a default Windows Server VM with a private IP address. + command: > + az vm create -n MyVm -g MyResourceGroup --public-ip-address "" --image Win2012R2Datacenter + - summary: Create a VM from a custom managed image. + command: > + az vm create -g MyResourceGroup -n MyVm --image MyImage + - summary: Create a VM by attaching to a managed operating system disk. + command: > + az vm create -g MyResourceGroup -n MyVm --attach-os-disk MyOsDisk --os-type linux + - summary: 'Create an Ubuntu Linux VM using a cloud-init script for configuration. See: https://docs.microsoft.com/azure/virtual-machines/virtual-machines-linux-using-cloud-init.' + command: > + az vm create -g MyResourceGroup -n MyVm --image debian --custom-data MyCloudInitScript.yml + - summary: Create a Debian VM with SSH key authentication and a public DNS entry, located on an existing virtual network and availability set. + command: | + az vm create -n MyVm -g MyResourceGroup --image debian --vnet-name MyVnet --subnet subnet1 \ + --availability-set MyAvailabilitySet --public-ip-address-dns-name MyUniqueDnsName \ + --ssh-key-value @key-file + - summary: Create a simple Ubuntu Linux VM with a public IP address, DNS entry, two data disks (10GB and 20GB), and then generate ssh key pairs. + command: | + az vm create -n MyVm -g MyResourceGroup --public-ip-address-dns-name MyUniqueDnsName \ + --image ubuntults --data-disk-sizes-gb 10 20 --size Standard_DS2_v2 \ + --generate-ssh-keys + - summary: Create a Debian VM using Key Vault secrets. + command: > + az keyvault certificate create --vault-name vaultname -n cert1 \ + -p "$(az keyvault certificate get-default-policy)" + + secrets=$(az keyvault secret list-versions --vault-name vaultname \ + -n cert1 --query "[?attributes.enabled].id" -o tsv) + + vm_secrets=$(az vm secret format -s "$secrets") + + + az vm create -g group-name -n vm-name --admin-username deploy \ + --image debian --secrets "$vm_secrets" + - summary: Create a CentOS VM with a system assigned identity. The VM will have a 'Contributor' role with access to a storage account. + command: > + az vm create -n MyVm -g rg1 --image centos --assign-identity --scope /subscriptions/99999999-1bf0-4dda-aec3-cb9272f09590/MyResourceGroup/myRG/providers/Microsoft.Storage/storageAccounts/storage1 + - summary: Create a debian VM with a user assigned identity. + command: > + az vm create -n MyVm -g rg1 --image debian --assign-identity /subscriptions/99999999-1bf0-4dda-aec3-cb9272f09590/resourcegroups/myRG/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myID + - summary: Create a debian VM with both system and user assigned identity. + command: > + az vm create -n MyVm -g rg1 --image debian --assign-identity [system] /subscriptions/99999999-1bf0-4dda-aec3-cb9272f09590/resourcegroups/myRG/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myID + - summary: Create a VM in an availability zone in the current resource group's region + command: > + az vm create -n MyVm -g MyResourceGroup --image Centos --zone 1 + min_profile: latest +- command: + name: vmss create + summary: Create an Azure Virtual Machine Scale Set. + description: For an end-to-end tutorial, see https://docs.microsoft.com/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-linux-create-cli. + arguments: + - name: --image + summary: > + The name of the operating system image as a URN alias, URN, custom image name or ID, or VHD blob URI. + Valid URN format: "Publisher:Offer:Sku:Version". + value-sources: + - link: + command: az vm image list + - link: + command: az vm image show + examples: + - summary: Create a Windows VM scale set with 5 instances, a load balancer, a public IP address, and a 2GB data disk. + command: > + az vmss create -n MyVmss -g MyResourceGroup --instance-count 5 --image Win2016Datacenter --data-disk-sizes-gb 2 + - summary: Create a Linux VM scale set with an auto-generated ssh key pair, a public IP address, a DNS entry, an existing load balancer, and an existing virtual network. + command: | + az vmss create -n MyVmss -g MyResourceGroup --public-ip-address-dns-name my-globally-dns-name \ + --load-balancer MyLoadBalancer --vnet-name MyVnet --subnet MySubnet --image UbuntuLTS \ + --generate-ssh-keys + - summary: Create a Linux VM scale set from a custom image using the default existing public SSH key. + command: > + az vmss create -n MyVmss -g MyResourceGroup --image MyImage + - summary: Create a Linux VM scale set with a load balancer and custom DNS servers. Each VM has a public-ip address and a custom domain name. + command: > + az vmss create -n MyVmss -g MyResourceGroup --image centos \ + --public-ip-per-vm --vm-domain-name myvmss --dns-servers 10.0.0.6 10.0.0.5 + - summary: 'Create a Linux VM scale set using a cloud-init script for configuration. See: https://docs.microsoft.com/azure/virtual-machines/virtual-machines-linux-using-cloud-init' + command: > + az vmss create -g MyResourceGroup -n MyVmss --image debian --custom-data MyCloudInitScript.yml + - summary: Create a Debian VM scaleset using Key Vault secrets. + command: > + az keyvault certificate create --vault-name vaultname -n cert1 \ + -p "$(az keyvault certificate get-default-policy)" + + secrets=$(az keyvault secret list-versions --vault-name vaultname \ + -n cert1 --query "[?attributes.enabled].id" -o tsv) + + vm_secrets=$(az vm secret format -s "$secrets") + + + az vmss create -g group-name -n vm-name --admin-username deploy \ + --image debian --secrets "$vm_secrets" + - summary: Create a VM scaleset with system assigned identity. The VM will have a 'Contributor' Role with access to a storage account. + command: > + az vmss create -n MyVmss -g MyResourceGroup --image centos --assign-identity --scope /subscriptions/99999999-1bf0-4dda-aec3-cb9272f09590/MyResourceGroup/myRG/providers/Microsoft.Storage/storageAccounts/storage1 + - summary: Create a debian VM scaleset with a user assigned identity. + command: > + az vmss create -n MyVmss -g rg1 --image debian --assign-identity /subscriptions/99999999-1bf0-4dda-aec3-cb9272f09590/resourcegroups/myRG/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myID + - summary: Create a debian VM scaleset with both system and user assigned identity. + command: > + az vmss create -n MyVmss -g rg1 --image debian --assign-identity [system] /subscriptions/99999999-1bf0-4dda-aec3-cb9272f09590/resourcegroups/myRG/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myID + - summary: Create a single zone VM scaleset in the current resource group's region + command: > + az vmss create -n MyVmss -g MyResourceGroup --image Centos --zones 1 + min_profile: latest +- command: + name: vm availability-set create + summary: Create an Azure Availability Set. + description: For more information, see https://docs.microsoft.com/azure/virtual-machines/virtual-machines-linux-manage-availability. + examples: + - summary: Create an availability set. + command: az vm availability-set create -n MyAvSet -g MyResourceGroup --platform-fault-domain-count 2 --platform-update-domain-count 2 +- command: + name: vm availability-set update + summary: Update an Azure Availability Set. + examples: + - summary: Update an availability set. + command: az vm availability-set update -n MyAvSet -g MyResourceGroup + - summary: Update an availability set tag. + command: az vm availability-set update -n MyAvSet -g MyResourceGroup --set tags.foo=value + - summary: Remove an availability set tag. + command: az vm availability-set update -n MyAvSet -g MyResourceGroup --remove tags.foo +- command: + name: vm availability-set convert + summary: Convert an Azure Availability Set to contain VMs with managed disks. + examples: + - summary: Convert an availabiity set to use managed disks by name. + command: az vm availability-set convert -g MyResourceGroup -n MyAvSet + - summary: Convert an availability set to use managed disks by ID. + command: > + az vm availability-set convert --ids $(az vm availability-set list -g MyResourceGroup --query "[].id" -o tsv) +- command: + name: vm extension set + summary: Set extensions for a VM. + description: Get extension details from `az vm extension image list`. + arguments: + - name: --name + value-sources: + - link: + command: az vm extension image list + examples: + - summary: Add a user account to a Linux VM. + command: | + az vm extension set -n VMAccessForLinux --publisher Microsoft.OSTCExtensions --version 1.4 \ + --vm-name MyVm --resource-group MyResourceGroup \ + --protected-settings '{"username":"user1", "ssh_key":"ssh_rsa ..."}' +- command: + name: vm extension wait + summary: Place the CLI in a waiting state until a condition of a virtual machine extension is met. +- command: + name: vm availability-set delete + summary: Delete an availability set. + examples: + - summary: Delete an availability set. + command: az vm availability-set delete -n MyAvSet -g MyResourceGroup +- command: + name: vm availability-set list + summary: List availability sets. + examples: + - summary: List availability sets. + command: az vm availability-set list -g MyResourceGroup +- command: + name: vm availability-set list-sizes + summary: List VM sizes for an availability set. + examples: + - summary: List VM sizes for an availability set. + command: az vm availability-set list-sizes -n MyAvSet -g MyResourceGroup +- command: + name: vm availability-set show + summary: Get information for an availability set. + examples: + - summary: Get information about an availability set. + command: az vm availability-set show -n MyAvSet -g MyResourceGroup +- command: + name: vm update + summary: Update the properties of a VM. + description: Update VM objects and properties using paths that correspond to 'az vm show'. + examples: + - summary: Add or update a tag. + command: az vm update -n name -g group --set tags.tagName=tagValue + - summary: Remove a tag. + command: az vm update -n name -g group --remove tags.tagName + - summary: Set the primary NIC of a VM. + command: az vm update -n name -g group --set networkProfile.networkInterfaces[1].primary=false networkProfile.networkInterfaces[0].primary=true + - summary: Add a new non-primary NIC to a VM. + command: az vm update -n name -g group --add networkProfile.networkInterfaces primary=false id= + - summary: Remove the fourth NIC from a VM. + command: az vm update -n name -g group --remove networkProfile.networkInterfaces 3 +- command: + name: vmss deallocate + summary: Deallocate VMs within a VMSS. +- command: + name: vmss delete-instances + summary: Delete VMs within a VMSS. +- command: + name: vmss get-instance-view + summary: View an instance of a VMSS. + arguments: + - name: --instance-id + summary: A VM instance ID or "*" to list instance view for all VMs in a scale set. +- command: + name: vmss list + summary: List VMSS. +- command: + name: vmss reimage + summary: Reimage VMs within a VMSS. + arguments: + - name: --instance-id + summary: VM instance ID. If missing, reimage all instances. +- command: + name: vmss restart + summary: Restart VMs within a VMSS. +- command: + name: vmss scale + summary: Change the number of VMs within a VMSS. + arguments: + - name: --new-capacity + summary: Number of VMs in the VMSS. +- command: + name: vmss show + summary: Get details on VMs within a VMSS. + arguments: + - name: --instance-id + summary: VM instance ID. If missing, show the VMSS. +- command: + name: vmss start + summary: Start VMs within a VMSS. +- command: + name: vmss stop + summary: Power off (stop) VMs within a VMSS. + description: The VMs will continue to be billed. To avoid this, you can deallocate VM instances within a VMSS through "az vmss deallocate" +- command: + name: vmss update + summary: Update a VMSS. +- command: + name: vmss update-instances + summary: Upgrade VMs within a VMSS. +- command: + name: vmss wait + summary: Place the CLI in a waiting state until a condition of a scale set is met. +- group: + name: vmss disk + summary: Manage data disks of a VMSS. +- command: + name: vmss disk attach + summary: Attach managed data disks to a scale set or its instances. +- command: + name: vmss disk detach + summary: Detach managed data disks from a scale set or its instances. +- group: + name: vmss nic + summary: Manage network interfaces of a VMSS. +- group: + name: vmss rolling-upgrade + summary: (PREVIEW) Manage rolling upgrades. +- command: + name: vm convert + summary: Convert a VM with unmanaged disks to use managed disks. + examples: + - summary: Convert a VM with unmanaged disks to use managed disks. + command: az vm convert -g MyResourceGroup -n MyVm + - summary: Convert all VMs with unmanaged disks in a resource group to use managed disks. + command: > + az vm convert --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) +- group: + name: vm + summary: Manage Linux or Windows virtual machines. +- group: + name: vm user + summary: Manage user accounts for a VM. +- command: + name: vm user delete + summary: Delete a user account from a VM. + examples: + - summary: Delete a user account. + command: az vm user delete -u username -n MyVm -g MyResourceGroup + - summary: Delete a user on all VMs in a resource group. + command: > + az vm user delete -u username --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) +- command: + name: vm user reset-ssh + summary: Reset the SSH configuration on a VM. + description: > + The extension will restart the SSH service, open the SSH port on your VM, and reset the SSH configuration to default values. The user account (name, password, and SSH keys) are not changed. + examples: + - summary: Reset the SSH configuration. + command: az vm user reset-ssh -n MyVm -g MyResourceGroup + - summary: Reset the SSH server on all VMs in a resource group. + command: > + az vm user reset-ssh --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) +- command: + name: vm user update + summary: Update a user account. + arguments: + - name: --ssh-key-value + summary: SSH public key file value or public key file path + examples: + - summary: Update a Windows user account. + command: az vm user update -u username -p password -n MyVm -g MyResourceGroup + - summary: Update a Linux user account. + command: az vm user update -u username --ssh-key-value "$(< ~/.ssh/id_rsa.pub)" -n MyVm -g MyResourceGroup + - summary: Update a user on all VMs in a resource group. + command: > + az vm user update -u username --ssh-key-value "$(< ~/.ssh/id_rsa.pub)" --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) +- group: + name: vm availability-set + summary: Group resources into availability sets. + description: > + To provide redundancy to an application, it is recommended to group two or more virtual machines in an availability set. + This configuration ensures that during either a planned or unplanned maintenance event, at least one virtual machine + will be available. +- group: + name: vm boot-diagnostics + summary: Troubleshoot the startup of an Azure Virtual Machine. + description: Use this feature to troubleshoot boot failures for custom or platform images. +- command: + name: vm boot-diagnostics disable + summary: Disable the boot diagnostics on a VM. + examples: + - summary: Disable boot diagnostics on all VMs in a resource group. + command: > + az vm boot-diagnostics disable --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) +- command: + name: vm boot-diagnostics enable + summary: Enable the boot diagnostics on a VM. + arguments: + - name: --storage + summary: Name or URI of a storage account (e.g. https://your_storage_account_name.blob.core.windows.net/) + examples: + - summary: Enable boot diagnostics on all VMs in a resource group. + command: > + az vm boot-diagnostics enable --storage https://mystor.blob.core.windows.net/ --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) +- command: + name: vm boot-diagnostics get-boot-log + summary: Get the boot diagnostics log from a VM. + examples: + - summary: Get diagnostics logs for all VMs in a resource group. + command: > + az vm boot-diagnostics get-boot-log --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) +- group: + name: vm diagnostics + summary: Configure the Azure Virtual Machine diagnostics extension. +- command: + name: vm diagnostics get-default-config + summary: Get the default configuration settings for a VM. + examples: + - summary: Get the default diagnostics for a Linux VM and override the storage account name and the VM resource ID. + command: | + az vm diagnostics get-default-config \ + | sed "s#__DIAGNOSTIC_STORAGE_ACCOUNT__#MyStorageAccount#g" \ + | sed "s#__VM_OR_VMSS_RESOURCE_ID__#MyVmResourceId#g" + - summary: Get the default diagnostics for a Windows VM. + command: > + az vm diagnostics get-default-config --is-windows-os +- command: + name: vm diagnostics set + summary: Configure the Azure VM diagnostics extension. + examples: + - summary: Set up default diagnostics on a Linux VM for Azure Portal VM metrics graphs and syslog collection. + command: | + # Set the following 3 parameters first. + my_resource_group= + my_linux_vm= + my_diagnostic_storage_account= + + my_vm_resource_id=$(az vm show -g $my_resource_group -n $my_linux_vm --query "id" -o tsv) + + default_config=$(az vm diagnostics get-default-config \ + | sed "s#__DIAGNOSTIC_STORAGE_ACCOUNT__#$my_diagnostic_storage_account#g" \ + | sed "s#__VM_OR_VMSS_RESOURCE_ID__#$my_vm_resource_id#g") + + storage_sastoken=$(az storage account generate-sas \ + --account-name $my_diagnostic_storage_account --expiry 2037-12-31T23:59:00Z \ + --permissions wlacu --resource-types co --services bt -o tsv) + + protected_settings="{'storageAccountName': '$my_diagnostic_storage_account', \ + 'storageAccountSasToken': '$storage_sastoken'}" + + az vm diagnostics set --settings "$default_config" \ + --protected-settings "$protected_settings" \ + --resource-group $my_resource_group --vm-name $my_linux_vm + - summary: Set up default diagnostics on a Windows VM. + command: | + # Set the following 3 parameters first. + my_resource_group= + my_windows_vm= + my_diagnostic_storage_account= + + my_vm_resource_id=$(az vm show -g $my_resource_group -n $my_windows_vm --query "id" -o tsv) + + default_config=$(az vm diagnostics get-default-config --is-windows-os \ + | sed "s#__DIAGNOSTIC_STORAGE_ACCOUNT__#$my_diagnostic_storage_account#g" \ + | sed "s#__VM_OR_VMSS_RESOURCE_ID__#$my_vm_resource_id#g") + + # Please use the same options, the WAD diagnostic extension has strict + # expectations of the sas token's format. Set the expiry as desired. + storage_sastoken=$(az storage account generate-sas \ + --account-name $my_diagnostic_storage_account --expiry 2037-12-31T23:59:00Z \ + --permissions acuw --resource-types co --services bt --https-only --output tsv) + + protected_settings="{'storageAccountName': '$my_diagnostic_storage_account', \ + 'storageAccountSasToken': '$storage_sastoken'}" + + az vm diagnostics set --settings "$default_config" \ + --protected-settings "$protected_settings" \ + --resource-group $my_resource_group --vm-name $my_windows_vm + + # # Alternatively, if the WAD extension has issues parsing the sas token, + # # one can use a storage account key instead. + storage_account_key=$(az storage account keys list --account-name {my_storage_account} \ + --query [0].value -o tsv) + protected_settings="{'storageAccountName': '$my_diagnostic_storage_account', \ + 'storageAccountKey': '$storage_account_key'}" +- group: + name: vm disk + summary: Manage the managed data disks attached to a VM. + description: >2 + + Azure Virtual Machines use disks as a place to store an operating system, applications, and data. + All Azure virtual machines have at least two disks: An operating system disk, and a temporary disk. + The operating system disk is created from an image, and both the operating system disk and the image are actually virtual hard disks (VHDs) + stored in an Azure storage account. Virtual machines also can have one or more data disks, that are also stored as VHDs. + + + Azure Managed and Unmanaged Data Disks have a maximum size of 4095 GB (with the exception of larger disks in preview). Azure Unmanaged Disks also have a maximum capacity of 4095 GB. + + + For more information, see: + + - Azure Disks - https://docs.microsoft.com/en-us/azure/virtual-machines/linux/about-disks-and-vhds and https://docs.microsoft.com/en-us/azure/virtual-machines/windows/about-disks-and-vhds. + + - Larger Managed Disks in Public Preview - https://azure.microsoft.com/en-us/blog/introducing-the-public-preview-of-larger-managed-disks-sizes/ + + - Ultra SSD Managed Disks in Public Preview - https://docs.microsoft.com/en-us/azure/virtual-machines/windows/disks-ultra-ssd +- group: + name: vm unmanaged-disk + summary: Manage the unmanaged data disks attached to a VM. + description: >2 + + Azure Virtual Machines use disks as a place to store an operating system, applications, and data. + All Azure virtual machines have at least two disks: An operating system disk, and a temporary disk. + The operating system disk is created from an image, and both the operating system disk and the image are actually virtual hard disks (VHDs) + stored in an Azure storage account. Virtual machines also can have one or more data disks, that are also stored as VHDs. + + + Azure Managed and Unmanaged Data Disks have a maximum size of 4095 GB (with the exception of larger disks in preview). Azure Unmanaged Disks also have a maximum capacity of 4095 GB. + + + For more information, see: + + - Azure Disks - https://docs.microsoft.com/en-us/azure/virtual-machines/linux/about-disks-and-vhds and https://docs.microsoft.com/en-us/azure/virtual-machines/windows/about-disks-and-vhds. + + - Larger Managed Disks in Public Preview - https://azure.microsoft.com/en-us/blog/introducing-the-public-preview-of-larger-managed-disks-sizes/ + + - Ultra SSD Managed Disks in Public Preview - https://docs.microsoft.com/en-us/azure/virtual-machines/windows/disks-ultra-ssd +- command: + name: vm unmanaged-disk attach + summary: Attach an unmanaged persistent disk to a VM. + description: This allows for the preservation of data, even if the VM is reprovisioned due to maintenance or resizing. + examples: + - summary: Attach a new default sized (1023 GB) unmanaged data disk to a VM. + command: az vm unmanaged-disk attach -g MyResourceGroup --vm-name MyVm --new + - summary: Attach an existing data disk to a VM as unmanaged. + command: > + az vm unmanaged-disk attach -g MyResourceGroup --vm-name MyVm \ + --vhd-uri https://mystorage.blob.core.windows.net/vhds/d1.vhd +- command: + name: vm unmanaged-disk detach + summary: Detach an unmanaged disk from a VM. + examples: + - summary: Detach a data disk from a VM. + command: > + az vm unmanaged-disk detach -g MyResourceGroup --vm-name MyVm -n disk_name +- command: + name: vm unmanaged-disk list + summary: List unmanaged disks of a VM. + examples: + - summary: List the unmanaged disks attached to a VM. + command: az vm unmanaged-disk list -g MyResourceGroup --vm-name MyVm + - summary: List unmanaged disks with names containing the string "data_disk". + command: > + az vm unmanaged-disk list -g MyResourceGroup --vm-name MyVm \ + --query "[?contains(name, 'data_disk')]" --output table +- command: + name: vm disk detach + summary: Detach a managed disk from a VM. + examples: + - summary: Detach a data disk from a VM. + command: > + az vm disk detach -g MyResourceGroup --vm-name MyVm --name disk_name +- command: + name: vm disk attach + summary: Attach a managed persistent disk to a VM. + description: This allows for the preservation of data, even if the VM is reprovisioned due to maintenance or resizing. + examples: + - summary: Attach a new default sized (1023 GB) managed data disk to a VM. + command: az vm disk attach -g MyResourceGroup --vm-name MyVm --name disk_name --new +- group: + name: vm encryption + summary: Manage encryption of VM disks. + description: 'For more information, see: https://docs.microsoft.com/en-us/azure/security/azure-security-disk-encryption-overview' +- command: + name: vm encryption enable + summary: Enable disk encryption on the OS disk and/or data disks. + description: 'For more information, see: https://docs.microsoft.com/en-us/azure/security/azure-security-disk-encryption-overview' + arguments: + - name: --aad-client-id + summary: Client ID of an AAD app with permissions to write secrets to the key vault. + - name: --aad-client-secret + summary: Client secret of the AAD app with permissions to write secrets to the key vault. + - name: --aad-client-cert-thumbprint + summary: Thumbprint of the AAD app certificate with permissions to write secrets to the key vault. + examples: + - summary: encrypt a VM using a key vault in the same resource group + command: > + az vm encryption enable -g MyResourceGroup -n MyVm --disk-encryption-keyvault MyVault +- command: + name: vm encryption disable + summary: Disable disk encryption on the OS disk and/or data disks. +- command: + name: vm encryption show + summary: Show encryption status. +- group: + name: vm extension + summary: Manage extensions on VMs. + description: > + Extensions are small applications that provide post-deployment configuration and automation tasks on Azure virtual machines. + For example, if a virtual machine requires software installation, anti-virus protection, or Docker configuration, a VM extension + can be used to complete these tasks. Extensions can be bundled with a new virtual machine deployment or run against any existing system. +- command: + name: vm extension list + summary: List the extensions attached to a VM. + examples: + - summary: List attached extensions to a named VM. + command: az vm extension list -g MyResourceGroup --vm-name MyVm +- command: + name: vm extension delete + summary: Remove an extension attached to a VM. + examples: + - summary: Use a VM name and extension to delete an extension from a VM. + command: az vm extension delete -g MyResourceGroup --vm-name MyVm -n extension_name + - summary: Delete extensions with IDs containing the string "MyExtension" from a VM. + command: > + az vm extension delete --ids \ + $(az resource list --query "[?contains(name, 'MyExtension')].id" -o tsv) +- command: + name: vm extension show + summary: Display information about extensions attached to a VM. + examples: + - summary: Use VM name and extension name to show the extensions attached to a VM. + command: az vm extension show -g MyResourceGroup --vm-name MyVm -n extension_name +- group: + name: vm extension image + summary: Find the available VM extensions for a subscription and region. +- command: + name: vm extension image list + summary: List the information on available extensions. + examples: + - summary: List the unique publishers for extensions. + command: az vm extension image list --query "[].publisher" -o tsv | sort -u + - summary: Find extensions with "Docker" in the name. + command: az vm extension image list --query "[].name" -o tsv | sort -u | grep Docker + - summary: List extension names where the publisher name starts with "Microsoft.Azure.App". + command: | + az vm extension image list --query \ + "[?starts_with(publisher, 'Microsoft.Azure.App')].publisher" \ + -o tsv | sort -u | xargs -I{} az vm extension image list-names --publisher {} -l westus +- command: + name: vm extension image list-names + summary: List the names of available extensions. + examples: + - summary: Find Docker extensions by publisher and location. + command: > + az vm extension image list-names --publisher Microsoft.Azure.Extensions \ + -l westus --query "[?starts_with(name, 'Docker')]" + - summary: Find CustomScript extensions by publisher and location. + command: > + az vm extension image list-names --publisher Microsoft.Azure.Extensions \ + -l westus --query "[?starts_with(name, 'Custom')]" +- command: + name: vm extension image list-versions + summary: List the versions for available extensions. + examples: + - summary: Find the available versions for the Docker extension. + command: > + az vm extension image list-versions --publisher Microsoft.Azure.Extensions \ + -l westus -n DockerExtension -otable +- command: + name: vm extension image show + summary: Display information for an extension. + examples: + - summary: Show the CustomScript extension version 2.0.2. + command: > + az vm extension image show -l westus -n CustomScript \ + --publisher Microsoft.Azure.Extensions --version 2.0.2 + - summary: Show the latest version of the Docker extension. + command: > + publisher=Microsoft.Azure.Extensions + + extension=DockerExtension + + location=westus + + + latest=$(az vm extension image list-versions \ + --publisher {publisher} -l {location} -n {extension} \ + --query "[].name" -o tsv | sort | tail -n 1) + + az vm extension image show -l {location} \ + --publisher {publisher} -n {extension} --version {latest} +- group: + name: vm image + summary: Information on available virtual machine images. +- command: + name: vm image list + summary: List the VM/VMSS images available in the Azure Marketplace. + arguments: + - name: --all + summary: Retrieve image list from live Azure service rather using an offline image list + - name: --offer + summary: Image offer name, partial name is accepted + - name: --publisher + summary: Image publisher name, partial name is accepted + - name: --sku + summary: Image sku name, partial name is accepted + examples: + - summary: List all available images. + command: az vm image list --all + - summary: List all offline cached CentOS images. + command: az vm image list -f CentOS + - summary: List all CentOS images. + command: az vm image list -f CentOS --all +- command: + name: vm image list-offers + summary: List the VM image offers available in the Azure Marketplace. + arguments: + - name: --publisher + value-sources: + - link: + command: az vm list-publishers + examples: + - summary: List all offers from Microsoft in the West US region. + command: az vm image list-offers -l westus -p MicrosoftWindowsServer + - summary: List all offers from OpenLocic in the West US region. + command: az vm image list-offers -l westus -p OpenLogic +- command: + name: vm image list-publishers + summary: List the VM image publishers available in the Azure Marketplace. + examples: + - summary: List all publishers in the West US region. + command: az vm image list-publishers -l westus + - summary: List all publishers with names starting with "Open" in westus. + command: az vm image list-publishers -l westus --query "[?starts_with(name, 'Open')]" +- command: + name: vm image list-skus + summary: List the VM image SKUs available in the Azure Marketplace. + arguments: + - name: --publisher + value-sources: + - link: + command: az vm list-publishers + examples: + - summary: List all skus available for CentOS published by OpenLogic in the West US region. + command: az vm image list-skus -l westus -f CentOS -p OpenLogic +- command: + name: vm image show + summary: Get the details for a VM image available in the Azure Marketplace. + examples: + - summary: Show information for the latest available CentOS image from OpenLogic. + command: > + latest=$(az vm image list -p OpenLogic -s 7.3 --all --query \ + "[?offer=='CentOS'].version" -o tsv | sort -u | tail -n 1) + az vm image show -l westus -f CentOS -p OpenLogic --sku 7.3 --version {latest} +- command: + name: vm image accept-terms + summary: Accept Azure Marketplace term so that the image can be used to create VMs +- group: + name: vm nic + summary: Manage network interfaces. See also `az network nic`. + description: > + A network interface (NIC) is the interconnection between a VM and the underlying software + network. For more information, see https://docs.microsoft.com/azure/virtual-network/virtual-network-network-interface-overview. +- command: + name: vm nic list + summary: List the NICs available on a VM. + examples: + - summary: List all of the NICs on a VM. + command: az vm nic list -g MyResourceGroup --vm-name MyVm +- command: + name: vm nic add + summary: Add existing NICs to a VM. + examples: + - summary: Add two NICs to a VM. + command: az vm nic add -g MyResourceGroup --vm-name MyVm --nics nic_name1 nic_name2 +- command: + name: vm nic remove + summary: Remove NICs from a VM. + examples: + - summary: Remove two NICs from a VM. + command: az vm nic remove -g MyResourceGroup --vm-name MyVm --nics nic_name1 nic_name2 +- command: + name: vm nic show + summary: Display information for a NIC attached to a VM. + examples: + - summary: Show details of a NIC on a VM. + command: az vm nic show -g MyResourceGroup --vm-name MyVm --nic nic_name1 +- command: + name: vm nic set + summary: Configure settings of a NIC attached to a VM. + examples: + - summary: Set a NIC on a VM to be the primary interface. + command: az vm nic set -g MyResourceGroup --vm-name MyVm --nic nic_name1 nic_name2 --primary-nic nic_name2 +- group: + name: vmss + summary: Manage groupings of virtual machines in an Azure Virtual Machine Scale Set (VMSS). +- group: + name: vmss diagnostics + summary: Configure the Azure Virtual Machine Scale Set diagnostics extension. +- command: + name: vmss diagnostics get-default-config + summary: Show the default config file which defines data to be collected. +- command: + name: vmss diagnostics set + summary: Enable diagnostics on a VMSS. +- command: + name: vmss list-instance-connection-info + summary: Get the IP address and port number used to connect to individual VM instances within a set. +- command: + name: vmss list-instance-public-ips + summary: List public IP addresses of VM instances within a set. +- group: + name: vmss extension + summary: Manage extensions on a VM scale set. +- command: + name: vmss extension delete + summary: Delete an extension from a VMSS. +- command: + name: vmss extension list + summary: List extensions associated with a VMSS. +- command: + name: vmss extension set + summary: Add an extension to a VMSS or update an existing extension. + description: Get extension details from `az vmss extension image list`. + arguments: + - name: --name + value-sources: + - link: + command: az vm extension image list + examples: + - summary: > + Set an extension which depends on two previously set extensions. That is, When a VMSS instance is + created or reimaged, the customScript extension will be provisioned only after all extensions that + it depends on have been provisioned. The extension need not depend on the other extensions for + pre-requisite configurations. + command: > + az vmss extension set --vmss-name my-vmss --name customScript --resource-group my-group \ + --version 2.0 --publisher Microsoft.Azure.Extensions \ + --provision-after-extensions NetworkWatcherAgentLinux VMAccessForLinux \ + --settings '{"commandToExecute": "echo testing"}' +- command: + name: vmss extension show + summary: Show details on a VMSS extension. +- group: + name: vmss extension image + summary: Find the available VM extensions for a subscription and region. +- command: + name: vmss extension image list + summary: List the information on available extensions. + examples: + - summary: List the unique publishers for extensions. + command: az vmss extension image list --query "[].publisher" -o tsv | sort -u + - summary: Find extensions with "Docker" in the name. + command: az vmss extension image list --query "[].name" -o tsv | sort -u | grep Docker + - summary: List extension names where the publisher name starts with "Microsoft.Azure.App". + command: | + az vmss extension image list --query \ + "[?starts_with(publisher, 'Microsoft.Azure.App')].publisher" \ + -o tsv | sort -u | xargs -I{} az vmss extension image list-names --publisher {} -l westus +- group: + name: vmss encryption + summary: (PREVIEW) Manage encryption of VMSS. + description: 'For more information, see: https://docs.microsoft.com/en-us/azure/security/azure-security-disk-encryption-overview' +- command: + name: vmss encryption enable + summary: Encrypt a VMSS with managed disks. + description: 'For more information, see: For more information, see: https://docs.microsoft.com/en-us/azure/security/azure-security-disk-encryption-overview' + examples: + - summary: encrypt a VM scale set using a key vault in the same resource group + command: > + az vmss encryption enable -g MyResourceGroup -n MyVmss --disk-encryption-keyvault MyVault +- command: + name: vmss encryption disable + summary: Disable the encryption on a VMSS with managed disks. + examples: + - summary: disable encryption a VMSS + command: > + az vmss encryption disable -g MyResourceGroup -n MyVm +- command: + name: vmss encryption show + summary: Show encryption status. +- command: + name: vm capture + summary: Capture information for a stopped VM. + description: For an end-to-end tutorial, see https://docs.microsoft.com/azure/virtual-machines/virtual-machines-linux-capture-image + arguments: + - name: --vhd-name-prefix + summary: The VHD name prefix specify for the VM disks. + - name: --storage-container + summary: The storage account container name in which to save the disks. + - name: --overwrite + summary: Overwrite the existing disk file. + examples: + - summary: Deallocate, generalize, and capture a stopped virtual machine. + command: | + az vm deallocate -g MyResourceGroup -n MyVm + az vm generalize -g MyResourceGroup -n MyVm + az vm capture -g MyResourceGroup -n MyVm --vhd-name-prefix MyPrefix + - summary: Deallocate, generalize, and capture multiple stopped virtual machines. + command: | + vms_ids=$(az vm list -g MyResourceGroup --query "[].id" -o tsv) + az vm deallocate --ids {vms_ids} + az vm generalize --ids {vms_ids} + az vm capture --ids {vms_ids} --vhd-name-prefix MyPrefix +- command: + name: vm delete + summary: Delete a VM. + examples: + - summary: Delete a VM without a prompt for confirmation. + command: > + az vm delete -g MyResourceGroup -n MyVm --yes + - summary: Delete all VMs in a resource group. + command: > + az vm delete --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) +- command: + name: vm deallocate + summary: Deallocate a VM. + description: For an end-to-end tutorial, see https://docs.microsoft.com/azure/virtual-machines/virtual-machines-linux-capture-image + examples: + - summary: Deallocate, generalize, and capture a stopped virtual machine. + command: | + az vm deallocate -g MyResourceGroup -n MyVm + az vm generalize -g MyResourceGroup -n MyVm + az vm capture -g MyResourceGroup -n MyVm --vhd-name-prefix MyPrefix + - summary: Deallocate, generalize, and capture multiple stopped virtual machines. + command: | + vms_ids=$(az vm list -g MyResourceGroup --query "[].id" -o tsv) + az vm deallocate --ids {vms_ids} + az vm generalize --ids {vms_ids} + az vm capture --ids {vms_ids} --vhd-name-prefix MyPrefix +- command: + name: vm generalize + summary: Mark a VM as generalized, allowing it to be imaged for multiple deployments. + description: For an end-to-end tutorial, see https://docs.microsoft.com/azure/virtual-machines/virtual-machines-linux-capture-image + examples: + - summary: Deallocate, generalize, and capture a stopped virtual machine. + command: | + az vm deallocate -g MyResourceGroup -n MyVm + az vm generalize -g MyResourceGroup -n MyVm + az vm capture -g MyResourceGroup -n MyVm --vhd-name-prefix MyPrefix + - summary: Deallocate, generalize, and capture multiple stopped virtual machines. + command: | + vms_ids=$(az vm list -g MyResourceGroup --query "[].id" -o tsv) + az vm deallocate --ids {vms_ids} + az vm generalize --ids {vms_ids} + az vm capture --ids {vms_ids} --vhd-name-prefix MyPrefix +- command: + name: vm get-instance-view + summary: Get instance information about a VM. + examples: + - summary: Use a resource group and name to get instance view information of a VM. + command: az vm get-instance-view -g MyResourceGroup -n MyVm + - summary: Get instance views for all VMs in a resource group. + command: > + az vm get-instance-view --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) +- command: + name: vm list + summary: List details of Virtual Machines. + description: For more information on querying information about Virtual Machines, see https://docs.microsoft.com/en-us/cli/azure/query-az-cli2 + examples: + - summary: List all VMs. + command: az vm list + - summary: List all VMs by resource group. + command: az vm list -g MyResourceGroup + - summary: List all VMs by resource group with details. + command: az vm list -g MyResourceGroup -d +- command: + name: vm list-ip-addresses + summary: List IP addresses associated with a VM. + examples: + - summary: Get the IP addresses for a VM. + command: az vm list-ip-addresses -g MyResourceGroup -n MyVm + - summary: Get IP addresses for all VMs in a resource group. + command: > + az vm list-ip-addresses --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) +- command: + name: vm list-sizes + summary: List available sizes for VMs. + examples: + - summary: List the available VM sizes in the West US region. + command: az vm list-sizes -l westus +- command: + name: vm list-usage + summary: List available usage resources for VMs. + examples: + - summary: Get the compute resource usage for the West US region. + command: az vm list-usage -l westus +- command: + name: vm list-vm-resize-options + summary: List available resizing options for VMs. + examples: + - summary: List all available VM sizes for resizing. + command: az vm list-vm-resize-options -g MyResourceGroup -n MyVm + - summary: List available sizes for all VMs in a resource group. + command: > + az vm list-vm-resize-options --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) +- command: + name: vm list-skus + summary: Get details for compute-related resource SKUs. + description: This command incorporates subscription level restriction, offering the most accurate information. + examples: + - summary: List all SKUs in the West US region. + command: az vm list-skus -l westus + - summary: List all available vm sizes in the East US2 region which support availability zone. + command: az vm list-skus -l eastus2 --zone + - summary: List all available vm sizes in the East US2 region which support availability zone with name like "standard_ds1...". + command: az vm list-skus -l eastus2 --zone --size standard_ds1 + - summary: List availability set related sku information in The West US region. + command: az vm list-skus -l westus --resource-type availabilitySets +- command: + name: vm open-port + summary: Opens a VM to inbound traffic on specified ports. + description: > + Adds a security rule to the network security group (NSG) that is attached to the VM's + network interface (NIC) or subnet. The existing NSG will be used or a new one will be + created. The rule name is 'open-port-{port}' and will overwrite an existing rule with + this name. For multi-NIC VMs, or for more fine-grained control, use the appropriate + network commands directly (nsg rule create, etc). + examples: + - summary: Open all ports on a VM to inbound traffic. + command: az vm open-port -g MyResourceGroup -n MyVm --port '*' + - summary: Open a range of ports on a VM to inbound traffic with the highest priority. + command: az vm open-port -g MyResourceGroup -n MyVm --port 80-100 --priority 100 + - summary: Open all ports for all VMs in a resource group. + command: > + az vm open-port --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) --port '*' +- command: + name: vm redeploy + summary: Redeploy an existing VM. + examples: + - summary: Redeploy a VM. + command: az vm redeploy -g MyResourceGroup -n MyVm + - summary: Redeploy all VMs in a resource group. + command: > + az vm redeploy --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) +- command: + name: vm resize + summary: Update a VM's size. + arguments: + - name: --size + summary: The VM size. + value-sources: + - link: + command: az vm list-vm-resize-options + examples: + - summary: Resize a VM. + command: az vm resize -g MyResourceGroup -n MyVm --size Standard_DS3_v2 + - summary: Resize all VMs in a resource group. + command: > + az vm resize --size Standard_DS3_v2 --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) +- command: + name: vm restart + summary: Restart VMs. + examples: + - summary: Restart a VM. + command: az vm restart -g MyResourceGroup -n MyVm + - summary: Restart all VMs in a resource group. + command: > + az vm restart --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) +- command: + name: vm show + summary: Get the details of a VM. + examples: + - summary: Show information about a VM. + command: az vm show -g MyResourceGroup -n MyVm -d + - summary: Get the details for all VMs in a resource group. + command: > + az vm show -d --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) +- command: + name: vm start + summary: Start a stopped VM. + examples: + - summary: Start a stopped VM. + command: az vm start -g MyResourceGroup -n MyVm + - summary: Start all VMs in a resource group. + command: > + az vm start --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) +- command: + name: vm stop + summary: Power off (stop) a running VM. + description: The VM will continue to be billed. To avoid this, you can deallocate the VM through "az vm deallocate" + examples: + - summary: Power off (stop) a running VM. + command: az vm stop -g MyResourceGroup -n MyVm + - summary: Stop all VMs in a resource group. + command: > + az vm stop --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) +- command: + name: vm wait + summary: Place the CLI in a waiting state until a condition of the VM is met. + examples: + - summary: Wait until a VM is created. + command: az vm wait -g MyResourceGroup -n MyVm --created + - summary: Wait until all VMs in a resource group are deleted. + command: > + az vm wait --deleted --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) +- group: + name: vm identity + summary: manage service identities of a VM +- command: + name: vm identity assign + summary: Enable managed service identity on a VM. + description: This is required to authenticate and interact with other Azure services using bearer tokens. + examples: + - summary: Enable the system assigned identity on a VM with the 'Reader' role. + command: az vm identity assign -g MyResourceGroup -n MyVm --role Reader --scope /subscriptions/db5eb68e-73e2-4fa8-b18a-0123456789999/resourceGroups/MyResourceGroup + - summary: Enable the system assigned identity and a user assigned identity on a VM. + command: az vm identity assign -g MyResourceGroup -n MyVm --role Reader --identities [system] myAssignedId +- command: + name: vm identity remove + summary: Remove managed service identities from a VM. + examples: + - summary: Remove the system assigned identity + command: az vm identity remove -g MyResourceGroup -n MyVm + - summary: Remove a user assigned identity + command: az vm identity remove -g MyResourceGroup -n MyVm --identities readerId + - summary: Remove 2 identities which are in the same resource group with the VM + command: az vm identity remove -g MyResourceGroup -n MyVm --identities readerId writerId + - summary: Remove the system assigned identity and a user identity + command: az vm identity remove -g MyResourceGroup -n MyVm --identities [system] readerId +- command: + name: vm identity show + summary: display VM's managed identity info. +- group: + name: vm run-command + summary: Manage run commands on a Virtual Machine. + description: For more information, see https://docs.microsoft.com/en-us/azure/virtual-machines/windows/run-command or https://docs.microsoft.com/en-us/azure/virtual-machines/linux/run-command. +- command: + name: vm run-command invoke + summary: Execute a specific run command on a vm. + arguments: + - name: --command-id + summary: The command id + value-sources: + - link: + command: az vm run-command list + examples: + - summary: install nginx on a vm + command: az vm run-command invoke -g MyResourceGroup -n MyVm --command-id RunShellScript --scripts "sudo apt-get update && sudo apt-get install -y nginx" + - summary: invoke command with parameters + command: az vm run-command invoke -g MyResourceGroup -n MyVm --command-id RunShellScript --scripts 'echo $1 $2' --parameters hello world +- command: + name: vm run-command show + arguments: + - name: --command-id + summary: The command id + value-sources: + - link: + command: az vm run-command list +- group: + name: vmss identity + summary: manage service identities of a VM scaleset. +- command: + name: vmss identity assign + summary: Enable managed service identity on a VMSS. + description: This is required to authenticate and interact with other Azure services using bearer tokens. + examples: + - summary: Enable system assigned identity on a VMSS with the 'Owner' role. + command: az vmss identity assign -g MyResourceGroup -n MyVmss --role Owner --scope /subscriptions/db5eb68e-73e2-4fa8-b18a-0123456789999/resourceGroups/MyResourceGroup +- command: + name: vmss identity remove + summary: (PREVIEW) Remove user assigned identities from a VM scaleset. + examples: + - summary: Remove system assigned identity + command: az vmss identity remove -g MyResourceGroup -n MyVmss + - summary: Remove 2 identities which are in the same resource group with the VM scaleset + command: az vmss identity remove -g MyResourceGroup -n MyVmss --identities readerId writerId + - summary: Remove system assigned identity and a user identity + command: az vmss identity remove -g MyResourceGroup -n MyVmss --identities [system] readerId +- command: + name: vmss identity show + summary: display VM scaleset's managed identity info. +- group: + name: vmss run-command + summary: Manage run commands on a Virtual Machine Scale Set. + description: For more information, see https://docs.microsoft.com/en-us/azure/virtual-machines/windows/run-command or https://docs.microsoft.com/en-us/azure/virtual-machines/linux/run-command. +- command: + name: vmss run-command invoke + summary: Execute a specific run command on a Virtual Machine Scale Set instance. + arguments: + - name: --command-id + summary: The command id + value-sources: + - link: + command: az vmss run-command list + - name: --instance-id + summary: Scale set VM instance id. + examples: + - summary: install nginx on a VMSS instance + command: az vmss run-command invoke -g MyResourceGroup -n MyVMSS --command-id RunShellScript \ --instance-id 0 --scripts "sudo apt-get update && sudo apt-get install -y nginx" + - summary: invoke a run-command with parameters on a VMSS instance + command: az vmss run-command invoke -g MyResourceGroup -n MyVMSS --command-id RunShellScript \ --instance-id 4 --scripts 'echo $1 $2' --parameters hello world + - summary: 'invoke command on all VMSS instances using the VMSS instance resource IDs. Note: "@-" expands to stdin.' + command: | + az vmss list-instances -n MyVMSS -g ova-test --query "[].id" --output tsv | \ + az vmss run-command invoke --scripts 'echo $1 $2' --parameters hello world \ + --command-id RunShellScript --ids @- +- command: + name: vmss run-command show + arguments: + - name: --command-id + summary: The command id + value-sources: + - link: + command: az vmss run-command list +- group: + name: disk + summary: Manage Azure Managed Disks. + description: >2 + + Azure Virtual Machines use disks as a place to store an operating system, applications, and data. + All Azure virtual machines have at least two disks: An operating system disk, and a temporary disk. + The operating system disk is created from an image, and both the operating system disk and the image are actually virtual hard disks (VHDs) + stored in an Azure storage account. Virtual machines also can have one or more data disks, that are also stored as VHDs. + + + Azure Managed and Unmanaged Data Disks have a maximum size of 4095 GB (with the exception of larger disks in preview). Azure Unmanaged Disks also have a maximum capacity of 4095 GB. + + + For more information, see: + + - Azure Disks - https://docs.microsoft.com/en-us/azure/virtual-machines/linux/about-disks-and-vhds and https://docs.microsoft.com/en-us/azure/virtual-machines/windows/about-disks-and-vhds. + + - Larger Managed Disks in Public Preview - https://azure.microsoft.com/en-us/blog/introducing-the-public-preview-of-larger-managed-disks-sizes/ + + - Ultra SSD Managed Disks in Public Preview - https://docs.microsoft.com/en-us/azure/virtual-machines/windows/disks-ultra-ssd +- group: + name: image + summary: Manage custom virtual machine images. +- command: + name: disk create + summary: Create a managed disk. + examples: + - summary: Create a managed disk by importing from a blob uri. + command: > + az disk create -g MyResourceGroup -n MyDisk --source https://vhd1234.blob.core.windows.net/vhds/osdisk1234.vhd + - summary: Create an empty managed disk. + command: > + az disk create -g MyResourceGroup -n MyDisk --size-gb 10 + - summary: Create a managed disk by copying an existing disk or snapshot. + command: > + az disk create -g MyResourceGroup -n MyDisk2 --source MyDisk + - summary: Create a disk in an availability zone in the region of "East US 2" + command: > + az disk create -n MyDisk -g MyResourceGroup --size-gb 10 --location eastus2 --zone 1 +- command: + name: disk list + summary: List managed disks. +- command: + name: disk delete + summary: Delete a managed disk. +- command: + name: disk update + summary: Update a managed disk. +- command: + name: disk wait + summary: Place the CLI in a waiting state until a condition of a managed disk is met. +- command: + name: disk grant-access + summary: Grant a resource read access to a managed disk. +- command: + name: disk revoke-access + summary: Revoke a resource's read access to a managed disk. +- group: + name: snapshot + summary: Manage point-in-time copies of managed disks, native blobs, or other snapshots. +- command: + name: snapshot create + summary: Create a snapshot. + examples: + - summary: Create a snapshot by importing from a blob uri. + command: > + az snapshot create -g MyResourceGroup -n MySnapshot --source https://vhd1234.blob.core.windows.net/vhds/osdisk1234.vhd + - summary: Create an empty snapshot. + command: az snapshot create -g MyResourceGroup -n MySnapshot --size-gb 10 + - summary: Create a snapshot by copying an existing disk in the same resource group. + command: az snapshot create -g MyResourceGroup -n MySnapshot2 --source MyDisk +- command: + name: snapshot update + summary: Update a snapshot. +- command: + name: snapshot list + summary: List snapshots. +- command: + name: snapshot grant-access + summary: Grant read access to a snapshot. +- command: + name: snapshot revoke-access + summary: Revoke read access to a snapshot. +- command: + name: snapshot wait + summary: Place the CLI in a waiting state until a condition of a snapshot is met. +- command: + name: image create + summary: Create a custom Virtual Machine Image from managed disks or snapshots. + examples: + - summary: Create an image from an existing disk. + command: | + az image create -g MyResourceGroup -n image1 --os-type Linux \ + --source /subscriptions/db5eb68e-73e2-4fa8-b18a-0123456789999/resourceGroups/rg1/providers/Microsoft.Compute/snapshots/s1 + - summary: Create an image by capturing an existing generalized virtual machine in the same resource group. + command: az image create -g MyResourceGroup -n image1 --source MyVm1 +- command: + name: image list + summary: List custom VM images. +- group: + name: sig + summary: manage shared image gallery +- command: + name: sig create + summary: create a share image gallery. +- command: + name: sig list + summary: list share image galleries. +- command: + name: sig update + summary: update a share image gallery. +- group: + name: sig image-definition + summary: create an image definition +- command: + name: sig image-definition create + summary: create a gallery image definition + examples: + - summary: Create a linux image defintion + command: | + az sig image-definition create -g MyResourceGroup --gallery-name MyGallery --gallery-image-definition MyImage --publisher GreatPublisher --offer GreatOffer --sku GreatSku --os-type linux +- command: + name: sig image-definition update + summary: update a share image defintiion. +- group: + name: sig image-version + summary: create a new version from an image defintion +- command: + name: sig image-version create + summary: creat a new image version + description: this operation might take a long time depending on the replicate region number. Use "--no-wait" is advised. + examples: + - summary: Add a new image version + command: | + az sig image-version create -g MyResourceGroup --gallery-name MyGallery --gallery-image-definition MyImage --gallery-image-version 1.0.0 --managed-image /subscriptions/00000000-0000-0000-0000-00000000xxxx/resourceGroups/imageGroups/providers/images/MyManagedImage + - summary: Add a new image version replicated across multiple regions with different replication counts each. Eastus2 will have it's replica count set to the default replica count. + command: | + az sig image-version create -g MyResourceGroup --gallery-name MyGallery \ + --gallery-image-definition MyImage --gallery-image-version 1.0.0 \ + --managed-image image-name --target-regions eastus2 ukwest=3 southindia=2 + - summary: Add a new image version and don't wait on it. Later you can invoke "az sig image-version wait" command when ready to create a vm from the gallery image version + command: | + az sig image-version create --no-wait -g MyResourceGroup --gallery-name MyGallery \ + --gallery-image-definition MyImage --gallery-image-version 1.0.0 \ + --managed-image imageInTheSameResourceGroup +- command: + name: sig image-version update + summary: update a share image version + examples: + - summary: Replicate to a new set of regions + command: | + az sig image-version update -g MyResourceGroup --gallery-name MyGallery --gallery-image-definition MyImage --gallery-image-version 1.0.0 --target-regions westcentralus=2 eastus2 + - summary: Replicate to one more region + command: | + az sig image-version update -g MyResourceGroup --gallery-name MyGallery --gallery-image-definition MyImage --gallery-image-version 1.0.0 --add publishingProfile.targetRegions name=westcentralus +- command: + name: sig image-version wait + summary: wait for image version related operation + examples: + - summary: wait for an image version gets updated + command: | + az sig image-version wait --updated -g MyResourceGroup --gallery-name MyGallery --gallery-image-definition MyImage --gallery-image-version 1.0.0 From 6a73d91ed94e945098b5e84f01ca92b9f6f8447c Mon Sep 17 00:00:00 2001 From: Oluwatosin Adewale Date: Wed, 27 Feb 2019 10:43:37 -0800 Subject: [PATCH 2/4] Parse Yaml when caching file contents. Yaml parsing is expensive. Update tests. Remove help.yaml --- .../azure/cli/core/_help_loaders.py | 41 +- .../azure/cli/core/tests/test_help_loaders.py | 37 +- .../azure/cli/command_modules/vm/help.yaml | 1347 ----------------- 3 files changed, 36 insertions(+), 1389 deletions(-) delete mode 100644 src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/help.yaml diff --git a/src/azure-cli-core/azure/cli/core/_help_loaders.py b/src/azure-cli-core/azure/cli/core/_help_loaders.py index 7a36dea9069..e77c4b86bd8 100644 --- a/src/azure-cli-core/azure/cli/core/_help_loaders.py +++ b/src/azure-cli-core/azure/cli/core/_help_loaders.py @@ -4,10 +4,13 @@ # -------------------------------------------------------------------------------------------- import abc +import yaml +import os from knack.util import CLIError from knack.log import get_logger from azure.cli.core._help import (HelpExample, CliHelpFile) + logger = get_logger(__name__) try: @@ -127,29 +130,17 @@ def _get_yaml_help_files_list(nouns, cmd_loader_map_ref): return results @staticmethod - def _load_yaml_content(file_names_list, file_content_dict): - import os - - def _parse_yaml_from_string(text, help_file_path): - import yaml + def _parse_yaml_from_string(text, help_file_path): + dir_name, base_name = os.path.split(help_file_path) + pretty_file_path = os.path.join(os.path.basename(dir_name), base_name) - dir_name, base_name = os.path.split(help_file_path) - pretty_file_path = os.path.join(os.path.basename(dir_name), base_name) + if not text: + raise CLIError("No content passed for {}.".format(pretty_file_path)) - if not text: - raise CLIError("No content passed for {}.".format(pretty_file_path)) - - try: - return yaml.load(text) - except yaml.YAMLError as e: - raise CLIError("Error parsing {}:\n\n{}".format(pretty_file_path, e)) - - results = [] - for file_name in file_names_list: - content = file_content_dict.get(file_name, '') - results.append(_parse_yaml_from_string(content, file_name)) - - return results + try: + return yaml.load(text) + except yaml.YAMLError as e: + raise CLIError("Error parsing {}:\n\n{}".format(pretty_file_path, e)) class HelpLoaderV0(BaseHelpLoader): @@ -190,13 +181,19 @@ def get_noun_help_file_names(self, nouns): cmd_loader_map_ref = self.help_ctx.cli_ctx.invocation.commands_loader.cmd_to_loader_map return self._get_yaml_help_files_list(nouns, cmd_loader_map_ref) + def update_file_contents(self, file_contents): + for file_name in file_contents: + if file_name not in self._file_content_dict: + data_dict = {file_name: self._parse_yaml_from_string(file_contents[file_name], file_name)} + self._file_content_dict.update(data_dict) + def load_entry_data(self, help_obj, parser): prog = parser.prog if hasattr(parser, "prog") else parser._prog_prefix # pylint: disable=protected-access command_nouns = prog.split()[1:] cmd_loader_map_ref = self.help_ctx.cli_ctx.invocation.commands_loader.cmd_to_loader_map files_list = self._get_yaml_help_files_list(command_nouns, cmd_loader_map_ref) - data_list = self._load_yaml_content(files_list, self._file_content_dict) + data_list = [self._file_content_dict[name] for name in files_list] self._entry_data = self._get_entry_data(help_obj.command, data_list) diff --git a/src/azure-cli-core/azure/cli/core/tests/test_help_loaders.py b/src/azure-cli-core/azure/cli/core/tests/test_help_loaders.py index 2f48558e9d5..a76e7454bca 100644 --- a/src/azure-cli-core/azure/cli/core/tests/test_help_loaders.py +++ b/src/azure-cli-core/azure/cli/core/tests/test_help_loaders.py @@ -90,29 +90,20 @@ def _get_json_help_files_list(nouns, cmd_loader_map_ref): return results @staticmethod - def _load_json_content(file_names_list, file_content_dict): + def _parse_json_from_string(text, help_file_path): import os + import json - def _parse_json_from_string(text, help_file_path): - import json + dir_name, base_name = os.path.split(help_file_path) + pretty_file_path = os.path.join(os.path.basename(dir_name), base_name) - dir_name, base_name = os.path.split(help_file_path) - pretty_file_path = os.path.join(os.path.basename(dir_name), base_name) + if not text: + raise CLIError("No content passed for {}.".format(pretty_file_path)) - if not text: - raise CLIError("No content passed for {}.".format(pretty_file_path)) - - try: - return json.loads(text) - except ValueError as e: - raise CLIError("Error parsing {}:\n\n{}".format(pretty_file_path, e)) - - results = [] - for file_name in file_names_list: - content = file_content_dict.get(file_name, '') - results.append(_parse_json_from_string(content, file_name)) - - return results + try: + return json.loads(text) + except ValueError as e: + raise CLIError("Error parsing {}:\n\n{}".format(pretty_file_path, e)) # test Help Loader, loads from help.json @@ -130,13 +121,19 @@ def get_noun_help_file_names(self, nouns): cmd_loader_map_ref = self.help_ctx.cli_ctx.invocation.commands_loader.cmd_to_loader_map return self._get_json_help_files_list(nouns, cmd_loader_map_ref) + def update_file_contents(self, file_contents): + for file_name in file_contents: + if file_name not in self._file_content_dict: + data_dict = {file_name: self._parse_json_from_string(file_contents[file_name], file_name)} + self._file_content_dict.update(data_dict) + def load_entry_data(self, help_obj, parser): prog = parser.prog if hasattr(parser, "prog") else parser._prog_prefix # pylint: disable=protected-access command_nouns = prog.split()[1:] cmd_loader_map_ref = self.help_ctx.cli_ctx.invocation.commands_loader.cmd_to_loader_map files_list = self._get_json_help_files_list(command_nouns, cmd_loader_map_ref) - data_list = self._load_json_content(files_list, self._file_content_dict) + data_list = [self._file_content_dict[name] for name in files_list] self._entry_data = self._get_entry_data(help_obj.command, data_list) diff --git a/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/help.yaml b/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/help.yaml deleted file mode 100644 index 444b96b1b4b..00000000000 --- a/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/help.yaml +++ /dev/null @@ -1,1347 +0,0 @@ -version: 1 -content: -- group: - name: vm secret - summary: Manage VM secrets. -- command: - name: vm secret add - summary: Add a secret to a VM. -- command: - name: vm secret list - summary: List secrets on a VM. -- command: - name: vm secret remove - summary: Remove a secret from a VM. -- command: - name: vm secret format - summary: Transform secrets into a form that can be used by VMs and VMSSes. - arguments: - - name: --secrets - description: > - The command will attempt to resolve the vault ID for each secret. If it is unable to do so, - specify the vault ID to use for *all* secrets using: --keyvault NAME --resource-group NAME | --keyvault ID. - examples: - - summary: Create a self-signed certificate with the default policy, and add it to a virtual machine. - command: > - az keyvault certificate create --vault-name vaultname -n cert1 \ - -p "$(az keyvault certificate get-default-policy)" - - secrets=$(az keyvault secret list-versions --vault-name vaultname \ - -n cert1 --query "[?attributes.enabled].id" -o tsv) - - vm_secrets=$(az vm secret format -s "$secrets") - - az vm create -g group-name -n vm-name --admin-username deploy \ - --image debian --secrets "$vm_secrets" -- command: - name: vm create - summary: Create an Azure Virtual Machine. - description: For an end-to-end tutorial, see https://docs.microsoft.com/azure/virtual-machines/virtual-machines-linux-quick-create-cli. - arguments: - - name: --image - summary: > - The name of the operating system image as a URN alias, URN, custom image name or ID, or VHD blob URI. - This parameter is required unless using `--attach-os-disk.` Valid URN format: "Publisher:Offer:Sku:Version". - value-sources: - - link: - command: az vm image list - - link: - command: az vm image show - - name: --ssh-key-value - summary: The SSH public key or public key file path. - examples: - - summary: Create a default Ubuntu VM with automatic SSH authentication. - command: > - az vm create -n MyVm -g MyResourceGroup --image UbuntuLTS - - summary: Create a default RedHat VM with automatic SSH authentication using an image URN. - command: > - az vm create -n MyVm -g MyResourceGroup --image RedHat:RHEL:7-RAW:7.4.2018010506 - - summary: Create a default Windows Server VM with a private IP address. - command: > - az vm create -n MyVm -g MyResourceGroup --public-ip-address "" --image Win2012R2Datacenter - - summary: Create a VM from a custom managed image. - command: > - az vm create -g MyResourceGroup -n MyVm --image MyImage - - summary: Create a VM by attaching to a managed operating system disk. - command: > - az vm create -g MyResourceGroup -n MyVm --attach-os-disk MyOsDisk --os-type linux - - summary: 'Create an Ubuntu Linux VM using a cloud-init script for configuration. See: https://docs.microsoft.com/azure/virtual-machines/virtual-machines-linux-using-cloud-init.' - command: > - az vm create -g MyResourceGroup -n MyVm --image debian --custom-data MyCloudInitScript.yml - - summary: Create a Debian VM with SSH key authentication and a public DNS entry, located on an existing virtual network and availability set. - command: | - az vm create -n MyVm -g MyResourceGroup --image debian --vnet-name MyVnet --subnet subnet1 \ - --availability-set MyAvailabilitySet --public-ip-address-dns-name MyUniqueDnsName \ - --ssh-key-value @key-file - - summary: Create a simple Ubuntu Linux VM with a public IP address, DNS entry, two data disks (10GB and 20GB), and then generate ssh key pairs. - command: | - az vm create -n MyVm -g MyResourceGroup --public-ip-address-dns-name MyUniqueDnsName \ - --image ubuntults --data-disk-sizes-gb 10 20 --size Standard_DS2_v2 \ - --generate-ssh-keys - - summary: Create a Debian VM using Key Vault secrets. - command: > - az keyvault certificate create --vault-name vaultname -n cert1 \ - -p "$(az keyvault certificate get-default-policy)" - - secrets=$(az keyvault secret list-versions --vault-name vaultname \ - -n cert1 --query "[?attributes.enabled].id" -o tsv) - - vm_secrets=$(az vm secret format -s "$secrets") - - - az vm create -g group-name -n vm-name --admin-username deploy \ - --image debian --secrets "$vm_secrets" - - summary: Create a CentOS VM with a system assigned identity. The VM will have a 'Contributor' role with access to a storage account. - command: > - az vm create -n MyVm -g rg1 --image centos --assign-identity --scope /subscriptions/99999999-1bf0-4dda-aec3-cb9272f09590/MyResourceGroup/myRG/providers/Microsoft.Storage/storageAccounts/storage1 - - summary: Create a debian VM with a user assigned identity. - command: > - az vm create -n MyVm -g rg1 --image debian --assign-identity /subscriptions/99999999-1bf0-4dda-aec3-cb9272f09590/resourcegroups/myRG/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myID - - summary: Create a debian VM with both system and user assigned identity. - command: > - az vm create -n MyVm -g rg1 --image debian --assign-identity [system] /subscriptions/99999999-1bf0-4dda-aec3-cb9272f09590/resourcegroups/myRG/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myID - - summary: Create a VM in an availability zone in the current resource group's region - command: > - az vm create -n MyVm -g MyResourceGroup --image Centos --zone 1 - min_profile: latest -- command: - name: vmss create - summary: Create an Azure Virtual Machine Scale Set. - description: For an end-to-end tutorial, see https://docs.microsoft.com/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-linux-create-cli. - arguments: - - name: --image - summary: > - The name of the operating system image as a URN alias, URN, custom image name or ID, or VHD blob URI. - Valid URN format: "Publisher:Offer:Sku:Version". - value-sources: - - link: - command: az vm image list - - link: - command: az vm image show - examples: - - summary: Create a Windows VM scale set with 5 instances, a load balancer, a public IP address, and a 2GB data disk. - command: > - az vmss create -n MyVmss -g MyResourceGroup --instance-count 5 --image Win2016Datacenter --data-disk-sizes-gb 2 - - summary: Create a Linux VM scale set with an auto-generated ssh key pair, a public IP address, a DNS entry, an existing load balancer, and an existing virtual network. - command: | - az vmss create -n MyVmss -g MyResourceGroup --public-ip-address-dns-name my-globally-dns-name \ - --load-balancer MyLoadBalancer --vnet-name MyVnet --subnet MySubnet --image UbuntuLTS \ - --generate-ssh-keys - - summary: Create a Linux VM scale set from a custom image using the default existing public SSH key. - command: > - az vmss create -n MyVmss -g MyResourceGroup --image MyImage - - summary: Create a Linux VM scale set with a load balancer and custom DNS servers. Each VM has a public-ip address and a custom domain name. - command: > - az vmss create -n MyVmss -g MyResourceGroup --image centos \ - --public-ip-per-vm --vm-domain-name myvmss --dns-servers 10.0.0.6 10.0.0.5 - - summary: 'Create a Linux VM scale set using a cloud-init script for configuration. See: https://docs.microsoft.com/azure/virtual-machines/virtual-machines-linux-using-cloud-init' - command: > - az vmss create -g MyResourceGroup -n MyVmss --image debian --custom-data MyCloudInitScript.yml - - summary: Create a Debian VM scaleset using Key Vault secrets. - command: > - az keyvault certificate create --vault-name vaultname -n cert1 \ - -p "$(az keyvault certificate get-default-policy)" - - secrets=$(az keyvault secret list-versions --vault-name vaultname \ - -n cert1 --query "[?attributes.enabled].id" -o tsv) - - vm_secrets=$(az vm secret format -s "$secrets") - - - az vmss create -g group-name -n vm-name --admin-username deploy \ - --image debian --secrets "$vm_secrets" - - summary: Create a VM scaleset with system assigned identity. The VM will have a 'Contributor' Role with access to a storage account. - command: > - az vmss create -n MyVmss -g MyResourceGroup --image centos --assign-identity --scope /subscriptions/99999999-1bf0-4dda-aec3-cb9272f09590/MyResourceGroup/myRG/providers/Microsoft.Storage/storageAccounts/storage1 - - summary: Create a debian VM scaleset with a user assigned identity. - command: > - az vmss create -n MyVmss -g rg1 --image debian --assign-identity /subscriptions/99999999-1bf0-4dda-aec3-cb9272f09590/resourcegroups/myRG/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myID - - summary: Create a debian VM scaleset with both system and user assigned identity. - command: > - az vmss create -n MyVmss -g rg1 --image debian --assign-identity [system] /subscriptions/99999999-1bf0-4dda-aec3-cb9272f09590/resourcegroups/myRG/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myID - - summary: Create a single zone VM scaleset in the current resource group's region - command: > - az vmss create -n MyVmss -g MyResourceGroup --image Centos --zones 1 - min_profile: latest -- command: - name: vm availability-set create - summary: Create an Azure Availability Set. - description: For more information, see https://docs.microsoft.com/azure/virtual-machines/virtual-machines-linux-manage-availability. - examples: - - summary: Create an availability set. - command: az vm availability-set create -n MyAvSet -g MyResourceGroup --platform-fault-domain-count 2 --platform-update-domain-count 2 -- command: - name: vm availability-set update - summary: Update an Azure Availability Set. - examples: - - summary: Update an availability set. - command: az vm availability-set update -n MyAvSet -g MyResourceGroup - - summary: Update an availability set tag. - command: az vm availability-set update -n MyAvSet -g MyResourceGroup --set tags.foo=value - - summary: Remove an availability set tag. - command: az vm availability-set update -n MyAvSet -g MyResourceGroup --remove tags.foo -- command: - name: vm availability-set convert - summary: Convert an Azure Availability Set to contain VMs with managed disks. - examples: - - summary: Convert an availabiity set to use managed disks by name. - command: az vm availability-set convert -g MyResourceGroup -n MyAvSet - - summary: Convert an availability set to use managed disks by ID. - command: > - az vm availability-set convert --ids $(az vm availability-set list -g MyResourceGroup --query "[].id" -o tsv) -- command: - name: vm extension set - summary: Set extensions for a VM. - description: Get extension details from `az vm extension image list`. - arguments: - - name: --name - value-sources: - - link: - command: az vm extension image list - examples: - - summary: Add a user account to a Linux VM. - command: | - az vm extension set -n VMAccessForLinux --publisher Microsoft.OSTCExtensions --version 1.4 \ - --vm-name MyVm --resource-group MyResourceGroup \ - --protected-settings '{"username":"user1", "ssh_key":"ssh_rsa ..."}' -- command: - name: vm extension wait - summary: Place the CLI in a waiting state until a condition of a virtual machine extension is met. -- command: - name: vm availability-set delete - summary: Delete an availability set. - examples: - - summary: Delete an availability set. - command: az vm availability-set delete -n MyAvSet -g MyResourceGroup -- command: - name: vm availability-set list - summary: List availability sets. - examples: - - summary: List availability sets. - command: az vm availability-set list -g MyResourceGroup -- command: - name: vm availability-set list-sizes - summary: List VM sizes for an availability set. - examples: - - summary: List VM sizes for an availability set. - command: az vm availability-set list-sizes -n MyAvSet -g MyResourceGroup -- command: - name: vm availability-set show - summary: Get information for an availability set. - examples: - - summary: Get information about an availability set. - command: az vm availability-set show -n MyAvSet -g MyResourceGroup -- command: - name: vm update - summary: Update the properties of a VM. - description: Update VM objects and properties using paths that correspond to 'az vm show'. - examples: - - summary: Add or update a tag. - command: az vm update -n name -g group --set tags.tagName=tagValue - - summary: Remove a tag. - command: az vm update -n name -g group --remove tags.tagName - - summary: Set the primary NIC of a VM. - command: az vm update -n name -g group --set networkProfile.networkInterfaces[1].primary=false networkProfile.networkInterfaces[0].primary=true - - summary: Add a new non-primary NIC to a VM. - command: az vm update -n name -g group --add networkProfile.networkInterfaces primary=false id= - - summary: Remove the fourth NIC from a VM. - command: az vm update -n name -g group --remove networkProfile.networkInterfaces 3 -- command: - name: vmss deallocate - summary: Deallocate VMs within a VMSS. -- command: - name: vmss delete-instances - summary: Delete VMs within a VMSS. -- command: - name: vmss get-instance-view - summary: View an instance of a VMSS. - arguments: - - name: --instance-id - summary: A VM instance ID or "*" to list instance view for all VMs in a scale set. -- command: - name: vmss list - summary: List VMSS. -- command: - name: vmss reimage - summary: Reimage VMs within a VMSS. - arguments: - - name: --instance-id - summary: VM instance ID. If missing, reimage all instances. -- command: - name: vmss restart - summary: Restart VMs within a VMSS. -- command: - name: vmss scale - summary: Change the number of VMs within a VMSS. - arguments: - - name: --new-capacity - summary: Number of VMs in the VMSS. -- command: - name: vmss show - summary: Get details on VMs within a VMSS. - arguments: - - name: --instance-id - summary: VM instance ID. If missing, show the VMSS. -- command: - name: vmss start - summary: Start VMs within a VMSS. -- command: - name: vmss stop - summary: Power off (stop) VMs within a VMSS. - description: The VMs will continue to be billed. To avoid this, you can deallocate VM instances within a VMSS through "az vmss deallocate" -- command: - name: vmss update - summary: Update a VMSS. -- command: - name: vmss update-instances - summary: Upgrade VMs within a VMSS. -- command: - name: vmss wait - summary: Place the CLI in a waiting state until a condition of a scale set is met. -- group: - name: vmss disk - summary: Manage data disks of a VMSS. -- command: - name: vmss disk attach - summary: Attach managed data disks to a scale set or its instances. -- command: - name: vmss disk detach - summary: Detach managed data disks from a scale set or its instances. -- group: - name: vmss nic - summary: Manage network interfaces of a VMSS. -- group: - name: vmss rolling-upgrade - summary: (PREVIEW) Manage rolling upgrades. -- command: - name: vm convert - summary: Convert a VM with unmanaged disks to use managed disks. - examples: - - summary: Convert a VM with unmanaged disks to use managed disks. - command: az vm convert -g MyResourceGroup -n MyVm - - summary: Convert all VMs with unmanaged disks in a resource group to use managed disks. - command: > - az vm convert --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) -- group: - name: vm - summary: Manage Linux or Windows virtual machines. -- group: - name: vm user - summary: Manage user accounts for a VM. -- command: - name: vm user delete - summary: Delete a user account from a VM. - examples: - - summary: Delete a user account. - command: az vm user delete -u username -n MyVm -g MyResourceGroup - - summary: Delete a user on all VMs in a resource group. - command: > - az vm user delete -u username --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) -- command: - name: vm user reset-ssh - summary: Reset the SSH configuration on a VM. - description: > - The extension will restart the SSH service, open the SSH port on your VM, and reset the SSH configuration to default values. The user account (name, password, and SSH keys) are not changed. - examples: - - summary: Reset the SSH configuration. - command: az vm user reset-ssh -n MyVm -g MyResourceGroup - - summary: Reset the SSH server on all VMs in a resource group. - command: > - az vm user reset-ssh --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) -- command: - name: vm user update - summary: Update a user account. - arguments: - - name: --ssh-key-value - summary: SSH public key file value or public key file path - examples: - - summary: Update a Windows user account. - command: az vm user update -u username -p password -n MyVm -g MyResourceGroup - - summary: Update a Linux user account. - command: az vm user update -u username --ssh-key-value "$(< ~/.ssh/id_rsa.pub)" -n MyVm -g MyResourceGroup - - summary: Update a user on all VMs in a resource group. - command: > - az vm user update -u username --ssh-key-value "$(< ~/.ssh/id_rsa.pub)" --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) -- group: - name: vm availability-set - summary: Group resources into availability sets. - description: > - To provide redundancy to an application, it is recommended to group two or more virtual machines in an availability set. - This configuration ensures that during either a planned or unplanned maintenance event, at least one virtual machine - will be available. -- group: - name: vm boot-diagnostics - summary: Troubleshoot the startup of an Azure Virtual Machine. - description: Use this feature to troubleshoot boot failures for custom or platform images. -- command: - name: vm boot-diagnostics disable - summary: Disable the boot diagnostics on a VM. - examples: - - summary: Disable boot diagnostics on all VMs in a resource group. - command: > - az vm boot-diagnostics disable --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) -- command: - name: vm boot-diagnostics enable - summary: Enable the boot diagnostics on a VM. - arguments: - - name: --storage - summary: Name or URI of a storage account (e.g. https://your_storage_account_name.blob.core.windows.net/) - examples: - - summary: Enable boot diagnostics on all VMs in a resource group. - command: > - az vm boot-diagnostics enable --storage https://mystor.blob.core.windows.net/ --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) -- command: - name: vm boot-diagnostics get-boot-log - summary: Get the boot diagnostics log from a VM. - examples: - - summary: Get diagnostics logs for all VMs in a resource group. - command: > - az vm boot-diagnostics get-boot-log --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) -- group: - name: vm diagnostics - summary: Configure the Azure Virtual Machine diagnostics extension. -- command: - name: vm diagnostics get-default-config - summary: Get the default configuration settings for a VM. - examples: - - summary: Get the default diagnostics for a Linux VM and override the storage account name and the VM resource ID. - command: | - az vm diagnostics get-default-config \ - | sed "s#__DIAGNOSTIC_STORAGE_ACCOUNT__#MyStorageAccount#g" \ - | sed "s#__VM_OR_VMSS_RESOURCE_ID__#MyVmResourceId#g" - - summary: Get the default diagnostics for a Windows VM. - command: > - az vm diagnostics get-default-config --is-windows-os -- command: - name: vm diagnostics set - summary: Configure the Azure VM diagnostics extension. - examples: - - summary: Set up default diagnostics on a Linux VM for Azure Portal VM metrics graphs and syslog collection. - command: | - # Set the following 3 parameters first. - my_resource_group= - my_linux_vm= - my_diagnostic_storage_account= - - my_vm_resource_id=$(az vm show -g $my_resource_group -n $my_linux_vm --query "id" -o tsv) - - default_config=$(az vm diagnostics get-default-config \ - | sed "s#__DIAGNOSTIC_STORAGE_ACCOUNT__#$my_diagnostic_storage_account#g" \ - | sed "s#__VM_OR_VMSS_RESOURCE_ID__#$my_vm_resource_id#g") - - storage_sastoken=$(az storage account generate-sas \ - --account-name $my_diagnostic_storage_account --expiry 2037-12-31T23:59:00Z \ - --permissions wlacu --resource-types co --services bt -o tsv) - - protected_settings="{'storageAccountName': '$my_diagnostic_storage_account', \ - 'storageAccountSasToken': '$storage_sastoken'}" - - az vm diagnostics set --settings "$default_config" \ - --protected-settings "$protected_settings" \ - --resource-group $my_resource_group --vm-name $my_linux_vm - - summary: Set up default diagnostics on a Windows VM. - command: | - # Set the following 3 parameters first. - my_resource_group= - my_windows_vm= - my_diagnostic_storage_account= - - my_vm_resource_id=$(az vm show -g $my_resource_group -n $my_windows_vm --query "id" -o tsv) - - default_config=$(az vm diagnostics get-default-config --is-windows-os \ - | sed "s#__DIAGNOSTIC_STORAGE_ACCOUNT__#$my_diagnostic_storage_account#g" \ - | sed "s#__VM_OR_VMSS_RESOURCE_ID__#$my_vm_resource_id#g") - - # Please use the same options, the WAD diagnostic extension has strict - # expectations of the sas token's format. Set the expiry as desired. - storage_sastoken=$(az storage account generate-sas \ - --account-name $my_diagnostic_storage_account --expiry 2037-12-31T23:59:00Z \ - --permissions acuw --resource-types co --services bt --https-only --output tsv) - - protected_settings="{'storageAccountName': '$my_diagnostic_storage_account', \ - 'storageAccountSasToken': '$storage_sastoken'}" - - az vm diagnostics set --settings "$default_config" \ - --protected-settings "$protected_settings" \ - --resource-group $my_resource_group --vm-name $my_windows_vm - - # # Alternatively, if the WAD extension has issues parsing the sas token, - # # one can use a storage account key instead. - storage_account_key=$(az storage account keys list --account-name {my_storage_account} \ - --query [0].value -o tsv) - protected_settings="{'storageAccountName': '$my_diagnostic_storage_account', \ - 'storageAccountKey': '$storage_account_key'}" -- group: - name: vm disk - summary: Manage the managed data disks attached to a VM. - description: >2 - - Azure Virtual Machines use disks as a place to store an operating system, applications, and data. - All Azure virtual machines have at least two disks: An operating system disk, and a temporary disk. - The operating system disk is created from an image, and both the operating system disk and the image are actually virtual hard disks (VHDs) - stored in an Azure storage account. Virtual machines also can have one or more data disks, that are also stored as VHDs. - - - Azure Managed and Unmanaged Data Disks have a maximum size of 4095 GB (with the exception of larger disks in preview). Azure Unmanaged Disks also have a maximum capacity of 4095 GB. - - - For more information, see: - - - Azure Disks - https://docs.microsoft.com/en-us/azure/virtual-machines/linux/about-disks-and-vhds and https://docs.microsoft.com/en-us/azure/virtual-machines/windows/about-disks-and-vhds. - - - Larger Managed Disks in Public Preview - https://azure.microsoft.com/en-us/blog/introducing-the-public-preview-of-larger-managed-disks-sizes/ - - - Ultra SSD Managed Disks in Public Preview - https://docs.microsoft.com/en-us/azure/virtual-machines/windows/disks-ultra-ssd -- group: - name: vm unmanaged-disk - summary: Manage the unmanaged data disks attached to a VM. - description: >2 - - Azure Virtual Machines use disks as a place to store an operating system, applications, and data. - All Azure virtual machines have at least two disks: An operating system disk, and a temporary disk. - The operating system disk is created from an image, and both the operating system disk and the image are actually virtual hard disks (VHDs) - stored in an Azure storage account. Virtual machines also can have one or more data disks, that are also stored as VHDs. - - - Azure Managed and Unmanaged Data Disks have a maximum size of 4095 GB (with the exception of larger disks in preview). Azure Unmanaged Disks also have a maximum capacity of 4095 GB. - - - For more information, see: - - - Azure Disks - https://docs.microsoft.com/en-us/azure/virtual-machines/linux/about-disks-and-vhds and https://docs.microsoft.com/en-us/azure/virtual-machines/windows/about-disks-and-vhds. - - - Larger Managed Disks in Public Preview - https://azure.microsoft.com/en-us/blog/introducing-the-public-preview-of-larger-managed-disks-sizes/ - - - Ultra SSD Managed Disks in Public Preview - https://docs.microsoft.com/en-us/azure/virtual-machines/windows/disks-ultra-ssd -- command: - name: vm unmanaged-disk attach - summary: Attach an unmanaged persistent disk to a VM. - description: This allows for the preservation of data, even if the VM is reprovisioned due to maintenance or resizing. - examples: - - summary: Attach a new default sized (1023 GB) unmanaged data disk to a VM. - command: az vm unmanaged-disk attach -g MyResourceGroup --vm-name MyVm --new - - summary: Attach an existing data disk to a VM as unmanaged. - command: > - az vm unmanaged-disk attach -g MyResourceGroup --vm-name MyVm \ - --vhd-uri https://mystorage.blob.core.windows.net/vhds/d1.vhd -- command: - name: vm unmanaged-disk detach - summary: Detach an unmanaged disk from a VM. - examples: - - summary: Detach a data disk from a VM. - command: > - az vm unmanaged-disk detach -g MyResourceGroup --vm-name MyVm -n disk_name -- command: - name: vm unmanaged-disk list - summary: List unmanaged disks of a VM. - examples: - - summary: List the unmanaged disks attached to a VM. - command: az vm unmanaged-disk list -g MyResourceGroup --vm-name MyVm - - summary: List unmanaged disks with names containing the string "data_disk". - command: > - az vm unmanaged-disk list -g MyResourceGroup --vm-name MyVm \ - --query "[?contains(name, 'data_disk')]" --output table -- command: - name: vm disk detach - summary: Detach a managed disk from a VM. - examples: - - summary: Detach a data disk from a VM. - command: > - az vm disk detach -g MyResourceGroup --vm-name MyVm --name disk_name -- command: - name: vm disk attach - summary: Attach a managed persistent disk to a VM. - description: This allows for the preservation of data, even if the VM is reprovisioned due to maintenance or resizing. - examples: - - summary: Attach a new default sized (1023 GB) managed data disk to a VM. - command: az vm disk attach -g MyResourceGroup --vm-name MyVm --name disk_name --new -- group: - name: vm encryption - summary: Manage encryption of VM disks. - description: 'For more information, see: https://docs.microsoft.com/en-us/azure/security/azure-security-disk-encryption-overview' -- command: - name: vm encryption enable - summary: Enable disk encryption on the OS disk and/or data disks. - description: 'For more information, see: https://docs.microsoft.com/en-us/azure/security/azure-security-disk-encryption-overview' - arguments: - - name: --aad-client-id - summary: Client ID of an AAD app with permissions to write secrets to the key vault. - - name: --aad-client-secret - summary: Client secret of the AAD app with permissions to write secrets to the key vault. - - name: --aad-client-cert-thumbprint - summary: Thumbprint of the AAD app certificate with permissions to write secrets to the key vault. - examples: - - summary: encrypt a VM using a key vault in the same resource group - command: > - az vm encryption enable -g MyResourceGroup -n MyVm --disk-encryption-keyvault MyVault -- command: - name: vm encryption disable - summary: Disable disk encryption on the OS disk and/or data disks. -- command: - name: vm encryption show - summary: Show encryption status. -- group: - name: vm extension - summary: Manage extensions on VMs. - description: > - Extensions are small applications that provide post-deployment configuration and automation tasks on Azure virtual machines. - For example, if a virtual machine requires software installation, anti-virus protection, or Docker configuration, a VM extension - can be used to complete these tasks. Extensions can be bundled with a new virtual machine deployment or run against any existing system. -- command: - name: vm extension list - summary: List the extensions attached to a VM. - examples: - - summary: List attached extensions to a named VM. - command: az vm extension list -g MyResourceGroup --vm-name MyVm -- command: - name: vm extension delete - summary: Remove an extension attached to a VM. - examples: - - summary: Use a VM name and extension to delete an extension from a VM. - command: az vm extension delete -g MyResourceGroup --vm-name MyVm -n extension_name - - summary: Delete extensions with IDs containing the string "MyExtension" from a VM. - command: > - az vm extension delete --ids \ - $(az resource list --query "[?contains(name, 'MyExtension')].id" -o tsv) -- command: - name: vm extension show - summary: Display information about extensions attached to a VM. - examples: - - summary: Use VM name and extension name to show the extensions attached to a VM. - command: az vm extension show -g MyResourceGroup --vm-name MyVm -n extension_name -- group: - name: vm extension image - summary: Find the available VM extensions for a subscription and region. -- command: - name: vm extension image list - summary: List the information on available extensions. - examples: - - summary: List the unique publishers for extensions. - command: az vm extension image list --query "[].publisher" -o tsv | sort -u - - summary: Find extensions with "Docker" in the name. - command: az vm extension image list --query "[].name" -o tsv | sort -u | grep Docker - - summary: List extension names where the publisher name starts with "Microsoft.Azure.App". - command: | - az vm extension image list --query \ - "[?starts_with(publisher, 'Microsoft.Azure.App')].publisher" \ - -o tsv | sort -u | xargs -I{} az vm extension image list-names --publisher {} -l westus -- command: - name: vm extension image list-names - summary: List the names of available extensions. - examples: - - summary: Find Docker extensions by publisher and location. - command: > - az vm extension image list-names --publisher Microsoft.Azure.Extensions \ - -l westus --query "[?starts_with(name, 'Docker')]" - - summary: Find CustomScript extensions by publisher and location. - command: > - az vm extension image list-names --publisher Microsoft.Azure.Extensions \ - -l westus --query "[?starts_with(name, 'Custom')]" -- command: - name: vm extension image list-versions - summary: List the versions for available extensions. - examples: - - summary: Find the available versions for the Docker extension. - command: > - az vm extension image list-versions --publisher Microsoft.Azure.Extensions \ - -l westus -n DockerExtension -otable -- command: - name: vm extension image show - summary: Display information for an extension. - examples: - - summary: Show the CustomScript extension version 2.0.2. - command: > - az vm extension image show -l westus -n CustomScript \ - --publisher Microsoft.Azure.Extensions --version 2.0.2 - - summary: Show the latest version of the Docker extension. - command: > - publisher=Microsoft.Azure.Extensions - - extension=DockerExtension - - location=westus - - - latest=$(az vm extension image list-versions \ - --publisher {publisher} -l {location} -n {extension} \ - --query "[].name" -o tsv | sort | tail -n 1) - - az vm extension image show -l {location} \ - --publisher {publisher} -n {extension} --version {latest} -- group: - name: vm image - summary: Information on available virtual machine images. -- command: - name: vm image list - summary: List the VM/VMSS images available in the Azure Marketplace. - arguments: - - name: --all - summary: Retrieve image list from live Azure service rather using an offline image list - - name: --offer - summary: Image offer name, partial name is accepted - - name: --publisher - summary: Image publisher name, partial name is accepted - - name: --sku - summary: Image sku name, partial name is accepted - examples: - - summary: List all available images. - command: az vm image list --all - - summary: List all offline cached CentOS images. - command: az vm image list -f CentOS - - summary: List all CentOS images. - command: az vm image list -f CentOS --all -- command: - name: vm image list-offers - summary: List the VM image offers available in the Azure Marketplace. - arguments: - - name: --publisher - value-sources: - - link: - command: az vm list-publishers - examples: - - summary: List all offers from Microsoft in the West US region. - command: az vm image list-offers -l westus -p MicrosoftWindowsServer - - summary: List all offers from OpenLocic in the West US region. - command: az vm image list-offers -l westus -p OpenLogic -- command: - name: vm image list-publishers - summary: List the VM image publishers available in the Azure Marketplace. - examples: - - summary: List all publishers in the West US region. - command: az vm image list-publishers -l westus - - summary: List all publishers with names starting with "Open" in westus. - command: az vm image list-publishers -l westus --query "[?starts_with(name, 'Open')]" -- command: - name: vm image list-skus - summary: List the VM image SKUs available in the Azure Marketplace. - arguments: - - name: --publisher - value-sources: - - link: - command: az vm list-publishers - examples: - - summary: List all skus available for CentOS published by OpenLogic in the West US region. - command: az vm image list-skus -l westus -f CentOS -p OpenLogic -- command: - name: vm image show - summary: Get the details for a VM image available in the Azure Marketplace. - examples: - - summary: Show information for the latest available CentOS image from OpenLogic. - command: > - latest=$(az vm image list -p OpenLogic -s 7.3 --all --query \ - "[?offer=='CentOS'].version" -o tsv | sort -u | tail -n 1) - az vm image show -l westus -f CentOS -p OpenLogic --sku 7.3 --version {latest} -- command: - name: vm image accept-terms - summary: Accept Azure Marketplace term so that the image can be used to create VMs -- group: - name: vm nic - summary: Manage network interfaces. See also `az network nic`. - description: > - A network interface (NIC) is the interconnection between a VM and the underlying software - network. For more information, see https://docs.microsoft.com/azure/virtual-network/virtual-network-network-interface-overview. -- command: - name: vm nic list - summary: List the NICs available on a VM. - examples: - - summary: List all of the NICs on a VM. - command: az vm nic list -g MyResourceGroup --vm-name MyVm -- command: - name: vm nic add - summary: Add existing NICs to a VM. - examples: - - summary: Add two NICs to a VM. - command: az vm nic add -g MyResourceGroup --vm-name MyVm --nics nic_name1 nic_name2 -- command: - name: vm nic remove - summary: Remove NICs from a VM. - examples: - - summary: Remove two NICs from a VM. - command: az vm nic remove -g MyResourceGroup --vm-name MyVm --nics nic_name1 nic_name2 -- command: - name: vm nic show - summary: Display information for a NIC attached to a VM. - examples: - - summary: Show details of a NIC on a VM. - command: az vm nic show -g MyResourceGroup --vm-name MyVm --nic nic_name1 -- command: - name: vm nic set - summary: Configure settings of a NIC attached to a VM. - examples: - - summary: Set a NIC on a VM to be the primary interface. - command: az vm nic set -g MyResourceGroup --vm-name MyVm --nic nic_name1 nic_name2 --primary-nic nic_name2 -- group: - name: vmss - summary: Manage groupings of virtual machines in an Azure Virtual Machine Scale Set (VMSS). -- group: - name: vmss diagnostics - summary: Configure the Azure Virtual Machine Scale Set diagnostics extension. -- command: - name: vmss diagnostics get-default-config - summary: Show the default config file which defines data to be collected. -- command: - name: vmss diagnostics set - summary: Enable diagnostics on a VMSS. -- command: - name: vmss list-instance-connection-info - summary: Get the IP address and port number used to connect to individual VM instances within a set. -- command: - name: vmss list-instance-public-ips - summary: List public IP addresses of VM instances within a set. -- group: - name: vmss extension - summary: Manage extensions on a VM scale set. -- command: - name: vmss extension delete - summary: Delete an extension from a VMSS. -- command: - name: vmss extension list - summary: List extensions associated with a VMSS. -- command: - name: vmss extension set - summary: Add an extension to a VMSS or update an existing extension. - description: Get extension details from `az vmss extension image list`. - arguments: - - name: --name - value-sources: - - link: - command: az vm extension image list - examples: - - summary: > - Set an extension which depends on two previously set extensions. That is, When a VMSS instance is - created or reimaged, the customScript extension will be provisioned only after all extensions that - it depends on have been provisioned. The extension need not depend on the other extensions for - pre-requisite configurations. - command: > - az vmss extension set --vmss-name my-vmss --name customScript --resource-group my-group \ - --version 2.0 --publisher Microsoft.Azure.Extensions \ - --provision-after-extensions NetworkWatcherAgentLinux VMAccessForLinux \ - --settings '{"commandToExecute": "echo testing"}' -- command: - name: vmss extension show - summary: Show details on a VMSS extension. -- group: - name: vmss extension image - summary: Find the available VM extensions for a subscription and region. -- command: - name: vmss extension image list - summary: List the information on available extensions. - examples: - - summary: List the unique publishers for extensions. - command: az vmss extension image list --query "[].publisher" -o tsv | sort -u - - summary: Find extensions with "Docker" in the name. - command: az vmss extension image list --query "[].name" -o tsv | sort -u | grep Docker - - summary: List extension names where the publisher name starts with "Microsoft.Azure.App". - command: | - az vmss extension image list --query \ - "[?starts_with(publisher, 'Microsoft.Azure.App')].publisher" \ - -o tsv | sort -u | xargs -I{} az vmss extension image list-names --publisher {} -l westus -- group: - name: vmss encryption - summary: (PREVIEW) Manage encryption of VMSS. - description: 'For more information, see: https://docs.microsoft.com/en-us/azure/security/azure-security-disk-encryption-overview' -- command: - name: vmss encryption enable - summary: Encrypt a VMSS with managed disks. - description: 'For more information, see: For more information, see: https://docs.microsoft.com/en-us/azure/security/azure-security-disk-encryption-overview' - examples: - - summary: encrypt a VM scale set using a key vault in the same resource group - command: > - az vmss encryption enable -g MyResourceGroup -n MyVmss --disk-encryption-keyvault MyVault -- command: - name: vmss encryption disable - summary: Disable the encryption on a VMSS with managed disks. - examples: - - summary: disable encryption a VMSS - command: > - az vmss encryption disable -g MyResourceGroup -n MyVm -- command: - name: vmss encryption show - summary: Show encryption status. -- command: - name: vm capture - summary: Capture information for a stopped VM. - description: For an end-to-end tutorial, see https://docs.microsoft.com/azure/virtual-machines/virtual-machines-linux-capture-image - arguments: - - name: --vhd-name-prefix - summary: The VHD name prefix specify for the VM disks. - - name: --storage-container - summary: The storage account container name in which to save the disks. - - name: --overwrite - summary: Overwrite the existing disk file. - examples: - - summary: Deallocate, generalize, and capture a stopped virtual machine. - command: | - az vm deallocate -g MyResourceGroup -n MyVm - az vm generalize -g MyResourceGroup -n MyVm - az vm capture -g MyResourceGroup -n MyVm --vhd-name-prefix MyPrefix - - summary: Deallocate, generalize, and capture multiple stopped virtual machines. - command: | - vms_ids=$(az vm list -g MyResourceGroup --query "[].id" -o tsv) - az vm deallocate --ids {vms_ids} - az vm generalize --ids {vms_ids} - az vm capture --ids {vms_ids} --vhd-name-prefix MyPrefix -- command: - name: vm delete - summary: Delete a VM. - examples: - - summary: Delete a VM without a prompt for confirmation. - command: > - az vm delete -g MyResourceGroup -n MyVm --yes - - summary: Delete all VMs in a resource group. - command: > - az vm delete --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) -- command: - name: vm deallocate - summary: Deallocate a VM. - description: For an end-to-end tutorial, see https://docs.microsoft.com/azure/virtual-machines/virtual-machines-linux-capture-image - examples: - - summary: Deallocate, generalize, and capture a stopped virtual machine. - command: | - az vm deallocate -g MyResourceGroup -n MyVm - az vm generalize -g MyResourceGroup -n MyVm - az vm capture -g MyResourceGroup -n MyVm --vhd-name-prefix MyPrefix - - summary: Deallocate, generalize, and capture multiple stopped virtual machines. - command: | - vms_ids=$(az vm list -g MyResourceGroup --query "[].id" -o tsv) - az vm deallocate --ids {vms_ids} - az vm generalize --ids {vms_ids} - az vm capture --ids {vms_ids} --vhd-name-prefix MyPrefix -- command: - name: vm generalize - summary: Mark a VM as generalized, allowing it to be imaged for multiple deployments. - description: For an end-to-end tutorial, see https://docs.microsoft.com/azure/virtual-machines/virtual-machines-linux-capture-image - examples: - - summary: Deallocate, generalize, and capture a stopped virtual machine. - command: | - az vm deallocate -g MyResourceGroup -n MyVm - az vm generalize -g MyResourceGroup -n MyVm - az vm capture -g MyResourceGroup -n MyVm --vhd-name-prefix MyPrefix - - summary: Deallocate, generalize, and capture multiple stopped virtual machines. - command: | - vms_ids=$(az vm list -g MyResourceGroup --query "[].id" -o tsv) - az vm deallocate --ids {vms_ids} - az vm generalize --ids {vms_ids} - az vm capture --ids {vms_ids} --vhd-name-prefix MyPrefix -- command: - name: vm get-instance-view - summary: Get instance information about a VM. - examples: - - summary: Use a resource group and name to get instance view information of a VM. - command: az vm get-instance-view -g MyResourceGroup -n MyVm - - summary: Get instance views for all VMs in a resource group. - command: > - az vm get-instance-view --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) -- command: - name: vm list - summary: List details of Virtual Machines. - description: For more information on querying information about Virtual Machines, see https://docs.microsoft.com/en-us/cli/azure/query-az-cli2 - examples: - - summary: List all VMs. - command: az vm list - - summary: List all VMs by resource group. - command: az vm list -g MyResourceGroup - - summary: List all VMs by resource group with details. - command: az vm list -g MyResourceGroup -d -- command: - name: vm list-ip-addresses - summary: List IP addresses associated with a VM. - examples: - - summary: Get the IP addresses for a VM. - command: az vm list-ip-addresses -g MyResourceGroup -n MyVm - - summary: Get IP addresses for all VMs in a resource group. - command: > - az vm list-ip-addresses --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) -- command: - name: vm list-sizes - summary: List available sizes for VMs. - examples: - - summary: List the available VM sizes in the West US region. - command: az vm list-sizes -l westus -- command: - name: vm list-usage - summary: List available usage resources for VMs. - examples: - - summary: Get the compute resource usage for the West US region. - command: az vm list-usage -l westus -- command: - name: vm list-vm-resize-options - summary: List available resizing options for VMs. - examples: - - summary: List all available VM sizes for resizing. - command: az vm list-vm-resize-options -g MyResourceGroup -n MyVm - - summary: List available sizes for all VMs in a resource group. - command: > - az vm list-vm-resize-options --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) -- command: - name: vm list-skus - summary: Get details for compute-related resource SKUs. - description: This command incorporates subscription level restriction, offering the most accurate information. - examples: - - summary: List all SKUs in the West US region. - command: az vm list-skus -l westus - - summary: List all available vm sizes in the East US2 region which support availability zone. - command: az vm list-skus -l eastus2 --zone - - summary: List all available vm sizes in the East US2 region which support availability zone with name like "standard_ds1...". - command: az vm list-skus -l eastus2 --zone --size standard_ds1 - - summary: List availability set related sku information in The West US region. - command: az vm list-skus -l westus --resource-type availabilitySets -- command: - name: vm open-port - summary: Opens a VM to inbound traffic on specified ports. - description: > - Adds a security rule to the network security group (NSG) that is attached to the VM's - network interface (NIC) or subnet. The existing NSG will be used or a new one will be - created. The rule name is 'open-port-{port}' and will overwrite an existing rule with - this name. For multi-NIC VMs, or for more fine-grained control, use the appropriate - network commands directly (nsg rule create, etc). - examples: - - summary: Open all ports on a VM to inbound traffic. - command: az vm open-port -g MyResourceGroup -n MyVm --port '*' - - summary: Open a range of ports on a VM to inbound traffic with the highest priority. - command: az vm open-port -g MyResourceGroup -n MyVm --port 80-100 --priority 100 - - summary: Open all ports for all VMs in a resource group. - command: > - az vm open-port --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) --port '*' -- command: - name: vm redeploy - summary: Redeploy an existing VM. - examples: - - summary: Redeploy a VM. - command: az vm redeploy -g MyResourceGroup -n MyVm - - summary: Redeploy all VMs in a resource group. - command: > - az vm redeploy --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) -- command: - name: vm resize - summary: Update a VM's size. - arguments: - - name: --size - summary: The VM size. - value-sources: - - link: - command: az vm list-vm-resize-options - examples: - - summary: Resize a VM. - command: az vm resize -g MyResourceGroup -n MyVm --size Standard_DS3_v2 - - summary: Resize all VMs in a resource group. - command: > - az vm resize --size Standard_DS3_v2 --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) -- command: - name: vm restart - summary: Restart VMs. - examples: - - summary: Restart a VM. - command: az vm restart -g MyResourceGroup -n MyVm - - summary: Restart all VMs in a resource group. - command: > - az vm restart --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) -- command: - name: vm show - summary: Get the details of a VM. - examples: - - summary: Show information about a VM. - command: az vm show -g MyResourceGroup -n MyVm -d - - summary: Get the details for all VMs in a resource group. - command: > - az vm show -d --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) -- command: - name: vm start - summary: Start a stopped VM. - examples: - - summary: Start a stopped VM. - command: az vm start -g MyResourceGroup -n MyVm - - summary: Start all VMs in a resource group. - command: > - az vm start --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) -- command: - name: vm stop - summary: Power off (stop) a running VM. - description: The VM will continue to be billed. To avoid this, you can deallocate the VM through "az vm deallocate" - examples: - - summary: Power off (stop) a running VM. - command: az vm stop -g MyResourceGroup -n MyVm - - summary: Stop all VMs in a resource group. - command: > - az vm stop --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) -- command: - name: vm wait - summary: Place the CLI in a waiting state until a condition of the VM is met. - examples: - - summary: Wait until a VM is created. - command: az vm wait -g MyResourceGroup -n MyVm --created - - summary: Wait until all VMs in a resource group are deleted. - command: > - az vm wait --deleted --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv) -- group: - name: vm identity - summary: manage service identities of a VM -- command: - name: vm identity assign - summary: Enable managed service identity on a VM. - description: This is required to authenticate and interact with other Azure services using bearer tokens. - examples: - - summary: Enable the system assigned identity on a VM with the 'Reader' role. - command: az vm identity assign -g MyResourceGroup -n MyVm --role Reader --scope /subscriptions/db5eb68e-73e2-4fa8-b18a-0123456789999/resourceGroups/MyResourceGroup - - summary: Enable the system assigned identity and a user assigned identity on a VM. - command: az vm identity assign -g MyResourceGroup -n MyVm --role Reader --identities [system] myAssignedId -- command: - name: vm identity remove - summary: Remove managed service identities from a VM. - examples: - - summary: Remove the system assigned identity - command: az vm identity remove -g MyResourceGroup -n MyVm - - summary: Remove a user assigned identity - command: az vm identity remove -g MyResourceGroup -n MyVm --identities readerId - - summary: Remove 2 identities which are in the same resource group with the VM - command: az vm identity remove -g MyResourceGroup -n MyVm --identities readerId writerId - - summary: Remove the system assigned identity and a user identity - command: az vm identity remove -g MyResourceGroup -n MyVm --identities [system] readerId -- command: - name: vm identity show - summary: display VM's managed identity info. -- group: - name: vm run-command - summary: Manage run commands on a Virtual Machine. - description: For more information, see https://docs.microsoft.com/en-us/azure/virtual-machines/windows/run-command or https://docs.microsoft.com/en-us/azure/virtual-machines/linux/run-command. -- command: - name: vm run-command invoke - summary: Execute a specific run command on a vm. - arguments: - - name: --command-id - summary: The command id - value-sources: - - link: - command: az vm run-command list - examples: - - summary: install nginx on a vm - command: az vm run-command invoke -g MyResourceGroup -n MyVm --command-id RunShellScript --scripts "sudo apt-get update && sudo apt-get install -y nginx" - - summary: invoke command with parameters - command: az vm run-command invoke -g MyResourceGroup -n MyVm --command-id RunShellScript --scripts 'echo $1 $2' --parameters hello world -- command: - name: vm run-command show - arguments: - - name: --command-id - summary: The command id - value-sources: - - link: - command: az vm run-command list -- group: - name: vmss identity - summary: manage service identities of a VM scaleset. -- command: - name: vmss identity assign - summary: Enable managed service identity on a VMSS. - description: This is required to authenticate and interact with other Azure services using bearer tokens. - examples: - - summary: Enable system assigned identity on a VMSS with the 'Owner' role. - command: az vmss identity assign -g MyResourceGroup -n MyVmss --role Owner --scope /subscriptions/db5eb68e-73e2-4fa8-b18a-0123456789999/resourceGroups/MyResourceGroup -- command: - name: vmss identity remove - summary: (PREVIEW) Remove user assigned identities from a VM scaleset. - examples: - - summary: Remove system assigned identity - command: az vmss identity remove -g MyResourceGroup -n MyVmss - - summary: Remove 2 identities which are in the same resource group with the VM scaleset - command: az vmss identity remove -g MyResourceGroup -n MyVmss --identities readerId writerId - - summary: Remove system assigned identity and a user identity - command: az vmss identity remove -g MyResourceGroup -n MyVmss --identities [system] readerId -- command: - name: vmss identity show - summary: display VM scaleset's managed identity info. -- group: - name: vmss run-command - summary: Manage run commands on a Virtual Machine Scale Set. - description: For more information, see https://docs.microsoft.com/en-us/azure/virtual-machines/windows/run-command or https://docs.microsoft.com/en-us/azure/virtual-machines/linux/run-command. -- command: - name: vmss run-command invoke - summary: Execute a specific run command on a Virtual Machine Scale Set instance. - arguments: - - name: --command-id - summary: The command id - value-sources: - - link: - command: az vmss run-command list - - name: --instance-id - summary: Scale set VM instance id. - examples: - - summary: install nginx on a VMSS instance - command: az vmss run-command invoke -g MyResourceGroup -n MyVMSS --command-id RunShellScript \ --instance-id 0 --scripts "sudo apt-get update && sudo apt-get install -y nginx" - - summary: invoke a run-command with parameters on a VMSS instance - command: az vmss run-command invoke -g MyResourceGroup -n MyVMSS --command-id RunShellScript \ --instance-id 4 --scripts 'echo $1 $2' --parameters hello world - - summary: 'invoke command on all VMSS instances using the VMSS instance resource IDs. Note: "@-" expands to stdin.' - command: | - az vmss list-instances -n MyVMSS -g ova-test --query "[].id" --output tsv | \ - az vmss run-command invoke --scripts 'echo $1 $2' --parameters hello world \ - --command-id RunShellScript --ids @- -- command: - name: vmss run-command show - arguments: - - name: --command-id - summary: The command id - value-sources: - - link: - command: az vmss run-command list -- group: - name: disk - summary: Manage Azure Managed Disks. - description: >2 - - Azure Virtual Machines use disks as a place to store an operating system, applications, and data. - All Azure virtual machines have at least two disks: An operating system disk, and a temporary disk. - The operating system disk is created from an image, and both the operating system disk and the image are actually virtual hard disks (VHDs) - stored in an Azure storage account. Virtual machines also can have one or more data disks, that are also stored as VHDs. - - - Azure Managed and Unmanaged Data Disks have a maximum size of 4095 GB (with the exception of larger disks in preview). Azure Unmanaged Disks also have a maximum capacity of 4095 GB. - - - For more information, see: - - - Azure Disks - https://docs.microsoft.com/en-us/azure/virtual-machines/linux/about-disks-and-vhds and https://docs.microsoft.com/en-us/azure/virtual-machines/windows/about-disks-and-vhds. - - - Larger Managed Disks in Public Preview - https://azure.microsoft.com/en-us/blog/introducing-the-public-preview-of-larger-managed-disks-sizes/ - - - Ultra SSD Managed Disks in Public Preview - https://docs.microsoft.com/en-us/azure/virtual-machines/windows/disks-ultra-ssd -- group: - name: image - summary: Manage custom virtual machine images. -- command: - name: disk create - summary: Create a managed disk. - examples: - - summary: Create a managed disk by importing from a blob uri. - command: > - az disk create -g MyResourceGroup -n MyDisk --source https://vhd1234.blob.core.windows.net/vhds/osdisk1234.vhd - - summary: Create an empty managed disk. - command: > - az disk create -g MyResourceGroup -n MyDisk --size-gb 10 - - summary: Create a managed disk by copying an existing disk or snapshot. - command: > - az disk create -g MyResourceGroup -n MyDisk2 --source MyDisk - - summary: Create a disk in an availability zone in the region of "East US 2" - command: > - az disk create -n MyDisk -g MyResourceGroup --size-gb 10 --location eastus2 --zone 1 -- command: - name: disk list - summary: List managed disks. -- command: - name: disk delete - summary: Delete a managed disk. -- command: - name: disk update - summary: Update a managed disk. -- command: - name: disk wait - summary: Place the CLI in a waiting state until a condition of a managed disk is met. -- command: - name: disk grant-access - summary: Grant a resource read access to a managed disk. -- command: - name: disk revoke-access - summary: Revoke a resource's read access to a managed disk. -- group: - name: snapshot - summary: Manage point-in-time copies of managed disks, native blobs, or other snapshots. -- command: - name: snapshot create - summary: Create a snapshot. - examples: - - summary: Create a snapshot by importing from a blob uri. - command: > - az snapshot create -g MyResourceGroup -n MySnapshot --source https://vhd1234.blob.core.windows.net/vhds/osdisk1234.vhd - - summary: Create an empty snapshot. - command: az snapshot create -g MyResourceGroup -n MySnapshot --size-gb 10 - - summary: Create a snapshot by copying an existing disk in the same resource group. - command: az snapshot create -g MyResourceGroup -n MySnapshot2 --source MyDisk -- command: - name: snapshot update - summary: Update a snapshot. -- command: - name: snapshot list - summary: List snapshots. -- command: - name: snapshot grant-access - summary: Grant read access to a snapshot. -- command: - name: snapshot revoke-access - summary: Revoke read access to a snapshot. -- command: - name: snapshot wait - summary: Place the CLI in a waiting state until a condition of a snapshot is met. -- command: - name: image create - summary: Create a custom Virtual Machine Image from managed disks or snapshots. - examples: - - summary: Create an image from an existing disk. - command: | - az image create -g MyResourceGroup -n image1 --os-type Linux \ - --source /subscriptions/db5eb68e-73e2-4fa8-b18a-0123456789999/resourceGroups/rg1/providers/Microsoft.Compute/snapshots/s1 - - summary: Create an image by capturing an existing generalized virtual machine in the same resource group. - command: az image create -g MyResourceGroup -n image1 --source MyVm1 -- command: - name: image list - summary: List custom VM images. -- group: - name: sig - summary: manage shared image gallery -- command: - name: sig create - summary: create a share image gallery. -- command: - name: sig list - summary: list share image galleries. -- command: - name: sig update - summary: update a share image gallery. -- group: - name: sig image-definition - summary: create an image definition -- command: - name: sig image-definition create - summary: create a gallery image definition - examples: - - summary: Create a linux image defintion - command: | - az sig image-definition create -g MyResourceGroup --gallery-name MyGallery --gallery-image-definition MyImage --publisher GreatPublisher --offer GreatOffer --sku GreatSku --os-type linux -- command: - name: sig image-definition update - summary: update a share image defintiion. -- group: - name: sig image-version - summary: create a new version from an image defintion -- command: - name: sig image-version create - summary: creat a new image version - description: this operation might take a long time depending on the replicate region number. Use "--no-wait" is advised. - examples: - - summary: Add a new image version - command: | - az sig image-version create -g MyResourceGroup --gallery-name MyGallery --gallery-image-definition MyImage --gallery-image-version 1.0.0 --managed-image /subscriptions/00000000-0000-0000-0000-00000000xxxx/resourceGroups/imageGroups/providers/images/MyManagedImage - - summary: Add a new image version replicated across multiple regions with different replication counts each. Eastus2 will have it's replica count set to the default replica count. - command: | - az sig image-version create -g MyResourceGroup --gallery-name MyGallery \ - --gallery-image-definition MyImage --gallery-image-version 1.0.0 \ - --managed-image image-name --target-regions eastus2 ukwest=3 southindia=2 - - summary: Add a new image version and don't wait on it. Later you can invoke "az sig image-version wait" command when ready to create a vm from the gallery image version - command: | - az sig image-version create --no-wait -g MyResourceGroup --gallery-name MyGallery \ - --gallery-image-definition MyImage --gallery-image-version 1.0.0 \ - --managed-image imageInTheSameResourceGroup -- command: - name: sig image-version update - summary: update a share image version - examples: - - summary: Replicate to a new set of regions - command: | - az sig image-version update -g MyResourceGroup --gallery-name MyGallery --gallery-image-definition MyImage --gallery-image-version 1.0.0 --target-regions westcentralus=2 eastus2 - - summary: Replicate to one more region - command: | - az sig image-version update -g MyResourceGroup --gallery-name MyGallery --gallery-image-definition MyImage --gallery-image-version 1.0.0 --add publishingProfile.targetRegions name=westcentralus -- command: - name: sig image-version wait - summary: wait for image version related operation - examples: - - summary: wait for an image version gets updated - command: | - az sig image-version wait --updated -g MyResourceGroup --gallery-name MyGallery --gallery-image-definition MyImage --gallery-image-version 1.0.0 From 3e9d90f13cbb2c551a5ecfd72f2968d9d8f268f0 Mon Sep 17 00:00:00 2001 From: Oluwatosin Adewale Date: Thu, 28 Feb 2019 20:36:10 -0800 Subject: [PATCH 3/4] Minor style fixes. --- src/azure-cli-core/azure/cli/core/_help_loaders.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/_help_loaders.py b/src/azure-cli-core/azure/cli/core/_help_loaders.py index e77c4b86bd8..4a481bddbf0 100644 --- a/src/azure-cli-core/azure/cli/core/_help_loaders.py +++ b/src/azure-cli-core/azure/cli/core/_help_loaders.py @@ -4,8 +4,8 @@ # -------------------------------------------------------------------------------------------- import abc -import yaml import os +import yaml from knack.util import CLIError from knack.log import get_logger from azure.cli.core._help import (HelpExample, CliHelpFile) @@ -92,14 +92,13 @@ def _update_help_obj_params(help_obj, data_params, params_equal, attr_key_tups): help_obj.parameters = loaded_params -class YamlLoaderMixin(object): # pylint:disable=too-few-public-methods +class YamlLoaderMixin(object): # pylint:disable=too-few-public-methods """A class containing helper methods for Yaml Loaders.""" # get the list of yaml help file names for the command or group @staticmethod def _get_yaml_help_files_list(nouns, cmd_loader_map_ref): import inspect - import os command_nouns = " ".join(nouns) # if command in map, get the loader. Path of loader is path of helpfile. From e691bc52e3984627a267662f46a0366172297e7a Mon Sep 17 00:00:00 2001 From: Oluwatosin Adewale Date: Mon, 4 Mar 2019 13:59:15 -0800 Subject: [PATCH 4/4] Fix bad python 2 super call. --- src/azure-cli-core/azure/cli/core/_help.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli-core/azure/cli/core/_help.py b/src/azure-cli-core/azure/cli/core/_help.py index e3f6552d5fe..2721290b222 100644 --- a/src/azure-cli-core/azure/cli/core/_help.py +++ b/src/azure-cli-core/azure/cli/core/_help.py @@ -143,7 +143,7 @@ def new_normalize_text(s): # override def show_help(self, cli_name, nouns, parser, is_group): self.update_loaders_with_help_file_contents(nouns) - super().show_help(cli_name, nouns, parser, is_group) + super(AzCliHelp, self).show_help(cli_name, nouns, parser, is_group) def _register_help_loaders(self): import azure.cli.core._help_loaders as help_loaders