1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

feature #200: Finishing the CLI

This commit is contained in:
Tino Vázquez 2010-06-22 19:21:09 +02:00
parent ffd05b42f1
commit 4bd2506f00
3 changed files with 57 additions and 31 deletions

View File

@ -285,6 +285,10 @@ def get_user_id(name)
get_entity_id(name, OpenNebula::UserPool)
end
def get_image_id(name)
get_entity_id(name, OpenNebula::ImagePool)
end
def str_running_time(data)
stime=Time.at(data["stime"].to_i)
if data["etime"]=="0"
@ -299,7 +303,6 @@ end
def str_register_time(data)
regtime=Time.at(data["REGTIME"].to_i).getgm
regtime.strftime("%b %d, %Y %H:%M")
end

View File

@ -44,13 +44,13 @@ ShowTableImage={
:desc => "Name of the owner",
:size => 8,
:proc => lambda {|d,e|
d["UID"]
d["USERNAME"]
}
},
:name => {
:name => "NAME",
:desc => "Name of the Image",
:size => 8,
:size => 20,
:proc => lambda {|d,e|
d.name
}
@ -58,7 +58,7 @@ ShowTableImage={
:type => {
:name => "TYPE",
:desc => "Type of the Image",
:size => 2,
:size => 4,
:proc => lambda {|d,e|
d.short_type_str
}
@ -78,17 +78,17 @@ ShowTableImage={
:proc => lambda {|d,e| if d["PUBLIC"].to_i == 1 then "Y" else "N" end}
},
:state => {
:name => "ST",
:name => "STAT",
:desc => "State of the Image",
:size => 2,
:size => 4,
:proc => lambda {|d,e|
d.state_str
d.short_state_str
}
},
:runningvms => {
:name => "RUNNING_VMS",
:name => "#VMS",
:desc => "Number of VMs currently running from this Image",
:size => 2,
:size => 5,
:proc => lambda {|d,e| d['RUNNING_VMS'] }
},
@ -113,6 +113,24 @@ class ImageShow
puts ""
end
def top(options=nil)
delay=1
delay=options[:delay] if options && options[:delay]
result=nil
begin
while true
scr_cls
scr_move(0,0)
result=list_short(options)
sleep delay
end
rescue Exception
end
result
end
def list_short(options=nil)
res=@imagepool.info()
@ -193,6 +211,9 @@ Commands:
uid --> Images of the user identified by this uid (admin users)
user --> Images of the user identified by the username (admin users)
* top (Lists Images continuously)
onevm top
* show (Gets information about an specific Image)
oneimage show <image_id>
@ -264,23 +285,19 @@ when "register", "create", "add"
exit 0
end
when "update" # TODO finish this
check_parameters("deploy", 2)
host_id=get_host_id(ARGV[-1])
args=expand_args(ARGV[0..-2])
when "update"
check_parameters("update", 3)
image_id=get_image_id(ARGV[0])
args.each do |param|
vm_id=get_vm_id(param)
image=OpenNebula::Image.new_with_id(image_id, get_one_client)
vm=OpenNebula::VirtualMachine.new_with_id(vm_id, get_one_client)
result=vm.deploy(host_id)
if is_successful?(result)
puts "Deploying VM" if ops[:verbose]
else
break
end
result=image.update(ARGV[1],ARGV[2])
if is_successful?(result)
puts "Modified image" if ops[:verbose]
else
break
end
when "list"
ops.merge!(get_user_flags)
@ -295,13 +312,19 @@ when "list"
puts imagepool.to_xml
end
when "top"
ops.merge!(get_user_flags)
imagelist=ImageShow.new(get_one_client, ops[:filter_user].to_i)
ops[:columns]=ops[:list] if ops[:list]
result=imagelist.top(ops)
when "show"
check_parameters("get_info", 1)
args=expand_args(ARGV)
args.each do |param|
image_id=get_image_id(param)
pp image_id
image=OpenNebula::Image.new_with_id(image_id, get_one_client)
image.info
@ -347,9 +370,9 @@ when "delete"
args.each do |param|
image_id=get_image_id(param)
vm=OpenNebula::Image.new_with_id(image_id, get_one_client)
image=OpenNebula::Image.new_with_id(image_id, get_one_client)
result=image.finalize
result=image.delete
if is_successful?(result)
puts "Image correctly deleted" if ops[:verbose]
else

View File

@ -14,7 +14,7 @@ module OpenNebula
IMAGE_STATES=%w{INIT LOCKED READY USED}
IMAGE_SHORT_STATES={
SHORT_IMAGE_STATES={
"INIT" => "lock",
"LOCKED" => "lock",
"READY" => "rdy",
@ -39,7 +39,7 @@ module OpenNebula
def Image.build_xml(pe_id=nil)
if pe_id
image_xml = "<IMAGE><ID>#{pe_id}</ID></IMAGE>"
IMAGE
else
image_xml = "<IMAGE></IMAGE>"
end
@ -99,12 +99,12 @@ module OpenNebula
# Returns the type of the Image (string value)
def type_str
IMAGE_TYPES[state]
IMAGE_TYPES[type]
end
# Returns the state of the Image (string value)
def short_type_str
SHORT_IMAGE_TYPES[state_str]
end
SHORT_IMAGE_TYPES[type_str]
end
end
end