1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-10 01:17:40 +03:00

F #3859: Import State for Wild LXD

This commit is contained in:
Daniel Clavijo Coca 2020-05-18 14:27:26 -05:00
parent 392f0c00a8
commit c0482c3f86
No known key found for this signature in database
GPG Key ID: F4D2A4195D4E4064
2 changed files with 23 additions and 19 deletions

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}" ]

View File

@ -10,15 +10,6 @@ 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
# @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