Skip to content

Commit

Permalink
Inventory VM snapshots
Browse files Browse the repository at this point in the history
With this commit we support VM snapshot inventoring. Since vCloud is
quite modes with information it reveals about VM snapshots (only creation time,
size and poweredOn, which tells if if the virtual machine was powered on when the
snapshot was created) we need to compose `uid` and `ems_ref` dynamically.

Signed-off-by: Miha Pleško <miha.plesko@xlab.si>
Signed-off-by: Sašo Cvitkovič <saso.cvitkovic@xlab.si>
  • Loading branch information
miha-plesko committed Feb 27, 2018
1 parent d8c04f7 commit 678825c
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def parse_vm(vm)
:name => name,
:vendor => "vmware",
:raw_power_state => status,
:snapshots => [parse_snapshot(vm)].compact,

:hardware => {
:guest_os => guest_os,
Expand Down Expand Up @@ -217,4 +218,21 @@ def parse_vapp_template(vapp_template)

return uid, new_result
end

def parse_snapshot(vm)
resp = @connection.get_snapshot_section(vm.id).data
if (snapshot_resp = resp.fetch_path(:body, :Snapshot))
{
:name => "#{vm.name} (snapshot)",
:uid => "#{vm.id}_#{snapshot_resp[:created]}",
:ems_ref => "#{vm.id}_#{snapshot_resp[:created]}",
:parent_id => vm.id,
:parent_uid => vm.id,
:create_time => snapshot_resp[:created],
:total_size => snapshot_resp[:size]
}
else
return nil
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
assert_specific_vm_powered_on
assert_specific_vm_powered_off
assert_specific_orchestration_template
assert_specific_vm_with_snapshot
end
end

Expand Down Expand Up @@ -82,7 +83,7 @@ def assert_table_counts
expect(GuestDevice.count).to eq(0)
expect(Hardware.count).to eq(3)
expect(OperatingSystem.count).to eq(3)
expect(Snapshot.count).to eq(0)
expect(Snapshot.count).to eq(2)
expect(SystemService.count).to eq(0)

expect(Relationship.count).to eq(0)
Expand Down Expand Up @@ -280,7 +281,7 @@ def assert_specific_vm_powered_off
)

expect(v.custom_attributes.size).to eq(0)
expect(v.snapshots.size).to eq(0)
expect(v.snapshots.size).to eq(1)

expect(v.hardware).to have_attributes(
:config_version => nil,
Expand Down Expand Up @@ -348,4 +349,18 @@ def assert_specific_orchestration_template
expect(@template.content.include?('ovf:Envelope')).to be_truthy
expect(@template.md5).to eq('729bfcafe52065bdee376931efe104d9')
end

def assert_specific_vm_with_snapshot
vm = ManageIQ::Providers::Vmware::CloudManager::Vm.find_by(:name => "spec2-vm1")

expect(vm.snapshots.first).not_to be_nil
expect(vm.snapshots.first).to have_attributes(
:ems_ref => 'vm-a28be0c0-d70d-4047-92f8-fc217bbaa7f6_2018-02-22T12:22:20.784+01:00',
:uid => 'vm-a28be0c0-d70d-4047-92f8-fc217bbaa7f6_2018-02-22T12:22:20.784+01:00',
:parent_uid => 'vm-a28be0c0-d70d-4047-92f8-fc217bbaa7f6',
:name => 'spec2-vm1 (snapshot)',
:total_size => 4_294_967_296
)
expect(vm.snapshots.first.create_time.to_s).to eq('2018-02-22 11:22:20 UTC')
end
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 678825c

Please sign in to comment.