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 instance.
-
#list_by_location(location, options = {}) ⇒ Object
Return a list of virtual machines for the given
location
. - #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, #delete_by_id, #get_by_id, #list, #list_all
Methods inherited from ArmrestService
configure, #get_provider, #get_subscription, #list_locations, #list_resource_groups, #list_resources, #list_subscriptions, #locations, #poll, #tags, #tenants, #wait
Constructor Details
#initialize(configuration, options = {}) ⇒ VirtualMachineService
Create and return a new VirtualMachineService instance. Most methods for a VirtualMachineService instance will return one or more VirtualMachine instances.
This subclass accepts the additional :provider option as well. The default is ‘Microsoft.Compute’. You may need to set this to ‘Microsoft.ClassicCompute’ 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.
55 56 57 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 55 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.
61 62 63 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 61 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.
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 150 def delete_associated_resources(vmname, vmgroup, = {}) = { :network_interfaces => true, :ip_addresses => true, :os_disk => true, :data_disks => false, :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 if [:data_disks] delete_associated_data_disks(vm, ) end end |
#generalize(vmname, group = configuration.resource_group) ⇒ Object
Sets the OSState for the vmname
in group
to ‘Generalized’.
67 68 69 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 67 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.
78 79 80 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 78 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
.
92 93 94 95 96 97 98 99 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 92 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
.
85 86 87 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 85 def get_model_view(vmname, group = configuration.resource_group) get(vmname, group, true) end |
#list_by_location(location, options = {}) ⇒ Object
Return a list of virtual machines for the given location
.
21 22 23 24 25 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 21 def list_by_location(location, = {}) url = url_with_api_version(api_version, base_url, 'providers', provider, 'locations', location, service_name) response = rest_get(url) get_all_results(response, [:skip_accessors_definition]) end |
#model_class ⇒ Object
182 183 184 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 182 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.
107 108 109 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 107 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.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 30 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, '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.
117 118 119 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 117 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.
127 128 129 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 127 def stop(vmname, group = configuration.resource_group) vm_operate('powerOff', vmname, group) end |