From 21dce2bc09cb4b2494e22f0590a91037026be14f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Ezr?= Date: Sat, 23 Mar 2019 00:40:43 +0100 Subject: [PATCH] Refs #193 - retrieve boot_order --- lib/fog/vsphere/compute.rb | 21 +++++++++++++++++++++ lib/fog/vsphere/models/compute/server.rb | 1 + 2 files changed, 22 insertions(+) diff --git a/lib/fog/vsphere/compute.rb b/lib/fog/vsphere/compute.rb index 2ac60eb3..edb76663 100644 --- a/lib/fog/vsphere/compute.rb +++ b/lib/fog/vsphere/compute.rb @@ -164,6 +164,7 @@ module Shared cpuHotAddEnabled: 'config.cpuHotAddEnabled', memoryHotAddEnabled: 'config.memoryHotAddEnabled', firmware: 'config.firmware', + boot_order: 'config.bootOptions.bootOrder', annotation: 'config.annotation' }.freeze @@ -198,6 +199,8 @@ def props_to_attr_hash(vm_mob_ref, props) attrs['mo_ref'] = vm_mob_ref._ref # The name method "magically" appears after a VM is ready and # finished cloning. + attrs['boot_order'] = parse_boot_order(attrs['boot_order']) + if attrs['hypervisor'].is_a?(RbVmomi::VIM::HostSystem) host = attrs['hypervisor'] @@ -284,6 +287,24 @@ def parent_attribute(path, type) nil end + # Maps RbVmomi boot order values to fog understandable strings. + # Result is uniqued, what effectively means that the order is defined by the first occurence. + def parse_boot_order(vm_boot_devs) + return unless values.is_a?(Array) + vm_boot_devs.map do |vm_boot_dev| + case vm_boot_dev + when RbVmomi::VIM::VirtualMachineBootOptionsBootableEthernetDevice + 'network' + when RbVmomi::VIM::VirtualMachineBootOptionsBootableDiskDevice + 'disk' + when RbVmomi::VIM::VirtualMachineBootOptionsBootableCdromDevice + 'cdrom' + when RbVmomi::VIM::VirtualMachineBootOptionsBootableFloppyDevice + 'floppy' + end + end.compact.uniq + end + # returns vmware managed obj id string def managed_obj_id(obj) obj.to_s.match(/\("([^"]+)"\)/)[1] diff --git a/lib/fog/vsphere/models/compute/server.rb b/lib/fog/vsphere/models/compute/server.rb index 29ab0454..3d6e1380 100644 --- a/lib/fog/vsphere/models/compute/server.rb +++ b/lib/fog/vsphere/models/compute/server.rb @@ -50,6 +50,7 @@ class Server < Fog::Compute::Server attribute :cpuHotAddEnabled attribute :memoryHotAddEnabled attribute :firmware + attribute :boot_order attribute :annotation def initialize(attributes = {})