mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-23 22:50:09 +03:00
feature #3532: add importvm command in onehost
This commit is contained in:
parent
17a5bdb6c7
commit
dbc56154a3
@ -311,6 +311,41 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
end
|
||||
end
|
||||
|
||||
def get_wilds(host)
|
||||
[host.to_hash['HOST']['TEMPLATE']['VM']].flatten
|
||||
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['DEPLOY_ID'] == 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)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def print_update_info(current, total, host)
|
||||
@ -360,14 +395,6 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
OpenNebula::HostPool.new(@client)
|
||||
end
|
||||
|
||||
def get_wilds(host)
|
||||
[host.to_hash['HOST']['TEMPLATE']['VM']].flatten
|
||||
end
|
||||
|
||||
def get_importable_wilds(host)
|
||||
get_wilds(host).select {|w| Hash === w && w['IMPORT_TEMPLATE'] }
|
||||
end
|
||||
|
||||
def format_resource(host, options = {})
|
||||
str = "%-22s: %-20s"
|
||||
str_h1 = "%-80s"
|
||||
|
@ -239,4 +239,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
o.rename(args[1])
|
||||
end
|
||||
end
|
||||
|
||||
importvm_desc = <<-EOT.unindent
|
||||
Import VM to OpenNebula
|
||||
EOT
|
||||
|
||||
command :importvm, importvm_desc, :hostid, :name do
|
||||
helper.perform_action(args[0], options, "imported") do |o|
|
||||
helper.import_wild(o, args[1])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user