From 762aa624ac07f76d774bc852e4737637273cea30 Mon Sep 17 00:00:00 2001 From: Carl Caum Date: Fri, 28 Oct 2011 10:10:37 -0400 Subject: [PATCH] Adding a path attribute to the vm_mob_ref hash This patch adds a new `path` attribute to the vm_mob_ref hash returned by the `convert_vm_mob_ref_to_attr_hash` method. In order to support the new `path` attribute, this patch also adds a new `get_folder_path` method to the `list_virtual_machines` vsphere module. --- lib/fog/vsphere/compute.rb | 1 + lib/fog/vsphere/models/compute/server.rb | 1 + lib/fog/vsphere/requests/compute/list_virtual_machines.rb | 7 +++++++ 3 files changed, 9 insertions(+) diff --git a/lib/fog/vsphere/compute.rb b/lib/fog/vsphere/compute.rb index a2e85a916..214e04b0a 100644 --- a/lib/fog/vsphere/compute.rb +++ b/lib/fog/vsphere/compute.rb @@ -58,6 +58,7 @@ module Fog attrs['mo_ref'] = vm_mob_ref._ref attrs['hypervisor'] = attrs['host'].name attrs['mac_addresses'] = vm_mob_ref.macs + attrs['path'] = get_folder_path(vm_mob_ref.parent) end end diff --git a/lib/fog/vsphere/models/compute/server.rb b/lib/fog/vsphere/models/compute/server.rb index 49406a33b..0c7aa4738 100644 --- a/lib/fog/vsphere/models/compute/server.rb +++ b/lib/fog/vsphere/models/compute/server.rb @@ -33,6 +33,7 @@ module Fog attribute :is_a_template attribute :connection_state attribute :mo_ref + attribute :path def start(options = {}) requires :instance_uuid diff --git a/lib/fog/vsphere/requests/compute/list_virtual_machines.rb b/lib/fog/vsphere/requests/compute/list_virtual_machines.rb index 47818773c..1e68ddf0d 100644 --- a/lib/fog/vsphere/requests/compute/list_virtual_machines.rb +++ b/lib/fog/vsphere/requests/compute/list_virtual_machines.rb @@ -75,6 +75,13 @@ module Fog end results.flatten end + + def get_folder_path(folder, root = nil) + if ( not folder.methods.include?('parent') ) or ( folder == root ) + return + end + "#{get_folder_path(folder.parent)}/#{folder.name}" + end end class Mock