mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-17 18:33:32 +09:00
Merge branch 'feature-1640'
This commit is contained in:
commit
564f8671bd
16 files changed
+441
-94
No files matched your search
+50
-9
@@ -31,13 +31,14 @@ module CLIHelper
|
||||
# :description => "Order by these columns, column starting with - means decreasing order"
|
||||
#}
|
||||
#
|
||||
#FILTER = {
|
||||
# :name => "filter",
|
||||
# :short => "-f x,y,z",
|
||||
# :large => "--filter x,y,z",
|
||||
# :format => Array,
|
||||
# :description => "Filter data. An array is specified with column=value pairs."
|
||||
#}
|
||||
FILTER = {
|
||||
:name => "filter",
|
||||
:short => "-f x,y,z",
|
||||
:large => "--filter x,y,z",
|
||||
:format => Array,
|
||||
:description => "Filter data. An array is specified with\n"<<
|
||||
" "*31<<"column=value pairs."
|
||||
}
|
||||
#
|
||||
#HEADER = {
|
||||
# :name => "header",
|
||||
@@ -55,7 +56,7 @@ module CLIHelper
|
||||
}
|
||||
|
||||
#OPTIONS = [LIST, ORDER, FILTER, HEADER, DELAY]
|
||||
OPTIONS = [LIST, DELAY]
|
||||
OPTIONS = [LIST, DELAY, FILTER]
|
||||
|
||||
# Sets bold font
|
||||
def CLIHelper.scr_bold
|
||||
@@ -287,7 +288,47 @@ module CLIHelper
|
||||
}.compact.join(' ')
|
||||
end
|
||||
|
||||
# TBD def filter_data!
|
||||
def filter_data!(data, filter)
|
||||
# TBD: add more operators
|
||||
# operators=/(==|=|!=|<|<=|>|>=)/
|
||||
operators=/(=)/
|
||||
|
||||
stems=filter.map do |s|
|
||||
m=s.match(/^(.*?)#{operators}(.*?)$/)
|
||||
if m
|
||||
left, operator, right=m[1..3]
|
||||
index=@default_columns.index(left.to_sym)
|
||||
|
||||
if index
|
||||
{
|
||||
:left => left,
|
||||
:operator => operator,
|
||||
:right => right,
|
||||
:index => index
|
||||
}
|
||||
else
|
||||
STDERR.puts "Column '#{left}' not found"
|
||||
exit(-1)
|
||||
end
|
||||
else
|
||||
STDERR.puts "Expresion '#{s}' incorrect"
|
||||
exit(-1)
|
||||
end
|
||||
end
|
||||
|
||||
data.reject! do |d|
|
||||
pass=true
|
||||
|
||||
stems.each do |s|
|
||||
if d[s[:index]]!=s[:right]
|
||||
pass=false
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
!pass
|
||||
end
|
||||
end
|
||||
|
||||
# TBD def sort_data!
|
||||
end
|
||||
|
||||
+77
-29
@@ -65,6 +65,9 @@ module CommandParser
|
||||
@args = args
|
||||
@options = Hash.new
|
||||
|
||||
@before_proc=nil
|
||||
@comm_name=nil
|
||||
|
||||
define_default_formats
|
||||
|
||||
instance_eval(&block)
|
||||
@@ -97,6 +100,12 @@ module CommandParser
|
||||
@name = str
|
||||
end
|
||||
|
||||
# Defines a proc to be called before any command
|
||||
# @param [Proc] block
|
||||
def before_proc(&block)
|
||||
@before_proc = block
|
||||
end
|
||||
|
||||
# Defines a block that will be used to parse the arguments
|
||||
# of the command. Formats defined using this method con be used
|
||||
# in the arguments section of the command method, when defining a new
|
||||
@@ -399,7 +408,7 @@ module CommandParser
|
||||
comm = @main
|
||||
elsif
|
||||
if @args[0] && !@args[0].match(/^-/)
|
||||
comm_name = @args.shift.to_sym
|
||||
@comm_name = comm_name = @args.shift.to_sym
|
||||
comm = @commands[comm_name]
|
||||
end
|
||||
end
|
||||
@@ -413,6 +422,8 @@ module CommandParser
|
||||
parse(extra_options)
|
||||
|
||||
if comm
|
||||
@before_proc.call if @before_proc
|
||||
|
||||
check_args!(comm_name, comm[:arity], comm[:args_format])
|
||||
|
||||
rc = comm[:proc].call
|
||||
@@ -428,9 +439,12 @@ module CommandParser
|
||||
private
|
||||
|
||||
def parse(extra_options)
|
||||
with_proc=Array.new
|
||||
|
||||
@cmdparse=OptionParser.new do |opts|
|
||||
merge = @available_options
|
||||
merge = @available_options + extra_options if extra_options
|
||||
|
||||
merge.flatten.each do |e|
|
||||
args = []
|
||||
args << e[:short] if e[:short]
|
||||
@@ -440,16 +454,8 @@ module CommandParser
|
||||
|
||||
opts.on(*args) do |o|
|
||||
if e[:proc]
|
||||
rc = e[:proc].call(o, @options)
|
||||
if rc.instance_of?(Array)
|
||||
if rc[0] == 0
|
||||
options[e[:name].to_sym] = rc[1]
|
||||
else
|
||||
puts rc[1]
|
||||
puts "option #{e[:name]}: Parsing error"
|
||||
exit -1
|
||||
end
|
||||
end
|
||||
@options[e[:name].to_sym]=o
|
||||
with_proc<<e
|
||||
elsif e[:name]=="help"
|
||||
print_help
|
||||
exit
|
||||
@@ -469,6 +475,19 @@ module CommandParser
|
||||
puts e.message
|
||||
exit -1
|
||||
end
|
||||
|
||||
with_proc.each do |e|
|
||||
rc = e[:proc].call(@options[e[:name].to_sym], @options)
|
||||
if rc.instance_of?(Array)
|
||||
if rc[0] == 0
|
||||
@options[e[:name].to_sym] = rc[1]
|
||||
else
|
||||
puts rc[1]
|
||||
puts "option #{e[:name]}: Parsing error"
|
||||
exit -1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def check_args!(name, arity, args_format)
|
||||
@@ -550,6 +569,14 @@ module CommandParser
|
||||
########################################################################
|
||||
|
||||
def print_help
|
||||
if @comm_name
|
||||
print_command_help(@comm_name)
|
||||
else
|
||||
print_all_commands_help
|
||||
end
|
||||
end
|
||||
|
||||
def print_all_commands_help
|
||||
if @usage
|
||||
puts "## SYNOPSIS"
|
||||
puts
|
||||
@@ -570,37 +597,58 @@ module CommandParser
|
||||
end
|
||||
end
|
||||
|
||||
def print_command_help(name)
|
||||
command=@commands[name]
|
||||
|
||||
if !command
|
||||
STDERR.puts "Command '#{name}' not found"
|
||||
return print_all_commands_help
|
||||
end
|
||||
|
||||
puts "## USAGE"
|
||||
print "#{name} "
|
||||
print_command(@commands[name])
|
||||
|
||||
puts "## OPTIONS"
|
||||
command[:options].flatten.each do |o|
|
||||
print_option(o)
|
||||
end
|
||||
|
||||
@available_options.each do |o|
|
||||
print_option o
|
||||
end
|
||||
end
|
||||
|
||||
def print_options
|
||||
puts "## OPTIONS"
|
||||
|
||||
shown_opts = Array.new
|
||||
opt_format = "#{' '*5}%-25s %s"
|
||||
@commands.each{ |key,value|
|
||||
value[:options].flatten.each { |o|
|
||||
@commands.each do |key,value|
|
||||
value[:options].flatten.each do |o|
|
||||
if shown_opts.include?(o[:name])
|
||||
next
|
||||
else
|
||||
shown_opts << o[:name]
|
||||
|
||||
str = ""
|
||||
str << o[:short].split(' ').first << ', ' if o[:short]
|
||||
str << o[:large]
|
||||
|
||||
printf opt_format, str, o[:description]
|
||||
puts
|
||||
print_option(o)
|
||||
end
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@available_options.each{ |o|
|
||||
str = ""
|
||||
str << o[:short].split(' ').first << ', ' if o[:short]
|
||||
str << o[:large]
|
||||
@available_options.each do |o|
|
||||
print_option o
|
||||
end
|
||||
end
|
||||
|
||||
printf opt_format, str, o[:description]
|
||||
puts
|
||||
}
|
||||
def print_option(o)
|
||||
opt_format = "#{' '*5}%-25s %s"
|
||||
|
||||
str = ""
|
||||
str << o[:short].split(' ').first << ', ' if o[:short]
|
||||
str << o[:large]
|
||||
|
||||
printf opt_format, str, o[:description]
|
||||
puts
|
||||
end
|
||||
|
||||
def print_commands
|
||||
|
||||
+209
-15
@@ -76,14 +76,49 @@ EOT
|
||||
:format => String
|
||||
}
|
||||
|
||||
DRY={
|
||||
:name => 'dry',
|
||||
:large => '--dry',
|
||||
:description => 'Just print the template'
|
||||
}
|
||||
|
||||
CLIENT_OPTIONS=[
|
||||
{
|
||||
:name => 'user',
|
||||
:large => '--user name',
|
||||
:description => 'User name used to connect to OpenNebula',
|
||||
:format => String
|
||||
},
|
||||
{
|
||||
:name => 'password',
|
||||
:large => '--password password',
|
||||
:description => 'Password to authenticate with OpenNebula',
|
||||
:format => String
|
||||
},
|
||||
{
|
||||
:name => 'endpoint',
|
||||
:large => '--endpoint endpoint',
|
||||
:description => 'URL of OpenNebula xmlrpc frontend',
|
||||
:format => String
|
||||
}
|
||||
]
|
||||
|
||||
TEMPLATE_OPTIONS=[
|
||||
{
|
||||
:name => 'cpu',
|
||||
:large => '--cpu cpu',
|
||||
:description =>
|
||||
'CPU percentage reserved for the VM (1=100% one CPU)',
|
||||
"CPU percentage reserved for the VM (1=100% one\n"<<
|
||||
" "*31<<"CPU)",
|
||||
:format => Float
|
||||
},
|
||||
{
|
||||
:name => 'vcpu',
|
||||
:large => '--vcpu vcpu',
|
||||
:description =>
|
||||
"Number of virtualized CPUs",
|
||||
:format => Integer
|
||||
},
|
||||
{
|
||||
:name => 'arch',
|
||||
:large => '--arch arch',
|
||||
@@ -118,39 +153,130 @@ EOT
|
||||
{
|
||||
:name => 'disk',
|
||||
:large => '--disk disk0,disk1',
|
||||
:description => 'Disks to attach. To use a disk owned by other user use user[disk]',
|
||||
:description => "Disks to attach. To use a disk owned by other\n"<<
|
||||
" "*31<<"user use user[disk]",
|
||||
:format => Array
|
||||
},
|
||||
{
|
||||
:name => 'network',
|
||||
:large => '--network network0,network1',
|
||||
:description => 'Networks to attach. To use a network owned by other user use user[network]',
|
||||
:description => "Networks to attach. To use a network owned by\n"<<
|
||||
" "*31<<"other user use user[network]",
|
||||
:format => Array
|
||||
},
|
||||
{
|
||||
:name => 'raw',
|
||||
:large => '--raw string',
|
||||
:description => 'Raw string to add to the template. Not to be confused with the RAW attribute',
|
||||
:description => "Raw string to add to the template. Not to be\n"<<
|
||||
" "*31<<"confused with the RAW attribute",
|
||||
:format => String
|
||||
},
|
||||
{
|
||||
:name => 'vnc',
|
||||
:large => '--vnc',
|
||||
:description => 'Add VNC server to the VM'
|
||||
},
|
||||
{
|
||||
:name => 'ssh',
|
||||
:large => '--ssh [file]',
|
||||
:description => "Add an ssh public key to the context. If the \n"<<
|
||||
(' '*31)<<"file is omited then the user variable \n"<<
|
||||
(' '*31)<<"SSH_PUBLIC_KEY will be used.",
|
||||
:format => String,
|
||||
:proc => lambda do |o, options|
|
||||
if !o
|
||||
[0, true]
|
||||
else
|
||||
[0, o]
|
||||
end
|
||||
end
|
||||
},
|
||||
{
|
||||
:name => 'net_context',
|
||||
:large => '--net_context',
|
||||
:description => 'Add network contextualization parameters'
|
||||
},
|
||||
{
|
||||
:name => 'context',
|
||||
:large => '--context line1,line2,line3',
|
||||
:format => Array,
|
||||
:description => 'Lines to add to the context section'
|
||||
},
|
||||
{
|
||||
:name => 'boot',
|
||||
:large => '--boot device',
|
||||
:description => 'Select boot device (hd|fd|cdrom|network)',
|
||||
:format => String
|
||||
}
|
||||
]
|
||||
|
||||
TEMPLATE_OPTIONS_VM=[TEMPLATE_NAME_VM]+TEMPLATE_OPTIONS
|
||||
TEMPLATE_OPTIONS_VM=[TEMPLATE_NAME_VM]+TEMPLATE_OPTIONS+[DRY]
|
||||
|
||||
OPTIONS = XML, NUMERIC, KILOBYTES
|
||||
|
||||
class OneHelper
|
||||
def initialize(secret=nil, endpoint=nil)
|
||||
begin
|
||||
@client = OpenNebula::Client.new(secret,endpoint)
|
||||
rescue Exception => e
|
||||
puts e.message
|
||||
exit -1
|
||||
attr_accessor :client
|
||||
|
||||
def self.get_client(options)
|
||||
if defined?(@@client)
|
||||
@@client
|
||||
else
|
||||
secret=nil
|
||||
user=options[:user]
|
||||
if user
|
||||
password=options[:password]||self.get_password
|
||||
secret="#{user}:#{password}"
|
||||
end
|
||||
|
||||
endpoint=options[:endpoint]
|
||||
|
||||
@@client=OpenNebula::Client.new(secret, endpoint)
|
||||
end
|
||||
end
|
||||
|
||||
def self.client
|
||||
if defined?(@@client)
|
||||
@@client
|
||||
else
|
||||
self.get_client({})
|
||||
end
|
||||
end
|
||||
|
||||
if RUBY_VERSION>="1.9.3"
|
||||
require 'io/console'
|
||||
def self.get_password
|
||||
print "Password: "
|
||||
pass=nil
|
||||
STDIN.noecho {|io| pass=io.gets }
|
||||
puts
|
||||
|
||||
pass.chop! if pass
|
||||
pass
|
||||
end
|
||||
else
|
||||
# This function is copied from ruby net/imap.rb
|
||||
def self.get_password
|
||||
print "Password: "
|
||||
system("stty", "-echo")
|
||||
begin
|
||||
return gets.chop
|
||||
ensure
|
||||
system("stty", "echo")
|
||||
print "\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(secret=nil, endpoint=nil)
|
||||
@client=nil
|
||||
|
||||
@translation_hash = nil
|
||||
end
|
||||
|
||||
def set_client(options)
|
||||
@client=OpenNebulaHelper::OneHelper.get_client(options)
|
||||
end
|
||||
|
||||
def create_resource(options, &block)
|
||||
resource = factory
|
||||
|
||||
@@ -369,7 +495,7 @@ EOT
|
||||
end
|
||||
|
||||
def pool_to_array(pool)
|
||||
if !pool.instance_of?(Hash)
|
||||
if !pool.instance_of?(Hash)
|
||||
phash = pool.to_hash
|
||||
else
|
||||
phash = pool
|
||||
@@ -408,7 +534,7 @@ EOT
|
||||
def OpenNebulaHelper.rname_to_id(name, poolname)
|
||||
return 0, name.to_i if name.match(/^[0123456789]+$/)
|
||||
|
||||
client = OpenNebula::Client.new
|
||||
client=OneHelper.client
|
||||
|
||||
pool = case poolname
|
||||
when "HOST" then OpenNebula::HostPool.new(client)
|
||||
@@ -557,7 +683,7 @@ EOT
|
||||
|
||||
template<<"#{section.upcase}=[\n"
|
||||
template<<" #{name.upcase}_UNAME=\"#{user}\",\n" if user
|
||||
if object.match(/^\d$/)
|
||||
if object.match(/^\d+$/)
|
||||
template<<" #{name.upcase}_ID=#{object}\n"
|
||||
else
|
||||
template<<" #{name.upcase}=\"#{object}\"\n"
|
||||
@@ -568,12 +694,74 @@ EOT
|
||||
[0, template]
|
||||
end
|
||||
|
||||
def self.create_context(options)
|
||||
if !(options.keys & [:ssh, :net_context, :context]).empty?
|
||||
lines=[]
|
||||
|
||||
if options[:ssh]
|
||||
if options[:ssh]==true
|
||||
lines<<"SSH_PUBLIC_KEY=\"$USER[SSH_PUBLIC_KEY]\""
|
||||
else
|
||||
begin
|
||||
key=File.read(options[:ssh]).strip
|
||||
rescue Exception => e
|
||||
STDERR.puts e.message
|
||||
exit(-1)
|
||||
end
|
||||
lines<<"SSH_PUBLIC_KEY=\"#{key}\""
|
||||
end
|
||||
end
|
||||
|
||||
if options[:net_context] && options[:network]
|
||||
nets=options[:network].map {|n| parse_user_object(n).last }
|
||||
|
||||
if nets!=nets.uniq
|
||||
STDERR.puts "Network context generation from command "<<
|
||||
"line is not supported for VMs with\n"<<
|
||||
"more than one network with the same name."
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
nets.each_with_index do |name, index|
|
||||
lines<<"ETH#{index}_IP = \"$NIC[IP, NETWORK=\\\"#{name}\\\"]\""
|
||||
lines<<"ETH#{index}_NETWORK = \"$NETWORK[NETWORK_ADDRESS, NETWORK=\\\"#{name}\\\"]\""
|
||||
lines<<"ETH#{index}_MASK = \"$NETWORK[NETWORK_MASK, NETWORK=\\\"#{name}\\\"]\""
|
||||
lines<<"ETH#{index}_GATEWAY = \"$NETWORK[GATEWAY, NETWORK=\\\"#{name}\\\"]\""
|
||||
lines<<"ETH#{index}_DNS = \"$NETWORK[DNS, NETWORK=\\\"#{name}\\\"]\""
|
||||
end
|
||||
end
|
||||
|
||||
lines+=options[:context] if options[:context]
|
||||
|
||||
if !lines.empty?
|
||||
"CONTEXT=[\n"<<lines.map{|l| " "<<l }.join(",\n")<<"\n]\n"
|
||||
else
|
||||
nil
|
||||
end
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def self.create_template(options)
|
||||
template=''
|
||||
|
||||
template<<"NAME=\"#{options[:name]}\"\n" if options[:name]
|
||||
template<<"OS = [ ARCH = \"#{options[:arch]}\" ]\n" if options[:arch]
|
||||
|
||||
if options[:arch] || options[:boot]
|
||||
template<<"OS = [\n"
|
||||
|
||||
lines=[]
|
||||
lines<<" ARCH = \"#{options[:arch]}\"" if options[:arch]
|
||||
lines<<" BOOT = \"#{options[:boot]}\"" if options[:boot]
|
||||
|
||||
template<<lines.join(",\n")
|
||||
|
||||
template << " ]\n"
|
||||
end
|
||||
|
||||
template<<"CPU=#{options[:cpu]}\n" if options[:cpu]
|
||||
template<<"VCPU=#{options[:vcpu]}\n" if options[:vcpu]
|
||||
template<<"MEMORY=#{options[:memory]}\n" if options[:memory]
|
||||
template<<"#{options[:raw]}\n" if options[:raw]
|
||||
|
||||
@@ -591,6 +779,12 @@ EOT
|
||||
template<<res.last
|
||||
end
|
||||
|
||||
if options[:vnc]
|
||||
template<<'GRAPHICS=[ TYPE="vnc", LISTEN="0.0.0.0" ]'<<"\n"
|
||||
end
|
||||
|
||||
context=create_context(options)
|
||||
template<<context if context
|
||||
|
||||
[0, template]
|
||||
end
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'one_helper'
|
||||
require 'one_helper/onevm_helper'
|
||||
|
||||
class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
def self.rname
|
||||
@@ -192,5 +193,13 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
CLIHelper.print_header(str_h1 % "MONITORING INFORMATION", false)
|
||||
|
||||
puts host.template_str
|
||||
|
||||
puts
|
||||
CLIHelper.print_header("VIRTUAL MACHINES", false)
|
||||
puts
|
||||
|
||||
onevm_helper=OneVMHelper.new
|
||||
onevm_helper.client=@client
|
||||
onevm_helper.list_pool({:filter=>["HOST=#{host.name}"]}, false)
|
||||
end
|
||||
end
|
||||
@@ -53,7 +53,8 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
|
||||
{
|
||||
:name => "prefix",
|
||||
:large => "--prefix prefix",
|
||||
:description => "Device prefix for the disk (eg. hd, sd, xvd or vd)",
|
||||
:description => "Device prefix for the disk (eg. hd, sd, xvd\n"<<
|
||||
" "*31<<"or vd)",
|
||||
:format => String,
|
||||
:proc => lambda do |o, options|
|
||||
prefix=o.strip.downcase
|
||||
@@ -76,7 +77,9 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
|
||||
:description => "Path of the image file",
|
||||
:format => String,
|
||||
:proc => lambda do |o, options|
|
||||
if o[0,1]=='/'
|
||||
if o.match(/^https?:\/\//)
|
||||
next [0, o]
|
||||
elsif o[0,1]=='/'
|
||||
path=o
|
||||
else
|
||||
path=Dir.pwd+"/"+o
|
||||
@@ -113,7 +116,8 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
|
||||
:name => "source",
|
||||
:large => "--source source",
|
||||
:description =>
|
||||
"Source to be used. Useful for not file-based images",
|
||||
"Source to be used. Useful for not file-based\n"<<
|
||||
" "*31<<"images",
|
||||
:format => String
|
||||
},
|
||||
{
|
||||
@@ -147,8 +151,8 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
|
||||
{
|
||||
:name => "fstype",
|
||||
:large => "--fstype fstype",
|
||||
:description => "Type of file system to be built. This can be "<<
|
||||
"any value understood by mkfs unix command.",
|
||||
:description => "Type of file system to be built. This can be \n"<<
|
||||
" "*31<<"any value understood by mkfs unix command.",
|
||||
:format => String,
|
||||
:proc => lambda do |o, options|
|
||||
if !options[:type] || !(options[:type].upcase=='DATABLOCK')
|
||||
@@ -157,7 +161,8 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
|
||||
[0, o]
|
||||
end
|
||||
end
|
||||
}
|
||||
},
|
||||
OpenNebulaHelper::DRY
|
||||
]
|
||||
|
||||
def self.rname
|
||||
@@ -318,7 +323,7 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
|
||||
end
|
||||
|
||||
template=create_image_variables(
|
||||
options, template_options-[:persistent])
|
||||
options, template_options-[:persistent, :dry])
|
||||
|
||||
template<<"PERSISTENT=YES\n" if options[:persistent]
|
||||
|
||||
|
||||
+2
-2
@@ -37,6 +37,7 @@ cmd = CommandParser::CmdParser.new(ARGV) do
|
||||
description ""
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
|
||||
client = OpenNebulaHelper::OneHelper.get_client({})
|
||||
|
||||
option AcctHelper::ACCT_OPTIONS + CommandParser::OPTIONS
|
||||
|
||||
@@ -53,10 +54,8 @@ cmd = CommandParser::CmdParser.new(ARGV) do
|
||||
:xpath => options[:xpath]
|
||||
}
|
||||
|
||||
client = OpenNebula::Client.new
|
||||
pool = OpenNebula::VirtualMachinePool.new(client)
|
||||
|
||||
|
||||
if options[:json] || options[:xml]
|
||||
xml_str = pool.accounting_xml(filter_flag, common_opts)
|
||||
if OpenNebula.is_error?(xml_str)
|
||||
@@ -85,6 +84,7 @@ cmd = CommandParser::CmdParser.new(ARGV) do
|
||||
exit -1
|
||||
end
|
||||
|
||||
|
||||
if ( start_time != -1 or end_time != -1 )
|
||||
AcctHelper.print_start_end_time_header(start_time, end_time)
|
||||
end
|
||||
|
||||
+5
-1
@@ -36,10 +36,14 @@ cmd = CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
helper = OneAclHelper.new
|
||||
|
||||
before_proc do
|
||||
helper.set_client(options)
|
||||
end
|
||||
|
||||
########################################################################
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS
|
||||
set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
|
||||
|
||||
########################################################################
|
||||
# Formatters for arguments
|
||||
|
||||
+5
-1
@@ -36,10 +36,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
helper = OneClusterHelper.new
|
||||
|
||||
before_proc do
|
||||
helper.set_client(options)
|
||||
end
|
||||
|
||||
########################################################################
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS
|
||||
set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
|
||||
|
||||
list_options = CLIHelper::OPTIONS
|
||||
list_options << OpenNebulaHelper::XML
|
||||
|
||||
@@ -37,10 +37,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
helper = OneDatastoreHelper.new
|
||||
|
||||
before_proc do
|
||||
helper.set_client(options)
|
||||
end
|
||||
|
||||
########################################################################
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS
|
||||
set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
|
||||
|
||||
list_options = CLIHelper::OPTIONS
|
||||
list_options << OpenNebulaHelper::XML
|
||||
|
||||
+5
-1
@@ -36,10 +36,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
helper = OneGroupHelper.new
|
||||
|
||||
before_proc do
|
||||
helper.set_client(options)
|
||||
end
|
||||
|
||||
########################################################################
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS
|
||||
set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
|
||||
|
||||
list_options = CLIHelper::OPTIONS
|
||||
list_options << OpenNebulaHelper::XML
|
||||
|
||||
+5
-1
@@ -37,10 +37,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
helper = OneHostHelper.new
|
||||
|
||||
before_proc do
|
||||
helper.set_client(options)
|
||||
end
|
||||
|
||||
########################################################################
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS
|
||||
set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
|
||||
|
||||
IM = {
|
||||
:name => "im",
|
||||
|
||||
+20
-2
@@ -37,10 +37,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
helper = OneImageHelper.new
|
||||
|
||||
before_proc do
|
||||
helper.set_client(options)
|
||||
end
|
||||
|
||||
########################################################################
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS
|
||||
set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
|
||||
|
||||
list_options = CLIHelper::OPTIONS
|
||||
list_options << OpenNebulaHelper::XML
|
||||
@@ -72,6 +76,15 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
helper.filterflag_to_i(arg)
|
||||
end
|
||||
|
||||
format(:type, 'Image type: OS, DATABLOCK or CDROM') do |arg|
|
||||
type=arg.strip.upcase
|
||||
if %w{OS DATABLOCK CDROM}.include? type
|
||||
[0, type]
|
||||
else
|
||||
[1, "Image type not supported. Must be OS, DATABLOCK or CDROM."]
|
||||
end
|
||||
end
|
||||
|
||||
########################################################################
|
||||
# Commands
|
||||
########################################################################
|
||||
@@ -103,7 +116,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
command :create, create_desc, [:file, nil], :options=>CREATE_OPTIONS +
|
||||
OneImageHelper::TEMPLATE_OPTIONS do
|
||||
|
||||
if options[:datastore].nil?
|
||||
if options[:datastore].nil? && !options[:dry]
|
||||
STDERR.puts "Datastore to save the image is mandatory: "
|
||||
STDERR.puts "\t -d datastore_id"
|
||||
exit -1
|
||||
@@ -130,6 +143,11 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
template = res.last
|
||||
end
|
||||
|
||||
if options[:dry]
|
||||
puts template
|
||||
exit 0
|
||||
end
|
||||
|
||||
image.allocate(template, options[:datastore])
|
||||
rescue => e
|
||||
STDERR.puts e.messsage
|
||||
|
||||
+13
-3
@@ -36,10 +36,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
helper = OneTemplateHelper.new
|
||||
|
||||
before_proc do
|
||||
helper.set_client(options)
|
||||
end
|
||||
|
||||
########################################################################
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS
|
||||
set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
|
||||
|
||||
list_options = CLIHelper::OPTIONS
|
||||
list_options << OpenNebulaHelper::XML
|
||||
@@ -98,7 +102,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :create, create_desc, [:file, nil], :options =>
|
||||
[OneTemplateHelper::VM_NAME]+OpenNebulaHelper::TEMPLATE_OPTIONS do
|
||||
[OneTemplateHelper::VM_NAME]+OpenNebulaHelper::TEMPLATE_OPTIONS+
|
||||
[OpenNebulaHelper::DRY] do
|
||||
|
||||
if args[0] && OpenNebulaHelper.create_template_options_used?(options)
|
||||
STDERR.puts "You can not use both template file and template"<<
|
||||
@@ -121,7 +126,12 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
template = res.last
|
||||
end
|
||||
|
||||
tmpl.allocate(template)
|
||||
if options[:dry]
|
||||
puts template
|
||||
exit 0
|
||||
else
|
||||
tmpl.allocate(template)
|
||||
end
|
||||
rescue => e
|
||||
STDERR.puts e.messsage
|
||||
exit -1
|
||||
|
||||
+9
-20
@@ -37,10 +37,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
usage "`oneuser` <command> [<args>] [<options>]"
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
|
||||
helper = OneUserHelper.new
|
||||
|
||||
before_proc do
|
||||
helper.set_client(options)
|
||||
end
|
||||
|
||||
########################################################################
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS
|
||||
set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
|
||||
|
||||
list_options = CLIHelper::OPTIONS
|
||||
list_options << OpenNebulaHelper::XML
|
||||
@@ -57,7 +63,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
SHA1={
|
||||
:name => "sha1",
|
||||
:large => "--sha1",
|
||||
:description => "The password will be hashed using the sha1 algorithm"
|
||||
:description => "The password will be hashed using the sha1\n"<<
|
||||
" "*31<<"algorithm"
|
||||
}
|
||||
|
||||
SSH={
|
||||
@@ -135,12 +142,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
end
|
||||
|
||||
set :format, :userid, OneUserHelper.to_id_desc do |arg|
|
||||
helper = OneUserHelper.new
|
||||
helper.to_id(arg)
|
||||
end
|
||||
|
||||
set :format, :userid_list, OneUserHelper.list_to_id_desc do |arg|
|
||||
helper = OneUserHelper.new
|
||||
helper.list_to_id(arg)
|
||||
end
|
||||
|
||||
@@ -164,8 +169,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
command :create, create_desc, :username, [:password, nil],
|
||||
:options=>create_options do
|
||||
helper = OneUserHelper.new
|
||||
|
||||
if args[1]
|
||||
pass = args[1]
|
||||
else
|
||||
@@ -190,8 +193,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :update, update_desc, :userid, [:file, nil] do
|
||||
helper = OneUserHelper.new
|
||||
|
||||
helper.perform_action(args[0],options,"modified") do |user|
|
||||
str = OpenNebulaHelper.update_template(args[0], user, args[1])
|
||||
user.update(str)
|
||||
@@ -204,8 +205,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :quota, quota_desc, :userid, [:file, nil] do
|
||||
helper = OneUserHelper.new
|
||||
|
||||
helper.perform_action(args[0], options, "modified") do |user|
|
||||
str = OneQuotaHelper.set_quota(user, args[1])
|
||||
rc = user.set_quota(str)
|
||||
@@ -224,8 +223,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :batchquota, batchquota_desc, [:range, :userid_list], [:file, nil] do
|
||||
helper = OneUserHelper.new
|
||||
|
||||
batch_str = OneQuotaHelper.get_batch_quota(args[1])
|
||||
|
||||
helper.perform_actions(args[0], options, "modified") do |user|
|
||||
@@ -282,7 +279,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :delete, delete_desc, [:range, :userid_list] do
|
||||
helper = OneUserHelper.new
|
||||
helper.perform_actions(args[0], options, "deleted") do |user|
|
||||
user.delete
|
||||
end
|
||||
@@ -294,8 +290,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
command :passwd, passwd_desc, :userid, [:password, nil],
|
||||
:options=>create_options do
|
||||
helper = OneUserHelper.new
|
||||
|
||||
if args[1]
|
||||
pass = args[1]
|
||||
else
|
||||
@@ -317,7 +311,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :chgrp, chgrp_desc, [:range, :userid_list], :groupid do
|
||||
helper = OneUserHelper.new
|
||||
helper.perform_actions(args[0],options,"Group changed") do |user|
|
||||
user.chgrp(args[1].to_i)
|
||||
end
|
||||
@@ -344,8 +337,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
exit_with_code 0, "An Auth driver should be specified"
|
||||
end
|
||||
|
||||
helper = OneUserHelper.new
|
||||
|
||||
if args[2]
|
||||
pass = args[2]
|
||||
else
|
||||
@@ -369,7 +360,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :list, list_desc, :options=>list_options do
|
||||
helper = OneUserHelper.new
|
||||
helper.list_pool(options)
|
||||
end
|
||||
|
||||
@@ -380,7 +370,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
command :show, show_desc, [:userid, nil],
|
||||
:options=>OpenNebulaHelper::XML do
|
||||
user=args[0] || OpenNebula::User::SELF
|
||||
helper = OneUserHelper.new
|
||||
helper.show_resource(user,options)
|
||||
end
|
||||
|
||||
|
||||
+10
-1
@@ -36,6 +36,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
helper = OneVMHelper.new
|
||||
|
||||
before_proc do
|
||||
helper.set_client(options)
|
||||
end
|
||||
|
||||
TYPE={
|
||||
:name => "type",
|
||||
@@ -56,7 +59,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
########################################################################
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS
|
||||
set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
|
||||
|
||||
########################################################################
|
||||
# Formatters for arguments
|
||||
@@ -139,11 +142,17 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
template = res.last
|
||||
end
|
||||
|
||||
rescue Exception => e
|
||||
STDERR.puts "Error reading template."
|
||||
next -1
|
||||
end
|
||||
|
||||
if options[:dry]
|
||||
puts template
|
||||
exit 0
|
||||
end
|
||||
|
||||
number.times do
|
||||
exit_code = helper.create_resource(options) do |vm|
|
||||
error = vm.allocate(template)
|
||||
|
||||
+5
-1
@@ -37,10 +37,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
helper = OneVNetHelper.new
|
||||
|
||||
before_proc do
|
||||
helper.set_client(options)
|
||||
end
|
||||
|
||||
########################################################################
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS
|
||||
set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
|
||||
|
||||
CREATE_OPTIONS = [OneClusterHelper::CLUSTER]
|
||||
|
||||
|
||||
Reference in new issue
Block a user