Skip to content

Commit

Permalink
Add vm lookup to snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
swalberg committed Mar 19, 2018
1 parent 79f7f08 commit 4e1ad96
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions lib/chef/knife/vsphere_vm_snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

require 'chef/knife'
require 'chef/knife/base_vsphere_command'
require 'rbvmomi'
require 'netaddr'
require 'chef/knife/search_helper'

# Manage snapshots of a virtual machine
class Chef::Knife::VsphereVmSnapshot < Chef::Knife::BaseVsphereCommand
include SearchHelper
banner 'knife vsphere vm snapshot VMNAME (options)'

common_options
Expand Down Expand Up @@ -44,7 +44,7 @@ class Chef::Knife::VsphereVmSnapshot < Chef::Knife::BaseVsphereCommand
description: 'Indicates whether to wait for creation/removal to complete',
boolean: false

option :find,
option :find, # imma deprecate this
long: '--find',
description: 'Finds the virtual machine by searching all folders'

Expand Down Expand Up @@ -77,14 +77,7 @@ def run

vim_connection

vm = if get_config(:find)
puts "No folder entered, searching for #{vmname}"
src_folder = find_folder(get_config(:folder))
traverse_folders_for_vm(src_folder, vmname)
else
base_folder = find_folder get_config(:folder)
find_in_folder(base_folder, RbVmomi::VIM::VirtualMachine, vmname) || abort("VM #{vmname} not found")
end
vm = get_vm_by_name(vmname) || fatal_exit("Could not find #{vmname}")

if vm.snapshot
snapshot_list = vm.snapshot.rootSnapshotList
Expand Down

0 comments on commit 4e1ad96

Please sign in to comment.