mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-23 22:50:09 +03:00
oZones CLI now uses oZones server to retrieve Zone resources
(cherry picked from commit db1a2ba12f9aea4d2ce355b721344053fa82fb15)
This commit is contained in:
parent
d40095c523
commit
226e4242a8
@ -287,7 +287,12 @@ EOT
|
||||
end
|
||||
|
||||
def pool_to_array(pool)
|
||||
phash = pool.to_hash
|
||||
if !pool.instance_of?(Hash)
|
||||
phash = pool.to_hash
|
||||
else
|
||||
phash = pool
|
||||
end
|
||||
|
||||
rname = self.class.rname
|
||||
|
||||
if phash["#{rname}_POOL"] &&
|
||||
|
@ -44,6 +44,24 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
|
||||
exit_code
|
||||
end
|
||||
|
||||
def format_pool(options)
|
||||
config_file = self.class.table_conf
|
||||
|
||||
table = CLIHelper::ShowTable.new(config_file, self) do
|
||||
column :ID, "ONE identifier for the Group", :size=>4 do |d|
|
||||
d["ID"]
|
||||
end
|
||||
|
||||
column :NAME, "Name of the Group", :left, :size=>15 do |d|
|
||||
d["NAME"]
|
||||
end
|
||||
|
||||
default :ID, :NAME
|
||||
end
|
||||
|
||||
table
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def factory(id=nil)
|
||||
@ -75,22 +93,4 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
|
||||
puts "%-15s" % [uid]
|
||||
end
|
||||
end
|
||||
|
||||
def format_pool(options)
|
||||
config_file = self.class.table_conf
|
||||
|
||||
table = CLIHelper::ShowTable.new(config_file, self) do
|
||||
column :ID, "ONE identifier for the Group", :size=>4 do |d|
|
||||
d["ID"]
|
||||
end
|
||||
|
||||
column :NAME, "Name of the Group", :left, :size=>15 do |d|
|
||||
d["NAME"]
|
||||
end
|
||||
|
||||
default :ID, :NAME
|
||||
end
|
||||
|
||||
table
|
||||
end
|
||||
end
|
||||
|
@ -31,58 +31,6 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
return Host::SHORT_HOST_STATES[state_str]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def factory(id=nil)
|
||||
if id
|
||||
OpenNebula::Host.new_with_id(id, @client)
|
||||
else
|
||||
xml=OpenNebula::Host.build_xml
|
||||
OpenNebula::Host.new(xml, @client)
|
||||
end
|
||||
end
|
||||
|
||||
def factory_pool(user_flag=-2)
|
||||
#TBD OpenNebula::HostPool.new(@client, user_flag)
|
||||
OpenNebula::HostPool.new(@client)
|
||||
end
|
||||
|
||||
def format_resource(host)
|
||||
str = "%-22s: %-20s"
|
||||
str_h1 = "%-80s"
|
||||
|
||||
CLIHelper.print_header(
|
||||
str_h1 % "HOST #{host.id.to_s} INFORMATION", true)
|
||||
|
||||
puts str % ["ID", host.id.to_s]
|
||||
puts str % ["NAME", host.name]
|
||||
puts str % ["STATE", host.state_str]
|
||||
puts str % ["IM_MAD", host['IM_MAD']]
|
||||
puts str % ["VM_MAD", host['VM_MAD']]
|
||||
puts str % ["VN_MAD", host['VN_MAD']]
|
||||
puts str % ["TM_MAD", host['TM_MAD']]
|
||||
puts str % ["LAST MONITORING TIME", host['LAST_MON_TIME']]
|
||||
puts
|
||||
|
||||
CLIHelper.print_header(str_h1 % "HOST SHARES", false)
|
||||
|
||||
puts str % ["MAX MEM", host['HOST_SHARE/MAX_MEM']]
|
||||
puts str % ["USED MEM (REAL)", host['HOST_SHARE/USED_MEM']]
|
||||
puts str % ["USED MEM (ALLOCATED)", host['HOST_SHARE/MEM_USAGE']]
|
||||
puts str % ["MAX CPU", host['HOST_SHARE/MAX_CPU']]
|
||||
puts str % ["USED CPU (REAL)", host['HOST_SHARE/USED_CPU']]
|
||||
puts str % ["USED CPU (ALLOCATED)", host['HOST_SHARE/CPU_USAGE']]
|
||||
puts str % ["MAX DISK", host['HOST_SHARE/MAX_DISK']]
|
||||
puts str % ["USED DISK (REAL)", host['HOST_SHARE/USED_DISK']]
|
||||
puts str % ["USED DISK (ALLOCATED)", host['HOST_SHARE/DISK_USAGE']]
|
||||
puts str % ["RUNNING VMS", host['HOST_SHARE/RUNNING_VMS']]
|
||||
puts
|
||||
|
||||
CLIHelper.print_header(str_h1 % "MONITORING INFORMATION", false)
|
||||
|
||||
puts host.template_str
|
||||
end
|
||||
|
||||
def format_pool(options)
|
||||
config_file = self.class.table_conf
|
||||
|
||||
@ -144,4 +92,56 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
|
||||
table
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def factory(id=nil)
|
||||
if id
|
||||
OpenNebula::Host.new_with_id(id, @client)
|
||||
else
|
||||
xml=OpenNebula::Host.build_xml
|
||||
OpenNebula::Host.new(xml, @client)
|
||||
end
|
||||
end
|
||||
|
||||
def factory_pool(user_flag=-2)
|
||||
#TBD OpenNebula::HostPool.new(@client, user_flag)
|
||||
OpenNebula::HostPool.new(@client)
|
||||
end
|
||||
|
||||
def format_resource(host)
|
||||
str = "%-22s: %-20s"
|
||||
str_h1 = "%-80s"
|
||||
|
||||
CLIHelper.print_header(
|
||||
str_h1 % "HOST #{host.id.to_s} INFORMATION", true)
|
||||
|
||||
puts str % ["ID", host.id.to_s]
|
||||
puts str % ["NAME", host.name]
|
||||
puts str % ["STATE", host.state_str]
|
||||
puts str % ["IM_MAD", host['IM_MAD']]
|
||||
puts str % ["VM_MAD", host['VM_MAD']]
|
||||
puts str % ["VN_MAD", host['VN_MAD']]
|
||||
puts str % ["TM_MAD", host['TM_MAD']]
|
||||
puts str % ["LAST MONITORING TIME", host['LAST_MON_TIME']]
|
||||
puts
|
||||
|
||||
CLIHelper.print_header(str_h1 % "HOST SHARES", false)
|
||||
|
||||
puts str % ["MAX MEM", host['HOST_SHARE/MAX_MEM']]
|
||||
puts str % ["USED MEM (REAL)", host['HOST_SHARE/USED_MEM']]
|
||||
puts str % ["USED MEM (ALLOCATED)", host['HOST_SHARE/MEM_USAGE']]
|
||||
puts str % ["MAX CPU", host['HOST_SHARE/MAX_CPU']]
|
||||
puts str % ["USED CPU (REAL)", host['HOST_SHARE/USED_CPU']]
|
||||
puts str % ["USED CPU (ALLOCATED)", host['HOST_SHARE/CPU_USAGE']]
|
||||
puts str % ["MAX DISK", host['HOST_SHARE/MAX_DISK']]
|
||||
puts str % ["USED DISK (REAL)", host['HOST_SHARE/USED_DISK']]
|
||||
puts str % ["USED DISK (ALLOCATED)", host['HOST_SHARE/DISK_USAGE']]
|
||||
puts str % ["RUNNING VMS", host['HOST_SHARE/RUNNING_VMS']]
|
||||
puts
|
||||
|
||||
CLIHelper.print_header(str_h1 % "MONITORING INFORMATION", false)
|
||||
|
||||
puts host.template_str
|
||||
end
|
||||
end
|
||||
|
@ -36,60 +36,7 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
|
||||
type_str = Image::IMAGE_TYPES[id]
|
||||
return Image::SHORT_IMAGE_TYPES[type_str]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def factory(id=nil)
|
||||
if id
|
||||
OpenNebula::Image.new_with_id(id, @client)
|
||||
else
|
||||
xml=OpenNebula::Image.build_xml
|
||||
OpenNebula::Image.new(xml, @client)
|
||||
end
|
||||
end
|
||||
|
||||
def factory_pool(user_flag=-2)
|
||||
OpenNebula::ImagePool.new(@client, user_flag)
|
||||
end
|
||||
|
||||
def format_resource(image)
|
||||
str="%-15s: %-20s"
|
||||
str_h1="%-80s"
|
||||
|
||||
CLIHelper.print_header(str_h1 % "IMAGE #{image['ID']} INFORMATION")
|
||||
puts str % ["ID", image.id.to_s]
|
||||
puts str % ["NAME", image.name]
|
||||
puts str % ["USER", image['UNAME']]
|
||||
puts str % ["GROUP",image['GNAME']]
|
||||
puts str % ["TYPE", image.type_str]
|
||||
puts str % ["REGISTER TIME",
|
||||
OpenNebulaHelper.time_to_str(image['REGTIME'])]
|
||||
puts str % ["PERSISTENT",
|
||||
OpenNebulaHelper.boolean_to_str(image["PERSISTENT"])]
|
||||
puts str % ["SOURCE",image['SOURCE']]
|
||||
puts str % ["PATH",image['PATH']] if image['PATH'] && !image['PATH'].empty?
|
||||
puts str % ["FSTYPE",image['FSTYPE']] if image['FSTYPE'] && !image['FSTYPE'].empty?
|
||||
puts str % ["SIZE", image['SIZE']]
|
||||
puts str % ["STATE", image.short_state_str]
|
||||
puts str % ["RUNNING_VMS", image['RUNNING_VMS']]
|
||||
puts
|
||||
|
||||
CLIHelper.print_header(str_h1 % "PERMISSIONS",false)
|
||||
|
||||
["OWNER", "GROUP", "OTHER"].each { |e|
|
||||
mask = "---"
|
||||
mask[0] = "u" if image["PERMISSIONS/#{e}_U"] == "1"
|
||||
mask[1] = "m" if image["PERMISSIONS/#{e}_M"] == "1"
|
||||
mask[2] = "a" if image["PERMISSIONS/#{e}_A"] == "1"
|
||||
|
||||
puts str % [e, mask]
|
||||
}
|
||||
puts
|
||||
|
||||
CLIHelper.print_header(str_h1 % "IMAGE TEMPLATE",false)
|
||||
puts image.template_str
|
||||
end
|
||||
|
||||
|
||||
def format_pool(options)
|
||||
config_file = self.class.table_conf
|
||||
|
||||
@ -146,4 +93,57 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
|
||||
|
||||
table
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def factory(id=nil)
|
||||
if id
|
||||
OpenNebula::Image.new_with_id(id, @client)
|
||||
else
|
||||
xml=OpenNebula::Image.build_xml
|
||||
OpenNebula::Image.new(xml, @client)
|
||||
end
|
||||
end
|
||||
|
||||
def factory_pool(user_flag=-2)
|
||||
OpenNebula::ImagePool.new(@client, user_flag)
|
||||
end
|
||||
|
||||
def format_resource(image)
|
||||
str="%-15s: %-20s"
|
||||
str_h1="%-80s"
|
||||
|
||||
CLIHelper.print_header(str_h1 % "IMAGE #{image['ID']} INFORMATION")
|
||||
puts str % ["ID", image.id.to_s]
|
||||
puts str % ["NAME", image.name]
|
||||
puts str % ["USER", image['UNAME']]
|
||||
puts str % ["GROUP",image['GNAME']]
|
||||
puts str % ["TYPE", image.type_str]
|
||||
puts str % ["REGISTER TIME",
|
||||
OpenNebulaHelper.time_to_str(image['REGTIME'])]
|
||||
puts str % ["PERSISTENT",
|
||||
OpenNebulaHelper.boolean_to_str(image["PERSISTENT"])]
|
||||
puts str % ["SOURCE",image['SOURCE']]
|
||||
puts str % ["PATH",image['PATH']] if image['PATH'] && !image['PATH'].empty?
|
||||
puts str % ["FSTYPE",image['FSTYPE']] if image['FSTYPE'] && !image['FSTYPE'].empty?
|
||||
puts str % ["SIZE", image['SIZE']]
|
||||
puts str % ["STATE", image.short_state_str]
|
||||
puts str % ["RUNNING_VMS", image['RUNNING_VMS']]
|
||||
puts
|
||||
|
||||
CLIHelper.print_header(str_h1 % "PERMISSIONS",false)
|
||||
|
||||
["OWNER", "GROUP", "OTHER"].each { |e|
|
||||
mask = "---"
|
||||
mask[0] = "u" if image["PERMISSIONS/#{e}_U"] == "1"
|
||||
mask[1] = "m" if image["PERMISSIONS/#{e}_M"] == "1"
|
||||
mask[2] = "a" if image["PERMISSIONS/#{e}_A"] == "1"
|
||||
|
||||
puts str % [e, mask]
|
||||
}
|
||||
puts
|
||||
|
||||
CLIHelper.print_header(str_h1 % "IMAGE TEMPLATE",false)
|
||||
puts image.template_str
|
||||
end
|
||||
end
|
||||
|
@ -41,6 +41,38 @@ class OneTemplateHelper < OpenNebulaHelper::OneHelper
|
||||
"onetemplate.yaml"
|
||||
end
|
||||
|
||||
def format_pool(options)
|
||||
config_file = self.class.table_conf
|
||||
|
||||
table = CLIHelper::ShowTable.new(config_file, self) do
|
||||
column :ID, "ONE identifier for the Template", :size=>4 do |d|
|
||||
d["ID"]
|
||||
end
|
||||
|
||||
column :NAME, "Name of the Template", :left, :size=>15 do |d|
|
||||
d["NAME"]
|
||||
end
|
||||
|
||||
column :USER, "Username of the Template owner", :left,
|
||||
:size=>8 do |d|
|
||||
helper.user_name(d, options)
|
||||
end
|
||||
|
||||
column :GROUP, "Group of the Template", :left, :size=>8 do |d|
|
||||
helper.group_name(d, options)
|
||||
end
|
||||
|
||||
column :REGTIME, "Registration time of the Template",
|
||||
:size=>20 do |d|
|
||||
OpenNebulaHelper.time_to_str(d["REGTIME"])
|
||||
end
|
||||
|
||||
default :ID, :USER, :GROUP, :NAME, :REGTIME
|
||||
end
|
||||
|
||||
table
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def factory(id=nil)
|
||||
@ -85,36 +117,4 @@ class OneTemplateHelper < OpenNebulaHelper::OneHelper
|
||||
CLIHelper.print_header(str_h1 % "TEMPLATE CONTENTS",false)
|
||||
puts template.template_str
|
||||
end
|
||||
|
||||
def format_pool(options)
|
||||
config_file = self.class.table_conf
|
||||
|
||||
table = CLIHelper::ShowTable.new(config_file, self) do
|
||||
column :ID, "ONE identifier for the Template", :size=>4 do |d|
|
||||
d["ID"]
|
||||
end
|
||||
|
||||
column :NAME, "Name of the Template", :left, :size=>15 do |d|
|
||||
d["NAME"]
|
||||
end
|
||||
|
||||
column :USER, "Username of the Template owner", :left,
|
||||
:size=>8 do |d|
|
||||
helper.user_name(d, options)
|
||||
end
|
||||
|
||||
column :GROUP, "Group of the Template", :left, :size=>8 do |d|
|
||||
helper.group_name(d, options)
|
||||
end
|
||||
|
||||
column :REGTIME, "Registration time of the Template",
|
||||
:size=>20 do |d|
|
||||
OpenNebulaHelper.time_to_str(d["REGTIME"])
|
||||
end
|
||||
|
||||
default :ID, :USER, :GROUP, :NAME, :REGTIME
|
||||
end
|
||||
|
||||
table
|
||||
end
|
||||
end
|
||||
|
@ -143,6 +143,36 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
|
||||
return 0, 'export ONE_AUTH=' << auth.class::LOGIN_PATH
|
||||
end
|
||||
|
||||
def format_pool(options)
|
||||
config_file = self.class.table_conf
|
||||
|
||||
table = CLIHelper::ShowTable.new(config_file, self) do
|
||||
column :ID, "ONE identifier for the User", :size=>4 do |d|
|
||||
d["ID"]
|
||||
end
|
||||
|
||||
column :NAME, "Name of the User", :left, :size=>15 do |d|
|
||||
d["NAME"]
|
||||
end
|
||||
|
||||
column :GROUP, "Group of the User", :left, :size=>8 do |d|
|
||||
helper.group_name(d, options)
|
||||
end
|
||||
|
||||
column :AUTH, "Auth driver of the User", :left, :size=>8 do |d|
|
||||
d["AUTH_DRIVER"]
|
||||
end
|
||||
|
||||
column :PASSWORD, "Password of the User", :size=>50 do |d|
|
||||
d['PASSWORD']
|
||||
end
|
||||
|
||||
default :ID, :GROUP, :NAME, :AUTH, :PASSWORD
|
||||
end
|
||||
|
||||
table
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def factory(id=nil)
|
||||
@ -178,34 +208,4 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
|
||||
CLIHelper.print_header(str_h1 % "USER TEMPLATE",false)
|
||||
puts user.template_str
|
||||
end
|
||||
|
||||
def format_pool(options)
|
||||
config_file = self.class.table_conf
|
||||
|
||||
table = CLIHelper::ShowTable.new(config_file, self) do
|
||||
column :ID, "ONE identifier for the User", :size=>4 do |d|
|
||||
d["ID"]
|
||||
end
|
||||
|
||||
column :NAME, "Name of the User", :left, :size=>15 do |d|
|
||||
d["NAME"]
|
||||
end
|
||||
|
||||
column :GROUP, "Group of the User", :left, :size=>8 do |d|
|
||||
helper.group_name(d, options)
|
||||
end
|
||||
|
||||
column :AUTH, "Auth driver of the User", :left, :size=>8 do |d|
|
||||
d["AUTH_DRIVER"]
|
||||
end
|
||||
|
||||
column :PASSWORD, "Password of the User", :size=>50 do |d|
|
||||
d['PASSWORD']
|
||||
end
|
||||
|
||||
default :ID, :GROUP, :NAME, :AUTH, :PASSWORD
|
||||
end
|
||||
|
||||
table
|
||||
end
|
||||
end
|
||||
|
@ -47,6 +47,68 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
|
||||
return short_state_str
|
||||
end
|
||||
|
||||
def format_pool(options)
|
||||
config_file = self.class.table_conf
|
||||
|
||||
table = CLIHelper::ShowTable.new(config_file, self) do
|
||||
column :ID, "ONE identifier for Virtual Machine", :size=>6 do |d|
|
||||
d["ID"]
|
||||
end
|
||||
|
||||
column :NAME, "Name of the Virtual Machine", :left,
|
||||
:size=>15 do |d|
|
||||
d["NAME"]
|
||||
end
|
||||
|
||||
column :USER, "Username of the Virtual Machine owner", :left,
|
||||
:size=>8 do |d|
|
||||
helper.user_name(d, options)
|
||||
end
|
||||
|
||||
column :GROUP, "Group of the Virtual Machine", :left,
|
||||
:size=>8 do |d|
|
||||
helper.group_name(d, options)
|
||||
end
|
||||
|
||||
column :STAT, "Actual status", :size=>4 do |d,e|
|
||||
OneVMHelper.state_to_str(d["STATE"], d["LCM_STATE"])
|
||||
end
|
||||
|
||||
column :CPU, "CPU percentage used by the VM", :size=>3 do |d|
|
||||
d["CPU"]
|
||||
end
|
||||
|
||||
column :MEM, "Memory used by the VM", :size=>7 do |d|
|
||||
OpenNebulaHelper.unit_to_str(d["MEMORY"].to_i, options)
|
||||
end
|
||||
|
||||
column :HOSTNAME, "Host where the VM is running", :size=>15 do |d|
|
||||
if d['HISTORY_RECORDS'] && d['HISTORY_RECORDS']['HISTORY']
|
||||
state_str = VirtualMachine::VM_STATE[d['STATE'].to_i]
|
||||
if %w{ACTIVE SUSPENDED}.include? state_str
|
||||
d['HISTORY_RECORDS']['HISTORY']['HOSTNAME']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
column :TIME, "Time since the VM was submitted", :size=>11 do |d|
|
||||
stime = Time.at(d["STIME"].to_i)
|
||||
etime = d["ETIME"]=="0" ? Time.now : Time.at(d["ETIME"].to_i)
|
||||
dtime = Time.at(etime-stime).getgm
|
||||
"%02d %02d:%02d:%02d" % [
|
||||
dtime.yday-1,
|
||||
dtime.hour,
|
||||
dtime.min,
|
||||
dtime.sec]
|
||||
end
|
||||
|
||||
default :ID, :USER, :GROUP, :NAME, :STAT, :CPU, :MEM, :HOSTNAME,
|
||||
:TIME
|
||||
end
|
||||
|
||||
table
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def factory(id=nil)
|
||||
@ -120,68 +182,6 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
|
||||
end
|
||||
end
|
||||
|
||||
def format_pool(options)
|
||||
config_file = self.class.table_conf
|
||||
|
||||
table = CLIHelper::ShowTable.new(config_file, self) do
|
||||
column :ID, "ONE identifier for Virtual Machine", :size=>6 do |d|
|
||||
d["ID"]
|
||||
end
|
||||
|
||||
column :NAME, "Name of the Virtual Machine", :left,
|
||||
:size=>15 do |d|
|
||||
d["NAME"]
|
||||
end
|
||||
|
||||
column :USER, "Username of the Virtual Machine owner", :left,
|
||||
:size=>8 do |d|
|
||||
helper.user_name(d, options)
|
||||
end
|
||||
|
||||
column :GROUP, "Group of the Virtual Machine", :left,
|
||||
:size=>8 do |d|
|
||||
helper.group_name(d, options)
|
||||
end
|
||||
|
||||
column :STAT, "Actual status", :size=>4 do |d,e|
|
||||
OneVMHelper.state_to_str(d["STATE"], d["LCM_STATE"])
|
||||
end
|
||||
|
||||
column :CPU, "CPU percentage used by the VM", :size=>3 do |d|
|
||||
d["CPU"]
|
||||
end
|
||||
|
||||
column :MEM, "Memory used by the VM", :size=>7 do |d|
|
||||
OpenNebulaHelper.unit_to_str(d["MEMORY"].to_i, options)
|
||||
end
|
||||
|
||||
column :HOSTNAME, "Host where the VM is running", :size=>15 do |d|
|
||||
if d['HISTORY_RECORDS'] && d['HISTORY_RECORDS']['HISTORY']
|
||||
state_str = VirtualMachine::VM_STATE[d['STATE'].to_i]
|
||||
if %w{ACTIVE SUSPENDED}.include? state_str
|
||||
d['HISTORY_RECORDS']['HISTORY']['HOSTNAME']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
column :TIME, "Time since the VM was submitted", :size=>11 do |d|
|
||||
stime = Time.at(d["STIME"].to_i)
|
||||
etime = d["ETIME"]=="0" ? Time.now : Time.at(d["ETIME"].to_i)
|
||||
dtime = Time.at(etime-stime).getgm
|
||||
"%02d %02d:%02d:%02d" % [
|
||||
dtime.yday-1,
|
||||
dtime.hour,
|
||||
dtime.min,
|
||||
dtime.sec]
|
||||
end
|
||||
|
||||
default :ID, :USER, :GROUP, :NAME, :STAT, :CPU, :MEM, :HOSTNAME,
|
||||
:TIME
|
||||
end
|
||||
|
||||
table
|
||||
end
|
||||
|
||||
def format_history(vm)
|
||||
table=CLIHelper::ShowTable.new(nil, self) do
|
||||
column :SEQ, "Sequence number", :size=>4 do |d|
|
||||
|
@ -31,6 +31,53 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
|
||||
return VirtualNetwork::SHORT_VN_TYPES[type_str]
|
||||
end
|
||||
|
||||
def format_pool(options)
|
||||
config_file = self.class.table_conf
|
||||
|
||||
table = CLIHelper::ShowTable.new(config_file, self) do
|
||||
column :ID, "ONE identifier for Virtual Network", :size=>4 do |d|
|
||||
d["ID"]
|
||||
end
|
||||
|
||||
column :NAME, "Name of the Virtual Network", :left,
|
||||
:size=>15 do |d|
|
||||
d["NAME"]
|
||||
end
|
||||
|
||||
column :USER, "Username of the Virtual Network owner", :left,
|
||||
:size=>8 do |d|
|
||||
helper.user_name(d, options)
|
||||
end
|
||||
|
||||
column :GROUP, "Group of the Virtual Network", :left,
|
||||
:size=>8 do |d|
|
||||
helper.group_name(d, options)
|
||||
end
|
||||
|
||||
column :TYPE, "Type of Virtual Network", :size=>6 do |d|
|
||||
OneVNetHelper.type_to_str(d["TYPE"])
|
||||
end
|
||||
|
||||
column :SIZE, "Size of the Virtual Network", :size=>6 do |d|
|
||||
d["SIZE"]
|
||||
end
|
||||
|
||||
column :BRIDGE, "Bridge associated to the Virtual Network",
|
||||
:size=>6 do |d|
|
||||
d["BRIDGE"]
|
||||
end
|
||||
|
||||
column :LEASES, "Number of this Virtual Network's given leases",
|
||||
:size=>7 do |d|
|
||||
d["TOTAL_LEASES"]
|
||||
end
|
||||
|
||||
default :ID, :USER, :GROUP, :NAME, :TYPE, :BRIDGE, :LEASES
|
||||
end
|
||||
|
||||
table
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def factory(id=nil)
|
||||
@ -101,51 +148,4 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def format_pool(options)
|
||||
config_file = self.class.table_conf
|
||||
|
||||
table = CLIHelper::ShowTable.new(config_file, self) do
|
||||
column :ID, "ONE identifier for Virtual Network", :size=>4 do |d|
|
||||
d["ID"]
|
||||
end
|
||||
|
||||
column :NAME, "Name of the Virtual Network", :left,
|
||||
:size=>15 do |d|
|
||||
d["NAME"]
|
||||
end
|
||||
|
||||
column :USER, "Username of the Virtual Network owner", :left,
|
||||
:size=>8 do |d|
|
||||
helper.user_name(d, options)
|
||||
end
|
||||
|
||||
column :GROUP, "Group of the Virtual Network", :left,
|
||||
:size=>8 do |d|
|
||||
helper.group_name(d, options)
|
||||
end
|
||||
|
||||
column :TYPE, "Type of Virtual Network", :size=>6 do |d|
|
||||
OneVNetHelper.type_to_str(d["TYPE"])
|
||||
end
|
||||
|
||||
column :SIZE, "Size of the Virtual Network", :size=>6 do |d|
|
||||
d["SIZE"]
|
||||
end
|
||||
|
||||
column :BRIDGE, "Bridge associated to the Virtual Network",
|
||||
:size=>6 do |d|
|
||||
d["BRIDGE"]
|
||||
end
|
||||
|
||||
column :LEASES, "Number of this Virtual Network's given leases",
|
||||
:size=>7 do |d|
|
||||
d["TOTAL_LEASES"]
|
||||
end
|
||||
|
||||
default :ID, :USER, :GROUP, :NAME, :TYPE, :BRIDGE, :LEASES
|
||||
end
|
||||
|
||||
table
|
||||
end
|
||||
end
|
||||
|
@ -30,6 +30,15 @@ $: << RUBY_LIB_LOCATION+"/cli"
|
||||
require 'command_parser'
|
||||
require 'ozones_helper/zones_helper.rb'
|
||||
|
||||
|
||||
class Hash
|
||||
def self.transform_keys_to_strings(value)
|
||||
return value if not value.is_a?(Hash)
|
||||
hash = value.inject({}){|memo,(k,v)| memo[k.to_s] = Hash.transform_keys_to_strings(v); memo}
|
||||
return hash
|
||||
end
|
||||
end
|
||||
|
||||
cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
usage "`onezone` <command> [<args>] [<options>]"
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
@ -56,7 +65,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
show_desc = <<-EOT.unindent
|
||||
Show information of a particular Zone
|
||||
Available resources: host, vm, image, vn, template, user
|
||||
Available resources: host, vm, image, vnet, vmtemplate, user
|
||||
Examples:
|
||||
onezone show 4
|
||||
onezone show 4 host
|
||||
@ -67,50 +76,42 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
case args[1]
|
||||
when "host"
|
||||
aux_helper = OneHostHelper.new(
|
||||
zone[:ONENAME] + ":" + zone[:ONEPASS],
|
||||
zone[:ENDPOINT],
|
||||
false)
|
||||
|
||||
aux_helper.list_pool(options)
|
||||
aux_helper = OneHostHelper.new
|
||||
when "vm"
|
||||
aux_helper = OneVMHelper.new(
|
||||
zone[:ONENAME] + ":" + zone[:ONEPASS],
|
||||
zone[:ENDPOINT],
|
||||
false)
|
||||
|
||||
aux_helper.list_pool(options)
|
||||
aux_helper = OneVMHelper.new
|
||||
when "image"
|
||||
aux_helper = OneImageHelper.new(
|
||||
zone[:ONENAME] + ":" + zone[:ONEPASS],
|
||||
zone[:ENDPOINT],
|
||||
false)
|
||||
|
||||
aux_helper.list_pool(options)
|
||||
when "vn"
|
||||
aux_helper = OneVNetHelper.new(
|
||||
zone[:ONENAME] + ":" + zone[:ONEPASS],
|
||||
zone[:ENDPOINT],
|
||||
false)
|
||||
|
||||
aux_helper.list_pool(options)
|
||||
|
||||
when "template"
|
||||
aux_helper = OneTemplateHelper.new(
|
||||
zone[:ONENAME] + ":" + zone[:ONEPASS],
|
||||
zone[:ENDPOINT],
|
||||
false)
|
||||
|
||||
aux_helper.list_pool(options)
|
||||
|
||||
aux_helper = OneImageHelper.new
|
||||
when "vnet"
|
||||
aux_helper = OneVNetHelper.new
|
||||
when "vmtemplate"
|
||||
aux_helper = OneTemplateHelper.new
|
||||
when "user"
|
||||
aux_helper = OneUserHelper.new(
|
||||
zone[:ONENAME] + ":" + zone[:ONEPASS],
|
||||
zone[:ENDPOINT],
|
||||
false)
|
||||
|
||||
aux_helper.list_pool(options)
|
||||
aux_helper = OneUserHelper.new
|
||||
else
|
||||
puts "\n:!: Pool #{args[1]} doesn't exist or is not supported\n\n"
|
||||
next 0
|
||||
end
|
||||
|
||||
pool_hash_data = helper.get_resource_pool("zone", zone[:ID], args[1])
|
||||
|
||||
if pool_hash_data[0] != 0
|
||||
puts "\nError retrieving information for pool #{args[1]}. Reason: " + pool_hash_data[1] + "\n\n"
|
||||
next 0
|
||||
end
|
||||
|
||||
if !pool_hash_data[1]
|
||||
next 0
|
||||
end
|
||||
|
||||
if pool_hash_data[1].is_a?(Hash)
|
||||
pool_hash_data[1]=[Hash.transform_keys_to_strings(pool_hash_data[1])]
|
||||
else
|
||||
pool_hash_data[1].each{|hash| hash.replace(Hash.transform_keys_to_strings(hash))}
|
||||
end
|
||||
|
||||
table = aux_helper.format_pool(options)
|
||||
table.show(pool_hash_data[1])
|
||||
|
||||
0
|
||||
end
|
||||
|
||||
|
@ -61,6 +61,16 @@ module OZonesHelper
|
||||
end
|
||||
end
|
||||
|
||||
def get_resource_pool(kind, id, pool)
|
||||
rc = @client.get_resource_pool(kind, id, pool)
|
||||
|
||||
if Zona::is_error?(rc)
|
||||
[-1, rc.message]
|
||||
else
|
||||
[0 , Zona::OZonesJSON.parse_json(rc.body, pool.upcase+"_POOL")[pool.upcase.to_sym]]
|
||||
end
|
||||
end
|
||||
|
||||
def delete_resource(kind, id, options)
|
||||
rc = @client.delete_resource(kind, id)
|
||||
|
||||
|
@ -190,6 +190,23 @@ EOT
|
||||
return Client.parse_error(res, kind)
|
||||
end
|
||||
|
||||
# Retrieves a pool belonging to a specific resource
|
||||
# @param [String] Kind resource kind: vdc, zone...
|
||||
# @param [#to_i] id resource id
|
||||
# @param [String] Kind of pool: image, vm, host, etc
|
||||
# @return [String, Zona::Error] Response string or Error
|
||||
def get_resource_pool(kind, id, pool)
|
||||
url = URI.parse("#{@endpoint}/#{kind}/#{id}/#{pool}")
|
||||
req = Net::HTTP::Get.new(url.path)
|
||||
|
||||
req.basic_auth @ozonesauth[0], @ozonesauth[1]
|
||||
|
||||
res = Client.http_start(url, @timeout) {|http|
|
||||
http.request(req)
|
||||
}
|
||||
return Client.parse_error(res, kind)
|
||||
end
|
||||
|
||||
# Deletes a resource
|
||||
# @param [String] kind resource kind: vdc, zone...
|
||||
# @param [#to_i] id resource id
|
||||
|
Loading…
x
Reference in New Issue
Block a user