Class: ForemanAzureRm::AzureRmCompute
- Inherits:
-
Object
- Object
- ForemanAzureRm::AzureRmCompute
- Defined in:
- app/models/foreman_azure_rm/azure_rm_compute.rb
Instance Attribute Summary collapse
-
#azure_vm ⇒ Object
Returns the value of attribute azure_vm.
-
#nics ⇒ Object
Returns the value of attribute nics.
-
#nvidia_gpu_extension ⇒ Object
Returns the value of attribute nvidia_gpu_extension.
-
#resource_group ⇒ Object
Returns the value of attribute resource_group.
-
#script_command ⇒ Object
Returns the value of attribute script_command.
-
#script_uris ⇒ Object
Returns the value of attribute script_uris.
-
#sdk ⇒ Object
Returns the value of attribute sdk.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#volumes ⇒ Object
Returns the value of attribute volumes.
Instance Method Summary collapse
- #data_disks ⇒ Object
- #id ⇒ Object
- #identity ⇒ Object
- #identity=(setuuid) ⇒ Object
- #image_uuid ⇒ Object (also: #image_id)
-
#initialize(azure_vm: ComputeModels::VirtualMachine.new, sdk: nil, resource_group: azure_vm.resource_group, nics: [], volumes: [], script_command: nil, script_uris: nil, nvidia_gpu_extension: false, tags: []) ⇒ AzureRmCompute
constructor
A new instance of AzureRmCompute.
- #interfaces ⇒ Object
- #interfaces_attributes=(attrs) ⇒ Object
- #ip_addresses ⇒ Object
- #network_interface_card_ids ⇒ Object
- #os_disk_caching ⇒ Object
- #os_disk_size_gb ⇒ Object
- #password ⇒ Object
- #persisted? ⇒ Boolean
- #platform ⇒ Object
- #premium_os_disk ⇒ Object
- #private_ip_address ⇒ Object
- #provisioning_ip_address ⇒ Object
- #public_ip_address ⇒ Object
- #ready? ⇒ Boolean
- #reload ⇒ Object
- #ssh_key_data ⇒ Object
- #start ⇒ Object
- #state ⇒ Object
- #stop ⇒ Object
- #to_s ⇒ Object
- #username ⇒ Object
- #vm_description ⇒ Object
- #vm_extension ⇒ Object
- #vm_nvidia_gpu_extension ⇒ Object
-
#vm_size ⇒ Object
Following properties are for AzureRm These are not part of Foreman’s interface.
- #vm_status ⇒ Object
- #volumes_attributes=(attrs) ⇒ Object
- #wait_for(_timeout = 0, _interval = 0, &block) ⇒ Object
Constructor Details
#initialize(azure_vm: ComputeModels::VirtualMachine.new, sdk: nil, resource_group: azure_vm.resource_group, nics: [], volumes: [], script_command: nil, script_uris: nil, nvidia_gpu_extension: false, tags: []) ⇒ AzureRmCompute
Returns a new instance of AzureRmCompute.
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 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 14 def initialize(azure_vm: ComputeModels::VirtualMachine.new, sdk: nil, resource_group: azure_vm.resource_group, nics: [], volumes: [], script_command: nil, script_uris: nil, nvidia_gpu_extension: false, tags: []) @azure_vm = azure_vm @sdk = sdk @resource_group ||= resource_group @nics ||= nics @volumes ||= volumes @script_command ||= script_command @script_uris ||= script_uris @nvidia_gpu_extension ||= nvidia_gpu_extension @tags ||= @azure_vm.hardware_profile ||= ComputeModels::HardwareProfile.new @azure_vm.os_profile ||= ComputeModels::OSProfile.new @azure_vm.os_profile.linux_configuration ||= ComputeModels::LinuxConfiguration.new @azure_vm.os_profile.linux_configuration.ssh ||= ComputeModels::SshConfiguration.new @azure_vm.os_profile.linux_configuration.ssh.public_keys ||= [ComputeModels::SshPublicKey.new] @azure_vm.storage_profile ||= ComputeModels::StorageProfile.new @azure_vm.storage_profile.os_disk ||= ComputeModels::OSDisk.new @azure_vm.storage_profile.os_disk.managed_disk ||= ComputeModels::ManagedDiskParameters.new end |
Instance Attribute Details
#azure_vm ⇒ Object
Returns the value of attribute azure_vm.
4 5 6 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 4 def azure_vm @azure_vm end |
#nics ⇒ Object
Returns the value of attribute nics.
6 7 8 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 6 def nics @nics end |
#nvidia_gpu_extension ⇒ Object
Returns the value of attribute nvidia_gpu_extension.
8 9 10 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 8 def nvidia_gpu_extension @nvidia_gpu_extension end |
#resource_group ⇒ Object
Returns the value of attribute resource_group.
5 6 7 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 5 def resource_group @resource_group end |
#script_command ⇒ Object
Returns the value of attribute script_command.
7 8 9 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 7 def script_command @script_command end |
#script_uris ⇒ Object
Returns the value of attribute script_uris.
7 8 9 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 7 def script_uris @script_uris end |
#sdk ⇒ Object
Returns the value of attribute sdk.
3 4 5 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 3 def sdk @sdk end |
#tags ⇒ Object
Returns the value of attribute tags.
10 11 12 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 10 def @tags end |
#volumes ⇒ Object
Returns the value of attribute volumes.
9 10 11 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 9 def volumes @volumes end |
Instance Method Details
#data_disks ⇒ Object
131 132 133 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 131 def data_disks @data_disks ||= @azure_vm.storage_profile.data_disks || [] end |
#id ⇒ Object
43 44 45 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 43 def id @azure_vm.id end |
#identity ⇒ Object
145 146 147 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 145 def identity @azure_vm.name end |
#identity=(setuuid) ⇒ Object
149 150 151 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 149 def identity=(setuuid) @azure_vm.name = setuuid end |
#image_uuid ⇒ Object Also known as: image_id
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 196 def image_uuid image = @azure_vm.storage_profile.image_reference return nil unless image if image.id.nil? return "marketplace://#{image.publisher}:#{image.offer}:#{image.sku}:#{image.version}" else image_rg = image.id.split('/')[4] image_name = image.id.split('/')[-1] if sdk.list_custom_images.find { |custom_img| custom_img.name == image_name } return "custom://#{image_name}" elsif sdk.fetch_gallery_image_id(image_rg, image_name) return "gallery://#{image_name}" end end end |
#interfaces ⇒ Object
120 121 122 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 120 def interfaces nics end |
#interfaces_attributes=(attrs) ⇒ Object
124 125 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 124 def interfaces_attributes=(attrs) end |
#ip_addresses ⇒ Object
127 128 129 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 127 def ip_addresses [] end |
#network_interface_card_ids ⇒ Object
85 86 87 88 89 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 85 def network_interface_card_ids return nil unless @azure_vm.network_profile nics = @azure_vm.network_profile.network_interfaces nics.map(&:id) end |
#os_disk_caching ⇒ Object
192 193 194 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 192 def os_disk_caching @azure_vm.storage_profile.os_disk.caching end |
#os_disk_size_gb ⇒ Object
188 189 190 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 188 def os_disk_size_gb @azure_vm.storage_profile.os_disk.disk_size_gb end |
#password ⇒ Object
172 173 174 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 172 def password @azure_vm.os_profile.admin_password end |
#persisted? ⇒ Boolean
47 48 49 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 47 def persisted? !!identity && !!id end |
#platform ⇒ Object
164 165 166 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 164 def platform @azure_vm.storage_profile.os_disk.os_type end |
#premium_os_disk ⇒ Object
184 185 186 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 184 def premium_os_disk @azure_vm.storage_profile.os_disk.managed_disk.storage_account_type end |
#private_ip_address ⇒ Object
109 110 111 112 113 114 115 116 117 118 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 109 def private_ip_address interfaces.each do |nic| nic.ip_configurations.each do |configuration| next unless configuration.primary if configuration.private_ipaddress.present? return private_ip_address = configuration.private_ipaddress end end end end |
#provisioning_ip_address ⇒ Object
91 92 93 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 91 def provisioning_ip_address public_ip_address || private_ip_address end |
#public_ip_address ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 95 def public_ip_address interfaces.each do |nic| nic.ip_configurations.each do |configuration| next unless configuration.primary return nil if configuration.public_ipaddress.blank? ip_id = configuration.public_ipaddress.id ip_rg = ip_id.split('/')[4] ip_name = ip_id.split('/')[-1] public_ip = sdk.public_ip(ip_rg, ip_name) return public_ip.ip_address end end end |
#ready? ⇒ Boolean
56 57 58 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 56 def ready? vm_status == 'running' end |
#reload ⇒ Object
60 61 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 60 def reload end |
#ssh_key_data ⇒ Object
176 177 178 179 180 181 182 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 176 def ssh_key_data # since you can only give one additional # sshkey through foreman's UI sshkey = @azure_vm.os_profile.linux_configuration.ssh.public_keys[1] return unless sshkey.present? sshkey.key_data end |
#start ⇒ Object
67 68 69 70 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 67 def start sdk.start_vm(@azure_vm.resource_group, name) true end |
#state ⇒ Object
63 64 65 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 63 def state vm_status end |
#stop ⇒ Object
72 73 74 75 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 72 def stop sdk.stop_vm(@azure_vm.resource_group, name) true end |
#to_s ⇒ Object
77 78 79 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 77 def to_s name end |
#username ⇒ Object
168 169 170 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 168 def username @azure_vm.os_profile.admin_username end |
#vm_description ⇒ Object
153 154 155 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 153 def vm_description _("%{vm_size} VM Size") % {:vm_size => vm_size} end |
#vm_extension ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 214 def vm_extension return nil unless @azure_vm.resources @vm_extension ||= begin @azure_vm.resources.each do |ext| ext_name = ext.id.split('/')[-1] next unless ext_name == 'ForemanCustomScript' return sdk.get_vm_extension(@azure_vm.resource_group, name, ext_name) end nil end end |
#vm_nvidia_gpu_extension ⇒ Object
226 227 228 229 230 231 232 233 234 235 236 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 226 def vm_nvidia_gpu_extension return nil unless @azure_vm.resources @vm_nvidia_gpu_extension ||= begin @azure_vm.resources.each do |ext| ext_name = ext.id.split('/')[-1] next unless ['NvidiaGpuDriverLinux', 'NvidiaGpuDriverWindows'].include? ext_name return sdk.get_vm_extension(@azure_vm.resource_group, name, ext_name) end nil end end |
#vm_size ⇒ Object
Following properties are for AzureRm These are not part of Foreman’s interface
160 161 162 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 160 def vm_size @azure_vm.hardware_profile.vm_size end |
#vm_status ⇒ Object
81 82 83 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 81 def vm_status sdk.check_vm_status(@azure_vm.resource_group, name) end |
#volumes_attributes=(attrs) ⇒ Object
142 143 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 142 def volumes_attributes=(attrs) end |
#wait_for(_timeout = 0, _interval = 0, &block) ⇒ Object
51 52 53 54 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 51 def wait_for(_timeout = 0, _interval = 0, &block) instance_eval(&block) return true end |