F #3859: Import State for Wild LXD

This commit is contained in:
Daniel Clavijo Coca committed 2020-05-18 14:27:26 -05:00
1 parent 392f0c00a8
commit c0482c3f86
2 files changed
+23 -19

No files matched your search

+20
View File
@@ -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}" ]
@@ -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