mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
feature #3532: move import functionality to OCA
This commit is contained in:
parent
05a3c1ff4b
commit
dfcd8c449f
@ -311,43 +311,6 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
end
|
||||
end
|
||||
|
||||
def get_wilds(host)
|
||||
[host.to_hash['HOST']['TEMPLATE']['VM']].flatten.compact
|
||||
end
|
||||
|
||||
def get_importable_wilds(host)
|
||||
get_wilds(host).select {|w| Hash === w && w['IMPORT_TEMPLATE'] }
|
||||
end
|
||||
|
||||
def import_wild(host, name)
|
||||
host.info
|
||||
|
||||
wilds = get_importable_wilds(host)
|
||||
|
||||
vms = wilds.select {|vm| vm['VM_NAME'] == name }
|
||||
|
||||
if vms.length == 0
|
||||
return OpenNebula::Error.new("No importable wilds with name " <<
|
||||
"'#{name}' found.")
|
||||
elsif vms.length > 1
|
||||
return OpenNebula::Error.new("More than one importable wild " <<
|
||||
"with name '#{name}' found.")
|
||||
end
|
||||
|
||||
wild = vms.first
|
||||
|
||||
template = Base64.decode64(wild['IMPORT_TEMPLATE'])
|
||||
|
||||
xml = OpenNebula::VirtualMachine.build_xml
|
||||
vm = OpenNebula::VirtualMachine.new(xml, @client)
|
||||
|
||||
rc = vm.allocate(template)
|
||||
|
||||
return rc if OpenNebula.is_error?(rc)
|
||||
|
||||
vm.deploy(host.id, false)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def print_update_info(current, total, host)
|
||||
@ -443,7 +406,7 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
|
||||
CLIHelper.print_header(str_h1 % "MONITORING INFORMATION", false)
|
||||
|
||||
wilds = get_wilds(host)
|
||||
wilds = host.wilds
|
||||
|
||||
host.delete_element("TEMPLATE/VM")
|
||||
host.delete_element("TEMPLATE_WILDS")
|
||||
|
@ -246,7 +246,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
command :importvm, importvm_desc, :hostid, :name do
|
||||
helper.perform_action(args[0], options, "imported") do |o|
|
||||
helper.import_wild(o, args[1])
|
||||
rc = o.info
|
||||
next rc if OpenNebula.is_error?(rc)
|
||||
|
||||
o.import_wild(args[1])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -188,6 +188,37 @@ module OpenNebula
|
||||
return call(HOST_METHODS[:rename], @pe_id, name)
|
||||
end
|
||||
|
||||
# Imports a wild VM from the host and puts it in running state
|
||||
#
|
||||
# @param name [String] Name of the VM to import
|
||||
#
|
||||
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
||||
# otherwise
|
||||
def import_wild(name)
|
||||
vms = importable_wilds.select {|vm| vm['VM_NAME'] == name }
|
||||
|
||||
if vms.length == 0
|
||||
return OpenNebula::Error.new("No importable wilds with name " <<
|
||||
"'#{name}' found.")
|
||||
elsif vms.length > 1
|
||||
return OpenNebula::Error.new("More than one importable wild " <<
|
||||
"with name '#{name}' found.")
|
||||
end
|
||||
|
||||
wild = vms.first
|
||||
|
||||
template = Base64.decode64(wild['IMPORT_TEMPLATE'])
|
||||
|
||||
xml = OpenNebula::VirtualMachine.build_xml
|
||||
vm = OpenNebula::VirtualMachine.new(xml, @client)
|
||||
|
||||
rc = vm.allocate(template)
|
||||
|
||||
return rc if OpenNebula.is_error?(rc)
|
||||
|
||||
vm.deploy(id, false)
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# Helpers to get Host information
|
||||
#######################################################################
|
||||
@ -213,6 +244,16 @@ module OpenNebula
|
||||
template_like_str('TEMPLATE', indent)
|
||||
end
|
||||
|
||||
# Get wild VMs in the host
|
||||
def wilds
|
||||
[self.to_hash['HOST']['TEMPLATE']['VM']].flatten.compact
|
||||
end
|
||||
|
||||
# Get importable wild VMs in the host
|
||||
def importable_wilds
|
||||
wilds.select {|w| Hash === w && w['IMPORT_TEMPLATE'] }
|
||||
end
|
||||
|
||||
private
|
||||
def set_enabled(enabled)
|
||||
return Error.new('ID not defined') if !@pe_id
|
||||
|
Loading…
x
Reference in New Issue
Block a user