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 65 66 67 68 69 |
# 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 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_vhd_uri'] = vm.storage_profile.os_disk.vhd.uri 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'] = [] 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
117 118 119 120 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 117 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
101 102 103 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 101 def deallocate service.deallocate_virtual_machine(resource_group, name) end |
#destroy ⇒ Object
81 82 83 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 81 def destroy service.delete_virtual_machine(resource_group, name) end |
#detach_data_disk(disk_name) ⇒ Object
122 123 124 125 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 122 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
85 86 87 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 85 def generalize service.generalize_virtual_machine(resource_group, name) end |
#list_available_sizes ⇒ Object
109 110 111 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 109 def list_available_sizes service.list_available_sizes_for_virtual_machine(resource_group, name) end |
#power_off ⇒ Object
89 90 91 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 89 def power_off service.power_off_virtual_machine(resource_group, name) end |
#redeploy ⇒ Object
105 106 107 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 105 def redeploy service.redeploy_virtual_machine(resource_group, name) end |
#restart ⇒ Object
97 98 99 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 97 def restart service.restart_virtual_machine(resource_group, name) end |
#save ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 71 def save requires :name, :location, :resource_group, :vm_size, :storage_account_name, :username, :password, :network_interface_card_id requires :disable_password_authentication if platform.casecmp('linux').zero? requires :publisher, :offer, :sku, :version if vhd_path.nil? ssh_key_path = "/home/#{username}/.ssh/authorized_keys" unless ssh_key_data.nil? vm = service.create_virtual_machine(virtual_machine_params(ssh_key_path)) merge_attributes(Server.parse(vm)) end |
#start ⇒ Object
93 94 95 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 93 def start service.start_virtual_machine(resource_group, name) end |
#vm_status ⇒ Object
113 114 115 |
# File 'lib/fog/azurerm/models/compute/server.rb', line 113 def vm_status service.check_vm_status(resource_group, name) end |