Skip to content

Commit

Permalink
Fixes #29819 - Support byos images on azurerm
Browse files Browse the repository at this point in the history
  • Loading branch information
apuntamb committed May 14, 2020
1 parent 6db002e commit c468b52
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion app/models/concerns/foreman_azure_rm/vm_extensions/managed_vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,27 @@ def define_data_disks(vm_name, data_disks)
end
end

def marketplace_image_plan(image)
image_type, image_id = image.split('://')
if image_type == "marketplace"
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
image_plan
end

def marketplace_image_reference(publisher, offer, sku, version)
image_reference = ComputeModels::ImageReference.new
image_reference.publisher = publisher
image_reference.publisher = publisher.downcase
image_reference.offer = offer
image_reference.sku = sku
image_reference.version = version
Expand Down Expand Up @@ -209,6 +227,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

0 comments on commit c468b52

Please sign in to comment.