Skip to content

Commit

Permalink
Add EmsFolder class to VMware provider.
Browse files Browse the repository at this point in the history
Add EmsFolder class to VMware provider for move_into_folder method.

https://bugzilla.redhat.com/show_bug.cgi?id=1090957
  • Loading branch information
lfu committed Jun 11, 2018
1 parent 41438fd commit 639a52e
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 147 deletions.
1 change: 1 addition & 0 deletions app/models/manageiq/providers/vmware/infra_manager.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module ManageIQ::Providers
class Vmware::InfraManager < InfraManager
require_nested :DistributedVirtualSwitch
require_nested :EmsFolder
require_nested :EventCatcher
require_nested :EventParser
require_nested :RefreshWorker
Expand Down
13 changes: 13 additions & 0 deletions app/models/manageiq/providers/vmware/infra_manager/ems_folder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class ManageIQ::Providers::Vmware::InfraManager::EmsFolder < EmsFolder
def move_into_folder(vm)
raise _("Vm cannot be nil") if vm.nil?
vm_mor = vm.ems_ref_obj
log_header = "EmsFolder: [#{name}] Vm: id [#{vm.id}], name [#{vm.name}], ems_ref [#{vm_mor}]"

with_provider_object do |vim_folder|
_log.info("#{log_header} Invoking moveIntoFolder...")
vim_folder.send(:moveIntoFolder, vm_mor)
_log.info("#{log_header} Invoking moveIntoFolder...Complete")
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def self.parse_new_target(event)

def self.folder_update_to_hash(event)
mor = event[:mor]
klass = 'EmsFolder'
klass = 'ManageIQ::Providers::Vmware::InfraManager::EmsFolder'
hash = {
:folders => [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def parse_folder(object, kind, props)
:ems_ref => object._ref,
:ems_ref_obj => managed_object_to_vim_string(object),
:uid_ems => object._ref,
:type => "EmsFolder",
:type => "ManageIQ::Providers::Vmware::InfraManager::EmsFolder",
:name => CGI.unescape(props[:name]),
:parent => lazy_find_managed_object(props[:parent]),
:hidden => hidden,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ def self.folder_inv_to_hashes(inv, result, result_uids)
child_mors = get_mors(data, 'childEntity')

new_result = {
:type => EmsFolder.name,
:type => ManageIQ::Providers::Vmware::InfraManager::EmsFolder.name,
:ems_ref => mor,
:ems_ref_obj => mor,
:uid_ems => mor,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
describe ManageIQ::Providers::Vmware::InfraManager::EmsFolder do
describe "#move_into_folder" do
let(:folder) { FactoryGirl.create(:vmware_folder_vm) }
let(:vm) { FactoryGirl.create(:vm_vmware, :ems_ref_obj => "vm-1120") }
let(:provider_object) do
double("vm_vmware_provider_object", :destroy => nil).as_null_object
end

it "calls provider's method" do
expect(folder).to receive(:with_provider_object).and_yield(provider_object)
expect(provider_object).to receive(:send).with(:moveIntoFolder, vm.ems_ref_obj)
folder.move_into_folder(vm)
end
end
end
285 changes: 141 additions & 144 deletions spec/models/manageiq/providers/vmware/infra_manager/refresher_spec.rb

Large diffs are not rendered by default.

0 comments on commit 639a52e

Please sign in to comment.