Sha256: c315091b1bfd6c9cbf3c6cb618c3638342f40f0e3c8ee06f5957163842b249d8
Contents?: true
Size: 1.13 KB
Versions: 1
Compression:
Stored size: 1.13 KB
Contents
require "log4r" module VagrantPlugins module ProfitBricks module Action # This action reads the state of the machine and puts it in the # `:machine_state_id` key in the environment. class ReadState def initialize(app, env) @app = app @logger = Log4r::Logger.new("vagrant_profitbricks::action::read_state") end def call(env) env[:machine_state_id] = read_state(env[:profitbricks_compute], env[:machine]) @app.call(env) end def read_state(profitbricks, machine) return :not_created if machine.id.nil? # Find the machine server = profitbricks.servers.get(machine.provider_config.datacenter_id, machine.id) rescue Excon::Error::NotFound if server.nil? || server.state == "DELETED" # The machine can't be found @logger.info("Machine not found or deleted, assuming it got destroyed.") machine.id = nil return :not_created end # Return the state return server.state.downcase.to_sym end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
vagrant-profitbricks-1.0.0 | lib/vagrant-profitbricks/action/read_state.rb |