F #3264: VirtualMachineFolder refactor

This commit is contained in:
mouyaq committed 2019-05-27 18:44:16 +02:00
1 parent 2556fb2df9
commit 025734fbe7
4 files changed
+67 -48

No files matched your search

+2 -1
View File
@@ -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
@@ -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
############################################################################
@@ -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
@@ -85,6 +85,7 @@ require 'vm_template'
require 'virtual_machine'
require 'network'
require 'file_helper'
require 'vm_folder'
CHECK_REFS = true