Class: Azure::Armrest::VirtualMachineExtensionService

Inherits:
VirtualMachineService show all
Defined in:
lib/azure/armrest/virtual_machine_extension_service.rb

Overview

Base class for managing virtual machine extensions

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

Methods inherited from VirtualMachineService

#capture, #deallocate, #delete_associated_resources, #generalize, #list_by_location, #model_class, #restart, #series, #start, #stop

Methods inherited from ResourceGroupBasedService

#delete_by_id, #get_by_id, #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 = {}) ⇒ VirtualMachineExtensionService

Creates and returns a new VirtualMachineExtensionService object.



10
11
12
13
# File 'lib/azure/armrest/virtual_machine_extension_service.rb', line 10

def initialize(_configuration, options = {})
  super
  set_service_api_version(options, 'virtualMachines/extensions')
end

Instance Method Details

#create(vm_name, ext_name, options = {}, rgroup = nil) ⇒ Object Also known as: update

Creates a new extension for the provided VM with the given options. The possible options are:

  • :location - The location for the extension. Mandatory.

  • :type - The type of compute resource. The default is “Microsoft.Compute/virtualMachines/extensions”.

  • :tags - A list of key value pairs. Max 10 pairs. Optional.

  • :properties

    • :type - The type of extension. Required.

    • :publisher - Name of extension publisher. Default is the provider.

    • :typeHandlerVersion - Optional. Specifies the extension version. Default is “1.*”.

    • :settings - Public configuration that does not require encryption. Optional.

      • :fileUris - The script file path.

      • :commandToExecute - The command used to execute the script.

For convenience, you may also specify a :resource_group as an option.

Raises:

  • (ArgumentError)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/azure/armrest/virtual_machine_extension_service.rb', line 31

def create(vm_name, ext_name, options = {}, rgroup = nil)
  rgroup ||= options.delete(:resource_group) || configuration.resource_group

  raise ArgumentError, "no resource group provided" unless rgroup

  # Optional params with defaults
  options[:type] ||= "Microsoft.Compute/virtualMachines/extensions"
  options[:name] ||= ext_name
  options[:properties][:publisher] ||= @provider
  options[:properties][:typeHandlerVersion] ||= "1.*"

  url = build_url(rgroup, vm_name, ext_name)
  body = options.to_json

  response = rest_put(url, body)
  response.return!
end

#delete(vm_name, ext_name, rgroup = configuration.resource_group) ⇒ Object

Delete the given extension for the provided VM and resource group.

Raises:

  • (ArgumentError)


53
54
55
56
57
58
# File 'lib/azure/armrest/virtual_machine_extension_service.rb', line 53

def delete(vm_name, ext_name, rgroup = configuration.resource_group)
  raise ArgumentError, "no resource group provided" unless rgroup
  url = build_url(rgroup, vm_name, ext_name)
  response = rest_delete(url)
  response.return!
end

#get(vm_name, ext_name, rgroup = configuration.resource_group, instance_view = false) ⇒ Object

Retrieves the settings of an extension for the provided VM. If the instance_view option is true, it will retrieve instance view information instead.

Raises:

  • (ArgumentError)


64
65
66
67
68
69
70
# File 'lib/azure/armrest/virtual_machine_extension_service.rb', line 64

def get(vm_name, ext_name, rgroup = configuration.resource_group, instance_view = false)
  raise ArgumentError, "no resource group provided" unless rgroup
  url = build_url(rgroup, vm_name, ext_name)
  url << "&expand=instanceView" if instance_view
  response = rest_get(url)
  Azure::Armrest::VirtualMachineExtension.new(response)
end

#get_instance_view(vm_name, ext_name, rgroup = configuration.resource_group) ⇒ Object

Shortcut to get an extension in instance view.

Raises:

  • (ArgumentError)


79
80
81
82
# File 'lib/azure/armrest/virtual_machine_extension_service.rb', line 79

def get_instance_view(vm_name, ext_name, rgroup = configuration.resource_group)
  raise ArgumentError, "no resource group provided" unless rgroup
  get(vm_name, ext_name, rgroup, true)
end

#get_model_view(vm_name, ext_name, rgroup = configuration.resource_group) ⇒ Object

Shortcut to get an extension in model view.

Raises:

  • (ArgumentError)


73
74
75
76
# File 'lib/azure/armrest/virtual_machine_extension_service.rb', line 73

def get_model_view(vm_name, ext_name, rgroup = configuration.resource_group)
  raise ArgumentError, "no resource group provided" unless rgroup
  get(vm_name, ext_name, rgroup, false)
end

#list(vm_name, rgroup = configuration.resource_group, instance_view = false) ⇒ Object

Retrieves a list of extensions on the VM in the provided resource group. If the instance_view option is true, it will retrieve a list of instance view information instead.

Raises:

  • (ArgumentError)


88
89
90
91
92
93
94
# File 'lib/azure/armrest/virtual_machine_extension_service.rb', line 88

def list(vm_name, rgroup = configuration.resource_group, instance_view = false)
  raise ArgumentError, "no resource group provided" unless rgroup
  url = build_url(rgroup, vm_name)
  url << "&expand=instanceView" if instance_view
  response = rest_get(url)
  Azure::Armrest::ArmrestCollection.create_from_response(response, model_class)
end

#list_instance_view(vmname, rgroup = configuration.resource_group) ⇒ Object

Shortcut to get a list in instance view.

Raises:

  • (ArgumentError)


103
104
105
106
# File 'lib/azure/armrest/virtual_machine_extension_service.rb', line 103

def list_instance_view(vmname, rgroup = configuration.resource_group)
  raise ArgumentError, "no resource group provided" unless rgroup
  list(vmname, true, rgroup)
end

#list_model_view(vmname, rgroup = configuration.resource_group) ⇒ Object

Shortcut to get a list in model view.

Raises:

  • (ArgumentError)


97
98
99
100
# File 'lib/azure/armrest/virtual_machine_extension_service.rb', line 97

def list_model_view(vmname, rgroup = configuration.resource_group)
  raise ArgumentError, "no resource group provided" unless rgroup
  list(vmname, false, rgroup)
end