diff --git a/install.sh b/install.sh index 2ffa8352b6..a311d77f0d 100755 --- a/install.sh +++ b/install.sh @@ -815,7 +815,8 @@ VMM_EXEC_LIB_VCENTER_FILES="src/vmm_mad/remotes/lib/vcenter_driver/datastore.rb src/vmm_mad/remotes/lib/vcenter_driver/memoize.rb \ src/vmm_mad/remotes/lib/vcenter_driver/datacenter.rb \ src/vmm_mad/remotes/lib/vcenter_driver/vm_template.rb \ - src/vmm_mad/remotes/lib/vcenter_driver/network.rb" + src/vmm_mad/remotes/lib/vcenter_driver/network.rb \ + src/vmm_mad/remotes/lib/vcenter_driver/vm_folder.rb" #------------------------------------------------------------------------------- # VMM SH Driver LXD scripts, to be installed under $REMOTES_LOCATION/vmm/lxd diff --git a/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb b/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb index ffe80c0098..320a332f2b 100644 --- a/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb +++ b/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb @@ -16,53 +16,6 @@ module VCenterDriver -class VirtualMachineFolder - attr_accessor :item, :items - - def initialize(item) - @item = item - check_item(@item, nil) - @items = {} - end - - ######################################################################## - # Builds a hash with Datastore-Ref / Datastore to be used as a cache - # @return [Hash] in the form - # { ds_ref [Symbol] => Datastore object } - ######################################################################## - def fetch! - VIClient.get_entities(@item, "VirtualMachine").each do |item| - item_name = item._ref - @items[item_name.to_sym] = VirtualMachine.new_with_item(item) - end - end - - def fetch_templates! - VIClient.get_entities(@item, "VirtualMachine").each do |item| - if item.config.template - item_name = item._ref - @items[item_name.to_sym] = Template.new(item) - end - end - end - - ######################################################################## - # Returns a Datastore. Uses the cache if available. - # @param ref [Symbol] the vcenter ref - # @return Datastore - ######################################################################## - def get(ref) - if !@items[ref.to_sym] - rbvmomi_dc = RbVmomi::VIM::Datastore.new(@item._connection, ref) - @items[ref.to_sym] = Datastore.new(rbvmomi_dc) - end - - @items[ref.to_sym] - end -end # class VirtualMachineFolder - - - class VirtualMachine < VCenterDriver::Template ############################################################################ diff --git a/src/vmm_mad/remotes/lib/vcenter_driver/vm_folder.rb b/src/vmm_mad/remotes/lib/vcenter_driver/vm_folder.rb new file mode 100644 index 0000000000..d09a406639 --- /dev/null +++ b/src/vmm_mad/remotes/lib/vcenter_driver/vm_folder.rb @@ -0,0 +1,64 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + +module VCenterDriver + +class VirtualMachineFolder + attr_accessor :item, :items + + def initialize(item) + @item = item + check_item(@item, nil) + @items = {} + end + + ######################################################################## + # Builds a hash with Datastore-Ref / Datastore to be used as a cache + # @return [Hash] in the form + # { ds_ref [Symbol] => Datastore object } + ######################################################################## + def fetch! + VIClient.get_entities(@item, "VirtualMachine").each do |item| + item_name = item._ref + @items[item_name.to_sym] = VirtualMachine.new_with_item(item) + end + end + + def fetch_templates! + VIClient.get_entities(@item, "VirtualMachine").each do |item| + if item.config.template + item_name = item._ref + @items[item_name.to_sym] = Template.new(item) + end + end + end + + ######################################################################## + # Returns a Datastore. Uses the cache if available. + # @param ref [Symbol] the vcenter ref + # @return Datastore + ######################################################################## + def get(ref) + if !@items[ref.to_sym] + rbvmomi_dc = RbVmomi::VIM::Datastore.new(@item._connection, ref) + @items[ref.to_sym] = Datastore.new(rbvmomi_dc) + end + + @items[ref.to_sym] + end +end # class VirtualMachineFolder + +end # module VCenterDriver diff --git a/src/vmm_mad/remotes/vcenter/vcenter_driver.rb b/src/vmm_mad/remotes/vcenter/vcenter_driver.rb index 519e564efc..22042b09f4 100644 --- a/src/vmm_mad/remotes/vcenter/vcenter_driver.rb +++ b/src/vmm_mad/remotes/vcenter/vcenter_driver.rb @@ -85,6 +85,7 @@ require 'vm_template' require 'virtual_machine' require 'network' require 'file_helper' +require 'vm_folder' CHECK_REFS = true