1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-14 19:24:10 +03:00

feature #1112: new onehost command. Better arguments

This commit is contained in:
Ruben S. Montero 2012-03-09 17:04:33 +01:00
parent c32d1d4b2d
commit d265f67058
7 changed files with 90 additions and 14 deletions

View File

@ -311,7 +311,7 @@ EOT
opts.on(*args) do |o|
if e[:proc]
e[:proc].call(o, @options)
@options[e[:name].to_sym]=e[:proc].call(o, @options)
elsif e[:name]=="help"
help
exit

View File

@ -5,7 +5,12 @@
:NAME:
:desc: Name of the Host
:size: 15
:size: 12
:left: true
:CLUSTER:
:desc: Name of the Cluster
:size: 8
:left: true
:RVM:
@ -38,11 +43,12 @@
:STAT:
:desc: Host status
:size: 6
:size: 4
:default:
- :ID
- :NAME
- :CLUSTER
- :RVM
- :TCPU
- :FCPU

View File

@ -17,6 +17,20 @@
require 'one_helper'
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
"CLUSTER"
end

View File

@ -17,6 +17,19 @@
require 'one_helper'
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
"DATASTORE"
end

View File

@ -39,10 +39,18 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
d["ID"]
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"]
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|
d["HOST_SHARE"]["RUNNING_VMS"]
end
@ -82,11 +90,11 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
OpenNebulaHelper.unit_to_str(acpu,options)
end
column :STAT, "Host status", :size=>6 do |d|
column :STAT, "Host status", :size=>4 do |d|
OneHostHelper.state_to_str(d["STATE"])
end
default :ID, :NAME, :RVM, :TCPU, :FCPU, :ACPU, :TMEM, :FMEM,
default :ID, :NAME, :CLUSTER, :RVM, :TCPU, :FCPU, :ACPU, :TMEM, :FMEM,
:AMEM, :STAT
end

View File

@ -29,6 +29,7 @@ $: << RUBY_LIB_LOCATION+"/cli"
require 'command_parser'
require 'one_helper/onehost_helper'
require 'one_helper/onecluster_helper'
cmd=CommandParser::CmdParser.new(ARGV) do
usage "`onehost` <command> [<args>] [<options>]"
@ -41,6 +42,31 @@ cmd=CommandParser::CmdParser.new(ARGV) do
########################################################################
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
########################################################################
@ -60,14 +86,23 @@ cmd=CommandParser::CmdParser.new(ARGV) do
Creates a new Host
EOT
command :create, create_desc, :hostname, :im_mad, :vmm_mad,
:vnm_mad, [:clusterid, nil] do
command :create, create_desc, :hostname, :options=>CREAT_OPTIONS 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|
if args.size == 4
host.allocate(args[0], args[1], args[2], args[3])
else
host.allocate(args[0], args[1], args[2], args[3], args[4].to_i)
end
host.allocate(args[0],
options[:im],
options[:vmm],
options[:vnm],
cid)
end
end

View File

@ -82,7 +82,7 @@ module OpenNebula
# @param im [String] Name of the im_driver (information/monitoring)
# @param vmm [String] Name of the vmm_driver (hypervisor)
# @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
# success, error otherwise