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.
-
#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.
-
#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) ⇒ 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_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) ⇒ AzureRmCompute
Returns a new instance of AzureRmCompute.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 12 def initialize(azure_vm: ComputeModels::VirtualMachine.new, sdk: nil, resource_group: azure_vm.resource_group, nics: [], volumes: [], script_command: nil, script_uris: nil) @azure_vm = azure_vm @sdk = sdk @resource_group ||= resource_group @nics ||= nics @volumes ||= volumes @script_command ||= script_command @script_uris ||= script_uris @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 |
#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 |
#volumes ⇒ Object
Returns the value of attribute volumes.
8 9 10 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 8 def volumes @volumes end |
Instance Method Details
#data_disks ⇒ Object
125 126 127 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 125 def data_disks @data_disks ||= @azure_vm.storage_profile.data_disks || [] end |
#id ⇒ Object
37 38 39 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 37 def id @azure_vm.id end |
#identity ⇒ Object
139 140 141 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 139 def identity @azure_vm.name end |
#identity=(setuuid) ⇒ Object
143 144 145 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 143 def identity=(setuuid) @azure_vm.name = setuuid end |
#image_uuid ⇒ Object Also known as: image_id
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 190 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
114 115 116 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 114 def interfaces nics end |
#interfaces_attributes=(attrs) ⇒ Object
118 119 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 118 def interfaces_attributes=(attrs) end |
#ip_addresses ⇒ Object
121 122 123 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 121 def ip_addresses [] end |
#network_interface_card_ids ⇒ Object
79 80 81 82 83 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 79 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
186 187 188 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 186 def os_disk_caching @azure_vm.storage_profile.os_disk.caching end |
#os_disk_size_gb ⇒ Object
182 183 184 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 182 def os_disk_size_gb @azure_vm.storage_profile.os_disk.disk_size_gb end |
#password ⇒ Object
166 167 168 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 166 def password @azure_vm.os_profile.admin_password end |
#persisted? ⇒ Boolean
41 42 43 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 41 def persisted? !!identity && !!id end |
#platform ⇒ Object
158 159 160 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 158 def platform @azure_vm.storage_profile.os_disk.os_type end |
#premium_os_disk ⇒ Object
178 179 180 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 178 def premium_os_disk @azure_vm.storage_profile.os_disk.managed_disk.storage_account_type end |
#private_ip_address ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 103 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
85 86 87 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 85 def provisioning_ip_address public_ip_address || private_ip_address end |
#public_ip_address ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 89 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
50 51 52 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 50 def ready? vm_status == 'running' end |
#reload ⇒ Object
54 55 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 54 def reload end |
#ssh_key_data ⇒ Object
170 171 172 173 174 175 176 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 170 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
61 62 63 64 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 61 def start sdk.start_vm(@azure_vm.resource_group, name) true end |
#state ⇒ Object
57 58 59 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 57 def state vm_status end |
#stop ⇒ Object
66 67 68 69 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 66 def stop sdk.stop_vm(@azure_vm.resource_group, name) true end |
#to_s ⇒ Object
71 72 73 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 71 def to_s name end |
#username ⇒ Object
162 163 164 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 162 def username @azure_vm.os_profile.admin_username end |
#vm_description ⇒ Object
147 148 149 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 147 def vm_description _("%{vm_size} VM Size") % {:vm_size => vm_size} end |
#vm_extension ⇒ Object
208 209 210 211 212 213 214 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 208 def vm_extension return nil unless @azure_vm.resources @vm_extension ||= begin ext_name = @azure_vm.resources.first.id.split('/')[-1] sdk.get_vm_extension(@azure_vm.resource_group, name, ext_name) end end |
#vm_size ⇒ Object
Following properties are for AzureRm These are not part of Foreman’s interface
154 155 156 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 154 def vm_size @azure_vm.hardware_profile.vm_size end |
#vm_status ⇒ Object
75 76 77 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 75 def vm_status sdk.check_vm_status(@azure_vm.resource_group, name) end |
#volumes_attributes=(attrs) ⇒ Object
136 137 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 136 def volumes_attributes=(attrs) end |
#wait_for(_timeout = 0, _interval = 0, &block) ⇒ Object
45 46 47 48 |
# File 'app/models/foreman_azure_rm/azure_rm_compute.rb', line 45 def wait_for(_timeout = 0, _interval = 0, &block) instance_eval(&block) return true end |