foreman_azure_rm 2.0.7 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/helpers/azure_compute_resource_helper.rb +17 -0
- data/app/models/concerns/foreman_azure_rm/vm_extensions/managed_vm.rb +50 -28
- data/app/models/foreman_azure_rm/azure_rm.rb +86 -71
- data/app/models/foreman_azure_rm/azure_rm_compute.rb +34 -3
- data/app/views/compute_resources/form/_azurerm.html.erb +3 -6
- data/app/views/compute_resources_vms/form/azurerm/_base.html.erb +1 -1
- data/app/views/compute_resources_vms/form/azurerm/_volume.html.erb +20 -0
- data/app/views/images/form/_azurerm.html.erb +1 -1
- data/db/migrate/20200507103900_fix_image_uuid_prefix.rb +8 -0
- data/lib/foreman_azure_rm.rb +3 -0
- data/lib/foreman_azure_rm/azure_sdk_adapter.rb +68 -2
- data/lib/foreman_azure_rm/engine.rb +6 -0
- data/lib/foreman_azure_rm/version.rb +1 -1
- data/locale/Makefile +61 -0
- data/locale/action_names.rb +5 -0
- data/locale/ca/LC_MESSAGES/foreman_azure_rm.mo +0 -0
- data/locale/ca/foreman_azure_rm.po +185 -0
- data/locale/cs_CZ/LC_MESSAGES/foreman_azure_rm.mo +0 -0
- data/locale/cs_CZ/foreman_azure_rm.po +189 -0
- data/locale/de/LC_MESSAGES/foreman_azure_rm.mo +0 -0
- data/locale/de/foreman_azure_rm.po +191 -0
- data/locale/en/LC_MESSAGES/foreman_azure_rm.mo +0 -0
- data/locale/en/foreman_azure_rm.po +183 -0
- data/locale/en_GB/LC_MESSAGES/foreman_azure_rm.mo +0 -0
- data/locale/en_GB/foreman_azure_rm.po +187 -0
- data/locale/es/LC_MESSAGES/foreman_azure_rm.mo +0 -0
- data/locale/es/foreman_azure_rm.po +190 -0
- data/locale/foreman_azure_rm.pot +248 -0
- data/locale/fr/LC_MESSAGES/foreman_azure_rm.mo +0 -0
- data/locale/fr/foreman_azure_rm.po +187 -0
- data/locale/gl/LC_MESSAGES/foreman_azure_rm.mo +0 -0
- data/locale/gl/foreman_azure_rm.po +185 -0
- data/locale/it/LC_MESSAGES/foreman_azure_rm.mo +0 -0
- data/locale/it/foreman_azure_rm.po +187 -0
- data/locale/ja/LC_MESSAGES/foreman_azure_rm.mo +0 -0
- data/locale/ja/foreman_azure_rm.po +187 -0
- data/locale/ko/LC_MESSAGES/foreman_azure_rm.mo +0 -0
- data/locale/ko/foreman_azure_rm.po +186 -0
- data/locale/nl_NL/LC_MESSAGES/foreman_azure_rm.mo +0 -0
- data/locale/nl_NL/foreman_azure_rm.po +187 -0
- data/locale/pl/LC_MESSAGES/foreman_azure_rm.mo +0 -0
- data/locale/pl/foreman_azure_rm.po +188 -0
- data/locale/pt_BR/LC_MESSAGES/foreman_azure_rm.mo +0 -0
- data/locale/pt_BR/foreman_azure_rm.po +190 -0
- data/locale/ru/LC_MESSAGES/foreman_azure_rm.mo +0 -0
- data/locale/ru/foreman_azure_rm.po +190 -0
- data/locale/sv_SE/LC_MESSAGES/foreman_azure_rm.mo +0 -0
- data/locale/sv_SE/foreman_azure_rm.po +187 -0
- data/locale/zh_CN/LC_MESSAGES/foreman_azure_rm.mo +0 -0
- data/locale/zh_CN/foreman_azure_rm.po +188 -0
- data/locale/zh_TW/LC_MESSAGES/foreman_azure_rm.mo +0 -0
- data/locale/zh_TW/foreman_azure_rm.po +187 -0
- metadata +59 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56702d3d39f9bc9753e04e4681b4607d073cc913c1625835dda252a8a575cb6a
|
4
|
+
data.tar.gz: 59999cc6458945958f13933a0a9c1b08b63d8ddad0cb6ece337b86e367948190
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: beb3b60d5c7790ff3063c67634d749fa5ca13148bde4197e40f0d5014ec3bdab94956688b5a6de21fa13ee40e0edf76bccd7ce2fa6e1ebcd6be7fafb9f79057a
|
7
|
+
data.tar.gz: c4e0e9857dfe71bc31d09275c012ed263dde09e25d98ea5d32c75a8be812f8a325a0d5f2e9880f6a84109c9f8a6f2ff3ee5db0e1079b969c27102cd84fc2d54e
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module AzureComputeResourceHelper
|
2
|
+
def regions_list(azurerm_cr, f)
|
3
|
+
begin
|
4
|
+
regions = azurerm_cr.regions || []
|
5
|
+
rescue StandardError
|
6
|
+
#do nothing
|
7
|
+
regions = []
|
8
|
+
rescue Exception => ex
|
9
|
+
return information_box("Regions could not be loaded due to exception: #{ex}")
|
10
|
+
end
|
11
|
+
selectable_f(f, :url, regions, {}, {:label => _('Azure Region'), :disabled => regions.empty?, :required => true, :help_inline_permanent => load_button_f(f, regions.present?, _("Load Regions")) })
|
12
|
+
end
|
13
|
+
def azure_doc_url
|
14
|
+
doc_version = Foreman::Plugin.find(:foreman_azure_rm).version.scan(/\d+\.\d+/).first + '.x'
|
15
|
+
"https://theforeman.org/plugins/foreman_azure/#{doc_version}"
|
16
|
+
end
|
17
|
+
end
|
@@ -13,19 +13,7 @@ module ForemanAzureRm
|
|
13
13
|
os_disk.name = "#{vm_name}-osdisk"
|
14
14
|
os_disk.os_type = platform
|
15
15
|
os_disk.create_option = ComputeModels::DiskCreateOptionTypes::FromImage
|
16
|
-
os_disk.caching =
|
17
|
-
case os_disk_caching
|
18
|
-
when 'None'
|
19
|
-
ComputeModels::CachingTypes::None
|
20
|
-
when 'ReadOnly'
|
21
|
-
ComputeModels::CachingTypes::ReadOnly
|
22
|
-
when 'ReadWrite'
|
23
|
-
ComputeModels::CachingTypes::ReadWrite
|
24
|
-
end
|
25
|
-
else
|
26
|
-
# ARM best practices stipulate RW caching on the OS disk
|
27
|
-
ComputeModels::CachingTypes::ReadWrite
|
28
|
-
end
|
16
|
+
os_disk.caching = disk_caching(os_disk_caching)
|
29
17
|
managed_disk_params.storage_account_type = if premium_os_disk == 'true'
|
30
18
|
ComputeModels::StorageAccountTypes::PremiumLRS
|
31
19
|
else
|
@@ -33,10 +21,44 @@ module ForemanAzureRm
|
|
33
21
|
end
|
34
22
|
os_disk.managed_disk = managed_disk_params
|
35
23
|
storage_profile.os_disk = os_disk
|
36
|
-
|
37
24
|
storage_profile
|
38
25
|
end
|
39
26
|
|
27
|
+
def disk_caching(disk_type_caching)
|
28
|
+
case disk_type_caching
|
29
|
+
when 'None'
|
30
|
+
ComputeModels::CachingTypes::None
|
31
|
+
when 'ReadOnly'
|
32
|
+
ComputeModels::CachingTypes::ReadOnly
|
33
|
+
when 'ReadWrite'
|
34
|
+
ComputeModels::CachingTypes::ReadWrite
|
35
|
+
when nil, ""
|
36
|
+
nil
|
37
|
+
else
|
38
|
+
raise RuntimeError, "Disk caching value must be either 'None', 'ReadOnly' or 'ReadWrite'."
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def define_data_disks(vm_name, data_disks)
|
43
|
+
unless data_disks.nil?
|
44
|
+
disks = []
|
45
|
+
disk_count = 0
|
46
|
+
data_disks.each do |disk_num, attrs|
|
47
|
+
managed_data_disk = ComputeModels::ManagedDiskParameters.new
|
48
|
+
disk = ComputeModels::DataDisk.new
|
49
|
+
disk.name = "#{vm_name}-data-disk#{disk_count}"
|
50
|
+
disk.caching = disk_caching(attrs[:data_disk_caching])
|
51
|
+
disk.disk_size_gb = attrs[:disk_size_gb]
|
52
|
+
disk.create_option = ComputeModels::DiskCreateOption::Empty
|
53
|
+
disk.lun = disk_count + 1
|
54
|
+
disk.managed_disk = managed_data_disk
|
55
|
+
disk_count += 1
|
56
|
+
disks << disk
|
57
|
+
end
|
58
|
+
disks
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
40
62
|
def marketplace_image_reference(publisher, offer, sku, version)
|
41
63
|
image_reference = ComputeModels::ImageReference.new
|
42
64
|
image_reference.publisher = publisher
|
@@ -46,26 +68,25 @@ module ForemanAzureRm
|
|
46
68
|
image_reference
|
47
69
|
end
|
48
70
|
|
49
|
-
def define_image(
|
50
|
-
|
51
|
-
|
52
|
-
|
71
|
+
def define_image(rg_name, image)
|
72
|
+
image_type, image_id = image.split('://')
|
73
|
+
case image_type
|
74
|
+
when 'marketplace'
|
53
75
|
urn = image_id.split(':')
|
54
76
|
publisher = urn[0]
|
55
77
|
offer = urn[1]
|
56
78
|
sku = urn[2]
|
57
79
|
version = urn[3]
|
58
|
-
image_id = nil
|
59
|
-
end
|
60
|
-
|
61
|
-
if image_id.nil?
|
62
|
-
# For marketplace image
|
63
80
|
image_reference = marketplace_image_reference(publisher, offer, sku, version)
|
81
|
+
when 'custom'
|
82
|
+
custom_image = sdk.get_custom_image(rg_name, image_id)
|
83
|
+
image_reference = ComputeModels::ImageReference.new
|
84
|
+
image_reference.id = custom_image.id
|
85
|
+
when 'gallery'
|
86
|
+
image_reference = ComputeModels::ImageReference.new
|
87
|
+
image_reference.id = sdk.fetch_gallery_image_id(rg_name, image_id)
|
64
88
|
else
|
65
|
-
|
66
|
-
image_ref = ComputeModels::ImageReference.new
|
67
|
-
image_ref.id = image_id
|
68
|
-
image_reference = image_ref
|
89
|
+
image_reference = nil
|
69
90
|
end
|
70
91
|
image_reference
|
71
92
|
end
|
@@ -189,7 +210,8 @@ module ForemanAzureRm
|
|
189
210
|
def create_managed_virtual_machine(vm_hash)
|
190
211
|
vm_params = initialize_vm(vm_hash)
|
191
212
|
vm_params.network_profile = define_network_profile(vm_hash[:network_interface_card_ids])
|
192
|
-
vm_params.storage_profile.image_reference = define_image(vm_hash[:image_id])
|
213
|
+
vm_params.storage_profile.image_reference = define_image(vm_hash[:resource_group], vm_hash[:image_id])
|
214
|
+
vm_params.storage_profile.data_disks = define_data_disks(vm_hash[:name], vm_hash[:data_disks])
|
193
215
|
sdk.create_or_update_vm(vm_hash[:resource_group], vm_hash[:name], vm_params)
|
194
216
|
end
|
195
217
|
|
@@ -12,12 +12,14 @@ module ForemanAzureRm
|
|
12
12
|
alias_attribute :region, :url
|
13
13
|
alias_attribute :tenant, :uuid
|
14
14
|
|
15
|
-
validates :user, :password, :
|
15
|
+
validates :user, :password, :uuid, :app_ident, :presence => true
|
16
16
|
|
17
17
|
has_one :key_pair, :foreign_key => :compute_resource_id, :dependent => :destroy
|
18
18
|
|
19
19
|
before_create :test_connection, :setup_key_pair
|
20
20
|
|
21
|
+
validate :ensure_attributes_and_values
|
22
|
+
|
21
23
|
class VMContainer
|
22
24
|
attr_accessor :virtualmachines
|
23
25
|
delegate :each, to: :virtualmachines
|
@@ -47,6 +49,15 @@ module ForemanAzureRm
|
|
47
49
|
"#{name} (#{provider_friendly_name})"
|
48
50
|
end
|
49
51
|
|
52
|
+
def ensure_attributes_and_values
|
53
|
+
validate_region
|
54
|
+
end
|
55
|
+
|
56
|
+
def validate_region
|
57
|
+
return unless regions.present?
|
58
|
+
errors.add(:region, "is not valid, must be lowercase eg. 'eastus'. No special characters allowed.") unless regions.collect(&:second).include?(region)
|
59
|
+
end
|
60
|
+
|
50
61
|
def self.model_name
|
51
62
|
ComputeResource.model_name
|
52
63
|
end
|
@@ -56,81 +67,35 @@ module ForemanAzureRm
|
|
56
67
|
end
|
57
68
|
|
58
69
|
def capabilities
|
59
|
-
[:image]
|
60
|
-
end
|
61
|
-
|
62
|
-
def
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
['South Central US', 'southcentralus'],
|
67
|
-
['North Central US', 'northcentralus'],
|
68
|
-
['West Central US', 'westcentralus'],
|
69
|
-
['East US', 'eastus'],
|
70
|
-
['East US 2', 'eastus2'],
|
71
|
-
['West US', 'westus'],
|
72
|
-
['West US 2', 'westus2'],
|
73
|
-
['Canada Central', 'canadacentral'],
|
74
|
-
['Canada East', 'canadaeast'],
|
75
|
-
['Brazil South', 'brazilsouth'],
|
76
|
-
['North Europe', 'northeurope'],
|
77
|
-
['France Central', 'francecentral'],
|
78
|
-
['France South', 'francesouth'],
|
79
|
-
['UK South', 'uksouth'],
|
80
|
-
['UK West', 'ukwest'],
|
81
|
-
['Germany Central', 'germanycentral'],
|
82
|
-
['Germany Northeast', 'germanynortheast'],
|
83
|
-
['Germany West Central', 'germanywestcentral'],
|
84
|
-
['Germany North', 'germanynorth'],
|
85
|
-
['Switzerland North', 'switzerlandnorth'],
|
86
|
-
['Switzerland West', 'switzerlandwest'],
|
87
|
-
['Norway West', 'norwaywest'],
|
88
|
-
['Norway East', 'norwayeast'],
|
89
|
-
['East Asia', 'eastasia'],
|
90
|
-
['Southeast Asia', 'southeastasia'],
|
91
|
-
['Australia Central', 'australiacentral'],
|
92
|
-
['Australia Central 2', 'australiacentral2'],
|
93
|
-
['Australia East', 'australiaeast'],
|
94
|
-
['Australia Southeast', 'australiasoutheast'],
|
95
|
-
['China East', 'chinaeast'],
|
96
|
-
['China North', 'chinanorth'],
|
97
|
-
['China East 2', 'chinaeast2'],
|
98
|
-
['China North 2', 'chinanorth2'],
|
99
|
-
['Central India', 'centralindia'],
|
100
|
-
['South India', 'southindia'],
|
101
|
-
['West India', 'westindia'],
|
102
|
-
['Japan East', 'japaneast'],
|
103
|
-
['Japan West', 'japanwest'],
|
104
|
-
['Korea Central', 'koreacentral'],
|
105
|
-
['Korea South', 'koreasouth'],
|
106
|
-
['South Africa North', 'southafricanorth'],
|
107
|
-
['South Africa West', 'southafricawest'],
|
108
|
-
['UAE Central', 'uaecentral'],
|
109
|
-
['UAE North', 'uaenorth']
|
110
|
-
]
|
111
|
-
end
|
112
|
-
|
113
|
-
validates :region, inclusion: { in: regions.collect(&:second),
|
114
|
-
message: "%{value} must be lowercase eg. 'eastus'. No special characters allowed." }
|
70
|
+
[:image, :new_volume]
|
71
|
+
end
|
72
|
+
|
73
|
+
def regions
|
74
|
+
return unless sub_id.present?
|
75
|
+
sdk.list_regions(sub_id).value.map { |loc| [loc.display_name, loc.name] }
|
76
|
+
end
|
115
77
|
|
116
78
|
def resource_groups
|
117
79
|
sdk.rgs
|
118
80
|
end
|
119
81
|
|
120
82
|
def test_connection(options = {})
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
83
|
+
super
|
84
|
+
errors[:user].empty? && errors[:password].empty? && errors[:uuid].empty? && errors[:app_ident].empty? && regions
|
85
|
+
rescue StandardError => e
|
86
|
+
errors[:base] << e.message
|
87
|
+
rescue Excon::Error::Socket => e
|
88
|
+
errors[:base] << e.message
|
125
89
|
end
|
126
90
|
|
127
91
|
def new_vm(args = {})
|
128
92
|
return AzureRmCompute.new(sdk: sdk) if args.empty?
|
129
93
|
opts = vm_instance_defaults.merge(args.to_h).deep_symbolize_keys
|
130
94
|
# convert rails nested_attributes into a plain hash
|
131
|
-
|
132
|
-
|
133
|
-
|
95
|
+
[:interfaces, :volumes].each do |collection|
|
96
|
+
nested_args = opts.delete("#{collection}_attributes".to_sym)
|
97
|
+
opts[collection] = nested_attributes_for(collection, nested_args) if nested_args
|
98
|
+
end
|
134
99
|
opts.reject! { |k, v| v.nil? }
|
135
100
|
|
136
101
|
raw_vm = initialize_vm(location: region,
|
@@ -149,13 +114,54 @@ module ForemanAzureRm
|
|
149
114
|
ifaces << new_interface(iface_attrs)
|
150
115
|
end
|
151
116
|
end
|
152
|
-
|
117
|
+
|
118
|
+
vols = opts.fetch(:volumes, []).map { |vols_attrs| new_volume(vols_attrs) } if opts[:volumes].present?
|
119
|
+
|
120
|
+
AzureRmCompute.new(azure_vm: raw_vm ,sdk: sdk, resource_group: opts[:resource_group], nics: ifaces, volumes: vols, script_command: opts[:script_command], script_uris: opts[:script_uris])
|
153
121
|
end
|
154
122
|
|
155
123
|
def provided_attributes
|
156
124
|
super.merge({ :ip => :provisioning_ip_address })
|
157
125
|
end
|
158
126
|
|
127
|
+
def image_exists?(image)
|
128
|
+
image_type, image_id = image.split('://')
|
129
|
+
case image_type
|
130
|
+
when 'marketplace'
|
131
|
+
begin
|
132
|
+
urn = image_id.split(':')
|
133
|
+
publisher = urn[0]
|
134
|
+
offer = urn[1]
|
135
|
+
sku = urn[2]
|
136
|
+
version = urn[3]
|
137
|
+
if version == "latest"
|
138
|
+
all_versions = sdk.list_versions(region, publisher, offer, sku).map(&:name)
|
139
|
+
return true if all_versions.any?
|
140
|
+
end
|
141
|
+
sdk.get_marketplace_image(region, publisher, offer, sku, version).present?
|
142
|
+
rescue StandardError => e
|
143
|
+
return false
|
144
|
+
end
|
145
|
+
when 'gallery'
|
146
|
+
gallery_images_list = sdk.list_resources(filter: "resourceType eq 'Microsoft.Compute/galleries/images'")
|
147
|
+
gallery_image = gallery_images_list.detect { |gal_img| gal_img.id.split('/')[-1] == image_id }
|
148
|
+
if gallery_image.present?
|
149
|
+
rg_name = gallery_image.id.split('/')[4]
|
150
|
+
gallery_name = gallery_image.name.split('/')[0]
|
151
|
+
image_versions = sdk.list_gallery_image_versions(rg_name, gallery_name, image_id)
|
152
|
+
target_regions = image_versions.map do |image_version|
|
153
|
+
image_version.publishing_profile.target_regions.map(&:name)
|
154
|
+
end.flatten.uniq.map { |tgt_reg| tgt_reg.gsub(/\s+/, '').downcase }
|
155
|
+
return true if target_regions.include? region
|
156
|
+
end
|
157
|
+
when 'custom'
|
158
|
+
custom_image = sdk.list_custom_images.detect { |custom_img| custom_img.name == image_id && custom_img.location == region }
|
159
|
+
return custom_image.present?
|
160
|
+
else
|
161
|
+
false
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
159
165
|
def available_vnets(attr = {})
|
160
166
|
virtual_networks
|
161
167
|
end
|
@@ -188,6 +194,11 @@ module ForemanAzureRm
|
|
188
194
|
true
|
189
195
|
end
|
190
196
|
|
197
|
+
def new_volume(attrs = {})
|
198
|
+
args = { :disk_size_gb => 0, :data_disk_caching => "", 'persisted?' => false }.merge(attrs.to_h)
|
199
|
+
OpenStruct.new(args)
|
200
|
+
end
|
201
|
+
|
191
202
|
def vm_sizes
|
192
203
|
sdk.list_vm_sizes(region)
|
193
204
|
end
|
@@ -198,7 +209,8 @@ module ForemanAzureRm
|
|
198
209
|
|
199
210
|
def vm_instance_defaults
|
200
211
|
super.deep_merge(
|
201
|
-
interfaces: [new_interface]
|
212
|
+
interfaces: [new_interface],
|
213
|
+
volumes: [new_volume]
|
202
214
|
)
|
203
215
|
end
|
204
216
|
|
@@ -212,6 +224,10 @@ module ForemanAzureRm
|
|
212
224
|
ifaces
|
213
225
|
end
|
214
226
|
|
227
|
+
def vm_disks(vm)
|
228
|
+
vm.storage_profile.data_disks
|
229
|
+
end
|
230
|
+
|
215
231
|
def vms(attrs = {})
|
216
232
|
container = VMContainer.new
|
217
233
|
# Load all vms of the region
|
@@ -276,6 +292,7 @@ module ForemanAzureRm
|
|
276
292
|
image_id: args[:image_id],
|
277
293
|
os_disk_caching: args[:os_disk_caching],
|
278
294
|
premium_os_disk: args[:premium_os_disk],
|
295
|
+
data_disks: args[:volumes_attributes],
|
279
296
|
custom_data: args[:user_data],
|
280
297
|
script_command: args[:script_command],
|
281
298
|
script_uris: args[:script_uris],
|
@@ -283,7 +300,7 @@ module ForemanAzureRm
|
|
283
300
|
logger.debug "Virtual Machine #{args[:vm_name]} Created Successfully."
|
284
301
|
create_vm_extension(region, args)
|
285
302
|
# return the vm object using azure_vm
|
286
|
-
AzureRmCompute.new(azure_vm: vm, sdk: sdk, resource_group: args[:resource_group], nics: vm_nics(vm), script_command: user_command, script_uris: args[:script_uris])
|
303
|
+
AzureRmCompute.new(azure_vm: vm, sdk: sdk, resource_group: args[:resource_group], nics: vm_nics(vm), volumes: vm_disks(vm), script_command: user_command, script_uris: args[:script_uris])
|
287
304
|
rescue RuntimeError => e
|
288
305
|
Foreman::Logging.exception('Unhandled AzureRm error', e)
|
289
306
|
destroy_vm vm.id if vm
|
@@ -310,10 +327,8 @@ module ForemanAzureRm
|
|
310
327
|
end
|
311
328
|
end
|
312
329
|
end
|
313
|
-
if os_disk.present?
|
314
|
-
|
315
|
-
end
|
316
|
-
|
330
|
+
sdk.delete_disk(rg_name, os_disk.name) if os_disk.present?
|
331
|
+
data_disks.each { |data_disk| sdk.delete_disk(rg_name, data_disk.name) } if data_disks.present?
|
317
332
|
true
|
318
333
|
rescue ActiveRecord::RecordNotFound
|
319
334
|
logger.info "Could not find the selected vm."
|
@@ -5,6 +5,7 @@ module ForemanAzureRm
|
|
5
5
|
attr_accessor :resource_group
|
6
6
|
attr_accessor :nics
|
7
7
|
attr_accessor :script_command, :script_uris
|
8
|
+
attr_accessor :volumes
|
8
9
|
|
9
10
|
delegate :name, to: :azure_vm, allow_nil: true
|
10
11
|
|
@@ -12,6 +13,7 @@ module ForemanAzureRm
|
|
12
13
|
sdk: sdk,
|
13
14
|
resource_group: azure_vm.resource_group,
|
14
15
|
nics: [],
|
16
|
+
volumes: [],
|
15
17
|
script_command: nil,
|
16
18
|
script_uris: nil)
|
17
19
|
|
@@ -19,6 +21,7 @@ module ForemanAzureRm
|
|
19
21
|
@sdk = sdk
|
20
22
|
@resource_group ||= resource_group
|
21
23
|
@nics ||= nics
|
24
|
+
@volumes ||= volumes
|
22
25
|
@script_command ||= script_command
|
23
26
|
@script_uris ||= script_uris
|
24
27
|
@azure_vm.hardware_profile ||= ComputeModels::HardwareProfile.new
|
@@ -119,6 +122,20 @@ module ForemanAzureRm
|
|
119
122
|
[]
|
120
123
|
end
|
121
124
|
|
125
|
+
def data_disks
|
126
|
+
@data_disks ||= @azure_vm.storage_profile.data_disks || []
|
127
|
+
end
|
128
|
+
|
129
|
+
def volumes
|
130
|
+
return @volumes if data_disks.empty?
|
131
|
+
volumes = data_disks.map do |disk|
|
132
|
+
OpenStruct.new(:disk => disk, :persisted? => true)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def volumes_attributes=(attrs)
|
137
|
+
end
|
138
|
+
|
122
139
|
def identity
|
123
140
|
@azure_vm.name
|
124
141
|
end
|
@@ -169,7 +186,17 @@ module ForemanAzureRm
|
|
169
186
|
def image_uuid
|
170
187
|
image = @azure_vm.storage_profile.image_reference
|
171
188
|
return nil unless image
|
172
|
-
|
189
|
+
if image.id.nil?
|
190
|
+
return "marketplace://#{image.publisher}:#{image.offer}:#{image.sku}:#{image.version}"
|
191
|
+
else
|
192
|
+
image_rg = image.id.split('/')[4]
|
193
|
+
image_name = image.id.split('/')[-1]
|
194
|
+
if sdk.list_custom_images.find { |custom_img| custom_img.name == image_name }
|
195
|
+
return "custom://#{image_name}"
|
196
|
+
elsif sdk.fetch_gallery_image_id(image_rg, image_name)
|
197
|
+
return "gallery://#{image_name}"
|
198
|
+
end
|
199
|
+
end
|
173
200
|
end
|
174
201
|
|
175
202
|
alias_method :image_id, :image_uuid
|
@@ -188,8 +215,12 @@ module ForemanAzureRm
|
|
188
215
|
# Index is based on script_command that is being injected
|
189
216
|
# from the code in #create_vm. It can be partly hard-coded
|
190
217
|
# since the command shall no change frequently.
|
191
|
-
|
192
|
-
|
218
|
+
if ssh_key_data.nil?
|
219
|
+
user_cmd_index = (vm_extension.settings["commandToExecute"].index("-c"))+ 4
|
220
|
+
script_command = vm_extension.settings["commandToExecute"][user_cmd_index..-2]
|
221
|
+
else
|
222
|
+
vm_extension.settings["commandToExecute"]
|
223
|
+
end
|
193
224
|
else
|
194
225
|
@script_command
|
195
226
|
end
|