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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e741ec81cb86b9264c85d90144d72b977041fa7862719a2ffefb3ee0a08e091
4
- data.tar.gz: 1f650dc025e09281b48651d5b51a67a90fa406dd94adaddc8fe0cff66a1aa30d
3
+ metadata.gz: 910b1dd793ab445a40152db2f4613550f39d846cb53603da5a1b80cbd785f832
4
+ data.tar.gz: ed13a2dd55819f1c12f6c572173108b300c6ac456ec9d788507b68cf171c0260
5
5
  SHA512:
6
- metadata.gz: 87b2e1e4f809356ad3366b13b61e317f038b292e138431746f6d3360b45075326b3e220e2c53aa8f718985b18d9c414cd18a42ecdea4670ded22d41c741a6fd6
7
- data.tar.gz: 560fd23c83eeef07f8669edd5380d5ee51312000640e3c31c7779e546d00288527bb6d38cc4c83e4693dae0edec268b01192047fc630d725d44a87225a5599b1
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(vhd_path)
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 vhd_path.start_with?('/')
53
- urn = vhd_path.split(':')
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
- vhd_path = nil
58
+ image_id = nil
59
59
  end
60
60
 
61
- if vhd_path.nil?
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 = vhd_path
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[:vhd_path])
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
- args[:script_command] = sudoers_cmd + " ; su - \"#{args[:username]}\" -c \"#{args[:script_command]}\""
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
- vhd_path: args[:image_id],
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 :image_id
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
- :required => true,
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
- :help_inline => _("To perform commands as root, prefix it with 'sudo'.")
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, :authorizer => :authorizer) %></td>
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>Id</td>
10
- <td><%=@vm.id%></td>
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>
@@ -1,3 +1,3 @@
1
1
  module ForemanAzureRm
2
- VERSION = '2.0.5'.freeze
2
+ VERSION = '2.0.6'.freeze
3
3
  end
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.5
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-09 00:00:00.000000000 Z
13
+ date: 2020-01-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: deface