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) ⇒ Object
- #deallocate ⇒ Object
- #destroy ⇒ Object
- #detach_data_disk(disk_name) ⇒ Object
- #generalize ⇒ Object
- #list_available_sizes ⇒ Object
- #power_off ⇒ Object
- #redeploy ⇒ Object
- #restart ⇒ Object
- #save ⇒ Object
- #start ⇒ Object
- #vm_status ⇒ Object
Class Method Details
.parse(vm) ⇒ Object
33 34 35 36 37 38 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 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 33 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 hash['os_disk_name'] = vm.storage_profile.os_disk.name hash['os_disk_vhd_uri'] = vm.storage_profile.os_disk.vhd.uri 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 hash['username'] = vm.os_profile.admin_username hash['custom_data'] = vm.os_profile.custom_data hash['data_disks'] = [] vm.storage_profile.data_disks.each do |disk| data_disk = Fog::Storage::AzureRM::DataDisk.new hash['data_disks'] << data_disk.merge_attributes(Fog::Storage::AzureRM::DataDisk.parse(disk)) end unless vm.storage_profile.data_disks.nil? 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_id'] = vm.network_profile.network_interfaces[0].id hash['availability_set_id'] = vm.availability_set.id unless vm.availability_set.nil? hash end |
Instance Method Details
#attach_data_disk(disk_name, disk_size, storage_account_name) ⇒ Object
112 113 114 115 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 112 def attach_data_disk(disk_name, disk_size, storage_account_name) vm = service.attach_data_disk_to_vm(resource_group, name, disk_name, disk_size, storage_account_name) merge_attributes(Fog::Compute::AzureRM::Server.parse(vm)) end |
#deallocate ⇒ Object
96 97 98 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 96 def deallocate service.deallocate_virtual_machine(resource_group, name) end |
#destroy ⇒ Object
76 77 78 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 76 def destroy service.delete_virtual_machine(resource_group, name) end |
#detach_data_disk(disk_name) ⇒ Object
117 118 119 120 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 117 def detach_data_disk(disk_name) vm = service.detach_data_disk_from_vm(resource_group, name, disk_name) merge_attributes(Fog::Compute::AzureRM::Server.parse(vm)) end |
#generalize ⇒ Object
80 81 82 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 80 def generalize service.generalize_virtual_machine(resource_group, name) end |
#list_available_sizes ⇒ Object
104 105 106 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 104 def list_available_sizes service.list_available_sizes_for_virtual_machine(resource_group, name) end |
#power_off ⇒ Object
84 85 86 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 84 def power_off service.power_off_virtual_machine(resource_group, name) end |
#redeploy ⇒ Object
100 101 102 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 100 def redeploy service.redeploy_virtual_machine(resource_group, name) end |
#restart ⇒ Object
92 93 94 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 92 def restart service.restart_virtual_machine(resource_group, name) end |
#save ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 66 def save requires :name, :location, :resource_group, :vm_size, :storage_account_name, :username, :password, :network_interface_card_id, :publisher, :offer, :sku, :version requires :disable_password_authentication if platform.casecmp('linux').zero? ssh_key_path = "/home/#{username}/.ssh/authorized_keys" unless ssh_key_data.nil? virtual_machine_params = get_virtual_machine_params(ssh_key_path) vm = service.create_virtual_machine(virtual_machine_params) merge_attributes(Fog::Compute::AzureRM::Server.parse(vm)) end |
#start ⇒ Object
88 89 90 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 88 def start service.start_virtual_machine(resource_group, name) end |
#vm_status ⇒ Object
108 109 110 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 108 def vm_status service.check_vm_status(resource_group, name) end |