зеркало из https://github.com/microsoft/azure-cli.git
Merge pull request #202 from BurtBiel/commands/CreateVM
remove required password, load SSH key from a file, add choices to swagger
This commit is contained in:
Коммит
af6bd59025
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче