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
Instance Attribute Summary
Attributes inherited from ArmrestService
#api_version, #armrest_configuration, #base_url, #provider
Instance Method Summary collapse
-
#capture(vmname, options, group = configuration.resource_group) ⇒ Object
Captures the
vmnameand associated disks into a reusable CSM template. -
#deallocate(vmname, group = configuration.resource_group) ⇒ Object
Stop the VM
vmnameingroupand deallocate the tenant in Fabric. -
#generalize(vmname, group = configuration.resource_group) ⇒ Object
Sets the OSState for the
vmnameingroupto ‘Generalized’. -
#get(vmname, group = configuration.resource_group, model_view = true) ⇒ Object
Retrieves the settings of the VM named
vmnamein 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
vmnamein resource_groupgroup. -
#get_model_view(vmname, group = configuration.resource_group) ⇒ Object
Convenient wrapper around the get method that retrieves the model view for
vmnamein 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
vmnamefor 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
vmnamefor the givengroup, which will default to the same as the vmname. -
#stop(vmname, group = configuration.resource_group) ⇒ Object
Stop the VM
vmnamefor the givengroupgracefully.
Methods inherited from ResourceGroupBasedService
#create, #delete, #list, #list_all
Methods inherited from ArmrestService
configure, #get_provider, #get_subscription, #list_resource_groups, #list_resources, #list_subscriptions, #locations, #tags, #tenants
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 |
#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
124 125 126 |
# File 'lib/azure/armrest/virtual_machine_service.rb', line 124 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 |