This commit is contained in:
Burt Bielicki 2016-05-04 15:45:11 -07:00
Родитель 1a407f6507 f94ef2f00d
Коммит bd25ba8e3c
10 изменённых файлов: 128 добавлений и 37 удалений

Просмотреть файл

@ -81,6 +81,7 @@ def print_arguments(help_file):
+ str(not p.required) + p.name):
indent = 1
required_text = required_tag if p.required else ''
p.short_summary = (p.short_summary if p.short_summary else '') + _get_choices_str(p)
if p.group_name != last_group_name:
if p.group_name:
print('')
@ -134,6 +135,14 @@ def _print_groups(help_file):
indent)
_print_indent('')
def _get_choices_str(p):
choice_str = ""
if p.choices:
choice_str = (' ' if p.short_summary else '') \
+ '[{}{}]'.format(', '.join(p.choices),
('; default: ' + p.default) if p.default else '')
return choice_str
def _print_examples(help_file):
indent = 0
print('')
@ -216,6 +225,8 @@ class CommandHelpFile(HelpFile): #pylint: disable=too-few-public-methods
self.parameters.append(HelpParameter(' '.join(sorted(action.option_strings)),
action.help,
required=action.required,
choices=action.choices,
default=action.default,
group_name=action.container.description))
help_param = next(p for p in self.parameters if p.name == '--help -h')
@ -243,14 +254,17 @@ class CommandHelpFile(HelpFile): #pylint: disable=too-few-public-methods
self.parameters = loaded_params
class HelpParameter(object): #pylint: disable=too-few-public-methods
def __init__(self, param_name, description, required, group_name=False):
class HelpParameter(object): #pylint: disable=too-few-public-methods, too-many-instance-attributes
def __init__(self, param_name, description, required, choices=None, #pylint: disable=too-many-arguments
default=None, group_name=None):
self.name = param_name
self.required = required
self.type = 'string'
self.short_summary = description
self.long_summary = ''
self.value_sources = []
self.choices = choices
self.default = default
self.group_name = group_name
def update_from_data(self, data):

Просмотреть файл

@ -139,7 +139,8 @@ class Application(object):
global_group.add_argument('--subscription', dest='_subscription_id', help=argparse.SUPPRESS)
global_group.add_argument('--output', '-o', dest='_output_format',
choices=['list', 'json', 'tsv'],
help='Output format of type "list", "json" or "tsv"')
default='list',
help='Output format')
# The arguments for verbosity don't get parsed by argparse but we add it here for help.
global_group.add_argument('--verbose', dest='_log_verbosity_verbose',
help='Increase logging verbosity.'

Просмотреть файл

@ -303,7 +303,7 @@ blob_types_str = ' '.join(blob_types.keys())
@command_table.option(**PARAMETER_ALIASES['container_name'])
@command_table.option(**PARAMETER_ALIASES['blob_name'])
@command_table.option('--type', required=True, choices=blob_types.keys(),
help=L('type of blob to upload ({})'.format(blob_types_str)))
help=L('type of blob to upload'))
@command_table.option('--upload-from', required=True,
help=L('local path to upload from'))
@command_table.option_set(STORAGE_DATA_CLIENT_ARGS)

Просмотреть файл

