Sha256: 8238329eab58aabc8d299a2506b40b79297df3c8511267faf9dba0d2a3be6cc3

Contents?: true

Size: 1.98 KB

Versions: 7

Compression:

Stored size: 1.98 KB

Contents

module Fog
  module Compute
    class Vsphere
      class Real
        def list_vm_snapshots(vm_id, opts = {})
          vm_snapshot_info = get_vm_ref(vm_id).snapshot

          return [] unless vm_snapshot_info

          root_snapshots = vm_snapshot_info.rootSnapshotList.map do |snap|
            item = snapshot_info(snap, vm_id)
            [
              item,
              opts[:recursive] ? list_child_snapshots(item, opts) : nil
            ]
          end

          root_snapshots.flatten.compact
        end

        protected

        def snapshot_info(snap_tree, vm_id)
          {
            name: snap_tree.name,
            quiesced: snap_tree.quiesced,
            description: snap_tree.description,
            create_time: snap_tree.createTime,
            power_state: snap_tree.state,
            ref: snap_tree.snapshot._ref,
            mo_ref: snap_tree.snapshot,
            tree_node: snap_tree,
            ref_chain: "#{vm_id}/#{snap_tree.snapshot._ref}",
            snapshot_name_chain: "#{vm_id}/#{snap_tree.name}",
            server_id: vm_id
          }
        end
      end
      class Mock
        def list_vm_snapshots(vm_id, _opts = {})
          [
            {
              name: 'clean',
              quiesced: false,
              description: '',
              create_time: Time.now.utc,
              power_state: 'poweredOn',
              ref: 'snapshot-0101',
              mo_ref: nil,
              tree_node: nil,
              snapshot_name_chain: '123/clean',
              ref_chain: "#{vm_id}/snapshot-0101"
            },
            {
              name: 'dirty',
              quiesced: false,
              description: '',
              create_time: Time.now.utc,
              power_state: 'poweredOn',
              ref: 'snapshot-0102',
              mo_ref: nil,
              tree_node: nil,
              snapshot_name_chain: '123/dirty',
              ref_chain: "#{vm_id}/snapshot-0102"
            }
          ]
        end
      end
    end
  end
end

Version data entries

7 entries across 5 versions & 2 rubygems

Version Path
fog-vsphere-2.5.0 lib/fog/vsphere/requests/compute/list_vm_snapshots.rb
fog-vsphere-2.4.0 lib/fog/vsphere/requests/compute/list_vm_snapshots.rb
fog-vsphere-2.3.0 lib/fog/vsphere/requests/compute/list_vm_snapshots.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/fog-vsphere-2.2.0/lib/fog/vsphere/requests/compute/list_vm_snapshots.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-vsphere-2.2.0/lib/fog/vsphere/requests/compute/list_vm_snapshots.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/fog-vsphere-2.2.0/lib/fog/vsphere/requests/compute/list_vm_snapshots.rb
fog-vsphere-2.2.0 lib/fog/vsphere/requests/compute/list_vm_snapshots.rb