Class: VagrantPlugins::Filoo::Action::ReadState
- Inherits:
-
Object
- Object
- VagrantPlugins::Filoo::Action::ReadState
- Includes:
- CloudCompute
- Defined in:
- lib/vagrant_filoo/action/read_state.rb
Constant Summary collapse
- SERVERSTATUS_RESOURCE =
'/vserver/status'
Constants included from CloudCompute
CloudCompute::ADD_NIC_RESOURCE, CloudCompute::CREATE_SERVER_RESOURCE, CloudCompute::CREATE_SERVER_TIMEOUT, CloudCompute::DEFAULT_TIMEOUT, CloudCompute::DELETE_NIC_RESOURCE, CloudCompute::DELETE_SERVER_RESOURCE, CloudCompute::DELETE_SERVER_TIMEOUT, CloudCompute::IMAGES_RESOURCE, CloudCompute::LIST_NIC_RESOURCE, CloudCompute::LIST_SERVER_RESOURCE, CloudCompute::LOGGER, CloudCompute::SHOWJOB_RESOURCE, CloudCompute::START_INSTANCE_TIMEOUT, CloudCompute::START_RESOURCE, CloudCompute::STOP_INSTANCE_TIMEOUT, CloudCompute::STOP_RESOURCE, CloudCompute::VALID_CPU_COUNTS, CloudCompute::VALID_RAM, CloudCompute::VALID_TYPES
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ ReadState
constructor
A new instance of ReadState.
- #machineStateIdFromState(serverStatus) ⇒ Object
Methods included from CloudCompute
addNic, call, call4JobId, checkServerParams, checkServerStatus, compareServerStatus, createBody, createBoundary, createPartFromParam, createServer, deleteNic, deleteServer, doHttpCall, getAutoInstallImages, getServerStatus, getServers, hashAutoInstallListFromImageList, hashFromServerList, listNic, requestJobStatusWithResult, startInstance, stopInstance, waitJobDone
Constructor Details
#initialize(app, env) ⇒ ReadState
Returns a new instance of ReadState.
11 12 13 14 15 |
# File 'lib/vagrant_filoo/action/read_state.rb', line 11 def initialize(app, env) @app = app @baseUrl ="#{env[:machine].provider_config.filoo_api_entry_point}" @apiKey = env[:machine].provider_config.filoo_api_key() end |
Instance Method Details
#call(env) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/vagrant_filoo/action/read_state.rb', line 17 def call(env) if env[:machine].nil? or env[:machine].id.nil? env[:machine_state_id] = :not_created else vmid = env[:machine].id begin serverStatus = VagrantPlugins::Filoo::CloudCompute::getServerStatus(vmid, @baseUrl, @apiKey) env[:machine_state_id] = machineStateIdFromState(serverStatus) rescue VagrantPlugins::Filoo::Errors::FilooApiError => e errorCode = nil; begin errorCode = JSON.parse(e.)["code"] rescue JSON::ParserError => jsonErr raise e end if errorCode == 403 env[:machine_state_id] = :not_created else raise e end en end end @app.call(env) end |
#machineStateIdFromState(serverStatus) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/vagrant_filoo/action/read_state.rb', line 43 def machineStateIdFromState(serverStatus) case serverStatus["vmstatus"] when "running" return :running when "stopped" return :stopped when "processing_autoinstall" return :processing_autoinstall when "disabled" return :disabled when "activated" return :activated when "deleted" return :deleted when "unknown" return :unknown end end |