az_vm_template {AzureVM} | R Documentation |
Virtual machine template class
Description
Class representing a virtual machine deployment template. This class keeps track of all resources that are created as part of deploying a VM, and exposes methods for managing them.
Format
An R6 object of class az_vm_template
, inheriting from AzureRMR::az_template
.
Details
A single virtual machine in Azure is actually a collection of resources, including any and all of the following.
Network interface (Azure resource type
Microsoft.Network/networkInterfaces
)Network security group (Azure resource type
Microsoft.Network/networkSecurityGroups
)Virtual network (Azure resource type
Microsoft.Network/virtualNetworks
)Public IP address (Azure resource type
Microsoft.Network/publicIPAddresses
)The VM itself (Azure resource type
Microsoft.Compute/virtualMachines
)
By wrapping the deployment template used to create these resources, the az_vm_template
class allows managing them all as a single entity.
Fields
The following fields are exposed, in addition to those provided by the AzureRMR::az_template class.
-
dns_name
: The DNS name for the VM. Will be NULL if the VM is not publicly visible, or doesn't have a domain name assigned to its public IP address. -
identity
: The managed identity details for the VM. Will be NULL if the VM doesn't have an identity assigned.
Methods
The following methods are available, in addition to those provided by the AzureRMR::az_template class.
-
start(wait=TRUE)
: Start the VM. By default, wait until the startup process is complete. -
stop(deallocate=TRUE, wait=FALSE)
: Stop the VM. By default, deallocate it as well. -
restart(wait=TRUE)
: Restart the VM. -
run_deployed_command(command, parameters, script)
: Run a PowerShell command on the VM. -
run_script(script, parameters)
: Run a script on the VM. For a Linux VM, this will be a shell script; for a Windows VM, a PowerShell script. Pass the script as a character vector. -
sync_vm_status()
: Check the status of the VM. -
resize(size, deallocate=FALSE, wait=FALSE)
: Resize the VM. Optionally stop and deallocate it first (may sometimes be necessary). -
redeploy()
: Redeploy the VM. -
reimage()
: Reimage the VM. -
get_public_ip_address(nic=1, config=1)
: Get the public IP address of the VM. Returns NA if the VM is stopped, or is not publicly accessible. -
get_private_ip_address(nic=1, config=1)
: Get the private IP address of the VM. -
get_public_ip_resource(nic=1, config=1)
: Get the Azure resource for the VM's public IP address. -
get_nic(nic=1)
: Get the VM's network interface resource. -
get_vnet(nic=1, config=1)
: Get the VM's virtual network resource. -
get_nsg(nic=1, config=1)
: Get the VM's network security group resource. Note that an NSG can be attached to either the VM's network interface or to its virtual network subnet; if there is an NSG attached to both, this method returns a list containing the two NSG resource objects. -
get_disk(disk="os")
: Get a managed disk resource attached to the VM. Thedisk
argument can be "os" for the OS disk, or a number indicating the LUN of a data disk. AzureVM only supports managed disks. -
add_extension(publisher, type, version, settings=list(), protected_settings=list(), key_vault_settings=list())
: Add an extension to the VM. -
do_vm_operation(...)
: Carries out an arbitrary operation on the VM resource. See thedo_operation
method of the AzureRMR::az_resource class for more details.
Many of these methods are actually provided by the az_vm_resource class, and propagated to the template as active bindings.
See Also
AzureRMR::az_template, create_vm, get_vm, delete_vm
Examples
## Not run:
sub <- AzureRMR::get_azure_login()$
get_subscription("subscription_id")
vm <- sub$get_vm("myvm")
vm$identity
vm$start()
vm$get_private_ip_address()
vm$get_public_ip_address()
vm$run_script("echo hello world! > /tmp/hello.txt")
vm$stop()
vm$get_private_ip_address()
vm$get_public_ip_address() # NA, assuming VM has a dynamic IP address
vm$resize("Standard_DS13_v2")
vm$sync_vm_status()
## End(Not run)