class Azure::Armrest::VirtualMachineExtensionService
Base class for managing virtual machine extensions
Public Class Methods
Creates and returns a new VirtualMachineExtensionService
object.
# File lib/azure/armrest/virtual_machine_extension_service.rb, line 10 def initialize(_configuration, options = {}) super set_service_api_version(options, 'virtualMachines/extensions') end
Public Instance Methods
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.
# 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 the given extension for the provided VM and resource group.
# 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
Retrieves the settings of an extension for the provided VM. If the instance_view
option is true, it will retrieve instance view information instead.
# 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
Shortcut to get an extension in instance view.
# 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
Shortcut to get an extension in model view.
# 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
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.
# 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
Shortcut to get a list in instance view.
# 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
Shortcut to get a list in model view.
# 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
Private Instance Methods
Builds a URL based on subscription_id an resource_group and any other arguments provided, and appends it with the api_version.
# File lib/azure/armrest/virtual_machine_extension_service.rb, line 113 def build_url(resource_group, vm, *args) url = File.join( base_url, 'resourceGroups', resource_group, 'providers', @provider, 'virtualMachines', vm, 'extensions' ) url = File.join(url, *args) unless args.empty? url << "?api-version=#{@api_version}" end