Class: Azure::Armrest::VirtualMachineService
- Inherits:
-
ResourceGroupBasedService
- Object
- ArmrestService
- ResourceGroupBasedService
- Azure::Armrest::VirtualMachineService
- Defined in:
- lib/azure/armrest/virtual_machine_service.rb
Overview
Base class for managing virtual machines
Direct Known Subclasses
Constant Summary
Constants inherited from ResourceGroupBasedService
ResourceGroupBasedService::SERVICE_NAME_MAP
Instance Attribute Summary
Attributes inherited from ArmrestService
#api_version, #armrest_configuration, #base_url, #provider, #service_name
Instance Method Summary collapse
-
#capture(vmname, options, group = configuration.resource_group) ⇒ Object
Captures the
vmname
and associated disks into a reusable CSM template. -
#deallocate(vmname, group = configuration.resource_group) ⇒ Object
Stop the VM
vmname
ingroup
and deallocate the tenant in Fabric. -
#delete_associated_resources(vmname, vmgroup, options = {}) ⇒ Object
Delete the VM and associated resources.
-
#generalize(vmname, group = configuration.resource_group) ⇒ Object
Sets the OSState for the
vmname
ingroup
to ‘Generalized’. -
#get(vmname, group = configuration.resource_group, model_view = true) ⇒ Object
Retrieves the settings of the VM named
vmname
in resource groupgroup
, which will default to the same as the name of the VM. -
#get_instance_view(vmname, group = configuration.resource_group) ⇒ Object
Convenient wrapper around the get method that retrieves the instance view for
vmname
in resource_groupgroup
. -
#get_model_view(vmname, group = configuration.resource_group) ⇒ Object
Convenient wrapper around the get method that retrieves the model view for
vmname
in resource_groupgroup
. -
#initialize(configuration, options = {}) ⇒ VirtualMachineService
constructor
Create and return a new VirtualMachineService (VMM) instance.
- #model_class ⇒ Object
-
#restart(vmname, group = configuration.resource_group) ⇒ Object
Restart the VM
vmname
for the givengroup
, which will default to the same as the vmname. -
#series(location) ⇒ Object
(also: #sizes)
Return a list of available VM series (aka sizes, flavors, etc), such as “Basic_A1”, though other information is included as well.
-
#start(vmname, group = configuration.resource_group) ⇒ Object
Start the VM
vmname
for the givengroup
, which will default to the same as the vmname. -
#stop(vmname, group = configuration.resource_group) ⇒ Object
Stop the VM
vmname
for the givengroup
gracefully.
Methods inherited from ResourceGroupBasedService
#create, #delete, #get_associated_resource, #list, #list_all
Methods inherited from ArmrestService
configure, #get_provider, #get_subscription, #list_resource_groups, #list_resources, #list_subscriptions, #locations, #poll, #tags, #tenants, #wait
Constructor Details
#initialize(configuration, options = {}) ⇒ VirtualMachineService
Create and return a new VirtualMachineService (VMM) instance. Most methods for a VMM instance will return one or more VirtualMachine instances.
This subclass accepts the additional :provider option as well. The default is ‘Microsoft.ClassicCompute’. You may need to set this to ‘Microsoft.Compute’ for your purposes.
15 16 17 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 15 def initialize(configuration, = {}) super(configuration, 'virtualMachines', 'Microsoft.Compute', ) end |
Instance Method Details
#capture(vmname, options, group = configuration.resource_group) ⇒ Object
Captures the vmname
and associated disks into a reusable CSM template. The 3rd argument is a hash of options that supports the following keys:
-
vhdPrefix - The prefix in the name of the blobs.
-
destinationContainerName - The name of the container inside which the image will reside.
-
overwriteVhds - Boolean that indicates whether or not to overwrite any VHD’s
with the same prefix. The default is false.
48 49 50 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 48 def capture(vmname, , group = configuration.resource_group) vm_operate('capture', vmname, group, ) end |
#deallocate(vmname, group = configuration.resource_group) ⇒ Object
Stop the VM vmname
in group
and deallocate the tenant in Fabric.
54 55 56 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 54 def deallocate(vmname, group = configuration.resource_group) vm_operate('deallocate', vmname, group) end |
#delete_associated_resources(vmname, vmgroup, options = {}) ⇒ Object
Delete the VM and associated resources. By default, this will delete the VM, its NIC, the associated IP address, and the image files (.vhd and .status) for the VM.
If you want to delete other associated resources, such as any attached disks, the VM’s underlying storage account, or associated network security groups you must explicitly specify them as an option.
An attempt to delete a resource that cannot be deleted because it’s still associated with some other resource will be logged and skipped.
If the :verbose option is set to true, then additional messages are sent to your configuration log, or stdout if no log was specified.
Note that if all of your related resources are in a self-contained resource group, you do not necessarily need this method. You could just delete the resource group itself, which would automatically delete all of its resources.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 143 def delete_associated_resources(vmname, vmgroup, = {}) = { :network_interfaces => true, :ip_addresses => true, :os_disk => true, :network_security_groups => false, :storage_account => false, :verbose => false }.merge() Azure::Armrest::Configuration.log ||= STDOUT if [:verbose] vm = get(vmname, vmgroup) delete_and_wait(self, vmname, vmgroup, ) # Must delete network interfaces first if you want to delete # IP addresses or network security groups. if [:network_interfaces] || [:ip_addresses] || [:network_security_groups] delete_associated_nics(vm, ) end if [:os_disk] || [:storage_account] delete_associated_disk(vm, ) end end |
#generalize(vmname, group = configuration.resource_group) ⇒ Object
Sets the OSState for the vmname
in group
to ‘Generalized’.
60 61 62 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 60 def generalize(vmname, group = configuration.resource_group) vm_operate('generalize', vmname, group) end |
#get(vmname, group = configuration.resource_group, model_view = true) ⇒ Object
Retrieves the settings of the VM named vmname
in resource group group
, which will default to the same as the name of the VM.
By default this method will retrieve the model view. If the model_view
parameter is false, it will retrieve an instance view. The difference is in the details of the information retrieved.
71 72 73 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 71 def get(vmname, group = configuration.resource_group, model_view = true) model_view ? super(vmname, group) : get_instance_view(vmname, group) end |
#get_instance_view(vmname, group = configuration.resource_group) ⇒ Object
Convenient wrapper around the get method that retrieves the instance view for vmname
in resource_group group
.
85 86 87 88 89 90 91 92 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 85 def get_instance_view(vmname, group = configuration.resource_group) raise ArgumentError, "must specify resource group" unless group raise ArgumentError, "must specify name of the resource" unless vmname url = build_url(group, vmname, 'instanceView') response = rest_get(url) VirtualMachineInstance.new(response) end |
#get_model_view(vmname, group = configuration.resource_group) ⇒ Object
Convenient wrapper around the get method that retrieves the model view for vmname
in resource_group group
.
78 79 80 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 78 def get_model_view(vmname, group = configuration.resource_group) get(vmname, group, true) end |
#model_class ⇒ Object
170 171 172 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 170 def model_class VirtualMachineModel end |
#restart(vmname, group = configuration.resource_group) ⇒ Object
Restart the VM vmname
for the given group
, which will default to the same as the vmname.
This is an asynchronous operation that returns a response object which you can inspect, such as response.code or response.headers.
100 101 102 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 100 def restart(vmname, group = configuration.resource_group) vm_operate('restart', vmname, group) end |
#series(location) ⇒ Object Also known as: sizes
Return a list of available VM series (aka sizes, flavors, etc), such as “Basic_A1”, though other information is included as well.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 22 def series(location) namespace = 'microsoft.compute' version = configuration.provider_default_api_version(namespace, 'locations/vmsizes') unless version raise ArgumentError, "Unable to find resources for #{namespace}" end url = url_with_api_version( version, @base_url, 'subscriptions', configuration.subscription_id, 'providers', provider, 'locations', location, 'vmSizes' ) JSON.parse(rest_get(url))['value'].map{ |hash| VirtualMachineSize.new(hash) } end |
#start(vmname, group = configuration.resource_group) ⇒ Object
Start the VM vmname
for the given group
, which will default to the same as the vmname.
This is an asynchronous operation that returns a response object which you can inspect, such as response.code or response.headers.
110 111 112 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 110 def start(vmname, group = configuration.resource_group) vm_operate('start', vmname, group) end |
#stop(vmname, group = configuration.resource_group) ⇒ Object
Stop the VM vmname
for the given group
gracefully. However, a forced shutdown will occur after 15 minutes.
This is an asynchronous operation that returns a response object which you can inspect, such as response.code or response.headers.
120 121 122 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 120 def stop(vmname, group = configuration.resource_group) vm_operate('powerOff', vmname, group) end |