Class: VagrantPlugins::Proxmox::Action::ReadState
- Inherits:
-
ProxmoxAction
- Object
- ProxmoxAction
- VagrantPlugins::Proxmox::Action::ReadState
- Defined in:
- lib/vagrant-proxmox/action/read_state.rb
Overview
This action reads the state of a Proxmox virtual machine and stores it in env.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ ReadState
constructor
A new instance of ReadState.
Constructor Details
#initialize(app, env) ⇒ ReadState
Returns a new instance of ReadState.
9 10 11 12 |
# File 'lib/vagrant-proxmox/action/read_state.rb', line 9 def initialize app, env @app = app @logger = Log4r::Logger.new 'vagrant_proxmox::action::read_state' end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/vagrant-proxmox/action/read_state.rb', line 14 def call env begin if env[:machine].id node, vm_id = env[:machine].id.split '/' endpoint = env[:machine].provider_config.endpoint response = RestClient.get "#{endpoint}/nodes/#{node}/openvz/#{vm_id}/status/current", {cookies: {PVEAuthCookie: env[:proxmox_ticket]}} states = {'running' => :running, 'stopped' => :stopped} env[:machine_state_id] = states[JSON.parse(response.to_s)['data']['status']] else env[:machine_state_id] = :not_created end rescue RestClient::InternalServerError env[:machine_state_id] = :not_created end next_action env end |