mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-27 14:03:40 +03:00
feature #1112: new onehost command. Better arguments
This commit is contained in:
parent
c32d1d4b2d
commit
d265f67058
@ -311,7 +311,7 @@ EOT
|
|||||||
|
|
||||||
opts.on(*args) do |o|
|
opts.on(*args) do |o|
|
||||||
if e[:proc]
|
if e[:proc]
|
||||||
e[:proc].call(o, @options)
|
@options[e[:name].to_sym]=e[:proc].call(o, @options)
|
||||||
elsif e[:name]=="help"
|
elsif e[:name]=="help"
|
||||||
help
|
help
|
||||||
exit
|
exit
|
||||||
|
@ -5,7 +5,12 @@
|
|||||||
|
|
||||||
:NAME:
|
:NAME:
|
||||||
:desc: Name of the Host
|
:desc: Name of the Host
|
||||||
:size: 15
|
:size: 12
|
||||||
|
:left: true
|
||||||
|
|
||||||
|
:CLUSTER:
|
||||||
|
:desc: Name of the Cluster
|
||||||
|
:size: 8
|
||||||
:left: true
|
:left: true
|
||||||
|
|
||||||
:RVM:
|
:RVM:
|
||||||
@ -38,11 +43,12 @@
|
|||||||
|
|
||||||
:STAT:
|
:STAT:
|
||||||
:desc: Host status
|
:desc: Host status
|
||||||
:size: 6
|
:size: 4
|
||||||
|
|
||||||
:default:
|
:default:
|
||||||
- :ID
|
- :ID
|
||||||
- :NAME
|
- :NAME
|
||||||
|
- :CLUSTER
|
||||||
- :RVM
|
- :RVM
|
||||||
- :TCPU
|
- :TCPU
|
||||||
- :FCPU
|
- :FCPU
|
||||||
|
@ -17,6 +17,20 @@
|
|||||||
require 'one_helper'
|
require 'one_helper'
|
||||||
|
|
||||||
class OneClusterHelper < OpenNebulaHelper::OneHelper
|
class OneClusterHelper < OpenNebulaHelper::OneHelper
|
||||||
|
|
||||||
|
CLUSTER = {
|
||||||
|
:name => "cluster",
|
||||||
|
:short => "-c id|name",
|
||||||
|
:large => "--cluster id|name" ,
|
||||||
|
:description => "Selects the cluster",
|
||||||
|
:format => String,
|
||||||
|
:proc => lambda { |o, options|
|
||||||
|
ch = OneClusterHelper.new
|
||||||
|
rc, cid = ch.to_id(o)
|
||||||
|
cid
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def self.rname
|
def self.rname
|
||||||
"CLUSTER"
|
"CLUSTER"
|
||||||
end
|
end
|
||||||
|
@ -17,6 +17,19 @@
|
|||||||
require 'one_helper'
|
require 'one_helper'
|
||||||
|
|
||||||
class OneDatastoreHelper < OpenNebulaHelper::OneHelper
|
class OneDatastoreHelper < OpenNebulaHelper::OneHelper
|
||||||
|
DATASTORE = {
|
||||||
|
:name => "datastore",
|
||||||
|
:short => "-d id|name",
|
||||||
|
:large => "--datastore id|name" ,
|
||||||
|
:description => "Selects the datastore",
|
||||||
|
:format => String,
|
||||||
|
:proc => lambda { |o, options|
|
||||||
|
ch = OneDatastoreHelper.new
|
||||||
|
rc, dsid = ch.to_id(o)
|
||||||
|
dsid
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def self.rname
|
def self.rname
|
||||||
"DATASTORE"
|
"DATASTORE"
|
||||||
end
|
end
|
||||||
|
@ -39,10 +39,18 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
|||||||
d["ID"]
|
d["ID"]
|
||||||
end
|
end
|
||||||
|
|
||||||
column :NAME, "Name of the Host", :left, :size=>15 do |d|
|
column :NAME, "Name of the Host", :left, :size=>12 do |d|
|
||||||
d["NAME"]
|
d["NAME"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
column :CLUSTER, "Name of the Cluster", :left, :size=>8 do |d|
|
||||||
|
if d["CLUSTER"] == "none"
|
||||||
|
"-"
|
||||||
|
else
|
||||||
|
d["CLUSTER"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
column :RVM, "Number of Virtual Machines running", :size=>6 do |d|
|
column :RVM, "Number of Virtual Machines running", :size=>6 do |d|
|
||||||
d["HOST_SHARE"]["RUNNING_VMS"]
|
d["HOST_SHARE"]["RUNNING_VMS"]
|
||||||
end
|
end
|
||||||
@ -82,11 +90,11 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
|||||||
OpenNebulaHelper.unit_to_str(acpu,options)
|
OpenNebulaHelper.unit_to_str(acpu,options)
|
||||||
end
|
end
|
||||||
|
|
||||||
column :STAT, "Host status", :size=>6 do |d|
|
column :STAT, "Host status", :size=>4 do |d|
|
||||||
OneHostHelper.state_to_str(d["STATE"])
|
OneHostHelper.state_to_str(d["STATE"])
|
||||||
end
|
end
|
||||||
|
|
||||||
default :ID, :NAME, :RVM, :TCPU, :FCPU, :ACPU, :TMEM, :FMEM,
|
default :ID, :NAME, :CLUSTER, :RVM, :TCPU, :FCPU, :ACPU, :TMEM, :FMEM,
|
||||||
:AMEM, :STAT
|
:AMEM, :STAT
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ $: << RUBY_LIB_LOCATION+"/cli"
|
|||||||
|
|
||||||
require 'command_parser'
|
require 'command_parser'
|
||||||
require 'one_helper/onehost_helper'
|
require 'one_helper/onehost_helper'
|
||||||
|
require 'one_helper/onecluster_helper'
|
||||||
|
|
||||||
cmd=CommandParser::CmdParser.new(ARGV) do
|
cmd=CommandParser::CmdParser.new(ARGV) do
|
||||||
usage "`onehost` <command> [<args>] [<options>]"
|
usage "`onehost` <command> [<args>] [<options>]"
|
||||||
@ -41,6 +42,31 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
|||||||
########################################################################
|
########################################################################
|
||||||
set :option, CommandParser::OPTIONS
|
set :option, CommandParser::OPTIONS
|
||||||
|
|
||||||
|
IM = {
|
||||||
|
:name => "im",
|
||||||
|
:short => "-i im_mad",
|
||||||
|
:large => "--im im_mad" ,
|
||||||
|
:description => "Set the information driver for the host",
|
||||||
|
:format => String
|
||||||
|
}
|
||||||
|
|
||||||
|
VMM = {
|
||||||
|
:name => "vmm",
|
||||||
|
:short => "-v vmm_mad",
|
||||||
|
:large => "--vm vmm_mad" ,
|
||||||
|
:description => "Set the virtualization driver for the host",
|
||||||
|
:format => String
|
||||||
|
}
|
||||||
|
|
||||||
|
VNET = {
|
||||||
|
:name => "vnm",
|
||||||
|
:short => "-n vnet_mad",
|
||||||
|
:large => "--net vnet_mad" ,
|
||||||
|
:description => "Set the network driver for the host",
|
||||||
|
:format => String
|
||||||
|
}
|
||||||
|
|
||||||
|
CREAT_OPTIONS = [ IM, VMM, VNET, OneClusterHelper::CLUSTER ]
|
||||||
########################################################################
|
########################################################################
|
||||||
# Formatters for arguments
|
# Formatters for arguments
|
||||||
########################################################################
|
########################################################################
|
||||||
@ -60,14 +86,23 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
|||||||
Creates a new Host
|
Creates a new Host
|
||||||
EOT
|
EOT
|
||||||
|
|
||||||
command :create, create_desc, :hostname, :im_mad, :vmm_mad,
|
command :create, create_desc, :hostname, :options=>CREAT_OPTIONS do
|
||||||
:vnm_mad, [:clusterid, nil] do
|
if options[:im].nil? or options[:vmm].nil? or options[:vnm].nil?
|
||||||
|
STDERR.puts "Drivers are mandatory to create a host:"
|
||||||
|
STDERR.puts "\t -i information driver"
|
||||||
|
STDERR.puts "\t -v hypervisor driver"
|
||||||
|
STDERR.puts "\t -n network driver"
|
||||||
|
exit -1
|
||||||
|
end
|
||||||
|
|
||||||
|
cid = options[:cluster] || ClusterPool::NONE_CLUSTER_ID
|
||||||
|
|
||||||
helper.create_resource(options) do |host|
|
helper.create_resource(options) do |host|
|
||||||
if args.size == 4
|
host.allocate(args[0],
|
||||||
host.allocate(args[0], args[1], args[2], args[3])
|
options[:im],
|
||||||
else
|
options[:vmm],
|
||||||
host.allocate(args[0], args[1], args[2], args[3], args[4].to_i)
|
options[:vnm],
|
||||||
end
|
cid)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ module OpenNebula
|
|||||||
# @param im [String] Name of the im_driver (information/monitoring)
|
# @param im [String] Name of the im_driver (information/monitoring)
|
||||||
# @param vmm [String] Name of the vmm_driver (hypervisor)
|
# @param vmm [String] Name of the vmm_driver (hypervisor)
|
||||||
# @param tm [String] Name of the vnm_driver (networking)
|
# @param tm [String] Name of the vnm_driver (networking)
|
||||||
# @param cluster_id [Integer] Id of the cluster
|
# @param cluster_id [String] Id of the cluster
|
||||||
#
|
#
|
||||||
# @return [Integer, OpenNebula::Error] the new ID in case of
|
# @return [Integer, OpenNebula::Error] the new ID in case of
|
||||||
# success, error otherwise
|
# success, error otherwise
|
||||||
|
Loading…
x
Reference in New Issue
Block a user