foreman_azure_rm 2.0.5 → 2.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/concerns/foreman_azure_rm/vm_extensions/managed_vm.rb +10 -10
- data/app/models/foreman_azure_rm/azure_rm.rb +8 -4
- data/app/models/foreman_azure_rm/azure_rm_compute.rb +38 -2
- data/app/views/compute_resources_vms/form/azurerm/_base.html.erb +4 -3
- data/app/views/compute_resources_vms/index/_azurerm.html.erb +1 -1
- data/app/views/compute_resources_vms/show/_azurerm.html.erb +10 -6
- data/lib/foreman_azure_rm/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 910b1dd793ab445a40152db2f4613550f39d846cb53603da5a1b80cbd785f832
|
4
|
+
data.tar.gz: ed13a2dd55819f1c12f6c572173108b300c6ac456ec9d788507b68cf171c0260
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8876efb62862f4d57684d620a91ee740459187e3e7b64cf35da8d12473fde4189902a8a88ec0bb6aca6c6f3785b79cb1973b12a2d2cf00f7b5ff15aa27a0a7c0
|
7
|
+
data.tar.gz: 79b0e983f67fe039698c1ecb7ae2699435049d26aec02ed2389299492113c26e197e4366aac740bafd5e4b9251a18a7e3912fd65daf43628186c54cf83c78a26
|
@@ -21,10 +21,10 @@ module ForemanAzureRm
|
|
21
21
|
ComputeModels::CachingTypes::ReadOnly
|
22
22
|
when 'ReadWrite'
|
23
23
|
ComputeModels::CachingTypes::ReadWrite
|
24
|
-
else
|
25
|
-
# ARM best practices stipulate RW caching on the OS disk
|
26
|
-
ComputeModels::CachingTypes::ReadWrite
|
27
24
|
end
|
25
|
+
else
|
26
|
+
# ARM best practices stipulate RW caching on the OS disk
|
27
|
+
ComputeModels::CachingTypes::ReadWrite
|
28
28
|
end
|
29
29
|
managed_disk_params.storage_account_type = if premium_os_disk == 'true'
|
30
30
|
ComputeModels::StorageAccountTypes::PremiumLRS
|
@@ -46,25 +46,25 @@ module ForemanAzureRm
|
|
46
46
|
image_reference
|
47
47
|
end
|
48
48
|
|
49
|
-
def define_image(
|
49
|
+
def define_image(image_id)
|
50
50
|
# If image UUID begins with / it is a custom managed image
|
51
51
|
# Otherwise it is a marketplace URN
|
52
|
-
unless
|
53
|
-
urn =
|
52
|
+
unless image_id.start_with?('/')
|
53
|
+
urn = image_id.split(':')
|
54
54
|
publisher = urn[0]
|
55
55
|
offer = urn[1]
|
56
56
|
sku = urn[2]
|
57
57
|
version = urn[3]
|
58
|
-
|
58
|
+
image_id = nil
|
59
59
|
end
|
60
60
|
|
61
|
-
if
|
61
|
+
if image_id.nil?
|
62
62
|
# For marketplace image
|
63
63
|
image_reference = marketplace_image_reference(publisher, offer, sku, version)
|
64
64
|
else
|
65
65
|
# For custom managed image
|
66
66
|
image_ref = ComputeModels::ImageReference.new
|
67
|
-
image_ref.id =
|
67
|
+
image_ref.id = image_id
|
68
68
|
image_reference = image_ref
|
69
69
|
end
|
70
70
|
image_reference
|
@@ -189,7 +189,7 @@ module ForemanAzureRm
|
|
189
189
|
def create_managed_virtual_machine(vm_hash)
|
190
190
|
vm_params = initialize_vm(vm_hash)
|
191
191
|
vm_params.network_profile = define_network_profile(vm_hash[:network_interface_card_ids])
|
192
|
-
vm_params.storage_profile.image_reference = define_image(vm_hash[:
|
192
|
+
vm_params.storage_profile.image_reference = define_image(vm_hash[:image_id])
|
193
193
|
sdk.create_or_update_vm(vm_hash[:resource_group], vm_hash[:name], vm_params)
|
194
194
|
end
|
195
195
|
|
@@ -112,7 +112,7 @@ module ForemanAzureRm
|
|
112
112
|
ifaces << new_interface(iface_attrs)
|
113
113
|
end
|
114
114
|
end
|
115
|
-
AzureRmCompute.new(azure_vm: raw_vm ,sdk: sdk, resource_group: opts[:resource_group], nics: ifaces)
|
115
|
+
AzureRmCompute.new(azure_vm: raw_vm ,sdk: sdk, resource_group: opts[:resource_group], nics: ifaces, script_command: opts[:script_command], script_uris: opts[:script_uris])
|
116
116
|
end
|
117
117
|
|
118
118
|
def provided_attributes
|
@@ -207,10 +207,14 @@ module ForemanAzureRm
|
|
207
207
|
args[:vm_name] = args[:name].split('.')[0]
|
208
208
|
nics = create_nics(region, args)
|
209
209
|
if args[:password].present? && !args[:ssh_key_data].present?
|
210
|
+
# Any change to sudoers_cmd and formation of new
|
211
|
+
# args[:script_command] must be accordingly changed
|
212
|
+
# in script_command method in AzureRmCompute class
|
210
213
|
sudoers_cmd = "$echo #{args[:password]} | sudo -S echo '\"#{args[:username]}\" ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/waagent"
|
211
214
|
if args[:script_command].present?
|
212
215
|
# to run the script_cmd given through form as username
|
213
|
-
|
216
|
+
user_command = args[:script_command]
|
217
|
+
args[:script_command] = sudoers_cmd + " ; su - \"#{args[:username]}\" -c \"#{user_command}\""
|
214
218
|
else
|
215
219
|
args[:script_command] = sudoers_cmd
|
216
220
|
end
|
@@ -232,7 +236,7 @@ module ForemanAzureRm
|
|
232
236
|
disable_password_authentication: disable_password_auth,
|
233
237
|
network_interface_card_ids: nics.map(&:id),
|
234
238
|
platform: args[:platform],
|
235
|
-
|
239
|
+
image_id: args[:image_id],
|
236
240
|
os_disk_caching: args[:os_disk_caching],
|
237
241
|
premium_os_disk: args[:premium_os_disk],
|
238
242
|
custom_data: args[:user_data],
|
@@ -242,7 +246,7 @@ module ForemanAzureRm
|
|
242
246
|
logger.debug "Virtual Machine #{args[:vm_name]} Created Successfully."
|
243
247
|
create_vm_extension(region, args)
|
244
248
|
# return the vm object using azure_vm
|
245
|
-
AzureRmCompute.new(azure_vm: vm, sdk: sdk, resource_group: args[:resource_group], nics: vm_nics(vm))
|
249
|
+
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])
|
246
250
|
rescue RuntimeError => e
|
247
251
|
Foreman::Logging.exception('Unhandled AzureRm error', e)
|
248
252
|
destroy_vm vm.id if vm
|
@@ -4,19 +4,23 @@ module ForemanAzureRm
|
|
4
4
|
attr_accessor :azure_vm
|
5
5
|
attr_accessor :resource_group
|
6
6
|
attr_accessor :nics
|
7
|
-
attr_accessor :
|
7
|
+
attr_accessor :script_command, :script_uris
|
8
8
|
|
9
9
|
delegate :name, to: :azure_vm, allow_nil: true
|
10
10
|
|
11
11
|
def initialize(azure_vm: ComputeModels::VirtualMachine.new,
|
12
12
|
sdk: sdk,
|
13
13
|
resource_group: azure_vm.resource_group,
|
14
|
-
nics: []
|
14
|
+
nics: [],
|
15
|
+
script_command: nil,
|
16
|
+
script_uris: nil)
|
15
17
|
|
16
18
|
@azure_vm = azure_vm
|
17
19
|
@sdk = sdk
|
18
20
|
@resource_group ||= resource_group
|
19
21
|
@nics ||= nics
|
22
|
+
@script_command ||= script_command
|
23
|
+
@script_uris ||= script_uris
|
20
24
|
@azure_vm.hardware_profile ||= ComputeModels::HardwareProfile.new
|
21
25
|
@azure_vm.os_profile ||= ComputeModels::OSProfile.new
|
22
26
|
@azure_vm.os_profile.linux_configuration ||= ComputeModels::LinuxConfiguration.new
|
@@ -162,10 +166,42 @@ module ForemanAzureRm
|
|
162
166
|
@azure_vm.storage_profile.os_disk.caching
|
163
167
|
end
|
164
168
|
|
169
|
+
def image_uuid
|
170
|
+
image = @azure_vm.storage_profile.image_reference
|
171
|
+
return nil unless image
|
172
|
+
"#{image.publisher}:#{image.offer}:#{image.sku}:#{image.version}"
|
173
|
+
end
|
174
|
+
|
175
|
+
alias_method :image_id, :image_uuid
|
176
|
+
|
177
|
+
def vm_extension
|
178
|
+
return nil unless @azure_vm.resources
|
179
|
+
@vm_extension ||= begin
|
180
|
+
ext_name = @azure_vm.resources.first.id.split('/')[-1]
|
181
|
+
sdk.get_vm_extension(@azure_vm.resource_group, name, ext_name)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
165
185
|
def script_command
|
186
|
+
if vm_extension.present?
|
187
|
+
return @script_command if vm_extension.settings["commandToExecute"].ends_with?("waagent")
|
188
|
+
# Index is based on script_command that is being injected
|
189
|
+
# from the code in #create_vm. It can be partly hard-coded
|
190
|
+
# since the command shall no change frequently.
|
191
|
+
user_cmd_index = (vm_extension.settings["commandToExecute"].index("-c"))+ 4
|
192
|
+
script_command = vm_extension.settings["commandToExecute"][user_cmd_index..-2]
|
193
|
+
else
|
194
|
+
@script_command
|
195
|
+
end
|
166
196
|
end
|
167
197
|
|
168
198
|
def script_uris
|
199
|
+
if vm_extension.present?
|
200
|
+
return @script_uris unless vm_extension.settings["fileUris"]
|
201
|
+
script_uris = vm_extension.settings["fileUris"]
|
202
|
+
else
|
203
|
+
@script_uris
|
204
|
+
end
|
169
205
|
end
|
170
206
|
end
|
171
207
|
end
|
@@ -155,10 +155,10 @@
|
|
155
155
|
%>
|
156
156
|
|
157
157
|
<%= selectable_f f, :os_disk_caching, %w(None ReadOnly ReadWrite),
|
158
|
-
{},
|
158
|
+
{ :include_blank => _('Please select OS Disk Caching method') },
|
159
159
|
{
|
160
160
|
:label => _('OS Disk Caching'),
|
161
|
-
:
|
161
|
+
:label_help => _("Default ReadWrite"),
|
162
162
|
:class => "col-md-2"
|
163
163
|
}
|
164
164
|
%>
|
@@ -166,7 +166,7 @@
|
|
166
166
|
<%= text_f f, :script_command,
|
167
167
|
{
|
168
168
|
:label => _('Custom Script Command'),
|
169
|
-
:
|
169
|
+
:label_help => _("To perform commands as root, prefix it with 'sudo'")
|
170
170
|
}
|
171
171
|
%>
|
172
172
|
|
@@ -183,6 +183,7 @@
|
|
183
183
|
:disabled => images.empty?,
|
184
184
|
:label => _('Image'),
|
185
185
|
:required => true,
|
186
|
+
:selected => f.object.image_id,
|
186
187
|
:label_size => "col-md-2",
|
187
188
|
:id => 'azure_rm_image_id'
|
188
189
|
} if controller_name != "compute_attributes"
|
@@ -11,7 +11,7 @@
|
|
11
11
|
</thead>
|
12
12
|
<% @vms.each do |vm| %>
|
13
13
|
<tr>
|
14
|
-
<td><%= link_to_if_authorized vm.name, hash_for_compute_resource_vm_path(:compute_resource_id => @compute_resource, :id => vm.identity).merge(:auth_object => @compute_resource
|
14
|
+
<td><%= link_to_if_authorized vm.name, hash_for_compute_resource_vm_path(:compute_resource_id => @compute_resource, :id => vm.identity).merge(:auth_object => @compute_resource) %></td>
|
15
15
|
<td><%= vm.vm_size %></td>
|
16
16
|
<td><%= vm.resource_group %></td>
|
17
17
|
<td><%= vm.azure_vm.location %></td>
|
@@ -6,21 +6,25 @@
|
|
6
6
|
</thead>
|
7
7
|
<tbody>
|
8
8
|
<tr>
|
9
|
-
<td>
|
10
|
-
<td><%=@vm.
|
9
|
+
<td>VM Size</td>
|
10
|
+
<td><%=@vm.vm_size%></td>
|
11
11
|
</tr>
|
12
12
|
<tr>
|
13
13
|
<td>Location</td>
|
14
14
|
<td><%=@vm.azure_vm.location%></td>
|
15
15
|
</tr>
|
16
|
-
<tr>
|
17
|
-
<td>VM Size</td>
|
18
|
-
<td><%=@vm.vm_size%></td>
|
19
|
-
</tr>
|
20
16
|
<tr>
|
21
17
|
<td>Platform</td>
|
22
18
|
<td><%=@vm.azure_vm.storage_profile.os_disk.os_type%></td>
|
23
19
|
</tr>
|
20
|
+
<tr>
|
21
|
+
<td>Public IP address</td>
|
22
|
+
<td><%=@vm.public_ip_address%></td>
|
23
|
+
</tr>
|
24
|
+
<tr>
|
25
|
+
<td>Private IP address</td>
|
26
|
+
<td><%=@vm.private_ip_address%></td>
|
27
|
+
</tr>
|
24
28
|
</tbody>
|
25
29
|
</table>
|
26
30
|
</div>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_azure_rm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aditi Puntambekar
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-01-
|
13
|
+
date: 2020-01-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: deface
|