Class: Fog::Compute::AzureRM::Server
- Inherits:
-
Model
- Object
- Model
- Fog::Compute::AzureRM::Server
- Defined in:
- lib/fog/azurerm/models/compute/server.rb
Overview
This class is giving implementation of create/save and delete/destroy for Virtual Machine.
Class Method Summary collapse
Instance Method Summary collapse
- #attach_data_disk(disk_name, disk_size, storage_account_name, async = false) ⇒ Object
- #attach_managed_disk(disk_name, disk_resource_group, async = false) ⇒ Object
- #deallocate(async = false) ⇒ Object
- #delete_extra_resources ⇒ Object
- #destroy(async = false) ⇒ Object
- #detach_data_disk(disk_name, async = false) ⇒ Object
- #detach_managed_disk(disk_name, async = false) ⇒ Object
- #generalize(async = false) ⇒ Object
- #list_available_sizes(async = false) ⇒ Object
- #power_off(async = false) ⇒ Object
- #redeploy(async = false) ⇒ Object
- #restart(async = false) ⇒ Object
- #save(async = false) ⇒ Object
- #start(async = false) ⇒ Object
- #vm_status(async = false) ⇒ Object
Class Method Details
.parse(vm) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 39 def self.parse(vm) hash = {} hash['id'] = vm.id hash['name'] = vm.name hash['location'] = vm.location hash['resource_group'] = get_resource_group_from_id(vm.id) hash['vm_size'] = vm.hardware_profile.vm_size unless vm.hardware_profile.vm_size.nil? unless vm.storage_profile.nil? hash['os_disk_name'] = vm.storage_profile.os_disk.name hash['os_disk_size'] = vm.storage_profile.os_disk.disk_size_gb if vm.storage_profile.os_disk.vhd.nil? hash['managed_disk_storage_type'] = vm.storage_profile.os_disk.managed_disk.storage_account_type else hash['os_disk_vhd_uri'] = vm.storage_profile.os_disk.vhd.uri hash['storage_account_name'] = hash['os_disk_vhd_uri'].split('/')[2].split('.')[0] end hash['os_disk_caching'] = vm.storage_profile.os_disk.caching unless vm.storage_profile.image_reference.nil? hash['publisher'] = vm.storage_profile.image_reference.publisher hash['offer'] = vm.storage_profile.image_reference.offer hash['sku'] = vm.storage_profile.image_reference.sku hash['version'] = vm.storage_profile.image_reference.version end end hash['username'] = vm.os_profile.admin_username hash['custom_data'] = vm.os_profile.custom_data hash['data_disks'] = [] unless vm.storage_profile.data_disks.nil? vm.storage_profile.data_disks.each do |disk| data_disk = Fog::Compute::AzureRM::DataDisk.new hash['data_disks'] << data_disk.merge_attributes(Fog::Compute::AzureRM::DataDisk.parse(disk)) end end hash['disable_password_authentication'] = false hash['disable_password_authentication'] = vm.os_profile.linux_configuration.disable_password_authentication unless vm.os_profile.linux_configuration.nil? if vm.os_profile.windows_configuration hash['provision_vm_agent'] = vm.os_profile.windows_configuration.provision_vmagent hash['enable_automatic_updates'] = vm.os_profile.windows_configuration.enable_automatic_updates end hash['network_interface_card_ids'] = vm.network_profile.network_interfaces.map(&:id) hash['availability_set_id'] = vm.availability_set.id unless vm.availability_set.nil? hash['tags'] = vm. unless vm.instance_view.nil? hash['platform_update_domain'] = vm.instance_view.platform_update_domain hash['platform_fault_domain'] = vm.instance_view.platform_fault_domain end hash end |
Instance Method Details
#attach_data_disk(disk_name, disk_size, storage_account_name, async = false) ⇒ Object
159 160 161 162 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 159 def attach_data_disk(disk_name, disk_size, storage_account_name, async = false) response = service.attach_data_disk_to_vm(data_disk_params(disk_name, disk_size, storage_account_name), async) async ? create_fog_async_response(response) : merge_attributes(Fog::Compute::AzureRM::Server.parse(response)) end |
#attach_managed_disk(disk_name, disk_resource_group, async = false) ⇒ Object
169 170 171 172 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 169 def attach_managed_disk(disk_name, disk_resource_group, async = false) response = service.attach_data_disk_to_vm(data_disk_params(disk_name, nil, nil, disk_resource_group), async) async ? create_fog_async_response(response) : merge_attributes(Fog::Compute::AzureRM::Server.parse(response)) end |
#deallocate(async = false) ⇒ Object
140 141 142 143 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 140 def deallocate(async = false) response = service.deallocate_virtual_machine(resource_group, name, async) async ? create_fog_async_response(response) : response end |
#delete_extra_resources ⇒ Object
179 180 181 182 183 184 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 179 def delete_extra_resources unless vhd_path.nil? || !managed_disk_storage_type.nil? service.delete_generalized_image(resource_group, name) delete_storage_account_or_container(resource_group, storage_account_name, name) end end |
#destroy(async = false) ⇒ Object
115 116 117 118 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 115 def destroy(async = false) response = service.delete_virtual_machine(resource_group, name, async) async ? create_fog_async_response(response) : response end |
#detach_data_disk(disk_name, async = false) ⇒ Object
164 165 166 167 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 164 def detach_data_disk(disk_name, async = false) response = service.detach_data_disk_from_vm(resource_group, name, disk_name, async) async ? create_fog_async_response(response) : merge_attributes(Fog::Compute::AzureRM::Server.parse(response)) end |
#detach_managed_disk(disk_name, async = false) ⇒ Object
174 175 176 177 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 174 def detach_managed_disk(disk_name, async = false) response = service.detach_data_disk_from_vm(resource_group, name, disk_name, async) async ? create_fog_async_response(response) : merge_attributes(Fog::Compute::AzureRM::Server.parse(response)) end |
#generalize(async = false) ⇒ Object
120 121 122 123 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 120 def generalize(async = false) response = service.generalize_virtual_machine(resource_group, name, async) async ? create_fog_async_response(response) : response end |
#list_available_sizes(async = false) ⇒ Object
150 151 152 153 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 150 def list_available_sizes(async = false) response = service.list_available_sizes_for_virtual_machine(resource_group, name, async) async ? create_fog_async_response(response) : response end |
#power_off(async = false) ⇒ Object
125 126 127 128 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 125 def power_off(async = false) response = service.power_off_virtual_machine(resource_group, name, async) async ? create_fog_async_response(response) : response end |
#redeploy(async = false) ⇒ Object
145 146 147 148 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 145 def redeploy(async = false) response = service.redeploy_virtual_machine(resource_group, name, async) async ? create_fog_async_response(response) : response end |
#restart(async = false) ⇒ Object
135 136 137 138 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 135 def restart(async = false) response = service.restart_virtual_machine(resource_group, name, async) async ? create_fog_async_response(response) : response end |
#save(async = false) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 93 def save(async = false) requires :name, :location, :resource_group, :vm_size, :username, :network_interface_card_ids requires :publisher, :offer, :sku, :version if vhd_path.nil? && managed_disk_storage_type.nil? requires :storage_account_name if managed_disk_storage_type.nil? requires :managed_disk_storage_type if storage_account_name.nil? if platform_is_linux?(platform) requires :disable_password_authentication else requires :password end ssh_key_path = "/home/#{username}/.ssh/authorized_keys" unless ssh_key_data.nil? if async service.create_virtual_machine(virtual_machine_params(ssh_key_path), true) else vm = service.create_virtual_machine(virtual_machine_params(ssh_key_path)) merge_attributes(Fog::Compute::AzureRM::Server.parse(vm)) end end |
#start(async = false) ⇒ Object
130 131 132 133 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 130 def start(async = false) response = service.start_virtual_machine(resource_group, name, async) async ? create_fog_async_response(response) : response end |
#vm_status(async = false) ⇒ Object
155 156 157 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 155 def vm_status(async = false) service.check_vm_status(resource_group, name, async) end |