@ -1,5 +1,6 @@
import argparse
import re
import os
from azure.mgmt.compute import ComputeManagementClient, ComputeManagementClientConfiguration
from azure.mgmt.compute.operations import (AvailabilitySetsOperations,
VirtualMachineExtensionImagesOperations,
@ -210,11 +211,25 @@ class VMImageFieldAction(argparse.Action): #pylint: disable=too-few-public-metho
else:
namespace.os_type = image
class VMSSHFieldAction(argparse.Action): #pylint: disable=too-few-public-methods
def __call__(self, parser, namespace, values, option_string=None):
ssh_value = values
if os.path.exists(ssh_value):
with open(ssh_value, 'r') as f:
namespace.ssh_key_value = f.read()
else:
namespace.ssh_key_value = ssh_value
extra_parameters = [
{
'name': '--image',
'help': 'The OS image. Supported values: Common OS (e.g. Win2012R2Datacenter), URN (e.g. "publisher:offer:sku:version"), or existing VHD URI.',
'action': VMImageFieldAction
},
{
'name': '--ssh-key-value',
'action': VMSSHFieldAction
}
]
@ -247,7 +262,7 @@ helps['vm create'] = """
--virtual-network-type existing --virtual-network-name myvnet --subnet-name default
--availability-set-type existing --availability-set-id myavailset
--public-ip-address-type new --dns-name-for-public-ip myGloballyUniqueVmDnsName
-l "West US" -g myvms --name myvm18o --ssh-key-value "<ssh-rsa-key>"
-l "West US" -g myvms --name myvm18o --ssh-key-value "<ssh-rsa-key or key-file-path>"
"""
build_operation('vm',

Просмотреть файл

@ -11,8 +11,9 @@
},
"adminPassword": {
"type": "securestring",
"defaultValue": "",
"metadata": {
"description": "Password for the Virtual Machine."
"description": "Password for the Virtual Machine. Required if SSH (Linux only) is not specified."
}
},
"adminUsername": {

Просмотреть файл

@ -38,7 +38,8 @@ class DeploymentVM(Model):
used to access the Virtual Machine.
:type dns_name_for_public_ip: str
:param storage_account_type: Whether to use an existing storage account
or create a new one.
or create a new one. Possible values include: 'new', 'existing'. Default
value: "new" .
:type storage_account_type: str
:param os_disk_uri: URI for a custom VHD image.
:type os_disk_uri: str
@ -48,16 +49,21 @@ class DeploymentVM(Model):
:param name: The VM resource name.
:type name: str
:param virtual_network_type: Whether to use an existing VNet or create a
new one.
new one. Possible values include: 'new', 'existing'. Default value:
"new" .
:type virtual_network_type: str
:param admin_password: Password for the Virtual Machine.
:param admin_password: Password for the Virtual Machine. Required if SSH
(Linux only) is not specified.
:type admin_password: str
:param os_sku: The OS SKU to install.
:type os_sku: str
:param subnet_name: The subnet name.
:type subnet_name: str
:param os_type: Common OS choices. Choose 'Custom' to specify an image
with the osPublisher, osOffer, osSKU, and osVersion parameters.
with the osPublisher, osOffer, osSKU, and osVersion parameters. Possible
values include: 'CentOS', 'CoreOS', 'Debian', 'openSUSE', 'RHEL',
'SLES', 'UbuntuLTS', 'Win2012R2Datacenter', 'Win2012Datacenter',
'Win2008R2SP1', 'Custom'. Default value: "Win2012R2Datacenter" .
:type os_type: str
:param admin_username: Username for the Virtual Machine.
:type admin_username: str
@ -70,10 +76,12 @@ class DeploymentVM(Model):
:param os_offer: The OS Offer to install.
:type os_offer: str
:param public_ip_address_allocation: Dynamic or Static public IP address
allocation.
allocation. Possible values include: 'Dynamic', 'Static'. Default value:
"Dynamic" .
:type public_ip_address_allocation: str
:param authentication_type: Authentication method: password-only or add
ssh-keys (Linux-only).
ssh-keys (Linux-only). Possible values include: 'password', 'sshkey'.
Default value: "password" .
:type authentication_type: str
:param storage_account_name: Name of storage account for the VM OS disk.
:type storage_account_name: str
@ -82,7 +90,8 @@ class DeploymentVM(Model):
:param size: The VM Size that should be created (e.g. Standard_A2)
:type size: str
:param public_ip_address_type: Use a public IP Address for the VM Nic.
(new, existing or none).
(new, existing or none). Possible values include: 'none', 'new',
'existing'. Default value: "none" .
:type public_ip_address_type: str
:param virtual_network_ip_address_prefix: The IP address prefix.
:type virtual_network_ip_address_prefix: str
@ -95,12 +104,14 @@ class DeploymentVM(Model):
:param os_publisher: The OS publisher of the OS image.
:type os_publisher: str
:param availability_set_type: Flag to add the VM to an existing
availability set.
availability set. Possible values include: 'none', 'existing'. Default
value: "none" .
:type availability_set_type: str
:param public_ip_address_name: Name of public IP address to use.
:type public_ip_address_name: str
:param dns_name_type: Associate VMs with a public IP address to a DNS
name (new or none).
name (new or none). Possible values include: 'none', 'new'. Default
value: "none" .
:type dns_name_type: str
:ivar mode: Gets or sets the deployment mode. Default value:
"Incremental" .
@ -111,7 +122,6 @@ class DeploymentVM(Model):
'uri': {'required': True, 'constant': True},
'_artifacts_location': {'constant': True},
'name': {'required': True},
'admin_password': {'required': True},
'admin_username': {'required': True},
'mode': {'required': True, 'constant': True},
}
@ -161,7 +171,7 @@ class DeploymentVM(Model):
mode = "Incremental"
def __init__(self, name, admin_password, admin_username, content_version=None, storage_container_name=None, virtual_network_name=None, subnet_ip_address_prefix=None, private_ip_address_allocation=None, dns_name_for_public_ip=None, storage_account_type=None, os_disk_uri=None, virtual_network_type=None, os_sku=None, subnet_name=None, os_type=None, os_version=None, os_disk_name=None, ssh_key_path=None, os_offer=None, public_ip_address_allocation=None, authentication_type=None, storage_account_name=None, storage_redundancy_type=None, size=None, public_ip_address_type=None, virtual_network_ip_address_prefix=None, availability_set_id=None, ssh_key_value=None, location=None, os_publisher=None, availability_set_type=None, public_ip_address_name=None, dns_name_type=None):
def __init__(self, name, admin_username, content_version=None, storage_container_name=None, virtual_network_name=None, subnet_ip_address_prefix=None, private_ip_address_allocation=None, dns_name_for_public_ip=None, storage_account_type="new", os_disk_uri=None, virtual_network_type="new", admin_password=None, os_sku=None, subnet_name=None, os_type="Win2012R2Datacenter", os_version=None, os_disk_name=None, ssh_key_path=None, os_offer=None, public_ip_address_allocation="Dynamic", authentication_type="password", storage_account_name=None, storage_redundancy_type=None, size=None, public_ip_address_type="none", virtual_network_ip_address_prefix=None, availability_set_id=None, ssh_key_value=None, location=None, os_publisher=None, availability_set_type="none", public_ip_address_name=None, dns_name_type="none"):
self.content_version = content_version
self.storage_container_name = storage_container_name
self.virtual_network_name = virtual_network_name

Просмотреть файл

@ -32,7 +32,7 @@ class VMOperations(object):
self.config = config
def create_or_update(
self, resource_group_name, deployment_name, name, admin_password, admin_username, content_version=None, storage_container_name=None, virtual_network_name=None, subnet_ip_address_prefix=None, private_ip_address_allocation=None, dns_name_for_public_ip=None, storage_account_type=None, os_disk_uri=None, virtual_network_type=None, os_sku=None, subnet_name=None, os_type=None, os_version=None, os_disk_name=None, ssh_key_path=None, os_offer=None, public_ip_address_allocation=None, authentication_type=None, storage_account_name=None, storage_redundancy_type=None, size=None, public_ip_address_type=None, virtual_network_ip_address_prefix=None, availability_set_id=None, ssh_key_value=None, location=None, os_publisher=None, availability_set_type=None, public_ip_address_name=None, dns_name_type=None, custom_headers={}, raw=False, **operation_config):
self, resource_group_name, deployment_name, name, admin_username, content_version=None, storage_container_name=None, virtual_network_name=None, subnet_ip_address_prefix=None, private_ip_address_allocation=None, dns_name_for_public_ip=None, storage_account_type="new", os_disk_uri=None, virtual_network_type="new", admin_password=None, os_sku=None, subnet_name=None, os_type="Win2012R2Datacenter", os_version=None, os_disk_name=None, ssh_key_path=None, os_offer=None, public_ip_address_allocation="Dynamic", authentication_type="password", storage_account_name=None, storage_redundancy_type=None, size=None, public_ip_address_type="none", virtual_network_ip_address_prefix=None, availability_set_id=None, ssh_key_value=None, location=None, os_publisher=None, availability_set_type="none", public_ip_address_name=None, dns_name_type="none", custom_headers={}, raw=False, **operation_config):
"""
Create or update a virtual machine.
@ -43,8 +43,6 @@ class VMOperations(object):
:type deployment_name: str
:param name: The VM resource name.
:type name: str
:param admin_password: Password for the Virtual Machine.
:type admin_password: str
:param admin_username: Username for the Virtual Machine.
:type admin_username: str
:param content_version: If included it must match the ContentVersion
@ -64,19 +62,26 @@ class VMOperations(object):
Public IP used to access the Virtual Machine.
:type dns_name_for_public_ip: str
:param storage_account_type: Whether to use an existing storage
account or create a new one.
account or create a new one. Possible values include: 'new',
'existing'
:type storage_account_type: str
:param os_disk_uri: URI for a custom VHD image.
:type os_disk_uri: str
:param virtual_network_type: Whether to use an existing VNet or
create a new one.
create a new one. Possible values include: 'new', 'existing'
:type virtual_network_type: str
:param admin_password: Password for the Virtual Machine. Required if
SSH (Linux only) is not specified.
:type admin_password: str
:param os_sku: The OS SKU to install.
:type os_sku: str
:param subnet_name: The subnet name.
:type subnet_name: str
:param os_type: Common OS choices. Choose 'Custom' to specify an
image with the osPublisher, osOffer, osSKU, and osVersion parameters.
image with the osPublisher, osOffer, osSKU, and osVersion
parameters. Possible values include: 'CentOS', 'CoreOS', 'Debian',
'openSUSE', 'RHEL', 'SLES', 'UbuntuLTS', 'Win2012R2Datacenter',
'Win2012Datacenter', 'Win2008R2SP1', 'Custom'
:type os_type: str
:param os_version: The OS version to install.
:type os_version: str
@ -87,10 +92,11 @@ class VMOperations(object):
:param os_offer: The OS Offer to install.
:type os_offer: str
:param public_ip_address_allocation: Dynamic or Static public IP
address allocation.
address allocation. Possible values include: 'Dynamic', 'Static'
:type public_ip_address_allocation: str
:param authentication_type: Authentication method: password-only or
add ssh-keys (Linux-only).
add ssh-keys (Linux-only). Possible values include: 'password',
'sshkey'
:type authentication_type: str
:param storage_account_name: Name of storage account for the VM OS
disk.
@ -100,7 +106,8 @@ class VMOperations(object):
:param size: The VM Size that should be created (e.g. Standard_A2)
:type size: str
:param public_ip_address_type: Use a public IP Address for the VM
Nic. (new, existing or none).
Nic. (new, existing or none). Possible values include: 'none',
'new', 'existing'
:type public_ip_address_type: str
:param virtual_network_ip_address_prefix: The IP address prefix.
:type virtual_network_ip_address_prefix: str
@ -113,12 +120,12 @@ class VMOperations(object):
:param os_publisher: The OS publisher of the OS image.
:type os_publisher: str
:param availability_set_type: Flag to add the VM to an existing
availability set.
availability set. Possible values include: 'none', 'existing'
:type availability_set_type: str
:param public_ip_address_name: Name of public IP address to use.
:type public_ip_address_name: str
:param dns_name_type: Associate VMs with a public IP address to a DNS
name (new or none).
name (new or none). Possible values include: 'none', 'new'
:type dns_name_type: str
:param dict custom_headers: headers that will be added to the request
:param bool raw: returns the direct response alongside the

Просмотреть файл

@ -90,7 +90,6 @@
"osProfile": {
"computerName": "[variables('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]",
"linuxConfiguration": {
"disablePasswordAuthentication": true,
"ssh": {

Просмотреть файл

@ -88,7 +88,6 @@
"osProfile": {
"computerName": "[variables('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]",
"linuxConfiguration": {
"disablePasswordAuthentication": true,
"ssh": {

Просмотреть файл

@ -327,7 +327,6 @@
}
},
"required": [
"adminPassword",
"adminUsername",
"virtualMachineName"
]
@ -382,6 +381,11 @@
"value": {
"type": "string",
"description": "Whether to use an existing storage account or create a new one.",
"enum": [
"new",
"existing"
],
"default": "new",
"x-ms-client-name": "storageAccountType"
}
}
@ -427,6 +431,11 @@
"value": {
"type": "string",
"description": "Whether to use an existing VNet or create a new one.",
"enum": [
"new",
"existing"
],
"default": "new",
"x-ms-client-name": "virtualNetworkType"
}
}
@ -435,14 +444,10 @@
"properties": {
"value": {
"type": "string",
"description": "Password for the Virtual Machine.",
"description": "Password for the Virtual Machine. Required if SSH (Linux only) is not specified.",
"x-ms-client-name": "adminPassword"
}
},
"required": [
"value"
]
}
},
"DeploymentParameter_osSKU": {
"properties": {
@ -467,6 +472,20 @@
"value": {
"type": "string",
"description": "Common OS choices. Choose 'Custom' to specify an image with the osPublisher, osOffer, osSKU, and osVersion parameters.",
"enum": [
"CentOS",
"CoreOS",
"Debian",
"openSUSE",
"RHEL",
"SLES",
"UbuntuLTS",
"Win2012R2Datacenter",
"Win2012Datacenter",
"Win2008R2SP1",
"Custom"
],
"default": "Win2012R2Datacenter",
"x-ms-client-name": "osType"
}
}
@ -525,6 +544,11 @@
"value": {
"type": "string",
"description": "Dynamic or Static public IP address allocation.",
"enum": [
"Dynamic",
"Static"
],
"default": "Dynamic",
"x-ms-client-name": "publicIpAddressAllocation"
}
}
@ -534,6 +558,11 @@
"value": {
"type": "string",
"description": "Authentication method: password-only or add ssh-keys (Linux-only).",
"enum": [
"password",
"sshkey"
],
"default": "password",
"x-ms-client-name": "authenticationType"
}
}
@ -570,6 +599,12 @@
"value": {
"type": "string",
"description": "Use a public IP Address for the VM Nic. (new, existing or none).",
"enum": [
"none",
"new",
"existing"
],
"default": "none",
"x-ms-client-name": "publicIpAddressType"
}
}
@ -624,6 +659,11 @@
"value": {
"type": "string",
"description": "Flag to add the VM to an existing availability set.",
"enum": [
"none",
"existing"
],
"default": "none",
"x-ms-client-name": "availabilitySetType"
}
}
@ -642,6 +682,11 @@
"value": {
"type": "string",
"description": "Associate VMs with a public IP address to a DNS name (new or none).",
"enum": [
"none",
"new"
],
"default": "none",
"x-ms-client-name": "dnsNameType"
}
}