diff --git a/src/im_mad/remotes/lib/lxd.rb b/src/im_mad/remotes/lib/lxd.rb index 2e41fa1248..aea95b777e 100644 --- a/src/im_mad/remotes/lib/lxd.rb +++ b/src/im_mad/remotes/lib/lxd.rb @@ -27,6 +27,15 @@ module LXD CLIENT = LXDClient.new + # LXD to OpenNebula state mapping + STATE_MAP = { + 'RUNNING' => 'RUNNING', + 'FROZEN' => 'PAUSED', + 'STOPPED' => 'POWEROFF', + 'FAILURE' => 'FAILURE', + 'POWEROFF'=> 'POWEROFF' + } + # High level abstraction entity for monitoring LXD containers class Domain @@ -84,6 +93,16 @@ module LXD DomainList.usage_cpu([self]) end + # LXD -> ONE status mapping + def self.one_status(container) + state = STATE_MAP[container.status.upcase] + state ||= 'UNKNOWN' + + state + rescue StandardError + 'UNKNOWN' + end + # Returns VM string in template def template_string string = template_string_header @@ -138,6 +157,7 @@ module LXD CPU = #{cpu} VCPU = #{vcpu} MEMORY = #{mem} + IMPORT_STATE = #{self.class.one_status(@container)} HYPERVISOR = "lxd" DEPLOY_ID = "#{@deploy_id}" OS = [ ARCH="#{arch}" ] diff --git a/src/im_mad/remotes/lxd-probes.d/vm/status/state.rb b/src/im_mad/remotes/lxd-probes.d/vm/status/state.rb index 6f1d287d4c..cfeab8c915 100755 --- a/src/im_mad/remotes/lxd-probes.d/vm/status/state.rb +++ b/src/im_mad/remotes/lxd-probes.d/vm/status/state.rb @@ -10,16 +10,7 @@ require_relative '../../../lib/lxd' # ----------------------------------------------------------- module DomainList - # LXD to OpenNebula state mapping - STATE_MAP = { - 'RUNNING' => 'RUNNING', - 'FROZEN' => 'PAUSED', - 'STOPPED' => 'POWEROFF', - 'FAILURE' => 'FAILURE', - 'POWEROFF'=> 'POWEROFF' - } - - # Returns a vm hash with the containers running in LXD + # Returns a vm hash with the containers running in LXD # @param host [String] name of the host (not used here) # @param host_id [Integer] ID of the host (not used here) # @@ -38,7 +29,7 @@ module DomainList vm[:name] = name vm[:uuid] = "#{name}-#{Socket.gethostname}" - vm[:state] = one_status(container) + vm[:state] = Domain.one_status(container) vm[:deploy_id] = name @@ -56,14 +47,7 @@ module DomainList vms end - def self.one_status(container) - state = STATE_MAP[container.status.upcase] - state ||= 'UNKNOWN' - - state - rescue StandardError - 'UNKNOWN' - end + end