Class: VagrantPlugins::ESXi::Action::SnapshotList
- Inherits:
-
Object
- Object
- VagrantPlugins::ESXi::Action::SnapshotList
- Defined in:
- lib/vagrant-vmware-esxi/action/snapshot_list.rb
Overview
This action will list all the snapshots
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, _env) ⇒ SnapshotList
constructor
A new instance of SnapshotList.
- #snapshotlist(env) ⇒ Object
Constructor Details
#initialize(app, _env) ⇒ SnapshotList
Returns a new instance of SnapshotList.
9 10 11 12 |
# File 'lib/vagrant-vmware-esxi/action/snapshot_list.rb', line 9 def initialize(app, _env) @app = app @logger = Log4r::Logger.new('vagrant_vmware_esxi::action::snapshot_list') end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 |
# File 'lib/vagrant-vmware-esxi/action/snapshot_list.rb', line 14 def call(env) snapshotlist(env) @app.call(env) end |
#snapshotlist(env) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/vagrant-vmware-esxi/action/snapshot_list.rb', line 19 def snapshotlist(env) @logger.info('vagrant-vmware-esxi, snapshot_list: start...') # Get config. machine = env[:machine] config = env[:machine].provider_config @logger.info("vagrant-vmware-esxi, snapshot_list: machine id: #{machine.id}") @logger.info("vagrant-vmware-esxi, snapshot_list: current state: #{env[:machine_state]}") if env[:machine_state].to_s == 'not_created' env[:ui].info I18n.t('vagrant_vmware_esxi.vagrant_vmware_esxi_message', message: 'Cannot snapshot_list in this state') else Net::SSH.start(config.esxi_hostname, config.esxi_username, password: config.esxi_password, port: config.esxi_hostport, keys: config.local_private_keys, timeout: 20, number_of_password_prompts: 0, non_interactive: true ) do |ssh| r = ssh.exec!( "vim-cmd vmsvc/snapshot.get #{machine.id} 2>&1 | "\ "grep 'Snapshot Name'|sed 's/.*Snapshot Name : //g'") allsnapshots = r if r.exitstatus != 0 raise Errors::ESXiError, message: "Unable to list snapshots:\n"\ " #{allsnapshots}\n#{r.stderr}" end env[:machine_snapshot_list] = allsnapshots.split("\n") end end end |