Class: Fog::Compute::AzureRM::Real
- Inherits:
-
Object
- Object
- Fog::Compute::AzureRM::Real
- Defined in:
- lib/fog/azurerm/compute.rb,
lib/fog/azurerm/requests/compute/get_image.rb,
lib/fog/azurerm/requests/compute/create_image.rb,
lib/fog/azurerm/requests/compute/delete_image.rb,
lib/fog/azurerm/requests/compute/check_vm_exists.rb,
lib/fog/azurerm/requests/compute/check_vm_status.rb,
lib/fog/azurerm/requests/compute/get_managed_disk.rb,
lib/fog/azurerm/requests/compute/get_vm_extension.rb,
lib/fog/azurerm/requests/compute/delete_managed_disk.rb,
lib/fog/azurerm/requests/compute/delete_vm_extension.rb,
lib/fog/azurerm/requests/compute/get_virtual_machine.rb,
lib/fog/azurerm/requests/compute/get_availability_set.rb,
lib/fog/azurerm/requests/compute/list_virtual_machines.rb,
lib/fog/azurerm/requests/compute/start_virtual_machine.rb,
lib/fog/azurerm/requests/compute/attach_data_disk_to_vm.rb,
lib/fog/azurerm/requests/compute/create_virtual_machine.rb,
lib/fog/azurerm/requests/compute/delete_virtual_machine.rb,
lib/fog/azurerm/requests/compute/list_availability_sets.rb,
lib/fog/azurerm/requests/compute/create_availability_set.rb,
lib/fog/azurerm/requests/compute/delete_availability_set.rb,
lib/fog/azurerm/requests/compute/restart_virtual_machine.rb,
lib/fog/azurerm/requests/compute/detach_data_disk_from_vm.rb,
lib/fog/azurerm/requests/compute/list_managed_disks_by_rg.rb,
lib/fog/azurerm/requests/compute/redeploy_virtual_machine.rb,
lib/fog/azurerm/requests/compute/check_managed_disk_exists.rb,
lib/fog/azurerm/requests/compute/check_vm_extension_exists.rb,
lib/fog/azurerm/requests/compute/power_off_virtual_machine.rb,
lib/fog/azurerm/requests/compute/deallocate_virtual_machine.rb,
lib/fog/azurerm/requests/compute/generalize_virtual_machine.rb,
lib/fog/azurerm/requests/compute/grant_access_to_managed_disk.rb,
lib/fog/azurerm/requests/compute/check_availability_set_exists.rb,
lib/fog/azurerm/requests/compute/create_or_update_managed_disk.rb,
lib/fog/azurerm/requests/compute/create_or_update_vm_extension.rb,
lib/fog/azurerm/requests/compute/revoke_access_to_managed_disk.rb,
lib/fog/azurerm/requests/compute/list_managed_disks_in_subscription.rb,
lib/fog/azurerm/requests/compute/list_available_sizes_for_virtual_machine.rb
Overview
This class provides the actual implementation for service calls.
Instance Method Summary collapse
- #attach_data_disk_to_vm(disk_params, async) ⇒ Object
- #check_availability_set_exists(resource_group, name) ⇒ Object
- #check_managed_disk_exists(resource_group_name, disk_name) ⇒ Object
- #check_vm_exists(resource_group, name, async) ⇒ Object
- #check_vm_extension_exists(resource_group_name, virtual_machine_name, vm_extension_name) ⇒ Object
- #check_vm_status(resource_group, name, async) ⇒ Object
- #create_availability_set(availability_set_params) ⇒ Object
- #create_availability_set_sku(use_managed_disk) ⇒ Object
- #create_image(image_config) ⇒ Object
- #create_or_update_managed_disk(managed_disk_params) ⇒ Object
- #create_or_update_vm_extension(vm_extension_params) ⇒ Object
- #create_virtual_machine(vm_config, async = false) ⇒ Object
- #deallocate_virtual_machine(resource_group, name, async) ⇒ Object
- #delete_availability_set(resource_group, name) ⇒ Object
- #delete_image(resource_group, vm_name) ⇒ Object
- #delete_managed_disk(resource_group_name, disk_name, async) ⇒ Object
- #delete_virtual_machine(resource_group, name, async) ⇒ Object
- #delete_vm_extension(resource_group, vm_name, extension_name) ⇒ Object
- #detach_data_disk_from_vm(resource_group, vm_name, disk_name, async) ⇒ Object
- #generalize_virtual_machine(resource_group, name, async) ⇒ Object
- #get_availability_set(resource_group, name) ⇒ Object
-
#get_availability_set_properties(location, fault_domain_count, update_domain_count, use_managed_disk, tags) ⇒ Object
create the properties object for creating availability sets.
- #get_image(resource_group_name, image_name) ⇒ Object
- #get_managed_disk(resource_group_name, disk_name) ⇒ Object
- #get_status(virtual_machine) ⇒ Object
- #get_virtual_machine(resource_group, name, async) ⇒ Object
- #get_vm_extension(resource_group_name, virtual_machine_name, vm_extension_name) ⇒ Object
- #grant_access_to_managed_disk(resource_group_name, disk_name, access_type, duration_in_sec) ⇒ Object
-
#initialize(options) ⇒ Real
constructor
A new instance of Real.
- #list_availability_sets(resource_group) ⇒ Object
- #list_available_sizes_for_virtual_machine(resource_group, name, async) ⇒ Object
- #list_managed_disks_by_rg(resource_group_name) ⇒ Object
- #list_managed_disks_in_subscription ⇒ Object
- #list_virtual_machines(resource_group) ⇒ Object
- #power_off_virtual_machine(resource_group, name, async) ⇒ Object
- #redeploy_virtual_machine(resource_group, name, async) ⇒ Object
- #restart_virtual_machine(resource_group, name, async) ⇒ Object
- #revoke_access_to_managed_disk(resource_group_name, disk_name) ⇒ Object
- #start_virtual_machine(resource_group, name, async) ⇒ Object
Constructor Details
#initialize(options) ⇒ Real
Returns a new instance of Real.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/fog/azurerm/compute.rb', line 77 def initialize() begin require 'azure_mgmt_compute' require 'azure_mgmt_storage' require 'azure/storage' rescue LoadError => e retry if require('rubygems') raise e. end [:environment] = 'AzureCloud' if [:environment].nil? telemetry = "fog-azure-rm/#{Fog::AzureRM::VERSION}" credentials = Fog::Credentials::AzureRM.get_credentials([:tenant_id], [:client_id], [:client_secret], [:environment]) @compute_mgmt_client = ::Azure::ARM::Compute::ComputeManagementClient.new(credentials, resource_manager_endpoint_url([:environment])) @compute_mgmt_client.subscription_id = [:subscription_id] @compute_mgmt_client.add_user_agent_information(telemetry) @storage_mgmt_client = ::Azure::ARM::Storage::StorageManagementClient.new(credentials, resource_manager_endpoint_url([:environment])) @storage_mgmt_client.subscription_id = [:subscription_id] @storage_mgmt_client.add_user_agent_information(telemetry) @storage_service = Fog::Storage::AzureRM.new(tenant_id: [:tenant_id], client_id: [:client_id], client_secret: [:client_secret], subscription_id: [:subscription_id], environment: [:environment]) end |
Instance Method Details
#attach_data_disk_to_vm(disk_params, async) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fog/azurerm/requests/compute/attach_data_disk_to_vm.rb', line 6 def attach_data_disk_to_vm(disk_params, async) # Variable un-packing for easy access vm_name = disk_params[:vm_name] vm_resource_group = disk_params[:vm_resource_group] disk_name = disk_params[:disk_name] disk_resource_group = disk_params[:disk_resource_group] disk_size = disk_params[:disk_size_gb] storage_account_name = disk_params[:storage_account_name] caching = disk_params[:caching] || nil msg = "Attaching Data Disk #{disk_name} to Virtual Machine #{vm_name} in Resource Group #{vm_resource_group}" Fog::Logger.debug msg vm = get_virtual_machine_instance(vm_resource_group, vm_name) lun = get_logical_unit_number(vm.storage_profile.data_disks) # Attach data disk to VM if storage_account_name # Un-managed data disk access_key = get_storage_access_key(vm_resource_group, storage_account_name) data_disk = get_unmanaged_disk_object(disk_name, disk_size, lun, storage_account_name, access_key) elsif disk_resource_group # Managed data disk data_disk = get_data_disk_object(disk_resource_group, disk_name, lun, caching) end vm.storage_profile.data_disks.push(data_disk) begin if async response = @compute_mgmt_client.virtual_machines.create_or_update_async(vm_resource_group, vm_name, vm) else virtual_machine = @compute_mgmt_client.virtual_machines.create_or_update(vm_resource_group, vm_name, vm) end rescue MsRestAzure::AzureOperationError => e if e.body.to_s =~ /InvalidParameter/ && e.body.to_s =~ /already exists/ Fog::Logger.debug 'The disk is already attached' else raise_azure_exception(e, msg) end end if async response else Fog::Logger.debug "Data Disk #{disk_name} attached to Virtual Machine #{vm_name} successfully." virtual_machine end end |
#check_availability_set_exists(resource_group, name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/fog/azurerm/requests/compute/check_availability_set_exists.rb', line 6 def check_availability_set_exists(resource_group, name) msg = "Checking Availability set: #{name}" Fog::Logger.debug msg begin @compute_mgmt_client.availability_sets.get(resource_group, name) Fog::Logger.debug "Availability set #{name} exists." true rescue MsRestAzure::AzureOperationError => e if resource_not_found?(e) Fog::Logger.debug "Availability set #{name} doesn't exist." false else raise_azure_exception(e, msg) end end end |
#check_managed_disk_exists(resource_group_name, disk_name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/fog/azurerm/requests/compute/check_managed_disk_exists.rb', line 6 def check_managed_disk_exists(resource_group_name, disk_name) msg = "Checking if Managed Disk: #{disk_name} exists" Fog::Logger.debug msg begin @compute_mgmt_client.disks.get(resource_group_name, disk_name) Fog::Logger.debug "Managed Disk #{disk_name} exist." true rescue MsRestAzure::AzureOperationError => e if resource_not_found?(e) Fog::Logger.debug "Managed Disk #{disk_name} doesn't exist." false else raise_azure_exception(e, msg) end end end |
#check_vm_exists(resource_group, name, async) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fog/azurerm/requests/compute/check_vm_exists.rb', line 6 def check_vm_exists(resource_group, name, async) msg = "Checking Virtual Machine #{name}" Fog::Logger.debug msg begin if async response = @compute_mgmt_client.virtual_machines.get_async(resource_group, name, 'instanceView') else @compute_mgmt_client.virtual_machines.get(resource_group, name, 'instanceView') end rescue MsRestAzure::AzureOperationError => e if resource_not_found?(e) Fog::Logger.debug "Virtual machine #{name} doesn't exist." return false else raise_azure_exception(e, msg) end end if async response else Fog::Logger.debug "Virtual machine #{name} exists." true end end |
#check_vm_extension_exists(resource_group_name, virtual_machine_name, vm_extension_name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/fog/azurerm/requests/compute/check_vm_extension_exists.rb', line 6 def check_vm_extension_exists(resource_group_name, virtual_machine_name, vm_extension_name) msg = "Checking Virtual Machine Extension #{vm_extension_name}" Fog::Logger.debug msg begin @compute_mgmt_client.virtual_machine_extensions.get(resource_group_name, virtual_machine_name, vm_extension_name) Fog::Logger.debug "Virtual Machine Extension #{vm_extension_name} exists." true rescue MsRestAzure::AzureOperationError => e if resource_not_found?(e) Fog::Logger.debug "Virtual Machine Extension #{vm_extension_name} doesn't exist." false else raise_azure_exception(e, msg) end end end |
#check_vm_status(resource_group, name, async) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/azurerm/requests/compute/check_vm_status.rb', line 6 def check_vm_status(resource_group, name, async) msg = "Checking Virtual Machine #{name} status" Fog::Logger.debug msg begin virtual_machine = @compute_mgmt_client.virtual_machines.get(resource_group, name, 'instanceView') rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug "Successfully returned status of Virtual Machine #{name} in Resource Group #{resource_group}" get_status(virtual_machine) end |
#create_availability_set(availability_set_params) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fog/azurerm/requests/compute/create_availability_set.rb', line 6 def create_availability_set(availability_set_params) name = availability_set_params[:name] location = availability_set_params[:location] resource_group = availability_set_params[:resource_group] fault_domain_count = availability_set_params[:platform_fault_domain_count] update_domain_count = availability_set_params[:platform_update_domain_count] use_managed_disk = availability_set_params[:use_managed_disk].nil? ? false : availability_set_params[:use_managed_disk] = availability_set_params[:tags] msg = "Creating Availability Set '#{name}' in #{location} region." Fog::Logger.debug msg avail_set_params = get_availability_set_properties(location, fault_domain_count, update_domain_count, use_managed_disk, ) begin availability_set = @compute_mgmt_client.availability_sets.create_or_update(resource_group, name, avail_set_params) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug "Availability Set #{name} created successfully." availability_set end |
#create_availability_set_sku(use_managed_disk) ⇒ Object
39 40 41 42 43 |
# File 'lib/fog/azurerm/requests/compute/create_availability_set.rb', line 39 def create_availability_set_sku(use_managed_disk) sku = Azure::ARM::Compute::Models::Sku.new sku.name = use_managed_disk ? AS_SKU_ALIGNED : AS_SKU_CLASSIC sku end |
#create_image(image_config) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/fog/azurerm/requests/compute/create_image.rb', line 6 def create_image(image_config) msg = "Creating/Updating Image: #{image_config[:vm_name]}-osImage" Fog::Logger.debug msg image_name = "#{image_config[:vm_name]}-osImage" image = setup_params(image_config) begin image_obj = @compute_mgmt_client.images.create_or_update(image_config[:resource_group], image_name, image) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug "Image #{image_name} created/updated successfully." image_obj end |
#create_or_update_managed_disk(managed_disk_params) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/fog/azurerm/requests/compute/create_or_update_managed_disk.rb', line 6 def create_or_update_managed_disk(managed_disk_params) msg = "Creating/Updating Managed Disk: #{managed_disk_params[:name]}" Fog::Logger.debug msg disk = get_managed_disk_object(managed_disk_params) begin managed_disk = @compute_mgmt_client.disks.create_or_update(managed_disk_params[:resource_group_name], managed_disk_params[:name], disk) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug "Managed Disk #{managed_disk_params[:name]} created/updated successfully." managed_disk end |
#create_or_update_vm_extension(vm_extension_params) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/fog/azurerm/requests/compute/create_or_update_vm_extension.rb', line 6 def create_or_update_vm_extension(vm_extension_params) msg = "Creating/Updating Extension #{vm_extension_params[:name]} for Virtual Machine #{vm_extension_params[:vm_name]} in Resource Group #{vm_extension_params[:resource_group]}" Fog::Logger.debug msg vm_extension = create_virtual_machine_extension_object(vm_extension_params) begin vm_extension_obj = @compute_mgmt_client.virtual_machine_extensions.create_or_update(vm_extension_params[:resource_group], vm_extension_params[:vm_name], vm_extension_params[:name], vm_extension) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug "Extension #{vm_extension.name} for Virtual Machine #{vm_extension_params[:vm_name]} in Resource Group #{vm_extension_params[:resource_group]} created/updated successfully" vm_extension_obj end |
#create_virtual_machine(vm_config, async = false) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fog/azurerm/requests/compute/create_virtual_machine.rb', line 10 def create_virtual_machine(vm_config, async = false) vm_name = vm_config[:name] rg_name = vm_config[:resource_group] # In case of updating the VM, we check if the user has passed any value for os_disk_name # If the user has not passed any value, we try to retrieve the value of os_disk_name from the VM # If the VM exists then the os_disk_name is retrieved; else it remains nil os_disk_parameters = get_os_disk_parameters(rg_name, vm_name) if vm_config[:os_disk_name].nil? || vm_config[:os_disk_vhd_uri].nil? vm_config[:os_disk_name] = os_disk_parameters[:os_disk_name] if vm_config[:os_disk_name].nil? vm_config[:os_disk_vhd_uri] = os_disk_parameters[:os_disk_vhd_uri] if vm_config[:os_disk_vhd_uri].nil? msg = "Creating Virtual Machine '#{vm_name}' in Resource Group '#{rg_name}'..." Fog::Logger.debug msg vm = Azure::ARM::Compute::Models::VirtualMachine.new vm.location = vm_config[:location] vm. = vm_config[:tags] vm.availability_set = get_vm_availability_set(vm_config[:availability_set_id]) vm.hardware_profile = get_hardware_profile(vm_config[:vm_size]) vm.os_profile = get_os_profile(vm_config) vm.network_profile = get_network_profile(vm_config[:network_interface_card_ids]) vm.storage_profile = get_storage_profile(vm_config) begin response = if async @compute_mgmt_client.virtual_machines.create_or_update_async(rg_name, vm_name, vm) else @compute_mgmt_client.virtual_machines.create_or_update(rg_name, vm_name, vm) end rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end unless async unless vm_config[:vhd_path].nil? || vm_config[:managed_disk_storage_type].nil? delete_image(rg_name, vm_name) delete_storage_account_or_container(rg_name, vm_config[:storage_account_name], vm_name) end end Fog::Logger.debug "Virtual Machine #{vm_name} created successfully!" unless async response end |
#deallocate_virtual_machine(resource_group, name, async) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fog/azurerm/requests/compute/deallocate_virtual_machine.rb', line 6 def deallocate_virtual_machine(resource_group, name, async) msg = "Deallocating Virtual Machine #{name} in Resource Group #{resource_group}" Fog::Logger.debug msg begin if async response = @compute_mgmt_client.virtual_machines.deallocate_async(resource_group, name) else @compute_mgmt_client.virtual_machines.deallocate(resource_group, name) end rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end if async response else Fog::Logger.debug "Virtual Machine #{name} Deallocated Successfully." true end end |
#delete_availability_set(resource_group, name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/azurerm/requests/compute/delete_availability_set.rb', line 6 def delete_availability_set(resource_group, name) msg = "Deleting Availability Set: #{name}." Fog::Logger.debug msg begin @compute_mgmt_client.availability_sets.delete(resource_group, name) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug "Availability Set #{name} deleted successfully." true end |
#delete_image(resource_group, vm_name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/fog/azurerm/requests/compute/delete_image.rb', line 6 def delete_image(resource_group, vm_name) msg = "Deleting Image: #{vm_name}-osImage" Fog::Logger.debug msg image_name = "#{vm_name}-osImage" begin @compute_mgmt_client.images.delete(resource_group, image_name) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug "Image #{image_name} deleted successfully." true end |
#delete_managed_disk(resource_group_name, disk_name, async) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/fog/azurerm/requests/compute/delete_managed_disk.rb', line 7 def delete_managed_disk(resource_group_name, disk_name, async) msg = "Deleting Managed Disk: #{disk_name}" Fog::Logger.debug msg begin if async response = @compute_mgmt_client.disks.delete_async(resource_group_name, disk_name) else @compute_mgmt_client.disks.delete(resource_group_name, disk_name) end rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end if async response else Fog::Logger.debug "Managed Disk #{disk_name} deleted successfully." true end end |
#delete_virtual_machine(resource_group, name, async) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fog/azurerm/requests/compute/delete_virtual_machine.rb', line 6 def delete_virtual_machine(resource_group, name, async) msg = "Deleting Virtual Machine #{name} from Resource Group #{resource_group}" Fog::Logger.debug msg begin if async response = @compute_mgmt_client.virtual_machines.delete_async(resource_group, name) else @compute_mgmt_client.virtual_machines.delete(resource_group, name) end rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end if async response else Fog::Logger.debug "Virtual Machine #{name} Deleted Successfully." true end end |
#delete_vm_extension(resource_group, vm_name, extension_name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/azurerm/requests/compute/delete_vm_extension.rb', line 6 def delete_vm_extension(resource_group, vm_name, extension_name) msg = "Deleting Extension #{extension_name} of Virtual Machine #{vm_name} in Resource Group #{resource_group}" Fog::Logger.debug msg begin @compute_mgmt_client.virtual_machine_extensions.delete(resource_group, vm_name, extension_name) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug "Extension #{extension_name} of Virtual Machine #{vm_name} in Resource Group #{resource_group} deleted successfully" true end |
#detach_data_disk_from_vm(resource_group, vm_name, disk_name, async) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/fog/azurerm/requests/compute/detach_data_disk_from_vm.rb', line 6 def detach_data_disk_from_vm(resource_group, vm_name, disk_name, async) msg = "Detaching Data Disk #{disk_name} from Virtual Machine #{vm_name} in Resource Group #{resource_group}." Fog::Logger.debug msg vm = get_virtual_machine_instance(resource_group, vm_name) vm.storage_profile.data_disks.each_with_index do |disk, index| if disk.name == disk_name vm.storage_profile.data_disks.delete_at(index) end end begin if async response = @compute_mgmt_client.virtual_machines.create_or_update_async(resource_group, vm_name, vm) else virtual_machine = @compute_mgmt_client.virtual_machines.create_or_update(resource_group, vm_name, vm) end rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end if async response else Fog::Logger.debug "Data Disk #{disk_name} detached from Virtual Machine #{vm_name} successfully." virtual_machine end end |
#generalize_virtual_machine(resource_group, name, async) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fog/azurerm/requests/compute/generalize_virtual_machine.rb', line 6 def generalize_virtual_machine(resource_group, name, async) msg = "Generalizing Virtual Machine #{name} in Resource Group #{resource_group}" Fog::Logger.debug msg begin if async response = @compute_mgmt_client.virtual_machines.generalize_async(resource_group, name) else @compute_mgmt_client.virtual_machines.generalize(resource_group, name) end rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end if async response else Fog::Logger.debug "Virtual Machine #{name} Generalized Successfully." true end end |
#get_availability_set(resource_group, name) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/fog/azurerm/requests/compute/get_availability_set.rb', line 6 def get_availability_set(resource_group, name) msg = "Listing Availability Set: #{name} in Resource Group: #{resource_group}" Fog::Logger.debug msg begin @compute_mgmt_client.availability_sets.get(resource_group, name) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end end |
#get_availability_set_properties(location, fault_domain_count, update_domain_count, use_managed_disk, tags) ⇒ Object
create the properties object for creating availability sets
29 30 31 32 33 34 35 36 37 |
# File 'lib/fog/azurerm/requests/compute/create_availability_set.rb', line 29 def get_availability_set_properties(location, fault_domain_count, update_domain_count, use_managed_disk, ) avail_set = Azure::ARM::Compute::Models::AvailabilitySet.new avail_set.location = location avail_set.sku = create_availability_set_sku(use_managed_disk) avail_set.platform_fault_domain_count = fault_domain_count.nil? ? FAULT_DOMAIN_COUNT : fault_domain_count avail_set.platform_update_domain_count = update_domain_count.nil? ? UPDATE_DOMAIN_COUNT : update_domain_count avail_set. = avail_set end |
#get_image(resource_group_name, image_name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/azurerm/requests/compute/get_image.rb', line 6 def get_image(resource_group_name, image_name) msg = "Getting Image #{image_name} in Resource Group #{resource_group_name}" Fog::Logger.debug msg begin image = @compute_mgmt_client.images.get(resource_group_name, image_name) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug "#{msg} successful" image end |
#get_managed_disk(resource_group_name, disk_name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/azurerm/requests/compute/get_managed_disk.rb', line 6 def get_managed_disk(resource_group_name, disk_name) msg = "Getting Managed Disk: #{disk_name}" Fog::Logger.debug msg begin managed_disk = @compute_mgmt_client.disks.get(resource_group_name, disk_name) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug "Managed Disk #{disk_name} returned successfully." managed_disk end |
#get_status(virtual_machine) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fog/azurerm/requests/compute/check_vm_status.rb', line 18 def get_status(virtual_machine) vm_statuses = virtual_machine.instance_view.statuses vm_status = nil vm_statuses.each do |status| if status.code.include? 'PowerState' Fog::Logger.debug status.display_status.to_s vm_status = status.code.split('/')[1] end end vm_status end |
#get_virtual_machine(resource_group, name, async) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/fog/azurerm/requests/compute/get_virtual_machine.rb', line 8 def get_virtual_machine(resource_group, name, async) msg = "Getting Virtual Machine #{name} from Resource Group '#{resource_group}'" Fog::Logger.debug msg begin if async response = @compute_mgmt_client.virtual_machines.get_async(resource_group, name, INSTANCE_VIEW) else response = @compute_mgmt_client.virtual_machines.get(resource_group, name, INSTANCE_VIEW) end rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug "Getting Virtual Machine #{name} from Resource Group '#{resource_group}' successful" unless async response end |
#get_vm_extension(resource_group_name, virtual_machine_name, vm_extension_name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/azurerm/requests/compute/get_vm_extension.rb', line 6 def get_vm_extension(resource_group_name, virtual_machine_name, vm_extension_name) msg = "Getting Extension #{vm_extension_name} of Virtual Machine #{virtual_machine_name} in Resource Group #{resource_group_name}" Fog::Logger.debug msg begin vm_extension = @compute_mgmt_client.virtual_machine_extensions.get(resource_group_name, virtual_machine_name, vm_extension_name) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug "#{msg} successful" vm_extension end |
#grant_access_to_managed_disk(resource_group_name, disk_name, access_type, duration_in_sec) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/fog/azurerm/requests/compute/grant_access_to_managed_disk.rb', line 6 def grant_access_to_managed_disk(resource_group_name, disk_name, access_type, duration_in_sec) msg = "Granting access to Managed Disk: #{disk_name}" Fog::Logger.debug msg access_data = Azure::ARM::Compute::Models::GrantAccessData.new access_data.access = access_type access_data.duration_in_seconds = duration_in_sec begin access_uri = @compute_mgmt_client.disks.grant_access(resource_group_name, disk_name, access_data) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug "Access granted to managed disk: #{disk_name} successfully." access_uri.access_sas end |
#list_availability_sets(resource_group) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/azurerm/requests/compute/list_availability_sets.rb', line 6 def list_availability_sets(resource_group) msg = "Listing Availability Sets in Resource Group: #{resource_group}" Fog::Logger.debug msg begin avail_sets = @compute_mgmt_client.availability_sets.list(resource_group) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug "Listing Availability Sets in Resource Group: #{resource_group} successful." avail_sets.value end |
#list_available_sizes_for_virtual_machine(resource_group, name, async) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fog/azurerm/requests/compute/list_available_sizes_for_virtual_machine.rb', line 6 def list_available_sizes_for_virtual_machine(resource_group, name, async) msg = "Listing sizes for Virtual Machine #{name} in Resource Group #{resource_group}" Fog::Logger.debug msg begin if async response = @compute_mgmt_client.virtual_machines.list_available_sizes_async(resource_group, name) else vm_sizes = @compute_mgmt_client.virtual_machines.list_available_sizes(resource_group, name) end rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end if async response else Fog::Logger.debug "Successfully listed sizes for Virtual Machine #{name} in Resource Group #{resource_group}" vm_sizes.value end end |
#list_managed_disks_by_rg(resource_group_name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/azurerm/requests/compute/list_managed_disks_by_rg.rb', line 6 def list_managed_disks_by_rg(resource_group_name) msg = "Listing all Managed Disks in resource group: #{resource_group_name}" Fog::Logger.debug msg begin managed_disks = @compute_mgmt_client.disks.list_by_resource_group(resource_group_name) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug 'Managed Disks listed successfully.' managed_disks end |
#list_managed_disks_in_subscription ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/azurerm/requests/compute/list_managed_disks_in_subscription.rb', line 6 def list_managed_disks_in_subscription msg = 'Listing all Managed Disks' Fog::Logger.debug msg begin managed_disks = @compute_mgmt_client.disks.list rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug 'Managed Disks listed successfully.' managed_disks end |
#list_virtual_machines(resource_group) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/azurerm/requests/compute/list_virtual_machines.rb', line 6 def list_virtual_machines(resource_group) msg = "Listing Virtual Machines in Resource Group '#{resource_group}'" Fog::Logger.debug msg begin virtual_machines = @compute_mgmt_client.virtual_machines.list_as_lazy(resource_group) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug "listing Virtual Machines in Resource Group '#{resource_group}' successful" virtual_machines.value end |
#power_off_virtual_machine(resource_group, name, async) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fog/azurerm/requests/compute/power_off_virtual_machine.rb', line 6 def power_off_virtual_machine(resource_group, name, async) msg = "Powering off Virtual Machine #{name} in Resource Group #{resource_group}" Fog::Logger.debug msg begin if async response = @compute_mgmt_client.virtual_machines.power_off_async(resource_group, name) else @compute_mgmt_client.virtual_machines.power_off(resource_group, name) end rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end if async response else Fog::Logger.debug "Virtual Machine #{name} Powered off Successfully." true end end |
#redeploy_virtual_machine(resource_group, name, async) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fog/azurerm/requests/compute/redeploy_virtual_machine.rb', line 6 def redeploy_virtual_machine(resource_group, name, async) msg = "Redeploying Virtual Machine #{name} in Resource Group #{resource_group}." Fog::Logger.debug msg begin if async response = @compute_mgmt_client.virtual_machines.redeploy_async(resource_group, name) else @compute_mgmt_client.virtual_machines.redeploy(resource_group, name) end rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end if async response else Fog::Logger.debug "Virtual Machine #{name} Redeployed Successfully." true end end |
#restart_virtual_machine(resource_group, name, async) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fog/azurerm/requests/compute/restart_virtual_machine.rb', line 6 def restart_virtual_machine(resource_group, name, async) msg = "Restarting Virtual Machine #{name} in Resource Group #{resource_group}" Fog::Logger.debug msg begin if async response = @compute_mgmt_client.virtual_machines.restart_async(resource_group, name) else @compute_mgmt_client.virtual_machines.restart(resource_group, name) end rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end if async response else Fog::Logger.debug "Virtual Machine #{name} Restarted Successfully." true end end |
#revoke_access_to_managed_disk(resource_group_name, disk_name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/azurerm/requests/compute/revoke_access_to_managed_disk.rb', line 6 def revoke_access_to_managed_disk(resource_group_name, disk_name) msg = "Revoking access to Managed Disk: #{disk_name}" Fog::Logger.debug msg begin response = @compute_mgmt_client.disks.revoke_access(resource_group_name, disk_name) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug "Access revoked to managed disk: #{disk_name} successfully." response end |
#start_virtual_machine(resource_group, name, async) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fog/azurerm/requests/compute/start_virtual_machine.rb', line 6 def start_virtual_machine(resource_group, name, async) msg = "Starting Virtual Machine #{name} in Resource Group #{resource_group}." Fog::Logger.debug msg begin if async response = @compute_mgmt_client.virtual_machines.start_async(resource_group, name) else @compute_mgmt_client.virtual_machines.start(resource_group, name) end rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end if async response else Fog::Logger.debug "Virtual Machine #{name} started Successfully." true end end |