mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-15 09:13:15 +09:00
Ruby code formatting: CLI Part I
This commit is contained in:
1 parent
eb66b0f594
commit
64ef1f3e47
15 files changed
+1060
-950
No files matched your search
+33
-31
@@ -16,36 +16,36 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
ONE_LOCATION = ENV['ONE_LOCATION']
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
RUBY_LIB_LOCATION = '/usr/lib/one/ruby'
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cli"
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
|
||||
|
||||
require 'command_parser'
|
||||
require 'one_helper/oneacct_helper'
|
||||
|
||||
require 'json'
|
||||
|
||||
cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
usage "`oneacct` [<options>]"
|
||||
description ""
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
usage '`oneacct` [<options>]'
|
||||
description ''
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
|
||||
helper=OpenNebulaHelper::OneHelper.new
|
||||
helper = OpenNebulaHelper::OneHelper.new
|
||||
|
||||
before_proc do
|
||||
helper.set_client(options)
|
||||
end
|
||||
|
||||
option AcctHelper::ACCT_OPTIONS + CommandParser::OPTIONS +
|
||||
[OpenNebulaHelper::DESCRIBE, CLIHelper::LIST, CLIHelper::CSV_OPT] +
|
||||
OpenNebulaHelper::CLIENT_OPTIONS
|
||||
[OpenNebulaHelper::DESCRIBE, CLIHelper::LIST, CLIHelper::CSV_OPT] +
|
||||
OpenNebulaHelper::CLIENT_OPTIONS
|
||||
|
||||
main do
|
||||
if options[:describe]
|
||||
@@ -54,18 +54,22 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
end
|
||||
|
||||
filter_flag = (options[:userfilter] || VirtualMachinePool::INFO_ALL)
|
||||
start_time = options[:start_time] ? options[:start_time].to_i : -1
|
||||
if options[:start_time]
|
||||
start_time = options[:start_time].to_i
|
||||
else
|
||||
start_time = -1
|
||||
end
|
||||
|
||||
end_time = -1
|
||||
|
||||
if (!options[:end_time].nil?)
|
||||
if !options[:end_time].nil?
|
||||
# Not the safest way to add a day, but since managing date/time
|
||||
# in ruby is... not entirely convenient, this will do
|
||||
|
||||
t = options[:end_time]
|
||||
|
||||
if (t.hour == 0 && t.min == 0 && t.sec == 0)
|
||||
t += 24*60*60
|
||||
if t.hour.zero? && t.min.zero? && t.sec.zero?
|
||||
t += 24 * 60 * 60
|
||||
end
|
||||
|
||||
end_time = t.to_i
|
||||
@@ -79,13 +83,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
:xpath => options[:xpath]
|
||||
}
|
||||
|
||||
pool = OpenNebula::VirtualMachinePool.new(helper.client)
|
||||
pool = OpenNebula::VirtualMachinePool.new(helper.client)
|
||||
|
||||
if options[:json] || options[:xml]
|
||||
xml_str = pool.accounting_xml(filter_flag, common_opts)
|
||||
if OpenNebula.is_error?(xml_str)
|
||||
puts xml_str.message
|
||||
exit -1
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
if options[:json]
|
||||
@@ -96,10 +100,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
elsif options[:xml]
|
||||
puts xml_str
|
||||
end
|
||||
|
||||
exit_code 0
|
||||
else
|
||||
order_by = Hash.new
|
||||
order_by = {}
|
||||
order_by[:order_by_1] = 'VM/UID'
|
||||
|
||||
if options[:split] && !options[:csv]
|
||||
@@ -110,48 +112,48 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
common_opts.merge(order_by))
|
||||
if OpenNebula.is_error?(acct_hash)
|
||||
puts acct_hash.message
|
||||
exit -1
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
if options[:csv]
|
||||
a=Array.new
|
||||
a = []
|
||||
acct_hash.each do |user_id, value|
|
||||
value['HISTORY_RECORDS']['HISTORY'].each do |l|
|
||||
l['UID']=user_id
|
||||
l['UID'] = user_id
|
||||
a << l
|
||||
end
|
||||
end
|
||||
|
||||
cols = [ :UID ] + AcctHelper::ACCT_TABLE.default_columns
|
||||
cols = [:UID] + AcctHelper::ACCT_TABLE.default_columns
|
||||
options[:list] ||= cols
|
||||
|
||||
AcctHelper::ACCT_TABLE.show(a, options)
|
||||
exit(0)
|
||||
end
|
||||
|
||||
if ( start_time != -1 or end_time != -1 )
|
||||
if start_time != -1 || end_time != -1
|
||||
AcctHelper.print_start_end_time_header(start_time, end_time)
|
||||
end
|
||||
|
||||
acct_hash.each { |user_id, value|
|
||||
acct_hash.each do |user_id, value|
|
||||
AcctHelper.print_user_header(user_id)
|
||||
|
||||
if options[:split]
|
||||
# Use one table for each VM
|
||||
value.each { |vm_id, history_array|
|
||||
value.each do |_vm_id, history_array|
|
||||
array = history_array['HISTORY_RECORDS']['HISTORY']
|
||||
AcctHelper::ACCT_TABLE.show(array, options)
|
||||
puts
|
||||
}
|
||||
end
|
||||
else
|
||||
# Use the same table for all the VMs
|
||||
array = value['HISTORY_RECORDS']['HISTORY']
|
||||
AcctHelper::ACCT_TABLE.show(array, options)
|
||||
puts
|
||||
end
|
||||
}
|
||||
|
||||
exit_code 0
|
||||
end
|
||||
end
|
||||
|
||||
exit_code 0
|
||||
end
|
||||
end
|
||||
+15
-15
@@ -16,22 +16,22 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
ONE_LOCATION = ENV['ONE_LOCATION']
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
RUBY_LIB_LOCATION = '/usr/lib/one/ruby'
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cli"
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
|
||||
|
||||
require 'command_parser'
|
||||
require 'one_helper/oneacl_helper'
|
||||
|
||||
cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
usage "`oneacl` <command> [<args>] [<options>]"
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
usage '`oneacl` <command> [<args>] [<options>]'
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
|
||||
helper = OneAclHelper.new
|
||||
@@ -43,7 +43,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
########################################################################
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
|
||||
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
|
||||
|
||||
########################################################################
|
||||
# Formatters for arguments
|
||||
@@ -60,7 +60,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Adds a new ACL rule
|
||||
EOT
|
||||
|
||||
command :create, addrule_desc, [:user,:rulestr], [:resource, nil],
|
||||
command :create, addrule_desc, [:user, :rulestr], [:resource, nil],
|
||||
[:rights, nil] do
|
||||
case args.length
|
||||
when 1
|
||||
@@ -70,9 +70,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
next -1, new_args.message
|
||||
end
|
||||
when 3, 4
|
||||
new_args=args
|
||||
new_args = args
|
||||
else
|
||||
next -1, "Wrong number of arguments, must be 1 or 4"
|
||||
next -1, 'Wrong number of arguments, must be 1 or 4'
|
||||
end
|
||||
|
||||
helper.create_resource(options) do |rule|
|
||||
@@ -85,7 +85,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :delete, delrule_desc, [:range] do
|
||||
helper.perform_actions(args[0],options,"deleted") do |obj|
|
||||
helper.perform_actions(args[0], options, 'deleted') do |obj|
|
||||
obj.delete
|
||||
end
|
||||
end
|
||||
@@ -94,8 +94,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Lists the ACL rule set
|
||||
EOT
|
||||
|
||||
command :list, list_desc,:options=>[OpenNebulaHelper::XML,
|
||||
OpenNebulaHelper::DESCRIBE] do
|
||||
helper.list_pool( options )
|
||||
command :list, list_desc, :options => [OpenNebulaHelper::XML,
|
||||
OpenNebulaHelper::DESCRIBE] do
|
||||
helper.list_pool(options)
|
||||
end
|
||||
end
|
||||
+31
-31
@@ -16,22 +16,22 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
ONE_LOCATION = ENV['ONE_LOCATION']
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
RUBY_LIB_LOCATION = '/usr/lib/one/ruby'
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cli"
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
|
||||
|
||||
require 'command_parser'
|
||||
require 'one_helper/onecluster_helper'
|
||||
|
||||
cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
usage "`onecluster` <command> [<args>] [<options>]"
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
usage '`onecluster` <command> [<args>] [<options>]'
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
|
||||
helper = OneClusterHelper.new
|
||||
@@ -43,7 +43,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
########################################################################
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
|
||||
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
|
||||
|
||||
list_options = CLIHelper::OPTIONS
|
||||
list_options << OpenNebulaHelper::XML
|
||||
@@ -61,17 +61,17 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
helper.list_to_id(arg)
|
||||
end
|
||||
|
||||
set :format, :vnetid, OpenNebulaHelper.rname_to_id_desc("VNET") do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, "VNET")
|
||||
set :format, :vnetid, OpenNebulaHelper.rname_to_id_desc('VNET') do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, 'VNET')
|
||||
end
|
||||
|
||||
set :format, :hostid, OpenNebulaHelper.rname_to_id_desc("HOST") do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, "HOST")
|
||||
set :format, :hostid, OpenNebulaHelper.rname_to_id_desc('HOST') do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, 'HOST')
|
||||
end
|
||||
|
||||
set :format, :datastoreid,
|
||||
OpenNebulaHelper.rname_to_id_desc("DATASTORE") do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, "DATASTORE")
|
||||
OpenNebulaHelper.rname_to_id_desc('DATASTORE') do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, 'DATASTORE')
|
||||
end
|
||||
|
||||
########################################################################
|
||||
@@ -93,7 +93,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :delete, delete_desc, [:range, :clusterid_list] do
|
||||
helper.perform_actions(args[0],options,"deleted") do |obj|
|
||||
helper.perform_actions(args[0], options, 'deleted') do |obj|
|
||||
obj.delete
|
||||
end
|
||||
end
|
||||
@@ -102,7 +102,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Lists Clusters in the pool
|
||||
EOT
|
||||
|
||||
command :list, list_desc, :options=>list_options do
|
||||
command :list, list_desc, :options => list_options do
|
||||
helper.list_pool(options)
|
||||
end
|
||||
|
||||
@@ -110,8 +110,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Shows information for the given Cluster
|
||||
EOT
|
||||
|
||||
command :show, show_desc,:clusterid, :options=>OpenNebulaHelper::XML do
|
||||
helper.show_resource(args[0],options)
|
||||
command :show, show_desc, :clusterid, :options => OpenNebulaHelper::XML do
|
||||
helper.show_resource(args[0], options)
|
||||
end
|
||||
|
||||
addhost_desc = <<-EOT.unindent
|
||||
@@ -119,8 +119,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
# TODO: allow the second param to be [:range, :hostid_list]
|
||||
command :addhost, addhost_desc,:clusterid, :hostid do
|
||||
helper.perform_action(args[0],options,"updated") do |cluster|
|
||||
command :addhost, addhost_desc, :clusterid, :hostid do
|
||||
helper.perform_action(args[0], options, 'updated') do |cluster|
|
||||
cluster.addhost(args[1].to_i)
|
||||
end
|
||||
end
|
||||
@@ -131,7 +131,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
# TODO: allow the second param to be [:range, :hostid_list]
|
||||
command :delhost, delhost_desc, :clusterid, :hostid do
|
||||
helper.perform_action(args[0],options,"updated") do |cluster|
|
||||
helper.perform_action(args[0], options, 'updated') do |cluster|
|
||||
cluster.delhost(args[1].to_i)
|
||||
end
|
||||
end
|
||||
@@ -141,8 +141,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
# TODO: allow the second param to be [:range, :datastoreid_list]
|
||||
command :adddatastore, adddatastore_desc,:clusterid, :datastoreid do
|
||||
helper.perform_action(args[0],options,"updated") do |cluster|
|
||||
command :adddatastore, adddatastore_desc, :clusterid, :datastoreid do
|
||||
helper.perform_action(args[0], options, 'updated') do |cluster|
|
||||
cluster.adddatastore(args[1].to_i)
|
||||
end
|
||||
end
|
||||
@@ -153,7 +153,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
# TODO: allow the second param to be [:range, :datastoreid_list]
|
||||
command :deldatastore, deldatastore_desc, :clusterid, :datastoreid do
|
||||
helper.perform_action(args[0],options,"updated") do |cluster|
|
||||
helper.perform_action(args[0], options, 'updated') do |cluster|
|
||||
cluster.deldatastore(args[1].to_i)
|
||||
end
|
||||
end
|
||||
@@ -163,8 +163,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
# TODO: allow the second param to be [:range, :vnetid_list]
|
||||
command :addvnet, addvnet_desc,:clusterid, :vnetid do
|
||||
helper.perform_action(args[0],options,"updated") do |cluster|
|
||||
command :addvnet, addvnet_desc, :clusterid, :vnetid do
|
||||
helper.perform_action(args[0], options, 'updated') do |cluster|
|
||||
cluster.addvnet(args[1].to_i)
|
||||
end
|
||||
end
|
||||
@@ -174,8 +174,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
# TODO: allow the second param to be [:range, :vnetid_list]
|
||||
command :delvnet, delvnet_desc,:clusterid, :vnetid do
|
||||
helper.perform_action(args[0],options,"updated") do |cluster|
|
||||
command :delvnet, delvnet_desc, :clusterid, :vnetid do
|
||||
helper.perform_action(args[0], options, 'updated') do |cluster|
|
||||
cluster.delvnet(args[1].to_i)
|
||||
end
|
||||
end
|
||||
@@ -186,8 +186,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :update, update_desc, :clusterid, [:file, nil],
|
||||
:options=>OpenNebulaHelper::APPEND do
|
||||
helper.perform_action(args[0],options,"modified") do |obj|
|
||||
:options => OpenNebulaHelper::APPEND do
|
||||
helper.perform_action(args[0], options, 'modified') do |obj|
|
||||
if options[:append]
|
||||
str = OpenNebulaHelper.append_template(args[0], obj, args[1])
|
||||
else
|
||||
@@ -206,7 +206,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :rename, rename_desc, :clusterid, :name do
|
||||
helper.perform_action(args[0],options,"renamed") do |o|
|
||||
helper.perform_action(args[0], options, 'renamed') do |o|
|
||||
o.rename(args[1])
|
||||
end
|
||||
end
|
||||
|
||||
+35
-35
@@ -16,23 +16,23 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
ONE_LOCATION = ENV['ONE_LOCATION']
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
RUBY_LIB_LOCATION = '/usr/lib/one/ruby'
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cli"
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
|
||||
|
||||
require 'command_parser'
|
||||
require 'one_helper/onedatastore_helper'
|
||||
require 'one_helper/onecluster_helper'
|
||||
|
||||
cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
usage "`onedatastore` <command> [<args>] [<options>]"
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
usage '`onedatastore` <command> [<args>] [<options>]'
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
|
||||
helper = OneDatastoreHelper.new
|
||||
@@ -44,7 +44,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
########################################################################
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
|
||||
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
|
||||
|
||||
list_options = CLIHelper::OPTIONS
|
||||
list_options << OpenNebulaHelper::XML
|
||||
@@ -63,16 +63,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
end
|
||||
|
||||
set :format, :clusterid,
|
||||
OpenNebulaHelper.rname_to_id_desc("CLUSTER") do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, "CLUSTER")
|
||||
OpenNebulaHelper.rname_to_id_desc('CLUSTER') do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, 'CLUSTER')
|
||||
end
|
||||
|
||||
set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, "GROUP")
|
||||
set :format, :groupid, OpenNebulaHelper.rname_to_id_desc('GROUP') do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, 'GROUP')
|
||||
end
|
||||
|
||||
set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, "USER")
|
||||
set :format, :userid, OpenNebulaHelper.rname_to_id_desc('USER') do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, 'USER')
|
||||
end
|
||||
|
||||
########################################################################
|
||||
@@ -84,17 +84,17 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :create, create_desc, :file,
|
||||
:options=>[OneClusterHelper::CLUSTER] do
|
||||
:options => [OneClusterHelper::CLUSTER] do
|
||||
|
||||
cid = options[:cluster] || ClusterPool::NONE_CLUSTER_ID
|
||||
|
||||
helper.create_resource(options) do |datastore|
|
||||
begin
|
||||
template=File.read(args[0])
|
||||
template = File.read(args[0])
|
||||
datastore.allocate(template, cid)
|
||||
rescue =>e
|
||||
rescue StandardError => e
|
||||
STDERR.puts e.message
|
||||
exit -1
|
||||
exit(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -104,7 +104,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :delete, delete_desc, [:range, :datastoreid_list] do
|
||||
helper.perform_actions(args[0],options,"deleted") do |obj|
|
||||
helper.perform_actions(args[0], options, 'deleted') do |obj|
|
||||
obj.delete
|
||||
end
|
||||
end
|
||||
@@ -113,8 +113,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Changes the Datastore group
|
||||
EOT
|
||||
|
||||
command :chgrp, chgrp_desc,[:range, :datastoreid_list], :groupid do
|
||||
helper.perform_actions(args[0],options,"Group changed") do |obj|
|
||||
command :chgrp, chgrp_desc, [:range, :datastoreid_list], :groupid do
|
||||
helper.perform_actions(args[0], options, 'Group changed') do |obj|
|
||||
obj.chown(-1, args[1].to_i)
|
||||
end
|
||||
end
|
||||
@@ -124,9 +124,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :chown, chown_desc, [:range, :datastoreid_list], :userid,
|
||||
[:groupid,nil] do
|
||||
gid = args[2].nil? ? -1 : args[2].to_i
|
||||
helper.perform_actions(args[0],options,"Owner/Group changed") do |obj|
|
||||
[:groupid, nil] do
|
||||
args[2].nil? ? gid = -1 : gid = args[2].to_i
|
||||
helper.perform_actions(args[0], options, 'Owner/Group changed') do |obj|
|
||||
obj.chown(args[1].to_i, gid)
|
||||
end
|
||||
end
|
||||
@@ -136,7 +136,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :chmod, chmod_desc, [:range, :datastoreid_list], :octet do
|
||||
helper.perform_actions(args[0],options, "Permissions changed") do |obj|
|
||||
helper.perform_actions(args[0], options, 'Permissions changed') do |obj|
|
||||
obj.chmod_octet(args[1])
|
||||
end
|
||||
end
|
||||
@@ -145,7 +145,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Lists Datastores in the pool
|
||||
EOT
|
||||
|
||||
command :list, list_desc, :options=>list_options do
|
||||
command :list, list_desc, :options => list_options do
|
||||
helper.list_pool(options)
|
||||
end
|
||||
|
||||
@@ -153,8 +153,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Shows information for the given Datastore
|
||||
EOT
|
||||
|
||||
command :show, show_desc, :datastoreid, :options=>OpenNebulaHelper::XML do
|
||||
helper.show_resource(args[0],options)
|
||||
command :show, show_desc, :datastoreid, :options => OpenNebulaHelper::XML do
|
||||
helper.show_resource(args[0], options)
|
||||
end
|
||||
|
||||
update_desc = <<-EOT.unindent
|
||||
@@ -163,8 +163,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :update, update_desc, :datastoreid, [:file, nil],
|
||||
:options=>OpenNebulaHelper::APPEND do
|
||||
helper.perform_action(args[0],options,"modified") do |obj|
|
||||
:options => OpenNebulaHelper::APPEND do
|
||||
helper.perform_action(args[0], options, 'modified') do |obj|
|
||||
if options[:append]
|
||||
str = OpenNebulaHelper.append_template(args[0], obj, args[1])
|
||||
else
|
||||
@@ -183,7 +183,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :rename, rename_desc, :datastoreid, :name do
|
||||
helper.perform_action(args[0],options,"renamed") do |o|
|
||||
helper.perform_action(args[0], options, 'renamed') do |o|
|
||||
o.rename(args[1])
|
||||
end
|
||||
end
|
||||
@@ -192,8 +192,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Enables the given Datastore. Only available for System Datastores
|
||||
EOT
|
||||
|
||||
command :enable, enable_desc, [:range,:datastoreid_list] do
|
||||
helper.perform_actions(args[0],options,"enabled") do |obj|
|
||||
command :enable, enable_desc, [:range, :datastoreid_list] do
|
||||
helper.perform_actions(args[0], options, 'enabled') do |obj|
|
||||
obj.enable
|
||||
end
|
||||
end
|
||||
@@ -202,8 +202,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Disables the given Datastore. Only available for System Datastores
|
||||
EOT
|
||||
|
||||
command :disable, disable_desc, [:range,:datastoreid_list] do
|
||||
helper.perform_actions(args[0],options,"disabled") do |obj|
|
||||
command :disable, disable_desc, [:range, :datastoreid_list] do
|
||||
helper.perform_actions(args[0], options, 'disabled') do |obj|
|
||||
obj.disable
|
||||
end
|
||||
end
|
||||
|
||||
+267
-230
@@ -16,16 +16,16 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
ONE_LOCATION = ENV['ONE_LOCATION']
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
RUBY_LIB_LOCATION = '/usr/lib/one/ruby'
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+'/cli'
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
|
||||
|
||||
require 'command_parser'
|
||||
require 'opennebula/oneflow_client'
|
||||
@@ -35,139 +35,142 @@ require 'one_helper/onevm_helper'
|
||||
|
||||
require 'json'
|
||||
|
||||
USER_AGENT = "CLI"
|
||||
USER_AGENT = 'CLI'
|
||||
|
||||
# Base Path representing the resource to be used in the requests
|
||||
RESOURCE_PATH = "/service"
|
||||
RESOURCE_PATH = '/service'
|
||||
|
||||
#
|
||||
# Table
|
||||
#
|
||||
|
||||
SERVICE_TABLE = CLIHelper::ShowTable.new(nil, self) do
|
||||
column :ID, "ID", :size=>10 do |d|
|
||||
d["ID"]
|
||||
column :ID, 'ID', :size => 10 do |d|
|
||||
d['ID']
|
||||
end
|
||||
|
||||
column :USER, "Username", :left, :size=>15 do |d|
|
||||
d["UNAME"]
|
||||
column :USER, 'Username', :left, :size => 15 do |d|
|
||||
d['UNAME']
|
||||
end
|
||||
|
||||
column :GROUP, "Group", :left, :size=>15 do |d|
|
||||
d["GNAME"]
|
||||
column :GROUP, 'Group', :left, :size => 15 do |d|
|
||||
d['GNAME']
|
||||
end
|
||||
|
||||
column :NAME, "Name", :size=>25, :left=>true do |d|
|
||||
d["NAME"]
|
||||
column :NAME, 'Name', :size => 25, :left => true do |d|
|
||||
d['NAME']
|
||||
end
|
||||
|
||||
column :STATE, "State", :size=>11, :left=>true do |d|
|
||||
Service.state_str(d["TEMPLATE"]["BODY"]['state'])
|
||||
column :STATE, 'State', :size => 11, :left => true do |d|
|
||||
Service.state_str(d['TEMPLATE']['BODY']['state'])
|
||||
end
|
||||
|
||||
default :ID, :USER, :GROUP, :NAME, :STATE
|
||||
end
|
||||
|
||||
NODE_TABLE = CLIHelper::ShowTable.new(nil, self) do
|
||||
column :VM_ID, "ONE identifier for Virtual Machine", :size=>6 do |d|
|
||||
st = ""
|
||||
column :VM_ID, 'ONE identifier for Virtual Machine', :size => 6 do |d|
|
||||
st = ''
|
||||
if d['scale_up']
|
||||
st << "\u2191 "
|
||||
st << '\u2191 '
|
||||
elsif d['disposed']
|
||||
st << "\u2193 "
|
||||
st << '\u2193 '
|
||||
end
|
||||
|
||||
if d['vm_info'].nil?
|
||||
st << d['deploy_id'].to_s
|
||||
else
|
||||
st << d['vm_info']['VM']["ID"]
|
||||
st << d['vm_info']['VM']['ID']
|
||||
end
|
||||
|
||||
st
|
||||
end
|
||||
|
||||
column :NAME, "Name of the Virtual Machine", :left,
|
||||
:size=>23 do |d|
|
||||
column :NAME, 'Name of the Virtual Machine', :left,
|
||||
:size => 23 do |d|
|
||||
if !d['vm_info'].nil?
|
||||
if d['vm_info']['VM']["RESCHED"] == "1"
|
||||
"*#{d["NAME"]}"
|
||||
if d['vm_info']['VM']['RESCHED'] == '1'
|
||||
"*#{d['NAME']}"
|
||||
else
|
||||
d['vm_info']['VM']["NAME"]
|
||||
d['vm_info']['VM']['NAME']
|
||||
end
|
||||
else
|
||||
""
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
column :USER, "Username of the Virtual Machine owner", :left,
|
||||
:size=>8 do |d|
|
||||
column :USER, 'Username of the Virtual Machine owner', :left,
|
||||
:size => 8 do |d|
|
||||
if !d['vm_info'].nil?
|
||||
d['vm_info']['VM']["UNAME"]
|
||||
d['vm_info']['VM']['UNAME']
|
||||
else
|
||||
""
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
column :GROUP, "Group of the Virtual Machine", :left,
|
||||
:size=>8 do |d|
|
||||
column :GROUP, 'Group of the Virtual Machine', :left,
|
||||
:size => 8 do |d|
|
||||
if !d['vm_info'].nil?
|
||||
d['vm_info']['VM']["GNAME"]
|
||||
d['vm_info']['VM']['GNAME']
|
||||
else
|
||||
""
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
column :STAT, "Actual status", :size=>4 do |d,e|
|
||||
column :STAT, 'Actual status', :size => 4 do |d, _|
|
||||
if !d['vm_info'].nil?
|
||||
OneVMHelper.state_to_str(d['vm_info']['VM']["STATE"], d['vm_info']['VM']["LCM_STATE"])
|
||||
OneVMHelper.state_to_str(d['vm_info']['VM']['STATE'],
|
||||
d['vm_info']['VM']['LCM_STATE'])
|
||||
else
|
||||
""
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
column :UCPU, "CPU percentage used by the VM", :size=>4 do |d|
|
||||
column :UCPU, 'CPU percentage used by the VM', :size => 4 do |d|
|
||||
if !d['vm_info'].nil?
|
||||
d['vm_info']['VM']["CPU"]
|
||||
d['vm_info']['VM']['CPU']
|
||||
else
|
||||
""
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
column :UMEM, "Memory used by the VM", :size=>7 do |d|
|
||||
column :UMEM, 'Memory used by the VM', :size => 7 do |d|
|
||||
if !d['vm_info'].nil?
|
||||
OpenNebulaHelper.unit_to_str(d['vm_info']['VM']["MEMORY"].to_i, {})
|
||||
OpenNebulaHelper.unit_to_str(d['vm_info']['VM']['MEMORY'].to_i, {})
|
||||
else
|
||||
""
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
column :HOST, "Host where the VM is running", :left, :size=>20 do |d|
|
||||
column :HOST, 'Host where the VM is running', :left, :size => 20 do |d|
|
||||
if !d['vm_info'].nil?
|
||||
if d['vm_info']['VM']['HISTORY_RECORDS'] && d['vm_info']['VM']['HISTORY_RECORDS']['HISTORY']
|
||||
state_str = VirtualMachine::VM_STATE[d['vm_info']['VM']['STATE'].to_i]
|
||||
if %w{ACTIVE SUSPENDED}.include? state_str
|
||||
history = if d['vm_info']['VM']['HISTORY_RECORDS']['HISTORY'].instance_of?(Array)
|
||||
d['vm_info']['VM']['HISTORY_RECORDS']['HISTORY'].last
|
||||
else
|
||||
d['vm_info']['VM']['HISTORY_RECORDS']['HISTORY']
|
||||
end
|
||||
|
||||
if d['vm_info']['VM']['HISTORY_RECORDS'] &&
|
||||
d['vm_info']['VM']['HISTORY_RECORDS']['HISTORY']
|
||||
state_str =
|
||||
VirtualMachine::VM_STATE[d['vm_info']['VM']['STATE'].to_i]
|
||||
history = d['vm_info']['VM']['HISTORY_RECORDS']['HISTORY']
|
||||
if %w[ACTIVE SUSPENDED].include? state_str
|
||||
history = history.last if history.instance_of?(Array)
|
||||
history['HOSTNAME']
|
||||
end
|
||||
end
|
||||
else
|
||||
""
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
column :TIME, "Time since the VM was submitted", :size=>10 do |d|
|
||||
column :TIME, 'Time since the VM was submitted', :size => 10 do |d|
|
||||
if !d['vm_info'].nil?
|
||||
stime = d['vm_info']['VM']["STIME"].to_i
|
||||
etime = d['vm_info']['VM']["ETIME"]=="0" ? Time.now.to_i : d['vm_info']['VM']["ETIME"].to_i
|
||||
dtime = etime-stime
|
||||
stime = d['vm_info']['VM']['STIME'].to_i
|
||||
if d['vm_info']['VM']['ETIME'] == '0'
|
||||
etime = Time.now.to_i
|
||||
else
|
||||
etime = d['vm_info']['VM']['ETIME'].to_i
|
||||
end
|
||||
dtime = etime - stime
|
||||
OpenNebulaHelper.period_to_str(dtime, false)
|
||||
else
|
||||
""
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
@@ -176,19 +179,18 @@ end
|
||||
|
||||
# List the services. This method is used in top and list commands
|
||||
# @param [Service::Client] client
|
||||
# @param [Array] args
|
||||
# @param [Hash] options
|
||||
# @return [[Integer, String], Integer] Returns the exit_code and optionally
|
||||
# a String to be printed
|
||||
def list_services(client, args, options)
|
||||
def list_services(client, options)
|
||||
response = client.get(RESOURCE_PATH)
|
||||
|
||||
if CloudClient::is_error?(response)
|
||||
if CloudClient.is_error?(response)
|
||||
[response.code.to_i, response.to_s]
|
||||
else
|
||||
#[0,response.body]
|
||||
# [0,response.body]
|
||||
if options[:json]
|
||||
[0,response.body]
|
||||
[0, response.body]
|
||||
else
|
||||
array_list = JSON.parse(response.body)
|
||||
SERVICE_TABLE.show(array_list['DOCUMENT_POOL']['DOCUMENT'])
|
||||
@@ -206,73 +208,92 @@ end
|
||||
def show_service(client, args, options)
|
||||
response = client.get("#{RESOURCE_PATH}/#{args[0]}")
|
||||
|
||||
if CloudClient::is_error?(response)
|
||||
if CloudClient.is_error?(response)
|
||||
[response.code.to_i, response.to_s]
|
||||
else
|
||||
#[0,response.body]
|
||||
# [0,response.body]
|
||||
if options[:json]
|
||||
[0,response.body]
|
||||
[0, response.body]
|
||||
else
|
||||
str="%-20s: %-20s"
|
||||
str_h1="%-80s"
|
||||
str = '%-20s: %-20s'
|
||||
str_h1 = '%-80s'
|
||||
|
||||
document_hash = JSON.parse(response.body)
|
||||
template = document_hash['DOCUMENT']['TEMPLATE']['BODY']
|
||||
str_header = "SERVICE #{document_hash['DOCUMENT']['ID']} "\
|
||||
'INFORMATION'
|
||||
CLIHelper.print_header(str_h1 % str_header)
|
||||
|
||||
CLIHelper.print_header(str_h1 % "SERVICE #{document_hash['DOCUMENT']['ID']} INFORMATION")
|
||||
puts format(str, ['ID', document_hash['DOCUMENT']['ID']])
|
||||
puts format(str, ['NAME', document_hash['DOCUMENT']['NAME']])
|
||||
puts format(str, ['USER', document_hash['DOCUMENT']['UNAME']])
|
||||
puts format(str, ['GROUP', document_hash['DOCUMENT']['GNAME']])
|
||||
|
||||
puts str % ["ID", document_hash['DOCUMENT']['ID']]
|
||||
puts str % ["NAME", document_hash['DOCUMENT']['NAME']]
|
||||
puts str % ["USER", document_hash['DOCUMENT']['UNAME']]
|
||||
puts str % ["GROUP",document_hash['DOCUMENT']['GNAME']]
|
||||
|
||||
puts str % ["STRATEGY", template['deployment']]
|
||||
puts str % ["SERVICE STATE", Service.state_str(template['state'])]
|
||||
puts str % ["SHUTDOWN", template['shutdown_action']] if template['shutdown_action']
|
||||
puts format(str, ['STRATEGY', template['deployment']])
|
||||
puts format(str,
|
||||
['SERVICE STATE', Service.state_str(template['state'])])
|
||||
if template['shutdown_action']
|
||||
puts format(str, ['SHUTDOWN', template['shutdown_action']])
|
||||
end
|
||||
|
||||
puts
|
||||
|
||||
CLIHelper.print_header(str_h1 % "PERMISSIONS",false)
|
||||
CLIHelper.print_header(str_h1 % 'PERMISSIONS', false)
|
||||
|
||||
["OWNER", "GROUP", "OTHER"].each { |e|
|
||||
mask = "---"
|
||||
mask[0] = "u" if document_hash['DOCUMENT']['PERMISSIONS']["#{e}_U"] == "1"
|
||||
mask[1] = "m" if document_hash['DOCUMENT']['PERMISSIONS']["#{e}_M"] == "1"
|
||||
mask[2] = "a" if document_hash['DOCUMENT']['PERMISSIONS']["#{e}_A"] == "1"
|
||||
%w[OWNER GROUP OTHER].each do |e|
|
||||
mask = '---'
|
||||
permissions_hash = document_hash['DOCUMENT']['PERMISSIONS']
|
||||
mask[0] = 'u' if permissions_hash["#{e}_U"] == '1'
|
||||
mask[1] = 'm' if permissions_hash["#{e}_M"] == '1'
|
||||
mask[2] = 'a' if permissions_hash["#{e}_A"] == '1'
|
||||
|
||||
puts str % [e, mask]
|
||||
}
|
||||
puts format(str, [e, mask])
|
||||
end
|
||||
|
||||
puts
|
||||
|
||||
template['roles'].each {|role|
|
||||
template['roles'].each do |role|
|
||||
CLIHelper.print_header("ROLE #{role['name']}", false)
|
||||
|
||||
puts str % ["ROLE STATE", Role.state_str(role['state'])]
|
||||
puts str % ["PARENTS", role['parents'].join(', ')] if role['parents']
|
||||
puts str % ["VM TEMPLATE", role['vm_template']]
|
||||
puts str % ["CARDINALITY", role['cardinality']]
|
||||
puts str % ["MIN VMS", role['min_vms']] if role['min_vms']
|
||||
puts str % ["MAX VMS", role['max_vms']] if role['max_vms']
|
||||
puts str % ["COOLDOWN", "#{role['cooldown']}s"] if role['cooldown']
|
||||
puts str % ["SHUTDOWN", role['shutdown_action']] if role['shutdown_action']
|
||||
puts format(str, ['ROLE STATE', Role.state_str(role['state'])])
|
||||
if role['parents']
|
||||
puts format(str, ['PARENTS', role['parents'].join(', ')])
|
||||
end
|
||||
puts format(str, ['VM TEMPLATE', role['vm_template']])
|
||||
puts format(str, ['CARDINALITY', role['cardinality']])
|
||||
if role['min_vms']
|
||||
puts format(str, ['MIN VMS', role['min_vms']])
|
||||
end
|
||||
if role['max_vms']
|
||||
puts format(str, ['MAX VMS', role['max_vms']])
|
||||
end
|
||||
if role['coolddown']
|
||||
puts format(str, ['COOLDOWN', "#{role['cooldown']}s"])
|
||||
end
|
||||
if role['shutdown_action']
|
||||
puts format(str, ['SHUTDOWN', role['shutdown_action']])
|
||||
end
|
||||
|
||||
puts "NODES INFORMATION"
|
||||
puts 'NODES INFORMATION'
|
||||
NODE_TABLE.show(role['nodes'])
|
||||
|
||||
if !role['elasticity_policies'].nil? && role['elasticity_policies'].size > 0 || !role['scheduled_policies'].nil? && role['scheduled_policies'].size > 0
|
||||
if !role['elasticity_policies'].nil? &&
|
||||
!role['elasticity_policies'].empty? ||
|
||||
!role['scheduled_policies'].nil? &&
|
||||
!role['scheduled_policies'].emtpty?
|
||||
puts
|
||||
puts "ELASTICITY RULES"
|
||||
puts 'ELASTICITY RULES'
|
||||
|
||||
if role['elasticity_policies'] && role['elasticity_policies'].size > 0
|
||||
if role['elasticity_policies'] &&
|
||||
!role['elasticity_policies'].emtpty?
|
||||
puts
|
||||
# puts "ELASTICITY POLICIES"
|
||||
# puts 'ELASTICITY POLICIES'
|
||||
CLIHelper::ShowTable.new(nil, self) do
|
||||
column :ADJUST, "", :left, :size=>12 do |d|
|
||||
column :ADJUST, '', :left, :size => 12 do |d|
|
||||
adjust_str(d)
|
||||
end
|
||||
|
||||
column :EXPRESSION, "", :left, :size=>48 do |d|
|
||||
column :EXPRESSION, '', :left, :size => 48 do |d|
|
||||
if !d['expression_evaluated'].nil?
|
||||
d['expression_evaluated']
|
||||
else
|
||||
@@ -280,19 +301,20 @@ def show_service(client, args, options)
|
||||
end
|
||||
end
|
||||
|
||||
column :'EVALS', "", :right, :size=>5 do |d|
|
||||
column :EVALS, '', :right, :size => 5 do |d|
|
||||
if d['period_number']
|
||||
"#{d['true_evals'].to_i}/#{d['period_number']}"
|
||||
"#{d['true_evals'].to_i}/"\
|
||||
"#{d['period_number']}"
|
||||
else
|
||||
"-"
|
||||
'-'
|
||||
end
|
||||
end
|
||||
|
||||
column :PERIOD, "", :size=>6 do |d|
|
||||
d['period'] ? "#{d['period']}s" : '-'
|
||||
column :PERIOD, '', :size => 6 do |d|
|
||||
d['period'] ? "#{d['period']}s" : '-'
|
||||
end
|
||||
|
||||
column :COOL, "", :size=>5 do |d|
|
||||
column :COOL, '', :size => 5 do |d|
|
||||
d['cooldown'] ? "#{d['cooldown']}s" : '-'
|
||||
end
|
||||
|
||||
@@ -300,15 +322,16 @@ def show_service(client, args, options)
|
||||
end.show([role['elasticity_policies']].flatten, {})
|
||||
end
|
||||
|
||||
if role['scheduled_policies'] && role['scheduled_policies'].size > 0
|
||||
if role['scheduled_policies'] &&
|
||||
!role['scheduled_policies'].empty?
|
||||
puts
|
||||
# puts "SCHEDULED POLICIES"
|
||||
# puts 'SCHEDULED POLICIES'
|
||||
CLIHelper::ShowTable.new(nil, self) do
|
||||
column :ADJUST, "", :left, :size=>12 do |d|
|
||||
column :ADJUST, '', :left, :size => 12 do |d|
|
||||
adjust_str(d)
|
||||
end
|
||||
|
||||
column :TIME, "", :left, :size=>67 do |d|
|
||||
column :TIME, '', :left, :size => 67 do |d|
|
||||
if d['start_time']
|
||||
Time.parse(d['start_time']).to_s
|
||||
else
|
||||
@@ -322,17 +345,17 @@ def show_service(client, args, options)
|
||||
end
|
||||
|
||||
puts
|
||||
}
|
||||
end
|
||||
|
||||
puts
|
||||
|
||||
CLIHelper.print_header(str_h1 % "LOG MESSAGES",false)
|
||||
CLIHelper.print_header(str_h1 % 'LOG MESSAGES', false)
|
||||
|
||||
if template['log']
|
||||
template['log'].each { |log|
|
||||
t = Time.at(log['timestamp']).strftime("%m/%d/%y %H:%M")
|
||||
template['log'].each do |log|
|
||||
t = Time.at(log['timestamp']).strftime('%m/%d/%y %H:%M')
|
||||
puts "#{t} [#{log['severity']}] #{log['message']}"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
0
|
||||
@@ -341,7 +364,7 @@ def show_service(client, args, options)
|
||||
end
|
||||
|
||||
def adjust_str(policy)
|
||||
sign = policy['adjust'].to_i >= 0 ? "+" : "-"
|
||||
policy['adjust'].to_i >= 0 ? sign = '+' : sign = '-'
|
||||
adjust = policy['adjust'].to_i.abs
|
||||
|
||||
case policy['type']
|
||||
@@ -363,8 +386,8 @@ end
|
||||
# Commands
|
||||
#
|
||||
|
||||
cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
usage "`oneflow` <command> [<args>] [<options>]"
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
usage '`oneflow` <command> [<args>] [<options>]'
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
|
||||
set :option, Service::DEFAULT_OPTIONS
|
||||
@@ -374,27 +397,29 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
#
|
||||
# Formatters for arguments
|
||||
#
|
||||
set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, "GROUP")
|
||||
set :format, :groupid, OpenNebulaHelper.rname_to_id_desc('GROUP') do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, 'GROUP')
|
||||
end
|
||||
|
||||
set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, "USER")
|
||||
set :format, :userid, OpenNebulaHelper.rname_to_id_desc('USER') do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, 'USER')
|
||||
end
|
||||
|
||||
set :format, :service_id, Service.rname_to_id_desc("SERVICE") do |arg|
|
||||
Service.rname_to_id(arg, "SERVICE")
|
||||
set :format, :service_id, Service.rname_to_id_desc('SERVICE') do |arg|
|
||||
Service.rname_to_id(arg, 'SERVICE')
|
||||
end
|
||||
|
||||
set :format, :service_id_list, Service.list_to_id_desc("SERVICE") do |arg|
|
||||
Service.list_to_id(arg, "SERVICE")
|
||||
set :format, :service_id_list, Service.list_to_id_desc('SERVICE') do |arg|
|
||||
Service.list_to_id(arg, 'SERVICE')
|
||||
end
|
||||
|
||||
set :format, :vm_action, "Actions supported: #{Role::SCHEDULE_ACTIONS.join(', ')}" do |arg|
|
||||
set :format, :vm_action,
|
||||
'Actions supported: #{Role::SCHEDULE_ACTIONS.join(', ')}' do |arg|
|
||||
if Role::SCHEDULE_ACTIONS.include?(arg)
|
||||
[0, arg]
|
||||
else
|
||||
[-1, "Action #{arg} is not supported. Actions supported: #{Role::SCHEDULE_ACTIONS.join(', ')}"]
|
||||
[-1, "Action #{arg} is not supported. Actions supported: "\
|
||||
"#{Role::SCHEDULE_ACTIONS.join(', ')}"]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -408,12 +433,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
command :list, list_desc, :options => Service::JSON_FORMAT do
|
||||
client = Service::Client.new(
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT)
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT
|
||||
)
|
||||
|
||||
list_services(client, args, options)
|
||||
list_services(client, options)
|
||||
end
|
||||
|
||||
#
|
||||
@@ -426,10 +452,11 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
command :show, show_desc, :service_id, :options => Service::JSON_FORMAT do
|
||||
client = Service::Client.new(
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT)
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT
|
||||
)
|
||||
|
||||
show_service(client, args, options)
|
||||
end
|
||||
@@ -444,37 +471,34 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :top, top_desc, [:service_id, nil],
|
||||
:options => [Service::JSON_FORMAT, Service::TOP, CLIHelper::DELAY] do
|
||||
:options => [Service::JSON_FORMAT,
|
||||
Service::TOP,
|
||||
CLIHelper::DELAY] do
|
||||
client = Service::Client.new(
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT)
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT
|
||||
)
|
||||
|
||||
delay=options[:delay] ? options[:delay] : 3
|
||||
options[:delay] ? delay = options[:delay] : delay = 3
|
||||
|
||||
begin
|
||||
while true
|
||||
loop do
|
||||
CLIHelper.scr_cls
|
||||
CLIHelper.scr_move(0,0)
|
||||
CLIHelper.scr_move(0, 0)
|
||||
|
||||
if args[0]
|
||||
rc, message = show_service(client, args, options)
|
||||
|
||||
if rc != 0
|
||||
raise message
|
||||
end
|
||||
else
|
||||
rc, message = list_services(client, args, options)
|
||||
|
||||
if rc != 0
|
||||
raise message
|
||||
end
|
||||
rc, message = list_services(client, options)
|
||||
end
|
||||
|
||||
raise message if rc
|
||||
|
||||
sleep delay
|
||||
end
|
||||
rescue Exception => e
|
||||
rescue StandardError => e
|
||||
puts e.message
|
||||
-1
|
||||
end
|
||||
@@ -490,14 +514,15 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
command :delete, delete_desc, [:range, :service_id_list] do
|
||||
client = Service::Client.new(
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT)
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT
|
||||
)
|
||||
|
||||
Service.perform_actions(args[0]) { |service_id|
|
||||
Service.perform_actions(args[0]) do |service_id|
|
||||
client.delete("#{RESOURCE_PATH}/#{service_id}")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
@@ -511,16 +536,17 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
command :shutdown, shutdown_desc, [:range, :service_id_list] do
|
||||
client = Service::Client.new(
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT)
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT
|
||||
)
|
||||
|
||||
Service.perform_actions(args[0]) { |service_id|
|
||||
Service.perform_actions(args[0]) do |service_id|
|
||||
json_action = Service.build_json_action('shutdown')
|
||||
|
||||
client.post("#{RESOURCE_PATH}/#{service_id}/action", json_action)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
@@ -538,16 +564,17 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
command :recover, recover_desc, [:range, :service_id_list] do
|
||||
client = Service::Client.new(
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT)
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT
|
||||
)
|
||||
|
||||
Service.perform_actions(args[0]) { |service_id|
|
||||
Service.perform_actions(args[0]) do |service_id|
|
||||
json_action = Service.build_json_action('recover')
|
||||
|
||||
client.post("#{RESOURCE_PATH}/#{service_id}/action", json_action)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
@@ -558,27 +585,29 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Scale a role to the given cardinality
|
||||
EOT
|
||||
|
||||
command :'scale', scale_desc, :service_id, :role_name,
|
||||
:cardinality, :options => [Service::FORCE] do
|
||||
command :scale, scale_desc, :service_id, :role_name,
|
||||
:cardinality, :options => [Service::FORCE] do
|
||||
client = Service::Client.new(
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT)
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT
|
||||
)
|
||||
|
||||
if !(args[2] =~ /^\d+$/)
|
||||
puts "Cardinality must be an integer number"
|
||||
exit -1
|
||||
if args[2] !~ /^\d+$/
|
||||
puts 'Cardinality must be an integer number'
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
exit_code = 0
|
||||
|
||||
json = "{ \"cardinality\" : #{args[2]},\n"<<
|
||||
json = "{ \"cardinality\" : #{args[2]},\n" \
|
||||
" \"force\" : #{options[:force] == true} }"
|
||||
|
||||
response = client.put("#{RESOURCE_PATH}/#{args[0]}/role/#{args[1]}", json)
|
||||
response = client
|
||||
.put("#{RESOURCE_PATH}/#{args[0]}/role/#{args[1]}", json)
|
||||
|
||||
if CloudClient::is_error?(response)
|
||||
if CloudClient.is_error?(response)
|
||||
puts response.to_s
|
||||
exit_code = response.code.to_i
|
||||
end
|
||||
@@ -592,41 +621,44 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
command :chgrp, chgrp_desc, [:range, :service_id_list], :groupid do
|
||||
client = Service::Client.new(
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT)
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT
|
||||
)
|
||||
|
||||
Service.perform_actions(args[0]) { |service_id|
|
||||
params = Hash.new
|
||||
Service.perform_actions(args[0]) do |service_id|
|
||||
params = {}
|
||||
params['group_id'] = args[1].to_i
|
||||
|
||||
json_action = Service.build_json_action('chgrp', params)
|
||||
|
||||
client.post("#{RESOURCE_PATH}/#{service_id}/action", json_action)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
chown_desc = <<-EOT.unindent
|
||||
Changes the service owner and group
|
||||
EOT
|
||||
|
||||
command :chown, chown_desc, [:range, :service_id_list], :userid, [:groupid, nil] do
|
||||
command :chown, chown_desc,
|
||||
[:range, :service_id_list], :userid, [:groupid, nil] do
|
||||
client = Service::Client.new(
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT)
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT
|
||||
)
|
||||
|
||||
Service.perform_actions(args[0]) { |service_id|
|
||||
params = Hash.new
|
||||
Service.perform_actions(args[0]) do |service_id|
|
||||
params = {}
|
||||
params['owner_id'] = args[1]
|
||||
params['group_id'] = args[2] if args[2]
|
||||
|
||||
json_action = Service.build_json_action('chown', params)
|
||||
|
||||
client.post("#{RESOURCE_PATH}/#{service_id}/action", json_action)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
chmod_desc = <<-EOT.unindent
|
||||
@@ -635,40 +667,43 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
command :chmod, chmod_desc, [:range, :service_id_list], :octet do
|
||||
client = Service::Client.new(
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT)
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT
|
||||
)
|
||||
|
||||
Service.perform_actions(args[0]) { |service_id|
|
||||
params = Hash.new
|
||||
Service.perform_actions(args[0]) do |service_id|
|
||||
params = {}
|
||||
params['octet'] = args[1]
|
||||
|
||||
json_action = Service.build_json_action('chmod', params)
|
||||
|
||||
client.post("#{RESOURCE_PATH}/#{service_id}/action", json_action)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
rename_desc = <<-EOT.unindent
|
||||
Renames the Service
|
||||
Renames the Service
|
||||
EOT
|
||||
|
||||
command :rename, rename_desc, :service_id, :name do
|
||||
client = Service::Client.new(
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT)
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT
|
||||
)
|
||||
|
||||
params = Hash.new
|
||||
params = {}
|
||||
params['name'] = args[1]
|
||||
|
||||
json_action = Service.build_json_action('rename', params)
|
||||
|
||||
response = client.post("#{RESOURCE_PATH}/#{args[0]}/action", json_action)
|
||||
response = client
|
||||
.post("#{RESOURCE_PATH}/#{args[0]}/action", json_action)
|
||||
|
||||
if CloudClient::is_error?(response)
|
||||
if CloudClient.is_error?(response)
|
||||
[response.code.to_i, response.to_s]
|
||||
else
|
||||
response.code.to_i
|
||||
@@ -677,26 +712,28 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
action_desc = <<-EOT.unindent
|
||||
Perform an action on all the Virtual Machines of a given role.
|
||||
Actions supported: #{Role::SCHEDULE_ACTIONS.join(",")}
|
||||
Actions supported: #{Role::SCHEDULE_ACTIONS.join(',')}
|
||||
EOT
|
||||
|
||||
command :"action", action_desc, :service_id, :role_name, :vm_action,
|
||||
:options => [Service::PERIOD, Service::NUMBER] do
|
||||
command :action, action_desc, :service_id, :role_name, :vm_action,
|
||||
:options => [Service::PERIOD, Service::NUMBER] do
|
||||
|
||||
client = Service::Client.new(
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT)
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT
|
||||
)
|
||||
|
||||
Service.perform_actions([args[0]]) { |service_id|
|
||||
params = Hash.new
|
||||
Service.perform_actions([args[0]]) do |service_id|
|
||||
params = {}
|
||||
params[:period] = options[:period].to_i if options[:period]
|
||||
params[:number] = options[:number].to_i if options[:number]
|
||||
|
||||
json_action = Service.build_json_action(args[2], params)
|
||||
|
||||
client.post("#{RESOURCE_PATH}/#{service_id}/role/#{args[1]}/action", json_action)
|
||||
}
|
||||
client.post("#{RESOURCE_PATH}/#{service_id}/role/#{args[1]}/action",
|
||||
json_action)
|
||||
end
|
||||
end
|
||||
end
|
||||
+155
-132
@@ -16,26 +16,26 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
ONE_LOCATION = ENV['ONE_LOCATION']
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
RUBY_LIB_LOCATION = '/usr/lib/one/ruby'
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+'/cli'
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
|
||||
|
||||
require 'command_parser'
|
||||
require 'opennebula/oneflow_client'
|
||||
|
||||
require 'English'
|
||||
require 'cli_helper'
|
||||
require 'one_helper'
|
||||
|
||||
require 'json'
|
||||
|
||||
USER_AGENT = "CLI"
|
||||
USER_AGENT = 'CLI'
|
||||
|
||||
# Base Path representing the resource to be used in the requests
|
||||
RESOURCE_PATH = '/service_template'
|
||||
@@ -45,26 +45,25 @@ RESOURCE_PATH = '/service_template'
|
||||
#
|
||||
|
||||
TABLE = CLIHelper::ShowTable.new(nil, self) do
|
||||
column :ID, "ID", :size=>10 do |d|
|
||||
d["ID"]
|
||||
column :ID, 'ID', :size => 10 do |d|
|
||||
d['ID']
|
||||
end
|
||||
|
||||
column :USER, "Username", :left, :size=>15 do |d|
|
||||
d["UNAME"]
|
||||
column :USER, 'Username', :left, :size => 15 do |d|
|
||||
d['UNAME']
|
||||
end
|
||||
|
||||
column :GROUP, "Group", :left, :size=>15 do |d|
|
||||
d["GNAME"]
|
||||
column :GROUP, 'Group', :left, :size => 15 do |d|
|
||||
d['GNAME']
|
||||
end
|
||||
|
||||
column :NAME, "Name", :left, :size=>37 do |d|
|
||||
d["NAME"]
|
||||
column :NAME, 'Name', :left, :size => 37 do |d|
|
||||
d['NAME']
|
||||
end
|
||||
|
||||
default :ID, :USER, :GROUP, :NAME
|
||||
end
|
||||
|
||||
|
||||
# Show the service template information. This method is used in top and
|
||||
# show commands
|
||||
# @param [Service::Client] client
|
||||
@@ -75,43 +74,45 @@ end
|
||||
def show_service_template(client, args, options)
|
||||
response = client.get("#{RESOURCE_PATH}/#{args[0]}")
|
||||
|
||||
if CloudClient::is_error?(response)
|
||||
if CloudClient.is_error?(response)
|
||||
[response.code.to_i, response.to_s]
|
||||
else
|
||||
#[0,response.body]
|
||||
# [0,response.body]
|
||||
if options[:json]
|
||||
[0,response.body]
|
||||
[0, response.body]
|
||||
else
|
||||
str="%-20s: %-20s"
|
||||
str_h1="%-80s"
|
||||
str = '%-20s: %-20s'
|
||||
str_h1 = '%-80s'
|
||||
|
||||
document_hash = JSON.parse(response.body)
|
||||
template = document_hash['DOCUMENT']['TEMPLATE']['BODY']
|
||||
|
||||
CLIHelper.print_header(str_h1 %
|
||||
"SERVICE TEMPLATE #{document_hash['DOCUMENT']['ID']} INFORMATION")
|
||||
"SERVICE TEMPLATE #{document_hash['DOCUMENT']['ID']} "\
|
||||
'INFORMATION')
|
||||
|
||||
puts str % ["ID", document_hash['DOCUMENT']['ID']]
|
||||
puts str % ["NAME", document_hash['DOCUMENT']['NAME']]
|
||||
puts str % ["USER", document_hash['DOCUMENT']['UNAME']]
|
||||
puts str % ["GROUP",document_hash['DOCUMENT']['GNAME']]
|
||||
puts format(str, ['ID', document_hash['DOCUMENT']['ID']])
|
||||
puts format(str, ['NAME', document_hash['DOCUMENT']['NAME']])
|
||||
puts format(str, ['USER', document_hash['DOCUMENT']['UNAME']])
|
||||
puts format(str, ['GROUP', document_hash['DOCUMENT']['GNAME']])
|
||||
|
||||
puts
|
||||
|
||||
CLIHelper.print_header(str_h1 % "PERMISSIONS",false)
|
||||
CLIHelper.print_header(str_h1 % 'PERMISSIONS', false)
|
||||
|
||||
["OWNER", "GROUP", "OTHER"].each { |e|
|
||||
mask = "---"
|
||||
mask[0] = "u" if document_hash['DOCUMENT']['PERMISSIONS']["#{e}_U"] == "1"
|
||||
mask[1] = "m" if document_hash['DOCUMENT']['PERMISSIONS']["#{e}_M"] == "1"
|
||||
mask[2] = "a" if document_hash['DOCUMENT']['PERMISSIONS']["#{e}_A"] == "1"
|
||||
%w[OWNER GROUP OTHER].each do |e|
|
||||
mask = '---'
|
||||
permissions_hash = document_hash['DOCUMENT']['PERMISSIONS']
|
||||
mask[0] = 'u' if permissions_hash["#{e}_U"] == '1'
|
||||
mask[1] = 'm' if permissions_hash["#{e}_M"] == '1'
|
||||
mask[2] = 'a' if permissions_hash["#{e}_A"] == '1'
|
||||
|
||||
puts str % [e, mask]
|
||||
}
|
||||
puts format(str, [e, mask])
|
||||
end
|
||||
|
||||
puts
|
||||
|
||||
CLIHelper.print_header(str_h1 % "TEMPLATE CONTENTS",false)
|
||||
CLIHelper.print_header(str_h1 % 'TEMPLATE CONTENTS', false)
|
||||
puts JSON.pretty_generate(template)
|
||||
|
||||
0
|
||||
@@ -121,19 +122,18 @@ end
|
||||
|
||||
# List the services. This method is used in top and list commands
|
||||
# @param [Service::Client] client
|
||||
# @param [Array] args
|
||||
# @param [Hash] options
|
||||
# @return [[Integer, String], Integer] Returns the exit_code and optionally
|
||||
# a String to be printed
|
||||
def list_service_templates(client, args, options)
|
||||
def list_service_templates(client, options)
|
||||
response = client.get(RESOURCE_PATH)
|
||||
|
||||
if CloudClient::is_error?(response)
|
||||
if CloudClient.is_error?(response)
|
||||
[response.code.to_i, response.to_s]
|
||||
else
|
||||
#[0,response.body]
|
||||
# [0,response.body]
|
||||
if options[:json]
|
||||
[0,response.body]
|
||||
[0, response.body]
|
||||
else
|
||||
array_list = JSON.parse(response.body)
|
||||
TABLE.show(array_list['DOCUMENT_POOL']['DOCUMENT'])
|
||||
@@ -146,8 +146,8 @@ end
|
||||
# Commands
|
||||
#
|
||||
|
||||
cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
usage "`oneflow-template` <command> [<args>] [<options>]"
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
usage '`oneflow-template` <command> [<args>] [<options>]'
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
|
||||
set :option, Service::DEFAULT_OPTIONS
|
||||
@@ -157,20 +157,22 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
#
|
||||
# Formatters for arguments
|
||||
#
|
||||
set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, "GROUP")
|
||||
set :format, :groupid, OpenNebulaHelper.rname_to_id_desc('GROUP') do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, 'GROUP')
|
||||
end
|
||||
|
||||
set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, "USER")
|
||||
set :format, :userid, OpenNebulaHelper.rname_to_id_desc('USER') do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, 'USER')
|
||||
end
|
||||
|
||||
set :format, :templateid, Service.rname_to_id_desc("SERVICE TEMPLATE") do |arg|
|
||||
Service.rname_to_id(arg, "SERVICE TEMPLATE")
|
||||
set :format, :templateid,
|
||||
Service.rname_to_id_desc('SERVICE TEMPLATE') do |arg|
|
||||
Service.rname_to_id(arg, 'SERVICE TEMPLATE')
|
||||
end
|
||||
|
||||
set :format, :templateid_list, Service.list_to_id_desc("SERVICE TEMPLATE") do |arg|
|
||||
Service.list_to_id(arg, "SERVICE TEMPLATE")
|
||||
set :format, :templateid_list,
|
||||
Service.list_to_id_desc('SERVICE TEMPLATE') do |arg|
|
||||
Service.list_to_id(arg, 'SERVICE TEMPLATE')
|
||||
end
|
||||
|
||||
#
|
||||
@@ -183,12 +185,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
command :list, list_desc, :options => Service::JSON_FORMAT do
|
||||
client = Service::Client.new(
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT)
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT
|
||||
)
|
||||
|
||||
list_service_templates(client, args, options)
|
||||
list_service_templates(client, options)
|
||||
end
|
||||
|
||||
#
|
||||
@@ -200,21 +203,24 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :top, top_desc,
|
||||
:options => [Service::JSON_FORMAT, Service::TOP, CLIHelper::DELAY] do
|
||||
:options => [Service::JSON_FORMAT,
|
||||
Service::TOP,
|
||||
CLIHelper::DELAY] do
|
||||
client = Service::Client.new(
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT)
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT
|
||||
)
|
||||
|
||||
delay=options[:delay] ? options[:delay] : 3
|
||||
options[:delay] ? delay = options[:delay] : delay = 3
|
||||
|
||||
begin
|
||||
while true
|
||||
loop do
|
||||
CLIHelper.scr_cls
|
||||
CLIHelper.scr_move(0,0)
|
||||
CLIHelper.scr_move(0, 0)
|
||||
|
||||
rc, message = list_service_templates(client, args, options)
|
||||
rc, message = list_service_templates(client, options)
|
||||
|
||||
if rc != 0
|
||||
raise message
|
||||
@@ -222,7 +228,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
sleep delay
|
||||
end
|
||||
rescue Exception => e
|
||||
rescue StandardError => e
|
||||
puts e.message
|
||||
-1
|
||||
end
|
||||
@@ -238,18 +244,19 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
command :create, create_desc, :file, :options => Service::JSON_FORMAT do
|
||||
client = Service::Client.new(
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT)
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT
|
||||
)
|
||||
|
||||
response = client.post(RESOURCE_PATH, File.read(args[0]))
|
||||
|
||||
if CloudClient::is_error?(response)
|
||||
if CloudClient.is_error?(response)
|
||||
[response.code.to_i, response.to_s]
|
||||
else
|
||||
if options[:json]
|
||||
[0,response.body]
|
||||
[0, response.body]
|
||||
else
|
||||
template = JSON.parse(response.body)
|
||||
puts "ID: #{template['DOCUMENT']['ID']}"
|
||||
@@ -268,10 +275,11 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
command :show, show_desc, :templateid, :options => Service::JSON_FORMAT do
|
||||
client = Service::Client.new(
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT)
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT
|
||||
)
|
||||
|
||||
show_service_template(client, args, options)
|
||||
end
|
||||
@@ -286,14 +294,15 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
command :delete, delete_desc, [:range, :templateid_list] do
|
||||
client = Service::Client.new(
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT)
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT
|
||||
)
|
||||
|
||||
Service.perform_actions(args[0]) { |template_id|
|
||||
Service.perform_actions(args[0]) do |template_id|
|
||||
client.delete("#{RESOURCE_PATH}/#{template_id}")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
@@ -307,14 +316,15 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
command :instantiate, instantiate_desc, :templateid, [:file, nil],
|
||||
:options => [Service::JSON_FORMAT, Service::TOP] do
|
||||
client = Service::Client.new(
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT)
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT
|
||||
)
|
||||
|
||||
params = Hash.new
|
||||
params = {}
|
||||
|
||||
if(args[1])
|
||||
if args[1]
|
||||
params['merge_template'] = JSON.parse(File.read(args[1]))
|
||||
end
|
||||
|
||||
@@ -322,11 +332,11 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
response = client.post("#{RESOURCE_PATH}/#{args[0]}/action", json_str)
|
||||
|
||||
if CloudClient::is_error?(response)
|
||||
if CloudClient.is_error?(response)
|
||||
[response.code.to_i, response.to_s]
|
||||
else
|
||||
if options[:json]
|
||||
[0,response.body]
|
||||
[0, response.body]
|
||||
else
|
||||
template = JSON.parse(response.body)
|
||||
puts "ID: #{template['DOCUMENT']['ID']}"
|
||||
@@ -341,41 +351,44 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
command :chgrp, chgrp_desc, [:range, :templateid_list], :groupid do
|
||||
client = Service::Client.new(
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT)
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT
|
||||
)
|
||||
|
||||
Service.perform_actions(args[0]) { |service_id|
|
||||
params = Hash.new
|
||||
Service.perform_actions(args[0]) do |service_id|
|
||||
params = {}
|
||||
params['group_id'] = args[1].to_i
|
||||
|
||||
json_action = Service.build_json_action('chgrp', params)
|
||||
|
||||
client.post("#{RESOURCE_PATH}/#{service_id}/action", json_action)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
chown_desc = <<-EOT.unindent
|
||||
Changes the service template owner and group
|
||||
EOT
|
||||
|
||||
command :chown, chown_desc, [:range, :templateid_list], :userid, [:groupid, nil] do
|
||||
command :chown, chown_desc, [:range, :templateid_list],
|
||||
:userid, [:groupid, nil] do
|
||||
client = Service::Client.new(
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT)
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT
|
||||
)
|
||||
|
||||
Service.perform_actions(args[0]) { |service_id|
|
||||
params = Hash.new
|
||||
Service.perform_actions(args[0]) do |service_id|
|
||||
params = {}
|
||||
params['owner_id'] = args[1]
|
||||
params['group_id'] = args[2] if args[2]
|
||||
|
||||
json_action = Service.build_json_action('chown', params)
|
||||
|
||||
client.post("#{RESOURCE_PATH}/#{service_id}/action", json_action)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
chmod_desc = <<-EOT.unindent
|
||||
@@ -384,19 +397,20 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
command :chmod, chmod_desc, [:range, :templateid_list], :octet do
|
||||
client = Service::Client.new(
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT)
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT
|
||||
)
|
||||
|
||||
Service.perform_actions(args[0]) { |service_id|
|
||||
params = Hash.new
|
||||
Service.perform_actions(args[0]) do |service_id|
|
||||
params = {}
|
||||
params['octet'] = args[1]
|
||||
|
||||
json_action = Service.build_json_action('chmod', params)
|
||||
|
||||
client.post("#{RESOURCE_PATH}/#{service_id}/action", json_action)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
clone_desc = <<-EOT.unindent
|
||||
@@ -405,19 +419,21 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
command :clone, clone_desc, :templateid, :name do
|
||||
client = Service::Client.new(
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT)
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT
|
||||
)
|
||||
|
||||
params = Hash.new
|
||||
params = {}
|
||||
params['name'] = args[1]
|
||||
|
||||
json_action = Service.build_json_action('clone', params)
|
||||
|
||||
response = client.post("#{RESOURCE_PATH}/#{args[0]}/action", json_action)
|
||||
response = client.post("#{RESOURCE_PATH}/#{args[0]}/action",
|
||||
json_action)
|
||||
|
||||
if CloudClient::is_error?(response)
|
||||
if CloudClient.is_error?(response)
|
||||
[response.code.to_i, response.to_s]
|
||||
else
|
||||
if options[:json]
|
||||
@@ -436,19 +452,21 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
command :rename, rename_desc, :templateid, :name do
|
||||
client = Service::Client.new(
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT)
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT
|
||||
)
|
||||
|
||||
params = Hash.new
|
||||
params = {}
|
||||
params['name'] = args[1]
|
||||
|
||||
json_action = Service.build_json_action('rename', params)
|
||||
|
||||
response = client.post("#{RESOURCE_PATH}/#{args[0]}/action", json_action)
|
||||
response = client.post("#{RESOURCE_PATH}/#{args[0]}/action",
|
||||
json_action)
|
||||
|
||||
if CloudClient::is_error?(response)
|
||||
if CloudClient.is_error?(response)
|
||||
[response.code.to_i, response.to_s]
|
||||
else
|
||||
response.code.to_i
|
||||
@@ -466,7 +484,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
:username => options[:username],
|
||||
:password => options[:password],
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT)
|
||||
:user_agent => USER_AGENT
|
||||
)
|
||||
|
||||
if args[1]
|
||||
path = args[1]
|
||||
@@ -478,7 +497,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
response = client.get("#{RESOURCE_PATH}/#{template_id}")
|
||||
|
||||
if CloudClient::is_error?(response)
|
||||
if CloudClient.is_error?(response)
|
||||
exit_with_code response.code.to_i, response.to_s
|
||||
else
|
||||
document_hash = JSON.parse(response.body)
|
||||
@@ -487,12 +506,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
tmp << JSON.pretty_generate(template)
|
||||
tmp.flush
|
||||
|
||||
editor_path = ENV["EDITOR"] ? ENV["EDITOR"] : OpenNebulaHelper::EDITOR_PATH
|
||||
if ENV['EDITOR']
|
||||
editor_path = ENV['EDITOR']
|
||||
else
|
||||
editor_path = OpenNebulaHelper::EDITOR_PATH
|
||||
end
|
||||
system("#{editor_path} #{path}")
|
||||
|
||||
unless $?.exitstatus == 0
|
||||
puts "Editor not defined"
|
||||
exit -1
|
||||
unless $CHILD_STATUS.exitstatus.zero?
|
||||
puts 'Editor not defined'
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
tmp.close
|
||||
@@ -503,7 +526,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
t_str = File.read(path)
|
||||
response = client.put("#{RESOURCE_PATH}/#{template_id}", t_str)
|
||||
if CloudClient::is_error?(response)
|
||||
if CloudClient.is_error?(response)
|
||||
puts response.to_s
|
||||
exit_code = response.code.to_i
|
||||
end
|
||||
|
||||
+32
-30
@@ -16,22 +16,22 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
ONE_LOCATION = ENV['ONE_LOCATION']
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
RUBY_LIB_LOCATION = '/usr/lib/one/ruby'
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cli"
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
|
||||
|
||||
require 'command_parser'
|
||||
require 'one_helper/onegroup_helper'
|
||||
|
||||
cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
usage "`onegroup` <command> [<args>] [<options>]"
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
usage '`onegroup` <command> [<args>] [<options>]'
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
|
||||
helper = OneGroupHelper.new
|
||||
@@ -43,7 +43,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
########################################################################
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
|
||||
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
|
||||
|
||||
list_options = CLIHelper::OPTIONS
|
||||
list_options << OpenNebulaHelper::XML
|
||||
@@ -61,8 +61,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
helper.list_to_id(arg)
|
||||
end
|
||||
|
||||
set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, "USER")
|
||||
set :format, :userid, OpenNebulaHelper.rname_to_id_desc('USER') do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, 'USER')
|
||||
end
|
||||
|
||||
########################################################################
|
||||
@@ -89,14 +89,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
if options && options[:admin_user]
|
||||
if !options[:admin_password]
|
||||
STDERR.puts "Admin user needs password"
|
||||
STDERR.puts 'Admin user needs password'
|
||||
next -1
|
||||
end
|
||||
|
||||
admin_user=Hash.new
|
||||
admin_user = {}
|
||||
admin_user[:name] = options[:admin_user]
|
||||
admin_user[:password] = options[:admin_password]
|
||||
admin_user[:auth_driver]= options[:admin_driver] if options[:admin_driver]
|
||||
if options[:admin_driver]
|
||||
admin_user[:auth_driver] = options[:admin_driver]
|
||||
end
|
||||
|
||||
options[:group_admin] = admin_user
|
||||
end
|
||||
@@ -107,8 +109,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
elsif options[:name]
|
||||
helper.create_complete_resource(options)
|
||||
else
|
||||
STDERR.puts "Please use either a group name or command arguments."<<
|
||||
" Run onegroup create -h for more information"
|
||||
STDERR.puts 'Please use either a group name or command arguments.'\
|
||||
' Run onegroup create -h for more information'
|
||||
next -1
|
||||
end
|
||||
end
|
||||
@@ -119,8 +121,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :update, update_desc, :groupid, [:file, nil],
|
||||
:options=>OpenNebulaHelper::APPEND do
|
||||
helper.perform_action(args[0],options,"modified") do |obj|
|
||||
:options => OpenNebulaHelper::APPEND do
|
||||
helper.perform_action(args[0], options, 'modified') do |obj|
|
||||
if options[:append]
|
||||
str = OpenNebulaHelper.append_template(args[0], obj, args[1])
|
||||
else
|
||||
@@ -139,7 +141,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :delete, delete_desc, [:range, :groupid_list] do
|
||||
helper.perform_actions(args[0],options,"deleted") do |obj|
|
||||
helper.perform_actions(args[0], options, 'deleted') do |obj|
|
||||
obj.delete
|
||||
end
|
||||
end
|
||||
@@ -148,7 +150,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Lists Groups in the pool
|
||||
EOT
|
||||
|
||||
command :list, list_desc, :options=>list_options do
|
||||
command :list, list_desc, :options => list_options do
|
||||
helper.list_pool(options)
|
||||
end
|
||||
|
||||
@@ -156,9 +158,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Shows information for the given Group
|
||||
EOT
|
||||
|
||||
command :show, show_desc,[:groupid, nil], :options=>OpenNebulaHelper::XML do
|
||||
command :show, show_desc, [:groupid, nil],
|
||||
:options => OpenNebulaHelper::XML do
|
||||
group = args[0] || OpenNebula::Group::SELF
|
||||
helper.show_resource(group,options)
|
||||
helper.show_resource(group, options)
|
||||
end
|
||||
|
||||
add_admin_desc = <<-EOT.unindent
|
||||
@@ -166,7 +169,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :addadmin, add_admin_desc, [:range, :groupid_list], :userid do
|
||||
helper.perform_actions(args[0],options,"admin added") do |obj|
|
||||
helper.perform_actions(args[0], options, 'admin added') do |obj|
|
||||
obj.add_admin(args[1].to_i)
|
||||
end
|
||||
end
|
||||
@@ -176,7 +179,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :deladmin, del_admin_desc, [:range, :groupid_list], :userid do
|
||||
helper.perform_actions(args[0],options,"admin deleted") do |obj|
|
||||
helper.perform_actions(args[0], options, 'admin deleted') do |obj|
|
||||
obj.del_admin(args[1].to_i)
|
||||
end
|
||||
end
|
||||
@@ -187,12 +190,12 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :quota, quota_desc, :groupid, [:file, nil] do
|
||||
helper.perform_action(args[0], options, "modified") do |group|
|
||||
helper.perform_action(args[0], options, 'modified') do |group|
|
||||
rc = group.info
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
puts rc.message
|
||||
exit -1
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
str = OneQuotaHelper.set_quota(group, args[1])
|
||||
@@ -200,7 +203,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
puts rc.message
|
||||
exit -1
|
||||
exit(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -214,19 +217,18 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
[:file, nil] do
|
||||
batch_str = OneQuotaHelper.get_batch_quota(args[1])
|
||||
|
||||
helper.perform_actions(args[0], options, "modified") do |group|
|
||||
helper.perform_actions(args[0], options, 'modified') do |group|
|
||||
str = OneQuotaHelper.merge_quota(group, batch_str)
|
||||
|
||||
if OpenNebula.is_error?(str)
|
||||
str
|
||||
else
|
||||
rc = group.set_quota(str)
|
||||
rc = group.set_quota(str)
|
||||
rc
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
defaultquota_desc = <<-EOT.unindent
|
||||
Sets the default quota limits for the groups. If a path is not provided
|
||||
the editor will be launched to modify the current default quotas.
|
||||
@@ -235,7 +237,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
command :defaultquota, defaultquota_desc, [:file, nil] do
|
||||
system = System.new(OneGroupHelper.get_client(options))
|
||||
|
||||
default_quotas = system.get_group_quotas()
|
||||
default_quotas = system.get_group_quotas
|
||||
|
||||
if OpenNebula.is_error?(default_quotas)
|
||||
puts default_quotas.message
|
||||
|
||||
+80
-75
@@ -16,25 +16,25 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
ONE_LOCATION = ENV['ONE_LOCATION']
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
REMOTES_LOCATION="/var/lib/one/remotes/"
|
||||
RUBY_LIB_LOCATION = '/usr/lib/one/ruby'
|
||||
REMOTES_LOCATION = '/var/lib/one/remotes/'
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
REMOTES_LOCATION=ONE_LOCATION+"/var/remotes/"
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
|
||||
REMOTES_LOCATION = ONE_LOCATION + '/var/remotes/'
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cli"
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION
|
||||
$LOAD_PATH << 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>]"
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
usage '`onehost` <command> [<args>] [<options>]'
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
|
||||
helper = OneHostHelper.new
|
||||
@@ -46,49 +46,50 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
########################################################################
|
||||
# Global Options
|
||||
########################################################################
|
||||
cmd_options=CommandParser::OPTIONS-[CommandParser::VERBOSE]
|
||||
set :option, cmd_options+OpenNebulaHelper::CLIENT_OPTIONS
|
||||
cmd_options = CommandParser::OPTIONS - [CommandParser::VERBOSE]
|
||||
set :option, cmd_options + OpenNebulaHelper::CLIENT_OPTIONS
|
||||
|
||||
IM = {
|
||||
:name => "im",
|
||||
:short => "-i im_mad",
|
||||
:large => "--im im_mad" ,
|
||||
:description => "Set the information driver for the host",
|
||||
:format => String
|
||||
}
|
||||
|
||||
VMM = {
|
||||
:name => "vm",
|
||||
:short => "-v vmm_mad",
|
||||
:large => "--vm vmm_mad" ,
|
||||
:description => "Set the virtualization driver for the host",
|
||||
:format => String
|
||||
}
|
||||
|
||||
FORCE = {
|
||||
:name => "force",
|
||||
:large => "--force" ,
|
||||
:description => "Force probe upgrade in onehost sync"
|
||||
}
|
||||
|
||||
RSYNC = {
|
||||
:name => "rsync",
|
||||
:large => "--rsync" ,
|
||||
:description => "Use rsync to synchronize remotes. In case some " <<
|
||||
"probes are no longer in the fronted are deleted in the hosts." <<
|
||||
" rsync command must be installed in the frontend and nodes."
|
||||
}
|
||||
|
||||
TYPE = {
|
||||
:name => "type",
|
||||
:short => "-t remote_provider",
|
||||
:large => "--type remote_provider",
|
||||
:description => "Use type to create a host using Cloud Bursting ",
|
||||
:name => 'im',
|
||||
:short => '-i im_mad',
|
||||
:large => '--im im_mad',
|
||||
:description => 'Set the information driver for the host',
|
||||
:format => String
|
||||
}
|
||||
|
||||
CREAT_OPTIONS = [ IM, VMM, OneClusterHelper::CLUSTER, TYPE ]
|
||||
SYNC_OPTIONS = [ OneClusterHelper::CLUSTER, FORCE, RSYNC ]
|
||||
VMM = {
|
||||
:name => 'vm',
|
||||
:short => '-v vmm_mad',
|
||||
:large => '--vm vmm_mad',
|
||||
:description => 'Set the virtualization driver for the host',
|
||||
:format => String
|
||||
}
|
||||
|
||||
FORCE = {
|
||||
:name => 'force',
|
||||
:large => '--force',
|
||||
:description => 'Force probe upgrade in onehost sync'
|
||||
}
|
||||
|
||||
RSYNC = {
|
||||
:name => 'rsync',
|
||||
:large => '--rsync',
|
||||
:description => 'Use rsync to synchronize remotes. In case some '\
|
||||
'probes are no longer in the fronted ithey will be '\
|
||||
'deleted in the hosts. rsync command must be '\
|
||||
'installed in the frontend and nodes.'
|
||||
}
|
||||
|
||||
TYPE = {
|
||||
:name => 'type',
|
||||
:short => '-t remote_provider',
|
||||
:large => '--type remote_provider',
|
||||
:description => 'Use type to create a host using Cloud Bursting',
|
||||
:format => String
|
||||
}
|
||||
|
||||
CREAT_OPTIONS = [IM, VMM, OneClusterHelper::CLUSTER, TYPE]
|
||||
SYNC_OPTIONS = [OneClusterHelper::CLUSTER, FORCE, RSYNC]
|
||||
|
||||
########################################################################
|
||||
# Formatters for arguments
|
||||
@@ -110,12 +111,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Creates a new Host
|
||||
EOT
|
||||
|
||||
command :create, create_desc, :hostname, [:file, nil], :options=>CREAT_OPTIONS do
|
||||
command :create, create_desc, :hostname,
|
||||
[:file, nil], :options => CREAT_OPTIONS do
|
||||
if options[:im].nil? || options[:vm].nil?
|
||||
STDERR.puts "Drivers are mandatory to create a host:"
|
||||
STDERR.puts "\t -i information driver"
|
||||
STDERR.puts "\t -v hypervisor driver"
|
||||
exit -1
|
||||
STDERR.puts 'Drivers are mandatory to create a host:'
|
||||
STDERR.puts '\t -i information driver'
|
||||
STDERR.puts '\t -v hypervisor driver'
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
cid = options[:cluster] || ClusterPool::NONE_CLUSTER_ID
|
||||
@@ -124,7 +126,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
str = helper.set_hybrid(options[:type], args[1])
|
||||
end
|
||||
rc = host.allocate(args[0], options[:im], options[:vm], cid)
|
||||
host.update(str, true) if !OpenNebula.is_error?(rc) && !options[:type].nil?
|
||||
if !OpenNebula.is_error?(rc) && !options[:type].nil?
|
||||
host.update(str, true)
|
||||
end
|
||||
|
||||
rc
|
||||
end
|
||||
@@ -135,7 +139,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :delete, delete_desc, [:range, :hostid_list] do
|
||||
helper.perform_actions(args[0],options,"deleted") do |host|
|
||||
helper.perform_actions(args[0], options, 'deleted') do |host|
|
||||
host.delete
|
||||
end
|
||||
end
|
||||
@@ -144,8 +148,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Enables the given host, fully operational
|
||||
EOT
|
||||
|
||||
command :enable, enable_desc, [:range,:hostid_list] do
|
||||
helper.perform_actions(args[0],options,"enabled") do |host|
|
||||
command :enable, enable_desc, [:range, :hostid_list] do
|
||||
helper.perform_actions(args[0], options, 'enabled') do |host|
|
||||
host.enable
|
||||
end
|
||||
end
|
||||
@@ -157,8 +161,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
- manual deployment: enabled
|
||||
EOT
|
||||
|
||||
command :disable, disable_desc, [:range,:hostid_list] do
|
||||
helper.perform_actions(args[0],options,"disabled") do |host|
|
||||
command :disable, disable_desc, [:range, :hostid_list] do
|
||||
helper.perform_actions(args[0], options, 'disabled') do |host|
|
||||
host.disable
|
||||
end
|
||||
end
|
||||
@@ -170,8 +174,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
- manual deployment: disabled
|
||||
EOT
|
||||
|
||||
command :offline, offline_desc, [:range,:hostid_list] do
|
||||
helper.perform_actions(args[0],options,"offline") do |host|
|
||||
command :offline, offline_desc, [:range, :hostid_list] do
|
||||
helper.perform_actions(args[0], options, 'offline') do |host|
|
||||
host.offline
|
||||
end
|
||||
end
|
||||
@@ -182,8 +186,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :update, update_desc, :hostid, [:file, nil],
|
||||
:options=>OpenNebulaHelper::APPEND do
|
||||
helper.perform_action(args[0],options,"updated") do |obj|
|
||||
:options => OpenNebulaHelper::APPEND do
|
||||
helper.perform_action(args[0], options, 'updated') do |obj|
|
||||
if options[:append]
|
||||
str = OpenNebulaHelper.append_template(args[0], obj, args[1])
|
||||
else
|
||||
@@ -207,7 +211,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :sync, sync_desc, [:range, :hostid_list, nil],
|
||||
:options=>SYNC_OPTIONS do
|
||||
:options => SYNC_OPTIONS do
|
||||
helper.sync(args[0], options)
|
||||
end
|
||||
|
||||
@@ -216,8 +220,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :list, list_desc,
|
||||
:options=>CLIHelper::OPTIONS+OpenNebulaHelper::OPTIONS+
|
||||
[OpenNebulaHelper::DESCRIBE] do
|
||||
:options => CLIHelper::OPTIONS + OpenNebulaHelper::OPTIONS +
|
||||
[OpenNebulaHelper::DESCRIBE] do
|
||||
helper.list_pool(options)
|
||||
end
|
||||
|
||||
@@ -226,8 +230,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :show, show_desc, :hostid,
|
||||
:options=>OpenNebulaHelper::XML do
|
||||
helper.show_resource(args[0],options)
|
||||
:options => OpenNebulaHelper::XML do
|
||||
helper.show_resource(args[0], options)
|
||||
end
|
||||
|
||||
top_desc = <<-EOT.unindent
|
||||
@@ -235,7 +239,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :top, top_desc,
|
||||
:options=>CLIHelper::OPTIONS+OpenNebulaHelper::OPTIONS do
|
||||
:options => CLIHelper::OPTIONS + OpenNebulaHelper::OPTIONS do
|
||||
helper.list_pool(options, true)
|
||||
end
|
||||
|
||||
@@ -243,17 +247,18 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Disables the host and reschedules all the running VMs in it.
|
||||
EOT
|
||||
|
||||
command :flush, flush_desc, [:range,:hostid_list] do
|
||||
command :flush, flush_desc, [:range, :hostid_list] do
|
||||
begin
|
||||
if !ONE_LOCATION
|
||||
action = YAML.load_file("/etc/one/cli/onehost.yaml")[:default_actions][0][:flush]
|
||||
action = YAML.load_file('/etc/one/cli/onehost.yaml')
|
||||
else
|
||||
action = YAML.load_file("#{ONE_LOCATION}/etc/cli/onehost.yaml")[:default_actions][0][:flush]
|
||||
action = YAML.load_file("#{ONE_LOCATION}/etc/cli/onehost.yaml")
|
||||
end
|
||||
rescue Exception => e
|
||||
action = action[:default_actions][0][:flush]
|
||||
rescue StandardError => e
|
||||
STDERR.puts e
|
||||
end
|
||||
helper.perform_actions(args[0],options,"flush") do |host|
|
||||
helper.perform_actions(args[0], options, 'flush') do |host|
|
||||
host.flush action
|
||||
end
|
||||
end
|
||||
@@ -263,7 +268,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :rename, rename_desc, :hostid, :name do
|
||||
helper.perform_action(args[0],options,"renamed") do |o|
|
||||
helper.perform_action(args[0], options, 'renamed') do |o|
|
||||
o.rename(args[1])
|
||||
end
|
||||
end
|
||||
@@ -273,7 +278,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :importvm, importvm_desc, :hostid, :name do
|
||||
helper.perform_action(args[0], options, "imported") do |o|
|
||||
helper.perform_action(args[0], options, 'imported') do |o|
|
||||
rc = o.info
|
||||
next rc if OpenNebula.is_error?(rc)
|
||||
|
||||
|
||||
+92
-81
@@ -16,23 +16,23 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
ONE_LOCATION = ENV['ONE_LOCATION']
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
RUBY_LIB_LOCATION = '/usr/lib/one/ruby'
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cli"
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
|
||||
|
||||
require 'command_parser'
|
||||
require 'one_helper/oneimage_helper'
|
||||
require 'one_helper/onedatastore_helper'
|
||||
|
||||
cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
usage "`oneimage` <command> [<args>] [<options>]"
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
usage '`oneimage` <command> [<args>] [<options>]'
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
|
||||
helper = OneImageHelper.new
|
||||
@@ -41,34 +41,34 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
helper.set_client(options)
|
||||
end
|
||||
|
||||
USE={
|
||||
:name => "use",
|
||||
:large => "--use",
|
||||
:description => "lock use actions"
|
||||
USE = {
|
||||
:name => 'use',
|
||||
:large => '--use',
|
||||
:description => 'lock use actions'
|
||||
}
|
||||
|
||||
MANAGE={
|
||||
:name => "manage",
|
||||
:large => "--manage",
|
||||
:description => "lock manage actions"
|
||||
MANAGE = {
|
||||
:name => 'manage',
|
||||
:large => '--manage',
|
||||
:description => 'lock manage actions'
|
||||
}
|
||||
|
||||
ADMIN={
|
||||
:name => "admin",
|
||||
:large => "--admin",
|
||||
:description => "lock admin actions"
|
||||
ADMIN = {
|
||||
:name => 'admin',
|
||||
:large => '--admin',
|
||||
:description => 'lock admin actions'
|
||||
}
|
||||
|
||||
ALL={
|
||||
:name => "all",
|
||||
:large => "--all",
|
||||
:description => "lock all actions"
|
||||
ALL = {
|
||||
:name => 'all',
|
||||
:large => '--all',
|
||||
:description => 'lock all actions'
|
||||
}
|
||||
|
||||
########################################################################
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
|
||||
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
|
||||
|
||||
list_options = CLIHelper::OPTIONS
|
||||
list_options << OpenNebulaHelper::XML
|
||||
@@ -80,12 +80,12 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
########################################################################
|
||||
# Formatters for arguments
|
||||
########################################################################
|
||||
set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, "GROUP")
|
||||
set :format, :groupid, OpenNebulaHelper.rname_to_id_desc('GROUP') do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, 'GROUP')
|
||||
end
|
||||
|
||||
set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, "USER")
|
||||
set :format, :userid, OpenNebulaHelper.rname_to_id_desc('USER') do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, 'USER')
|
||||
end
|
||||
|
||||
set :format, :imageid, OneImageHelper.to_id_desc do |arg|
|
||||
@@ -100,13 +100,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
helper.filterflag_to_i(arg)
|
||||
end
|
||||
|
||||
format(:type, "Image type: #{Image::IMAGE_TYPES.join(", ")}") do |arg|
|
||||
type=arg.strip.upcase
|
||||
format(:type, "Image type: #{Image::IMAGE_TYPES.join(', ')}") do |arg|
|
||||
type = arg.strip.upcase
|
||||
if Image::IMAGE_TYPES.include? type
|
||||
[0, type]
|
||||
else
|
||||
[1, "Image type not supported. Must be "<<
|
||||
Image::IMAGE_TYPES.join(", ")<<"."]
|
||||
[1, 'Image type not supported. Must be ' <<
|
||||
Image::IMAGE_TYPES.join(', ') << '.']
|
||||
end
|
||||
end
|
||||
|
||||
@@ -138,27 +138,33 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
EOT
|
||||
|
||||
command :create, create_desc, [:file, nil], :options=>CREATE_OPTIONS +
|
||||
OneImageHelper::TEMPLATE_OPTIONS do
|
||||
command :create,
|
||||
create_desc,
|
||||
[:file, nil],
|
||||
:options => CREATE_OPTIONS + OneImageHelper::TEMPLATE_OPTIONS do
|
||||
|
||||
if options[:datastore].nil? && !options[:dry]
|
||||
STDERR.puts "Datastore to save the image is mandatory: "
|
||||
STDERR.puts "\t -d datastore_id"
|
||||
exit -1
|
||||
STDERR.puts 'Datastore to save the image is mandatory: '
|
||||
STDERR.puts '\t -d datastore_id'
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
check_capacity = options[:no_check_capacity].nil? ? false : true;
|
||||
if options[:no_check_capacity].nil?
|
||||
check_capacity = false
|
||||
else
|
||||
check_capacity = true
|
||||
end
|
||||
|
||||
if args[0] && OpenNebulaHelper.create_template_options_used?(options)
|
||||
STDERR.puts "You can not use both template file and template"<<
|
||||
" creation options."
|
||||
STDERR.puts 'You can not use both template file and template' \
|
||||
' creation options.'
|
||||
next -1
|
||||
end
|
||||
|
||||
helper.create_resource(options) do |image|
|
||||
begin
|
||||
if args[0]
|
||||
template=File.read(args[0])
|
||||
template = File.read(args[0])
|
||||
else
|
||||
res = OneImageHelper.create_image_template(options)
|
||||
|
||||
@@ -176,9 +182,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
end
|
||||
|
||||
image.allocate(template, options[:datastore], check_capacity)
|
||||
rescue => e
|
||||
rescue StandardError => e
|
||||
STDERR.puts e.messsage
|
||||
exit -1
|
||||
exit(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -188,8 +194,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :clone, clone_desc, :imageid, :name,
|
||||
:options=>[OneDatastoreHelper::DATASTORE] do
|
||||
helper.perform_action(args[0],options,"cloned") do |image|
|
||||
:options => [OneDatastoreHelper::DATASTORE] do
|
||||
helper.perform_action(args[0], options, 'cloned') do |image|
|
||||
ds_id = options[:datastore] || -1 # -1 clones to self
|
||||
res = image.clone(args[1], ds_id)
|
||||
|
||||
@@ -197,7 +203,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
puts "ID: #{res}"
|
||||
else
|
||||
puts res.message
|
||||
exit -1
|
||||
exit(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -207,7 +213,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :delete, delete_desc, [:range, :imageid_list] do
|
||||
helper.perform_actions(args[0],options,"deleted") do |image|
|
||||
helper.perform_actions(args[0], options, 'deleted') do |image|
|
||||
image.delete
|
||||
end
|
||||
end
|
||||
@@ -219,8 +225,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
one VM instance at a time.
|
||||
EOT
|
||||
|
||||
command :persistent, persistent_desc, [:range,:imageid_list] do
|
||||
helper.perform_actions(args[0],options,"made persistent") do |image|
|
||||
command :persistent, persistent_desc, [:range, :imageid_list] do
|
||||
helper.perform_actions(args[0], options, 'made persistent') do |image|
|
||||
image.persistent
|
||||
end
|
||||
end
|
||||
@@ -229,8 +235,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Makes the given Image non persistent. See 'oneimage persistent'
|
||||
EOT
|
||||
|
||||
command :nonpersistent, nonpersistent_desc, [:range,:imageid_list] do
|
||||
helper.perform_actions(args[0],options,"made non persistent") do |image|
|
||||
command :nonpersistent, nonpersistent_desc, [:range, :imageid_list] do
|
||||
helper.perform_actions(args[0],
|
||||
options,
|
||||
'made non persistent') do |image|
|
||||
image.nonpersistent
|
||||
end
|
||||
end
|
||||
@@ -241,8 +249,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :update, update_desc, :imageid, [:file, nil],
|
||||
:options=>OpenNebulaHelper::APPEND do
|
||||
helper.perform_action(args[0],options,"modified") do |obj|
|
||||
:options => OpenNebulaHelper::APPEND do
|
||||
helper.perform_action(args[0], options, 'modified') do |obj|
|
||||
if options[:append]
|
||||
str = OpenNebulaHelper.append_template(args[0], obj, args[1])
|
||||
else
|
||||
@@ -260,8 +268,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Enables the given Image
|
||||
EOT
|
||||
|
||||
command :enable, enable_desc, [:range,:imageid_list] do
|
||||
helper.perform_actions(args[0],options,"enabled") do |image|
|
||||
command :enable, enable_desc, [:range, :imageid_list] do
|
||||
helper.perform_actions(args[0], options, 'enabled') do |image|
|
||||
image.enable
|
||||
end
|
||||
end
|
||||
@@ -270,8 +278,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Changes the Image's type
|
||||
EOT
|
||||
|
||||
command :chtype, chtype_desc,[:range, :imageid_list], :type do
|
||||
helper.perform_actions(args[0],options,"Type changed") do |image|
|
||||
command :chtype, chtype_desc, [:range, :imageid_list], :type do
|
||||
helper.perform_actions(args[0], options, 'Type changed') do |image|
|
||||
image.chtype(args[1])
|
||||
end
|
||||
end
|
||||
@@ -280,8 +288,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Disables the given Image
|
||||
EOT
|
||||
|
||||
command :disable, disable_desc, [:range,:imageid_list] do
|
||||
helper.perform_actions(args[0],options,"disabled") do |image|
|
||||
command :disable, disable_desc, [:range, :imageid_list] do
|
||||
helper.perform_actions(args[0], options, 'disabled') do |image|
|
||||
image.disable
|
||||
end
|
||||
end
|
||||
@@ -290,8 +298,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Changes the Image group
|
||||
EOT
|
||||
|
||||
command :chgrp, chgrp_desc,[:range, :imageid_list], :groupid do
|
||||
helper.perform_actions(args[0],options,"Group changed") do |image|
|
||||
command :chgrp, chgrp_desc, [:range, :imageid_list], :groupid do
|
||||
helper.perform_actions(args[0], options, 'Group changed') do |image|
|
||||
image.chown(-1, args[1].to_i)
|
||||
end
|
||||
end
|
||||
@@ -301,10 +309,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :chown, chown_desc, [:range, :imageid_list], :userid,
|
||||
[:groupid,nil] do
|
||||
gid = args[2].nil? ? -1 : args[2].to_i
|
||||
helper.perform_actions(args[0],options,
|
||||
"Owner/Group changed") do |image|
|
||||
[:groupid, nil] do
|
||||
args[2].nil? ? gid = -1 : gid = args[2].to_i
|
||||
helper.perform_actions(args[0], options,
|
||||
'Owner/Group changed') do |image|
|
||||
image.chown(args[1].to_i, gid)
|
||||
end
|
||||
end
|
||||
@@ -314,8 +322,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :chmod, chmod_desc, [:range, :imageid_list], :octet do
|
||||
helper.perform_actions(args[0],options,
|
||||
"Permissions changed") do |image|
|
||||
helper.perform_actions(args[0], options,
|
||||
'Permissions changed') do |image|
|
||||
image.chmod_octet(args[1])
|
||||
end
|
||||
end
|
||||
@@ -325,7 +333,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :rename, rename_desc, :imageid, :name do
|
||||
helper.perform_action(args[0],options,"renamed") do |o|
|
||||
helper.perform_action(args[0], options, 'renamed') do |o|
|
||||
o.rename(args[1])
|
||||
end
|
||||
end
|
||||
@@ -334,8 +342,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Deletes a snapshot from the image
|
||||
EOT
|
||||
|
||||
command :"snapshot-delete", snapshot_delete_desc, :imageid, :snapshot_id do
|
||||
helper.perform_action(args[0], options, "snapshot deleted") do |o|
|
||||
command :'snapshot-delete', snapshot_delete_desc, :imageid, :snapshot_id do
|
||||
helper.perform_action(args[0], options, 'snapshot deleted') do |o|
|
||||
o.snapshot_delete(args[1].to_i)
|
||||
end
|
||||
end
|
||||
@@ -344,8 +352,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Reverts image state to a snapshot
|
||||
EOT
|
||||
|
||||
command :"snapshot-revert", snapshot_revert_desc, :imageid, :snapshot_id do
|
||||
helper.perform_action(args[0], options, "image state reverted") do |o|
|
||||
command :'snapshot-revert', snapshot_revert_desc, :imageid, :snapshot_id do
|
||||
helper.perform_action(args[0], options, 'image state reverted') do |o|
|
||||
o.snapshot_revert(args[1].to_i)
|
||||
end
|
||||
end
|
||||
@@ -354,8 +362,11 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Flattens the snapshot and removes all other snapshots in the image
|
||||
EOT
|
||||
|
||||
command :"snapshot-flatten", snapshot_flatten_desc, :imageid, :snapshot_id do
|
||||
helper.perform_action(args[0], options, "snapshot flattened") do |o|
|
||||
command :'snapshot-flatten',
|
||||
snapshot_flatten_desc,
|
||||
:imageid,
|
||||
:snapshot_id do
|
||||
helper.perform_action(args[0], options, 'snapshot flattened') do |o|
|
||||
o.snapshot_flatten(args[1].to_i)
|
||||
end
|
||||
end
|
||||
@@ -364,7 +375,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Lists Images in the pool
|
||||
EOT
|
||||
|
||||
command :list, list_desc, [:filterflag, nil], :options=>list_options do
|
||||
command :list, list_desc, [:filterflag, nil], :options => list_options do
|
||||
helper.list_pool(options, false, args[0])
|
||||
end
|
||||
|
||||
@@ -372,15 +383,15 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Shows information for the given Image
|
||||
EOT
|
||||
|
||||
command :show, show_desc, :imageid, :options=>OpenNebulaHelper::XML do
|
||||
helper.show_resource(args[0],options)
|
||||
command :show, show_desc, :imageid, :options => OpenNebulaHelper::XML do
|
||||
helper.show_resource(args[0], options)
|
||||
end
|
||||
|
||||
top_desc = <<-EOT.unindent
|
||||
Lists Images continuously
|
||||
EOT
|
||||
|
||||
command :top, top_desc, [:filterflag, nil], :options=>list_options do
|
||||
command :top, top_desc, [:filterflag, nil], :options => list_options do
|
||||
helper.list_pool(options, true, args[0])
|
||||
end
|
||||
|
||||
@@ -395,8 +406,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :lock, lock_desc, :imageid,
|
||||
:options => [USE, MANAGE, ADMIN, ALL] do
|
||||
helper.perform_action(args[0],options,"Image locked") do |i|
|
||||
:options => [USE, MANAGE, ADMIN, ALL] do
|
||||
helper.perform_action(args[0], options, 'Image locked') do |i|
|
||||
if !options[:use].nil?
|
||||
level = 1
|
||||
elsif !options[:manage].nil?
|
||||
@@ -418,7 +429,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :unlock, unlock_desc, :imageid do
|
||||
helper.perform_action(args[0],options,"Image unlocked") do |i|
|
||||
helper.perform_action(args[0], options, 'Image unlocked') do |i|
|
||||
i.unlock
|
||||
end
|
||||
end
|
||||
|
||||
+31
-29
@@ -16,22 +16,22 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
ONE_LOCATION = ENV['ONE_LOCATION']
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
RUBY_LIB_LOCATION = '/usr/lib/one/ruby'
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cli"
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
|
||||
|
||||
require 'command_parser'
|
||||
require 'one_helper/onemarket_helper'
|
||||
|
||||
cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
usage "`onemarket` <command> [<args>] [<options>]"
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
usage '`onemarket` <command> [<args>] [<options>]'
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
|
||||
helper = OneMarketPlaceHelper.new
|
||||
@@ -43,7 +43,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
########################################################################
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
|
||||
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
|
||||
|
||||
list_options = CLIHelper::OPTIONS
|
||||
list_options << OpenNebulaHelper::XML
|
||||
@@ -57,16 +57,18 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
helper.to_id(arg)
|
||||
end
|
||||
|
||||
set :format, :marketplaceid_list, OneMarketPlaceHelper.list_to_id_desc do |arg|
|
||||
set :format,
|
||||
:marketplaceid_list,
|
||||
OneMarketPlaceHelper.list_to_id_desc do |arg|
|
||||
helper.list_to_id(arg)
|
||||
end
|
||||
|
||||
set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, "GROUP")
|
||||
set :format, :groupid, OpenNebulaHelper.rname_to_id_desc('GROUP') do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, 'GROUP')
|
||||
end
|
||||
|
||||
set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, "USER")
|
||||
set :format, :userid, OpenNebulaHelper.rname_to_id_desc('USER') do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, 'USER')
|
||||
end
|
||||
|
||||
########################################################################
|
||||
@@ -78,14 +80,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :create, create_desc, :file do
|
||||
|
||||
helper.create_resource(options) do |marketplace|
|
||||
begin
|
||||
template = File.read(args[0])
|
||||
marketplace.allocate(template)
|
||||
rescue =>e
|
||||
rescue StandardError => e
|
||||
STDERR.puts e.message
|
||||
exit -1
|
||||
exit(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -95,7 +96,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :delete, delete_desc, [:range, :marketplaceid_list] do
|
||||
helper.perform_actions(args[0],options,"deleted") do |obj|
|
||||
helper.perform_actions(args[0], options, 'deleted') do |obj|
|
||||
obj.delete
|
||||
end
|
||||
end
|
||||
@@ -104,8 +105,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Changes the Marketplace group
|
||||
EOT
|
||||
|
||||
command :chgrp, chgrp_desc,[:range, :marketplaceid_list], :groupid do
|
||||
helper.perform_actions(args[0],options,"Group changed") do |obj|
|
||||
command :chgrp, chgrp_desc, [:range, :marketplaceid_list], :groupid do
|
||||
helper.perform_actions(args[0], options, 'Group changed') do |obj|
|
||||
obj.chown(-1, args[1].to_i)
|
||||
end
|
||||
end
|
||||
@@ -115,9 +116,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :chown, chown_desc, [:range, :marketplaceid_list], :userid,
|
||||
[:groupid,nil] do
|
||||
gid = args[2].nil? ? -1 : args[2].to_i
|
||||
helper.perform_actions(args[0],options,"Owner/Group changed") do |obj|
|
||||
[:groupid, nil] do
|
||||
args[2].nil? ? gid = -1 : gid = args[2].to_i
|
||||
helper.perform_actions(args[0], options, 'Owner/Group changed') do |obj|
|
||||
obj.chown(args[1].to_i, gid)
|
||||
end
|
||||
end
|
||||
@@ -127,7 +128,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :chmod, chmod_desc, [:range, :marketplaceid_list], :octet do
|
||||
helper.perform_actions(args[0],options, "Permissions changed") do |obj|
|
||||
helper.perform_actions(args[0], options, 'Permissions changed') do |obj|
|
||||
obj.chmod_octet(args[1])
|
||||
end
|
||||
end
|
||||
@@ -136,7 +137,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Lists Marketplaces
|
||||
EOT
|
||||
|
||||
command :list, list_desc, :options=>list_options do
|
||||
command :list, list_desc, :options => list_options do
|
||||
helper.list_pool(options)
|
||||
end
|
||||
|
||||
@@ -144,8 +145,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Shows Marketplace information
|
||||
EOT
|
||||
|
||||
command :show, show_desc, :marketplaceid, :options=>OpenNebulaHelper::XML do
|
||||
helper.show_resource(args[0],options)
|
||||
command :show, show_desc,
|
||||
:marketplaceid, :options => OpenNebulaHelper::XML do
|
||||
helper.show_resource(args[0], options)
|
||||
end
|
||||
|
||||
update_desc = <<-EOT.unindent
|
||||
@@ -154,8 +156,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :update, update_desc, :marketplaceid, [:file, nil],
|
||||
:options=>OpenNebulaHelper::APPEND do
|
||||
helper.perform_action(args[0],options,"modified") do |obj|
|
||||
:options => OpenNebulaHelper::APPEND do
|
||||
helper.perform_action(args[0], options, 'modified') do |obj|
|
||||
if options[:append]
|
||||
str = OpenNebulaHelper.append_template(args[0], obj, args[1])
|
||||
else
|
||||
@@ -171,7 +173,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :rename, rename_desc, :marketplaceid, :name do
|
||||
helper.perform_action(args[0],options,"renamed") do |o|
|
||||
helper.perform_action(args[0], options, 'renamed') do |o|
|
||||
o.rename(args[1])
|
||||
end
|
||||
end
|
||||
|
||||
+83
-75
@@ -16,26 +16,26 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
ONE_LOCATION = ENV['ONE_LOCATION']
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION = "/usr/lib/one/ruby"
|
||||
VAR_LOCATION = "/var/lib/one"
|
||||
RUBY_LIB_LOCATION = '/usr/lib/one/ruby'
|
||||
VAR_LOCATION = '/var/lib/one'
|
||||
else
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION + "/lib/ruby"
|
||||
VAR_LOCATION = ONE_LOCATION + "/var"
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
|
||||
VAR_LOCATION = ONE_LOCATION + '/var'
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cli"
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
|
||||
|
||||
require 'command_parser'
|
||||
require 'one_helper/onemarketapp_helper'
|
||||
require 'one_helper/onemarket_helper'
|
||||
require 'one_helper/onedatastore_helper'
|
||||
|
||||
cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
usage "`onemarket` <command> [<args>] [<options>]"
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
usage '`onemarket` <command> [<args>] [<options>]'
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
|
||||
helper = OneMarketPlaceAppHelper.new
|
||||
@@ -44,34 +44,34 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
helper.set_client(options)
|
||||
end
|
||||
|
||||
USE={
|
||||
:name => "use",
|
||||
:large => "--use",
|
||||
:description => "lock use actions"
|
||||
USE = {
|
||||
:name => 'use',
|
||||
:large => '--use',
|
||||
:description => 'lock use actions'
|
||||
}
|
||||
|
||||
MANAGE={
|
||||
:name => "manage",
|
||||
:large => "--manage",
|
||||
:description => "lock manage actions"
|
||||
MANAGE = {
|
||||
:name => 'manage',
|
||||
:large => '--manage',
|
||||
:description => 'lock manage actions'
|
||||
}
|
||||
|
||||
ADMIN={
|
||||
:name => "admin",
|
||||
:large => "--admin",
|
||||
:description => "lock admin actions"
|
||||
ADMIN = {
|
||||
:name => 'admin',
|
||||
:large => '--admin',
|
||||
:description => 'lock admin actions'
|
||||
}
|
||||
|
||||
ALL={
|
||||
:name => "all",
|
||||
:large => "--all",
|
||||
:description => "lock all actions"
|
||||
ALL = {
|
||||
:name => 'all',
|
||||
:large => '--all',
|
||||
:description => 'lock all actions'
|
||||
}
|
||||
|
||||
########################################################################
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
|
||||
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
|
||||
|
||||
list_options = CLIHelper::OPTIONS
|
||||
list_options << OpenNebulaHelper::XML
|
||||
@@ -79,17 +79,18 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
list_options << OpenNebulaHelper::DESCRIBE
|
||||
|
||||
CREATE_OPTIONS = [OneMarketPlaceHelper::MARKETPLACE]
|
||||
EXPORT_OPTIONS = [OneDatastoreHelper::DATASTORE, OneMarketPlaceAppHelper::VMNAME]
|
||||
EXPORT_OPTIONS = [OneDatastoreHelper::DATASTORE,
|
||||
OneMarketPlaceAppHelper::VMNAME]
|
||||
|
||||
########################################################################
|
||||
# Formatters for arguments
|
||||
########################################################################
|
||||
set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, "GROUP")
|
||||
set :format, :groupid, OpenNebulaHelper.rname_to_id_desc('GROUP') do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, 'GROUP')
|
||||
end
|
||||
|
||||
set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, "USER")
|
||||
set :format, :userid, OpenNebulaHelper.rname_to_id_desc('USER') do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, 'USER')
|
||||
end
|
||||
|
||||
set :format, :appid, OneMarketPlaceAppHelper.to_id_desc do |arg|
|
||||
@@ -100,7 +101,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
helper.list_to_id(arg)
|
||||
end
|
||||
|
||||
set :format, :filterflag, OneMarketPlaceAppHelper.filterflag_to_i_desc do |arg|
|
||||
set :format, :filterflag,
|
||||
OneMarketPlaceAppHelper.filterflag_to_i_desc do |arg|
|
||||
helper.filterflag_to_i(arg)
|
||||
end
|
||||
|
||||
@@ -112,27 +114,30 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Creates a new marketplace app in the given marketplace
|
||||
EOT
|
||||
|
||||
command :create, create_desc, [:file, nil], :options=>CREATE_OPTIONS +
|
||||
OneMarketPlaceAppHelper::TEMPLATE_OPTIONS do
|
||||
command :create, create_desc, [:file, nil],
|
||||
:options => CREATE_OPTIONS +
|
||||
OneMarketPlaceAppHelper::TEMPLATE_OPTIONS do
|
||||
|
||||
if options[:marketplace].nil?
|
||||
STDERR.puts "Marketplace to save the app is mandatory: "
|
||||
STDERR.puts "\t -m marketplace_id"
|
||||
STDERR.puts 'Marketplace to save the app is mandatory: '
|
||||
STDERR.puts '\t -m marketplace_id'
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
if args[0] && OneMarketPlaceAppHelper.create_template_options_used?(options)
|
||||
STDERR.puts "You can not use both template file and template"<<
|
||||
" creation options."
|
||||
if args[0] &&
|
||||
OneMarketPlaceAppHelper.create_template_options_used?(options)
|
||||
STDERR.puts 'You can not use both template file and template'\
|
||||
' creation options.'
|
||||
next -1
|
||||
end
|
||||
|
||||
helper.create_resource(options) do |app|
|
||||
begin
|
||||
if args[0]
|
||||
template=File.read(args[0])
|
||||
template = File.read(args[0])
|
||||
else
|
||||
res = OneMarketPlaceAppHelper.create_datastore_template(options)
|
||||
res = OneMarketPlaceAppHelper
|
||||
.create_datastore_template(options)
|
||||
|
||||
if res.first != 0
|
||||
STDERR.puts res.last
|
||||
@@ -148,7 +153,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
end
|
||||
|
||||
app.allocate(template, options[:marketplace])
|
||||
rescue => e
|
||||
rescue StandardError => e
|
||||
STDERR.puts e.message
|
||||
exit(-1)
|
||||
end
|
||||
@@ -159,27 +164,26 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Exports the marketplace app to the OpenNebula cloud
|
||||
EOT
|
||||
|
||||
command :export, export_desc, :appid, :name, :options=>EXPORT_OPTIONS do
|
||||
helper.perform_action(args[0], options, "exported") do |obj|
|
||||
|
||||
rc = obj.export({
|
||||
:dsid=>options[:datastore],
|
||||
:name=>args[1],
|
||||
:vmtemplate_name=>options[:vmname]
|
||||
})
|
||||
command :export, export_desc, :appid, :name, :options => EXPORT_OPTIONS do
|
||||
helper.perform_action(args[0], options, 'exported') do |obj|
|
||||
rc = obj.export(
|
||||
:dsid => options[:datastore],
|
||||
:name => args[1],
|
||||
:vmtemplate_name => options[:vmname]
|
||||
)
|
||||
|
||||
next rc if OpenNebula.is_error?(rc)
|
||||
|
||||
rc.each { |key, value|
|
||||
puts "#{key.to_s.upcase}"
|
||||
value.each{ |id|
|
||||
rc.each do |key, value|
|
||||
puts key.to_s.upcase
|
||||
value.each do |id|
|
||||
if OpenNebula.is_error?(id)
|
||||
puts id.to_str
|
||||
else
|
||||
puts " ID: #{id}"
|
||||
end
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -188,8 +192,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :download, download_desc, :appid, :path,
|
||||
:options => [OpenNebulaHelper::FORCE] do
|
||||
helper.perform_action(args[0],options,"downloaded") do |app|
|
||||
:options => [OpenNebulaHelper::FORCE] do
|
||||
helper.perform_action(args[0], options, 'downloaded') do
|
||||
download_args = [:marketplaceapp, args[0], args[1], options[:force]]
|
||||
OpenNebulaHelper.download_resource_sunstone(*download_args)
|
||||
end
|
||||
@@ -200,7 +204,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :delete, delete_desc, [:range, :appid_list] do
|
||||
helper.perform_actions(args[0], options, "deleted") do |app|
|
||||
helper.perform_actions(args[0], options, 'deleted') do |app|
|
||||
app.delete
|
||||
end
|
||||
end
|
||||
@@ -211,9 +215,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :update, update_desc, :appid, [:file, nil],
|
||||
:options=>OpenNebulaHelper::APPEND do
|
||||
:options => OpenNebulaHelper::APPEND do
|
||||
|
||||
helper.perform_action(args[0],options,"modified") do |obj|
|
||||
helper.perform_action(args[0], options, 'modified') do |obj|
|
||||
if options[:append]
|
||||
str = OpenNebulaHelper.append_template(args[0], obj, args[1])
|
||||
else
|
||||
@@ -228,8 +232,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Changes the marketplace app group
|
||||
EOT
|
||||
|
||||
command :chgrp, chgrp_desc,[:range, :appid_list], :groupid do
|
||||
helper.perform_actions(args[0], options, "Group changed") do |app|
|
||||
command :chgrp, chgrp_desc, [:range, :appid_list], :groupid do
|
||||
helper.perform_actions(args[0], options, 'Group changed') do |app|
|
||||
app.chown(-1, args[1].to_i)
|
||||
end
|
||||
end
|
||||
@@ -240,9 +244,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
command :chown, chown_desc, [:range, :appid_list], :userid,
|
||||
[:groupid, nil] do
|
||||
gid = args[2].nil? ? -1 : args[2].to_i
|
||||
args[2].nil? ? gid = -1 : gid = args[2].to_i
|
||||
|
||||
helper.perform_actions(args[0], options, "Owner/Group changed") do |app|
|
||||
helper.perform_actions(args[0], options, 'Owner/Group changed') do |app|
|
||||
app.chown(args[1].to_i, gid)
|
||||
end
|
||||
end
|
||||
@@ -252,7 +256,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :chmod, chmod_desc, [:range, :appid_list], :octet do
|
||||
helper.perform_actions(args[0], options, "Permissions changed") do |app|
|
||||
helper.perform_actions(args[0], options, 'Permissions changed') do |app|
|
||||
app.chmod_octet(args[1])
|
||||
end
|
||||
end
|
||||
@@ -262,7 +266,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :rename, rename_desc, :appid, :name do
|
||||
helper.perform_action(args[0], options, "renamed") do |o|
|
||||
helper.perform_action(args[0], options, 'renamed') do |o|
|
||||
o.rename(args[1])
|
||||
end
|
||||
end
|
||||
@@ -271,7 +275,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Lists marketplace apps
|
||||
EOT
|
||||
|
||||
command :list, list_desc, [:filterflag, nil], :options=>list_options do
|
||||
command :list, list_desc, [:filterflag, nil], :options => list_options do
|
||||
helper.list_pool(options, false, args[0])
|
||||
end
|
||||
|
||||
@@ -279,7 +283,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Shows information for the given marketplace app
|
||||
EOT
|
||||
|
||||
command :show, show_desc, :appid, :options=>OpenNebulaHelper::XML do
|
||||
command :show, show_desc, :appid, :options => OpenNebulaHelper::XML do
|
||||
helper.show_resource(args[0], options)
|
||||
end
|
||||
|
||||
@@ -288,7 +292,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :enable, enable_desc, [:range, :appid_list] do
|
||||
helper.perform_actions(args[0], options, "enabled") do |obj|
|
||||
helper.perform_actions(args[0], options, 'enabled') do |obj|
|
||||
obj.enable
|
||||
end
|
||||
end
|
||||
@@ -299,14 +303,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :disable, disable_desc, [:range, :appid_list] do
|
||||
helper.perform_actions(args[0], options, "disabled") do |obj|
|
||||
helper.perform_actions(args[0], options, 'disabled') do |obj|
|
||||
obj.disable
|
||||
end
|
||||
end
|
||||
|
||||
lock_desc = <<-EOT.unindent
|
||||
Locks a VM with differents levels for lock any actions with this VM, show and
|
||||
monitoring never will be locked.
|
||||
Locks a VM with differents levels for lock any actions with this VM,
|
||||
show and monitoring never will be locked.
|
||||
Valid states are: All.
|
||||
Levels:
|
||||
[Use]: locks Admin, Manage and Use actions.
|
||||
@@ -315,8 +319,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :lock, lock_desc, :appid,
|
||||
:options => [USE, MANAGE, ADMIN, ALL] do
|
||||
helper.perform_action(args[0],options,"MarketPlaceApp locked") do |app|
|
||||
:options => [USE, MANAGE, ADMIN, ALL] do
|
||||
helper.perform_action(args[0],
|
||||
options,
|
||||
'MarketPlaceApp locked') do |app|
|
||||
if !options[:use].nil?
|
||||
level = 1
|
||||
elsif !options[:manage].nil?
|
||||
@@ -338,7 +344,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :unlock, unlock_desc, :appid do
|
||||
helper.perform_action(args[0],options,"MarketPlaceApp unlocked") do |app|
|
||||
helper.perform_action(args[0],
|
||||
options,
|
||||
'MarketPlaceApp unlocked') do |app|
|
||||
app.unlock
|
||||
end
|
||||
end
|
||||
|
||||
+37
-33
@@ -16,22 +16,22 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
ONE_LOCATION = ENV['ONE_LOCATION']
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
RUBY_LIB_LOCATION = '/usr/lib/one/ruby'
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cli"
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
|
||||
|
||||
require 'command_parser'
|
||||
require 'one_helper/onesecgroup_helper'
|
||||
|
||||
cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
usage "`onesecgroup` <command> [<args>] [<options>]"
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
usage '`onesecgroup` <command> [<args>] [<options>]'
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
|
||||
helper = OneSecurityGroupHelper.new
|
||||
@@ -43,7 +43,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
########################################################################
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
|
||||
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
|
||||
|
||||
list_options = CLIHelper::OPTIONS
|
||||
list_options << OpenNebulaHelper::XML
|
||||
@@ -53,23 +53,27 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
########################################################################
|
||||
# Formatters for arguments
|
||||
########################################################################
|
||||
set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, "GROUP")
|
||||
set :format, :groupid, OpenNebulaHelper.rname_to_id_desc('GROUP') do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, 'GROUP')
|
||||
end
|
||||
|
||||
set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, "USER")
|
||||
set :format, :userid, OpenNebulaHelper.rname_to_id_desc('USER') do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, 'USER')
|
||||
end
|
||||
|
||||
set :format, :secgroupid, OneSecurityGroupHelper.to_id_desc do |arg|
|
||||
helper.to_id(arg)
|
||||
end
|
||||
|
||||
set :format, :secgroupid_list, OneSecurityGroupHelper.list_to_id_desc do |arg|
|
||||
set :format,
|
||||
:secgroupid_list,
|
||||
OneSecurityGroupHelper.list_to_id_desc do |arg|
|
||||
helper.list_to_id(arg)
|
||||
end
|
||||
|
||||
set :format, :filterflag, OneSecurityGroupHelper.filterflag_to_i_desc do |arg|
|
||||
set :format,
|
||||
:filterflag,
|
||||
OneSecurityGroupHelper.filterflag_to_i_desc do |arg|
|
||||
helper.filterflag_to_i(arg)
|
||||
end
|
||||
|
||||
@@ -87,9 +91,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
template = File.read(args[0])
|
||||
|
||||
obj.allocate(template)
|
||||
rescue => e
|
||||
rescue StandardError => e
|
||||
STDERR.puts e.messsage
|
||||
exit -1
|
||||
exit(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -99,7 +103,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :clone, clone_desc, :secgroupid, :name do
|
||||
helper.perform_action(args[0],options,"cloned") do |obj|
|
||||
helper.perform_action(args[0], options, 'cloned') do |obj|
|
||||
res = obj.clone(args[1])
|
||||
|
||||
if !OpenNebula.is_error?(res)
|
||||
@@ -115,7 +119,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :delete, delete_desc, [:range, :secgroupid_list] do
|
||||
helper.perform_actions(args[0],options,"deleted") do |obj|
|
||||
helper.perform_actions(args[0], options, 'deleted') do |obj|
|
||||
obj.delete
|
||||
end
|
||||
end
|
||||
@@ -124,8 +128,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Changes the Security Group's group
|
||||
EOT
|
||||
|
||||
command :chgrp, chgrp_desc,[:range, :secgroupid_list], :groupid do
|
||||
helper.perform_actions(args[0],options,"Group changed") do |obj|
|
||||
command :chgrp, chgrp_desc, [:range, :secgroupid_list], :groupid do
|
||||
helper.perform_actions(args[0], options, 'Group changed') do |obj|
|
||||
obj.chown(-1, args[1].to_i)
|
||||
end
|
||||
end
|
||||
@@ -135,9 +139,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :chown, chown_desc, [:range, :secgroupid_list], :userid,
|
||||
[:groupid,nil] do
|
||||
gid = args[2].nil? ? -1 : args[2].to_i
|
||||
helper.perform_actions(args[0],options,"Owner/Group changed") do |obj|
|
||||
[:groupid, nil] do
|
||||
args[2].nil? ? gid = -1 : gid = args[2].to_i
|
||||
helper.perform_actions(args[0], options, 'Owner/Group changed') do |obj|
|
||||
obj.chown(args[1].to_i, gid)
|
||||
end
|
||||
end
|
||||
@@ -147,7 +151,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :chmod, chmod_desc, [:range, :secgroupid_list], :octet do
|
||||
helper.perform_actions(args[0],options, "Permissions changed") do |t|
|
||||
helper.perform_actions(args[0], options, 'Permissions changed') do |t|
|
||||
t.chmod_octet(args[1])
|
||||
end
|
||||
end
|
||||
@@ -158,8 +162,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :update, update_desc, :secgroupid, [:file, nil],
|
||||
:options=>OpenNebulaHelper::APPEND do
|
||||
helper.perform_action(args[0],options,"modified") do |obj|
|
||||
:options => OpenNebulaHelper::APPEND do
|
||||
helper.perform_action(args[0], options, 'modified') do |obj|
|
||||
if options[:append]
|
||||
str = OpenNebulaHelper.append_template(args[0], obj, args[1])
|
||||
else
|
||||
@@ -178,7 +182,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :rename, rename_desc, :secgroupid, :name do
|
||||
helper.perform_action(args[0],options,"renamed") do |o|
|
||||
helper.perform_action(args[0], options, 'renamed') do |o|
|
||||
o.rename(args[1])
|
||||
end
|
||||
end
|
||||
@@ -191,9 +195,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :commit, commit_desc, :secgroupid,
|
||||
:options =>[OneSecurityGroupHelper::RECOVER] do
|
||||
helper.perform_action(args[0], options, "commit") do |o|
|
||||
o.commit(options[:recover]==true)
|
||||
:options => [OneSecurityGroupHelper::RECOVER] do
|
||||
helper.perform_action(args[0], options, 'commit') do |o|
|
||||
o.commit(options[:recover] == true)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -201,7 +205,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Lists Security Group in the pool
|
||||
EOT
|
||||
|
||||
command :list, list_desc, [:filterflag, nil], :options=>list_options do
|
||||
command :list, list_desc, [:filterflag, nil], :options => list_options do
|
||||
helper.list_pool(options, false, args[0])
|
||||
end
|
||||
|
||||
@@ -209,7 +213,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Shows information for the given Security Group
|
||||
EOT
|
||||
|
||||
command :show, show_desc, :secgroupid, :options=>OpenNebulaHelper::XML do
|
||||
helper.show_resource(args[0],options)
|
||||
command :show, show_desc, :secgroupid, :options => OpenNebulaHelper::XML do
|
||||
helper.show_resource(args[0], options)
|
||||
end
|
||||
end
|
||||
+35
-38
@@ -16,38 +16,37 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
ONE_LOCATION = ENV['ONE_LOCATION']
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
RUBY_LIB_LOCATION = '/usr/lib/one/ruby'
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cli"
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
|
||||
|
||||
require 'command_parser'
|
||||
require 'one_helper/oneacct_helper'
|
||||
|
||||
require 'json'
|
||||
|
||||
cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
@formats = {}
|
||||
|
||||
@formats = Hash.new
|
||||
|
||||
usage "`oneshowback` <command> [<options>]"
|
||||
description ""
|
||||
usage '`oneshowback` <command> [<options>]'
|
||||
description ''
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
|
||||
helper=OpenNebulaHelper::OneHelper.new
|
||||
helper = OpenNebulaHelper::OneHelper.new
|
||||
|
||||
before_proc do
|
||||
options[:timeout] = 60 #60 sec
|
||||
options[:timeout] = 60 # 60 sec
|
||||
helper.set_client(options)
|
||||
end
|
||||
|
||||
command :list, "Returns the showback records", :options =>
|
||||
command :list, 'Returns the showback records', :options =>
|
||||
AcctHelper::SHOWBACK_OPTIONS + CommandParser::OPTIONS +
|
||||
[OpenNebulaHelper::DESCRIBE, CLIHelper::LIST, CLIHelper::CSV_OPT] +
|
||||
OpenNebulaHelper::CLIENT_OPTIONS do
|
||||
@@ -62,7 +61,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
start_month = -1
|
||||
start_year = -1
|
||||
|
||||
if (options[:start_time])
|
||||
if options[:start_time]
|
||||
start_month = options[:start_time].month
|
||||
start_year = options[:start_time].year
|
||||
end
|
||||
@@ -70,7 +69,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
end_month = -1
|
||||
end_year = -1
|
||||
|
||||
if (options[:end_time])
|
||||
if options[:end_time]
|
||||
end_month = options[:end_time].month
|
||||
end_year = options[:end_time].year
|
||||
end
|
||||
@@ -90,7 +89,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
xml_str = pool.showback_xml(filter_flag, common_opts)
|
||||
if OpenNebula.is_error?(xml_str)
|
||||
puts xml_str.message
|
||||
exit -1
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
if options[:json]
|
||||
@@ -101,25 +100,22 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
elsif options[:xml]
|
||||
puts xml_str
|
||||
end
|
||||
|
||||
exit_code 0
|
||||
else
|
||||
|
||||
order_by = Hash.new
|
||||
order_by = {}
|
||||
if !options[:csv]
|
||||
order_by[:order_by_1] = 'YEAR'
|
||||
order_by[:order_by_2] = 'MONTH'
|
||||
end
|
||||
|
||||
data_hash = pool.showback(filter_flag,
|
||||
common_opts.merge(order_by))
|
||||
common_opts.merge(order_by))
|
||||
if OpenNebula.is_error?(data_hash)
|
||||
puts data_hash.message
|
||||
exit -1
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
if options[:csv]
|
||||
a = Array.new
|
||||
a = []
|
||||
|
||||
if data_hash['SHOWBACK_RECORDS']
|
||||
a = data_hash['SHOWBACK_RECORDS']['SHOWBACK']
|
||||
@@ -129,29 +125,28 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
exit(0)
|
||||
end
|
||||
|
||||
data_hash.each { |year, value|
|
||||
value.each { |month, showback_array|
|
||||
data_hash.each do |year, value|
|
||||
value.each do |month, showback_array|
|
||||
AcctHelper.print_month_header(year, month)
|
||||
|
||||
array = showback_array['SHOWBACK_RECORDS']['SHOWBACK']
|
||||
AcctHelper::SHOWBACK_TABLE.show(array, options)
|
||||
puts
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
}
|
||||
|
||||
exit_code 0
|
||||
end
|
||||
|
||||
exit_code 0
|
||||
end
|
||||
|
||||
command :"calculate", "Calculates the showback records", :options =>
|
||||
command :calculate, 'Calculates the showback records', :options =>
|
||||
[AcctHelper::START_TIME_SHOWBACK, AcctHelper::END_TIME_SHOWBACK] do
|
||||
|
||||
|
||||
start_month = -1
|
||||
start_year = -1
|
||||
|
||||
if (options[:start_time])
|
||||
if options[:start_time]
|
||||
start_month = options[:start_time].month
|
||||
start_year = options[:start_time].year
|
||||
end
|
||||
@@ -159,21 +154,23 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
end_month = -1
|
||||
end_year = -1
|
||||
|
||||
if (options[:end_time])
|
||||
if options[:end_time]
|
||||
end_month = options[:end_time].month
|
||||
end_year = options[:end_time].year
|
||||
end
|
||||
|
||||
rc = OpenNebula::VirtualMachinePool.new(helper.client).
|
||||
calculate_showback(start_month, start_year, end_month, end_year)
|
||||
rc = OpenNebula::VirtualMachinePool.new(helper.client)
|
||||
.calculate_showback(start_month,
|
||||
start_year,
|
||||
end_month,
|
||||
end_year)
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
warn rc.message
|
||||
exit -1
|
||||
exit(-1)
|
||||
else
|
||||
puts rc
|
||||
exit_code 0
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
+73
-70
@@ -16,23 +16,23 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
ONE_LOCATION = ENV['ONE_LOCATION']
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
RUBY_LIB_LOCATION = '/usr/lib/one/ruby'
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cli"
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
|
||||
|
||||
require 'command_parser'
|
||||
require 'one_helper/onetemplate_helper'
|
||||
require 'one_helper/onevm_helper'
|
||||
|
||||
cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
usage "`onetemplate` <command> [<args>] [<options>]"
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
usage '`onetemplate` <command> [<args>] [<options>]'
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
|
||||
helper = OneTemplateHelper.new
|
||||
@@ -41,34 +41,34 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
helper.set_client(options)
|
||||
end
|
||||
|
||||
USE={
|
||||
:name => "use",
|
||||
:large => "--use",
|
||||
:description => "lock use actions"
|
||||
USE = {
|
||||
:name => 'use',
|
||||
:large => '--use',
|
||||
:description => 'lock use actions'
|
||||
}
|
||||
|
||||
MANAGE={
|
||||
:name => "manage",
|
||||
:large => "--manage",
|
||||
:description => "lock manage actions"
|
||||
MANAGE = {
|
||||
:name => 'manage',
|
||||
:large => '--manage',
|
||||
:description => 'lock manage actions'
|
||||
}
|
||||
|
||||
ADMIN={
|
||||
:name => "admin",
|
||||
:large => "--admin",
|
||||
:description => "lock admin actions"
|
||||
ADMIN = {
|
||||
:name => 'admin',
|
||||
:large => '--admin',
|
||||
:description => 'lock admin actions'
|
||||
}
|
||||
|
||||
ALL={
|
||||
:name => "all",
|
||||
:large => "--all",
|
||||
:description => "lock all actions"
|
||||
ALL = {
|
||||
:name => 'all',
|
||||
:large => '--all',
|
||||
:description => 'lock all actions'
|
||||
}
|
||||
|
||||
########################################################################
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
|
||||
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
|
||||
|
||||
list_options = CLIHelper::OPTIONS
|
||||
list_options << OpenNebulaHelper::XML
|
||||
@@ -80,18 +80,18 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
OneTemplateHelper::MULTIPLE,
|
||||
OneTemplateHelper::USERDATA,
|
||||
OneVMHelper::HOLD,
|
||||
OneTemplateHelper::PERSISTENT,
|
||||
OneTemplateHelper::PERSISTENT
|
||||
]
|
||||
|
||||
########################################################################
|
||||
# Formatters for arguments
|
||||
########################################################################
|
||||
set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, "GROUP")
|
||||
set :format, :groupid, OpenNebulaHelper.rname_to_id_desc('GROUP') do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, 'GROUP')
|
||||
end
|
||||
|
||||
set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, "USER")
|
||||
set :format, :userid, OpenNebulaHelper.rname_to_id_desc('USER') do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, 'USER')
|
||||
end
|
||||
|
||||
set :format, :templateid, OneTemplateHelper.to_id_desc do |arg|
|
||||
@@ -131,12 +131,12 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :create, create_desc, [:file, nil], :options =>
|
||||
[OneTemplateHelper::VM_NAME]+OpenNebulaHelper::TEMPLATE_OPTIONS+
|
||||
[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"<<
|
||||
" creation options."
|
||||
STDERR.puts 'You can not use both template file and template' \
|
||||
' creation options.'
|
||||
next -1
|
||||
end
|
||||
|
||||
@@ -161,9 +161,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
else
|
||||
tmpl.allocate(template)
|
||||
end
|
||||
rescue => e
|
||||
rescue StandardError => e
|
||||
STDERR.puts e.messsage
|
||||
exit -1
|
||||
exit(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -173,11 +173,11 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :clone, clone_desc, :templateid, :name,
|
||||
:options =>OneTemplateHelper::RECURSIVE do
|
||||
:options => OneTemplateHelper::RECURSIVE do
|
||||
|
||||
recursive = (options[:recursive] == true)
|
||||
|
||||
helper.perform_action(args[0],options,"cloned") do |t|
|
||||
helper.perform_action(args[0], options, 'cloned') do |t|
|
||||
res = t.clone(args[1], recursive)
|
||||
|
||||
if !OpenNebula.is_error?(res)
|
||||
@@ -193,11 +193,11 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :delete, delete_desc, [:range, :templateid_list],
|
||||
:options =>OneTemplateHelper::RECURSIVE do
|
||||
:options => OneTemplateHelper::RECURSIVE do
|
||||
|
||||
recursive = (options[:recursive] == true)
|
||||
|
||||
helper.perform_actions(args[0],options,"deleted") do |t|
|
||||
helper.perform_actions(args[0], options, 'deleted') do |t|
|
||||
t.delete(recursive)
|
||||
end
|
||||
end
|
||||
@@ -211,12 +211,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :instantiate, instantiate_desc, :templateid, [:file, nil],
|
||||
:options=>instantiate_options+OpenNebulaHelper::TEMPLATE_OPTIONS do
|
||||
exit_code=0
|
||||
:options => instantiate_options +
|
||||
OpenNebulaHelper::TEMPLATE_OPTIONS do
|
||||
exit_code = 0
|
||||
|
||||
if args[1] && OpenNebulaHelper.create_template_options_used?(options)
|
||||
STDERR.puts "You cannot use both template file and template"<<
|
||||
" creation options."
|
||||
STDERR.puts 'You cannot use both template file and template' \
|
||||
' creation options.'
|
||||
next -1
|
||||
end
|
||||
|
||||
@@ -224,14 +225,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
user_inputs = nil
|
||||
|
||||
number.times do |i|
|
||||
exit_code=helper.perform_action(args[0], options,
|
||||
"instantiated") do |t|
|
||||
exit_code = helper.perform_action(args[0], options,
|
||||
'instantiated') do |t|
|
||||
name = options[:name]
|
||||
name = name.gsub("%i",i.to_s) if name
|
||||
name = name.gsub('%i', i.to_s) if name
|
||||
|
||||
on_hold = options[:hold] != nil
|
||||
on_hold = !options[:hold].nil?
|
||||
|
||||
extra_template = ""
|
||||
extra_template = ''
|
||||
rc = t.info
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
@@ -252,11 +253,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
extra_template = res.last
|
||||
end
|
||||
|
||||
user_inputs = OneTemplateHelper.get_user_inputs(t.to_hash) unless user_inputs
|
||||
if !user_inputs
|
||||
user_inputs = OneTemplateHelper.get_user_inputs(t.to_hash)
|
||||
end
|
||||
|
||||
extra_template << "\n" << user_inputs
|
||||
extra_template << '\n' << user_inputs
|
||||
|
||||
persistent = options[:persistent] != nil
|
||||
persistent = !options[:persistent].nil?
|
||||
|
||||
res = t.instantiate(name, on_hold, extra_template, persistent)
|
||||
|
||||
@@ -267,7 +270,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
res
|
||||
end
|
||||
|
||||
break if exit_code==-1
|
||||
break if exit_code == -1
|
||||
end
|
||||
|
||||
exit_code
|
||||
@@ -277,8 +280,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Changes the Template group
|
||||
EOT
|
||||
|
||||
command :chgrp, chgrp_desc,[:range, :templateid_list], :groupid do
|
||||
helper.perform_actions(args[0],options,"Group changed") do |t|
|
||||
command :chgrp, chgrp_desc, [:range, :templateid_list], :groupid do
|
||||
helper.perform_actions(args[0], options, 'Group changed') do |t|
|
||||
t.chown(-1, args[1].to_i)
|
||||
end
|
||||
end
|
||||
@@ -288,9 +291,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :chown, chown_desc, [:range, :templateid_list], :userid,
|
||||
[:groupid,nil] do
|
||||
gid = args[2].nil? ? -1 : args[2].to_i
|
||||
helper.perform_actions(args[0],options,"Owner/Group changed") do |t|
|
||||
[:groupid, nil] do
|
||||
args[2].nil? ? gid = -1 : gid = args[2].to_i
|
||||
helper.perform_actions(args[0], options, 'Owner/Group changed') do |t|
|
||||
t.chown(args[1].to_i, gid)
|
||||
end
|
||||
end
|
||||
@@ -300,11 +303,11 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :chmod, chmod_desc, [:range, :templateid_list], :octet,
|
||||
:options =>OneTemplateHelper::RECURSIVE do
|
||||
:options => OneTemplateHelper::RECURSIVE do
|
||||
|
||||
recursive = (options[:recursive] == true)
|
||||
|
||||
helper.perform_actions(args[0],options, "Permissions changed") do |t|
|
||||
helper.perform_actions(args[0], options, 'Permissions changed') do |t|
|
||||
t.chmod_octet(args[1], recursive)
|
||||
end
|
||||
end
|
||||
@@ -315,8 +318,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :update, update_desc, :templateid, [:file, nil],
|
||||
:options=>OpenNebulaHelper::APPEND do
|
||||
helper.perform_action(args[0],options,"modified") do |obj|
|
||||
:options => OpenNebulaHelper::APPEND do
|
||||
helper.perform_action(args[0], options, 'modified') do |obj|
|
||||
if options[:append]
|
||||
str = OpenNebulaHelper.append_template(args[0], obj, args[1])
|
||||
else
|
||||
@@ -339,12 +342,12 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :rename, rename_desc, :templateid, :name do
|
||||
helper.perform_action(args[0],options,"renamed") do |o|
|
||||
helper.perform_action(args[0], options, 'renamed') do |o|
|
||||
o.rename(args[1])
|
||||
end
|
||||
end
|
||||
|
||||
command :list, list_desc, [:filterflag, nil], :options=>list_options do
|
||||
command :list, list_desc, [:filterflag, nil], :options => list_options do
|
||||
helper.list_pool(options, false, args[0])
|
||||
end
|
||||
|
||||
@@ -353,22 +356,22 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :show, show_desc, :templateid,
|
||||
:options=>[OpenNebulaHelper::XML,OneTemplateHelper::EXTENDED] do
|
||||
:options => [OpenNebulaHelper::XML, OneTemplateHelper::EXTENDED] do
|
||||
|
||||
helper.show_resource(args[0],options)
|
||||
helper.show_resource(args[0], options)
|
||||
end
|
||||
|
||||
top_desc = <<-EOT.unindent
|
||||
Lists Templates continuously
|
||||
EOT
|
||||
|
||||
command :top, top_desc, [:filterflag, nil], :options=>list_options do
|
||||
command :top, top_desc, [:filterflag, nil], :options => list_options do
|
||||
helper.list_pool(options, true, args[0])
|
||||
end
|
||||
|
||||
lock_desc = <<-EOT.unindent
|
||||
Locks a VM with differents levels for lock any actions with this VM, show and
|
||||
monitoring never will be locked.
|
||||
Locks a VM with differents levels for lock any actions with this VM,
|
||||
show and monitoring never will be locked.
|
||||
Valid states are: All.
|
||||
Levels:
|
||||
[Use]: locks Admin, Manage and Use actions.
|
||||
@@ -377,8 +380,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :lock, lock_desc, :templateid,
|
||||
:options => [USE, MANAGE, ADMIN, ALL] do
|
||||
helper.perform_action(args[0],options,"Template locked") do |t|
|
||||
:options => [USE, MANAGE, ADMIN, ALL] do
|
||||
helper.perform_action(args[0], options, 'Template locked') do |t|
|
||||
if !options[:use].nil?
|
||||
level = 1
|
||||
elsif !options[:manage].nil?
|
||||
@@ -400,7 +403,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :unlock, unlock_desc, :templateid do
|
||||
helper.perform_action(args[0],options,"Template unlocked") do |t|
|
||||
helper.perform_action(args[0], options, 'Template unlocked') do |t|
|
||||
t.unlock
|
||||
end
|
||||
end
|
||||
|
||||
+61
-45
@@ -16,22 +16,22 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
ONE_LOCATION = ENV['ONE_LOCATION']
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
RUBY_LIB_LOCATION = '/usr/lib/one/ruby'
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cli"
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
|
||||
|
||||
require 'command_parser'
|
||||
require 'one_helper/onevdc_helper'
|
||||
|
||||
cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
usage "`onevdc` <command> [<args>] [<options>]"
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
usage '`onevdc` <command> [<args>] [<options>]'
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
|
||||
helper = OneVdcHelper.new
|
||||
@@ -43,7 +43,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
########################################################################
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
|
||||
set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
|
||||
|
||||
list_options = CLIHelper::OPTIONS
|
||||
list_options << OpenNebulaHelper::XML
|
||||
@@ -61,51 +61,63 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
helper.list_to_id(arg)
|
||||
end
|
||||
|
||||
set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, "GROUP")
|
||||
set :format, :groupid, OpenNebulaHelper.rname_to_id_desc('GROUP') do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, 'GROUP')
|
||||
end
|
||||
|
||||
set :format, :zoneid, OpenNebulaHelper.rname_to_id_desc("ZONE") do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, "ZONE")
|
||||
set :format, :zoneid, OpenNebulaHelper.rname_to_id_desc('ZONE') do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, 'ZONE')
|
||||
end
|
||||
|
||||
set :format, :clusterid,
|
||||
"#{OpenNebulaHelper.rname_to_id_desc('CLUSTER')}. Can be set to ALL" do |arg|
|
||||
"#{OpenNebulaHelper.rname_to_id_desc('CLUSTER')}. "\
|
||||
'Can be set to ALL' do |arg|
|
||||
|
||||
if !arg.nil? and arg.class != Fixnum and arg.upcase == "ALL"
|
||||
if !arg.nil? &&
|
||||
arg.class != Integer &&
|
||||
arg.casecmp?('ALL')
|
||||
[0, Vdc::ALL_RESOURCES]
|
||||
else
|
||||
OpenNebulaHelper.rname_to_id(arg, "CLUSTER")
|
||||
OpenNebulaHelper.rname_to_id(arg, 'CLUSTER')
|
||||
end
|
||||
end
|
||||
|
||||
set :format, :hostid,
|
||||
"#{OpenNebulaHelper.rname_to_id_desc('HOST')}. Can be set to ALL" do |arg|
|
||||
"#{OpenNebulaHelper.rname_to_id_desc('HOST')}. "\
|
||||
'Can be set to ALL' do |arg|
|
||||
|
||||
if !arg.nil? and arg.class != Fixnum and arg.upcase == "ALL"
|
||||
if !arg.nil? &&
|
||||
arg.class != Integer &&
|
||||
arg.casecmp?('ALL')
|
||||
[0, Vdc::ALL_RESOURCES]
|
||||
else
|
||||
OpenNebulaHelper.rname_to_id(arg, "HOST")
|
||||
OpenNebulaHelper.rname_to_id(arg, 'HOST')
|
||||
end
|
||||
end
|
||||
|
||||
set :format, :datastoreid,
|
||||
"#{OpenNebulaHelper.rname_to_id_desc('DATASTORE')}. Can be set to ALL" do |arg|
|
||||
"#{OpenNebulaHelper.rname_to_id_desc('DATASTORE')}. "\
|
||||
'Can be set to ALL' do |arg|
|
||||
|
||||
if !arg.nil? and arg.class != Fixnum and arg.upcase == "ALL"
|
||||
if !arg.nil? &&
|
||||
arg.class != Integer &&
|
||||
arg.casecmp?('ALL')
|
||||
[0, Vdc::ALL_RESOURCES]
|
||||
else
|
||||
OpenNebulaHelper.rname_to_id(arg, "DATASTORE")
|
||||
OpenNebulaHelper.rname_to_id(arg, 'DATASTORE')
|
||||
end
|
||||
end
|
||||
|
||||
set :format, :vnetid,
|
||||
"#{OpenNebulaHelper.rname_to_id_desc('VNET')}. Can be set to ALL" do |arg|
|
||||
"#{OpenNebulaHelper.rname_to_id_desc('VNET')}. "\
|
||||
'Can be set to ALL' do |arg|
|
||||
|
||||
if !arg.nil? and arg.class != Fixnum and arg.upcase == "ALL"
|
||||
if !arg.nil? &&
|
||||
arg.class != Integer &&
|
||||
arg.casecmp?('ALL')
|
||||
[0, Vdc::ALL_RESOURCES]
|
||||
else
|
||||
OpenNebulaHelper.rname_to_id(arg, "VNET")
|
||||
OpenNebulaHelper.rname_to_id(arg, 'VNET')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -129,7 +141,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :rename, rename_desc, :vdcid, :name do
|
||||
helper.perform_action(args[0],options,"renamed") do |o|
|
||||
helper.perform_action(args[0], options, 'renamed') do |o|
|
||||
o.rename(args[1])
|
||||
end
|
||||
end
|
||||
@@ -140,8 +152,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :update, update_desc, :vdcid, [:file, nil],
|
||||
:options=>OpenNebulaHelper::APPEND do
|
||||
helper.perform_action(args[0],options,"modified") do |obj|
|
||||
:options => OpenNebulaHelper::APPEND do
|
||||
helper.perform_action(args[0], options, 'modified') do |obj|
|
||||
if options[:append]
|
||||
str = OpenNebulaHelper.append_template(args[0], obj, args[1])
|
||||
else
|
||||
@@ -160,7 +172,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :delete, delete_desc, [:range, :vdcid_list] do
|
||||
helper.perform_actions(args[0],options,"deleted") do |obj|
|
||||
helper.perform_actions(args[0], options, 'deleted') do |obj|
|
||||
obj.delete
|
||||
end
|
||||
end
|
||||
@@ -170,7 +182,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :addgroup, add_group_desc, [:range, :vdcid_list], :groupid do
|
||||
helper.perform_actions(args[0],options,"group added") do |obj|
|
||||
helper.perform_actions(args[0], options, 'group added') do |obj|
|
||||
obj.add_group(args[1].to_i)
|
||||
end
|
||||
end
|
||||
@@ -180,7 +192,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :delgroup, del_group_desc, [:range, :vdcid_list], :groupid do
|
||||
helper.perform_actions(args[0],options,"group deleted") do |obj|
|
||||
helper.perform_actions(args[0], options, 'group deleted') do |obj|
|
||||
obj.del_group(args[1].to_i)
|
||||
end
|
||||
end
|
||||
@@ -189,8 +201,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Adds a Cluster (from a specific Zone) to the given VDC
|
||||
EOT
|
||||
|
||||
command :addcluster, add_cluster_desc, [:range, :vdcid_list], :zoneid, :clusterid do
|
||||
helper.perform_actions(args[0],options,"cluster added") do |obj|
|
||||
command :addcluster, add_cluster_desc,
|
||||
[:range, :vdcid_list], :zoneid, :clusterid do
|
||||
helper.perform_actions(args[0], options, 'cluster added') do |obj|
|
||||
obj.add_cluster(args[1].to_i, args[2].to_i)
|
||||
end
|
||||
end
|
||||
@@ -199,8 +212,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Deletes a Cluster (from a specific Zone) from the given VDC
|
||||
EOT
|
||||
|
||||
command :delcluster, del_cluster_desc, [:range, :vdcid_list], :zoneid, :clusterid do
|
||||
helper.perform_actions(args[0],options,"cluster deleted") do |obj|
|
||||
command :delcluster, del_cluster_desc,
|
||||
[:range, :vdcid_list], :zoneid, :clusterid do
|
||||
helper.perform_actions(args[0], options, 'cluster deleted') do |obj|
|
||||
obj.del_cluster(args[1].to_i, args[2].to_i)
|
||||
end
|
||||
end
|
||||
@@ -210,7 +224,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :addhost, add_host_desc, [:range, :vdcid_list], :zoneid, :hostid do
|
||||
helper.perform_actions(args[0],options,"host added") do |obj|
|
||||
helper.perform_actions(args[0], options, 'host added') do |obj|
|
||||
obj.add_host(args[1].to_i, args[2].to_i)
|
||||
end
|
||||
end
|
||||
@@ -220,7 +234,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :delhost, del_host_desc, [:range, :vdcid_list], :zoneid, :hostid do
|
||||
helper.perform_actions(args[0],options,"host deleted") do |obj|
|
||||
helper.perform_actions(args[0], options, 'host deleted') do |obj|
|
||||
obj.del_host(args[1].to_i, args[2].to_i)
|
||||
end
|
||||
end
|
||||
@@ -229,8 +243,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Adds a Datastore (from a specific Zone) to the given VDC
|
||||
EOT
|
||||
|
||||
command :adddatastore, add_datastore_desc, [:range, :vdcid_list], :zoneid, :datastoreid do
|
||||
helper.perform_actions(args[0],options,"datastore added") do |obj|
|
||||
command :adddatastore, add_datastore_desc,
|
||||
[:range, :vdcid_list], :zoneid, :datastoreid do
|
||||
helper.perform_actions(args[0], options, 'datastore added') do |obj|
|
||||
obj.add_datastore(args[1].to_i, args[2].to_i)
|
||||
end
|
||||
end
|
||||
@@ -239,8 +254,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Deletes a Datastore (from a specific Zone) from the given VDC
|
||||
EOT
|
||||
|
||||
command :deldatastore, del_datastore_desc, [:range, :vdcid_list], :zoneid, :datastoreid do
|
||||
helper.perform_actions(args[0],options,"datastore deleted") do |obj|
|
||||
command :deldatastore, del_datastore_desc,
|
||||
[:range, :vdcid_list], :zoneid, :datastoreid do
|
||||
helper.perform_actions(args[0], options, 'datastore deleted') do |obj|
|
||||
obj.del_datastore(args[1].to_i, args[2].to_i)
|
||||
end
|
||||
end
|
||||
@@ -250,7 +266,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :addvnet, add_vnet_desc, [:range, :vdcid_list], :zoneid, :vnetid do
|
||||
helper.perform_actions(args[0],options,"vnet added") do |obj|
|
||||
helper.perform_actions(args[0], options, 'vnet added') do |obj|
|
||||
obj.add_vnet(args[1].to_i, args[2].to_i)
|
||||
end
|
||||
end
|
||||
@@ -260,7 +276,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :delvnet, del_vnet_desc, [:range, :vdcid_list], :zoneid, :vnetid do
|
||||
helper.perform_actions(args[0],options,"vnet deleted") do |obj|
|
||||
helper.perform_actions(args[0], options, 'vnet deleted') do |obj|
|
||||
obj.del_vnet(args[1].to_i, args[2].to_i)
|
||||
end
|
||||
end
|
||||
@@ -269,7 +285,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Lists VDCs in the pool
|
||||
EOT
|
||||
|
||||
command :list, list_desc, :options=>list_options do
|
||||
command :list, list_desc, :options => list_options do
|
||||
helper.list_pool(options)
|
||||
end
|
||||
|
||||
@@ -277,7 +293,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Shows information for the given VDC
|
||||
EOT
|
||||
|
||||
command :show, show_desc,:vdcid, :options=>OpenNebulaHelper::XML do
|
||||
helper.show_resource(args[0],options)
|
||||
command :show, show_desc, :vdcid, :options => OpenNebulaHelper::XML do
|
||||
helper.show_resource(args[0], options)
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user