1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-20 14:03:36 +03:00

F #4298: Generic action helper

This commit is contained in:
Daniel Clavijo Coca 2020-05-04 20:16:32 -05:00
parent c05fd39d92
commit eca10507f2
2 changed files with 20 additions and 5 deletions

View File

@ -79,15 +79,28 @@ class Container
class << self
# Returns the LXD container definition
def search(name, client)
client.get("#{CONTAINERS}/#{name}")['metadata']
end
# Returns specific container, by its name
# Params:
# +name+:: container name
def get(name, one_xml, client)
info = client.get("#{CONTAINERS}/#{name}")['metadata']
info = nil
one = nil
one = OpenNebulaVM.new(one_xml) if one_xml
begin
info = search(name, client)
rescue LXDError => e # Get naming scheme from deploy_id
raise e unless e.code == 404
info = search(one.xml['//NAME'], client)
end
Container.new(info, one, client)
end

View File

@ -37,7 +37,7 @@ class LXDConfiguration < Hash
begin
merge!(YAML.load_file("#{__dir__}/#{LXDRC}"))
rescue => e
rescue StandardError => e
OpenNebula.log_error e
end
end
@ -57,8 +57,10 @@ class OpenNebulaVM
@xml = @xml.element('//VM')
@vm_id = @xml['//TEMPLATE/VMID']
@vm_name = @xml['//DEPLOY_ID']
@vm_name = "one-#{@vm_id}" if @vm_name.empty?
@vm_name = @xml['//NAME'] if wild?
# Load Driver configuration
@lxdrc = LXDConfiguration.new
@ -325,11 +327,11 @@ class OpenNebulaVM
end
def swap?(disk)
return disk['TYPE'] == 'swap'
disk['TYPE'] == 'swap'
end
def volatile?(disk)
return disk['TYPE'] == 'fs'
disk['TYPE'] == 'fs'
end
#---------------------------------------------------------------------------