Skip to content

Commit

Permalink
Fixes #29819 - Support byos images on azurerm (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
apuntamb authored Jun 9, 2020
1 parent c8014e7 commit 4924514
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
16 changes: 16 additions & 0 deletions app/models/concerns/foreman_azure_rm/vm_extensions/managed_vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ def define_data_disks(vm_name, data_disks)
end
end

def marketplace_image_plan(image)
image_type, image_id = image.split('://')
return nil unless image_type == 'marketplace' && image_id.include?('byos')
urn = image_id.split(':')
publisher = urn[0]
offer = urn[1]
sku = urn[2]
version = urn[3]
image_plan = ComputeModels::PurchasePlan.new
image_plan.publisher = publisher.downcase
image_plan.name = sku.downcase
image_plan.product = offer.downcase
image_plan
end

def marketplace_image_reference(publisher, offer, sku, version)
image_reference = ComputeModels::ImageReference.new
image_reference.publisher = publisher
Expand Down Expand Up @@ -209,6 +224,7 @@ def initialize_vm(vm_hash)

def create_managed_virtual_machine(vm_hash)
vm_params = initialize_vm(vm_hash)
vm_params.plan = marketplace_image_plan(vm_hash[:image_id])
vm_params.network_profile = define_network_profile(vm_hash[:network_interface_card_ids])
vm_params.storage_profile.image_reference = define_image(vm_hash[:resource_group], vm_hash[:image_id])
vm_params.storage_profile.data_disks = define_data_disks(vm_hash[:name], vm_hash[:data_disks])
Expand Down
4 changes: 2 additions & 2 deletions app/views/images/form/_azurerm.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
:help_inline => _("The user that will be used to SSH into the VM for completion")
%>
<%= password_f f, :password, :keep_value => true, :help_inline => _("Password to authenticate with - used for SSH finish step.") %>
<%= image_field(f, :label => _("Azure Image Name"), :help_inline => _("For custom or shared gallery image prefix the uuid with 'custom://' or 'gallery://'. For public image, prefix the uuid with 'marketplace://'.' (e.g. 'marketplace://OpenLogic:CentOS:7.5:latest' or 'custom://image-name')")) %>
<%= checkbox_f f, :user_data, :help_inline => _("Does this image support user data input?") %>
<%= image_field(f, :label => _("Azure Image Name"), :help_inline => _("For custom or shared gallery image, use prefix 'custom://' or 'gallery://'. For public and RHEL-byos images, prefix the uuid with 'marketplace://'. (e.g. 'marketplace://OpenLogic:CentOS:7.5:latest' or 'custom://image-name')")) %>
<%= checkbox_f f, :user_data, :help_inline => _("Does this image support user data input?") %>
2 changes: 1 addition & 1 deletion lib/foreman_azure_rm/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Engine < ::Rails::Engine
require 'azure_mgmt_subscriptions'

# Add format validation for azure images
::Image.validates :uuid, format: { with: /\A((marketplace|custom|gallery):\/\/)[^:]+(:[^:]+:[^:]+:[^:]+)?\z/,
::Image.validates :uuid, uniqueness: { scope: :compute_resource_id, case_sensitive: false }, format: { with: /\A((marketplace|custom|gallery):\/\/)[^:]+(:[^:]+:[^:]+:[^:]+)?\z/,
message: "Incorrect UUID format" }, if: -> (image){ image.compute_resource.is_a? ForemanAzureRm::AzureRm }

# Use excon as default so that HTTP Proxy settings of foreman works
Expand Down

0 comments on commit 4924514

Please sign in to comment.