Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render snapshot for VM #190

Merged
merged 1 commit into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading