1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

Revert "Lintin oneprovisoin and onevm CLI"

This reverts commit 59a346f60134e2d00342deac0a35f537b9fc4722.
This commit is contained in:
Tino Vazquez 2019-02-04 10:33:45 +01:00
parent 1ad704b185
commit 2b2b253f7c
No known key found for this signature in database
GPG Key ID: 2FE9C32E94AEABBE
2 changed files with 199 additions and 215 deletions

View File

@ -16,28 +16,28 @@
# 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'
ANSIBLE_LOCATION = '/usr/share/one/oneprovision/ansible'
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
REMOTES_LOCATION="/var/lib/one/remotes"
ANSIBLE_LOCATION="/usr/share/one/oneprovision/ansible"
else
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
REMOTES_LOCATION = ONE_LOCATION + '/var/remotes'
ANSIBLE_LOCATION = ONE_LOCATION + '/usr/share/oneprovision/ansible'
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
REMOTES_LOCATION=ONE_LOCATION+"/var/remotes"
ANSIBLE_LOCATION=ONE_LOCATION+"/usr/share/oneprovision/ansible"
end
$LOAD_PATH << RUBY_LIB_LOCATION
$LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
$: << RUBY_LIB_LOCATION
$: << RUBY_LIB_LOCATION+"/cli"
PING_TIMEOUT_DEFAULT = 20
PING_RETRIES_DEFAULT = 10
MAX_RETRIES_DEFAULT = 3
RUN_MODE_DEFAULT = :interactive
FAIL_CHOICE_DEFAULT = :quit
CLEANUP_DEFAULT = false
THREADS_DEFAULT = 3
$PING_TIMEOUT = 20
$PING_RETRIES = 10
$MAX_RETRIES = 3
$RUN_MODE = :interactive
$FAIL_CHOICE = :quit
$CLEANUP = false
$THREADS = 3
require 'command_parser'
require 'one_helper'
@ -52,27 +52,27 @@ require 'tempfile'
require 'base64'
CommandParser::CmdParser.new(ARGV) do
usage '`oneprovision` <command> [<file>] [<hostid>] [<args>] [<options>]'
usage "`oneprovision` <command> [<file>] [<hostid>] [<args>] [<options>]"
version OpenNebulaHelper::ONE_VERSION
@common_helper = CommonHelper.new
@host_helper = OneProvisionHostHelper.new
@ansible_helper = OneProvisionAnsibleHelper.new
@provision_helper = OneProvisionProvisionHelper.new
@cluster_helper = OneProvisionClusterHelper.new
@datastore_helper = OneProvisionDatastoreHelper.new
@vnet_helper = OneProvisionVnetHelper.new
$common_helper = CommonHelper.new
$host_helper = OneProvisionHostHelper.new
$ansible_helper = OneProvisionAnsibleHelper.new
$provision_helper = OneProvisionProvisionHelper.new
$cluster_helper = OneProvisionClusterHelper.new
$datastore_helper = OneProvisionDatastoreHelper.new
$vnet_helper = OneProvisionVnetHelper.new
@mutex = Mutex.new
$mutex = Mutex.new
before_proc do
@common_helper.set_client(options)
@host_helper.set_client(options)
@ansible_helper.set_client(options)
@provision_helper.set_client(options)
@cluster_helper.set_client(options)
@datastore_helper.set_client(options)
@vnet_helper.set_client(options)
$common_helper.set_client(options)
$host_helper.set_client(options)
$ansible_helper.set_client(options)
$provision_helper.set_client(options)
$cluster_helper.set_client(options)
$datastore_helper.set_client(options)
$vnet_helper.set_client(options)
end
########################################################################
@ -80,130 +80,125 @@ CommandParser::CmdParser.new(ARGV) do
########################################################################
VERBOSE = {
:name => 'verbose',
:short => '-d',
:large => '--verbose',
:description => 'Set verbose logging mode'
:name => "verbose",
:short => "-d",
:large => "--verbose",
:description => "Set verbose logging mode",
}
DEBUG = {
:name => 'debug',
:short => '-D',
:large => '--debug',
:description => 'Set debug logging mode',
:name => "debug",
:short => "-D",
:large => "--debug" ,
:description => "Set debug logging mode",
:format => String
}
BATCH = {
:name => 'batch',
:short => '-b',
:large => '--batch',
:description => 'Run in non-interactive mode (no questions)',
:format => String
:name => "batch",
:short => "-b",
:large => "--batch",
:description => "Run in non-interactive mode (no questions)",
:format => String,
}
FAIL_RETRY = {
:name => 'fail_retry',
:large => '--fail-retry number',
:description => 'Set batch failover mode to number of retries',
:name => "fail_retry",
:large => "--fail-retry number",
:description => "Set batch failover mode to number of retries",
:format => Integer
}
FAIL_CLEANUP = {
:name => 'fail_cleanup',
:large => '--fail-cleanup',
:description => 'Set batch failover mode to clean up and quit'
:name => "fail_cleanup",
:large => "--fail-cleanup",
:description => "Set batch failover mode to clean up and quit",
}
FAIL_SKIP = {
:name => 'fail_skip',
:large => '--fail-skip',
:description => 'Set batch failover mode to skip failing part'
:name => "fail_skip",
:large => "--fail-skip",
:description => "Set batch failover mode to skip failing part",
}
FAIL_QUIT = {
:name => 'fail_quit',
:large => '--fail-quit',
:description => 'Set batch failover mode to quit (default)'
:name => "fail_quit",
:large => "--fail-quit",
:description => "Set batch failover mode to quit (default)",
}
FORCE = {
:name => 'force',
:short => '-F',
:large => '--force',
:description => 'Force configure to execute',
:name => "force",
:short => "-F",
:large => "--force",
:description => "Force configure to execute",
:format => String
}
HARD = {
:name => 'hard',
:short => '-H',
:large => '--hard',
:description => 'Reset the host',
:name => "hard",
:short => "-H",
:large => "--hard",
:description => "Reset the host",
:format => String
}
PING_TIMEOUT = {
:name => 'ping_timeout',
:large => '--ping-timeout seconds',
:description => "Set timeout for ping (default: \
#{PING_TIMEOUT_DEFAULT} secs)",
:name => "ping_timeout",
:large => "--ping-timeout seconds",
:description => "Set timeout for ping (default: #{$PING_TIMEOUT} secs)",
:format => Integer
}
PING_RETRIES = {
:name => 'ping_retries',
:large => '--ping-retries number',
:description => "Set retries for ping (default: \
#{PING_RETRIES_DEFAULT})",
:name => "ping_retries",
:large => "--ping-retries number",
:description => "Set retries for ping (default: #{$PING_RETRIES})",
:format => Integer
}
THREADS = {
:name => 'threads',
:short => '-t threads',
:large => '--threads threads',
:description => "Set threads for create (default: #{THREADS_DEFAULT})",
:name => "threads",
:short => "-t threads",
:large => "--threads threads",
:description => "Set threads for create (default: #{$THREADS})",
:format => Integer
}
DELETE_ALL = {
:name => 'delete_all',
:large => '--delete-all',
:description => 'Delete all vms and images first, then delete the\
resources.'
:name => "delete_all",
:large => "--delete-all",
:description => "Delete all vms and images first, then delete the resources."
}
INCREMENTAL = {
:name => 'incremental',
:large => '--incremental',
:description => 'Configure just new hosts, default is configure \
the whole provision.'
:name => "incremental",
:large => "--incremental",
:description => "Configure just new hosts, default is configure the whole provision."
}
DUMP = {
:name => 'dump',
:large => '--dump',
:description => 'Dump the configuration file result.'
:name => "dump",
:large => "--dump",
:description => "Dump the configuration file result."
}
MODES = CommandParser::OPTIONS - [CommandParser::VERBOSE] + [
MODES = CommandParser::OPTIONS - [ CommandParser::VERBOSE ] + [
VERBOSE, DEBUG, BATCH,
FAIL_RETRY, FAIL_CLEANUP, FAIL_SKIP, FAIL_QUIT
]
FAIL_RETRY, FAIL_CLEANUP, FAIL_SKIP, FAIL_QUIT ]
CREATE_OPTIONS = [THREADS, MODES, PING_TIMEOUT, PING_RETRIES]
CREATE_OPTIONS = [ THREADS, MODES, PING_TIMEOUT, PING_RETRIES]
########################################################################
# Formatters for arguments
########################################################################
set :format, :hostid, CommonHelper.to_id_desc do |arg|
@host_helper.to_id(arg)
$host_helper.to_id(arg)
end
set :format, :hostid_list, CommonHelper.list_to_id_desc do |arg|
@host_helper.list_to_id(arg)
$host_helper.list_to_id(arg)
end
########################################################################
@ -214,10 +209,10 @@ CommandParser::CmdParser.new(ARGV) do
Provision a new cluster via bare metal provider
EOT
command :create, create_desc, :config, :options => CREATE_OPTIONS do
@common_helper.get_mode(options)
command :create, create_desc, :config, :options=>CREATE_OPTIONS do
$common_helper.get_mode(options)
@provision_helper.create(args[0], options)
$provision_helper.create(args[0], options)
0
end
@ -228,8 +223,8 @@ CommandParser::CmdParser.new(ARGV) do
Validate configuration file
EOT
command :validate, validate_desc, [:config_file], :options => DUMP do
@common_helper.validate_configuration(args[0], options)
command :validate, validate_desc, [:config_file], :options=>DUMP do
$common_helper.validate_configuration(args[0], options)
0
end
@ -240,14 +235,11 @@ CommandParser::CmdParser.new(ARGV) do
List all avaliable provisions
EOT
# TODO: add xml option
command :list, provision_list_desc,
:options => CommandParser::OPTIONS + CLIHelper::OPTIONS do
columns = %w[clusters hosts networks datastores]
#TODO add xml option
command :list, provision_list_desc, :options=>CommandParser::OPTIONS+CLIHelper::OPTIONS do
columns = ['clusters', 'hosts', 'networks', 'datastores']
@provision_helper.format_pool(options)
.show(@provision_helper.get_list(columns, true),
options)
$provision_helper.format_pool(options).show($provision_helper.get_list(columns, true), options)
0
end
@ -258,9 +250,8 @@ CommandParser::CmdParser.new(ARGV) do
Show provision details
EOT
command :show, provision_show_desc,
[:provisionid], :options => CommandParser::OPTIONS do
@provision_helper.show(args[0], options)
command :show, provision_show_desc, [:provisionid], :options=>CommandParser::OPTIONS do
$provision_helper.show(args[0], options)
0
end
@ -271,27 +262,43 @@ CommandParser::CmdParser.new(ARGV) do
Run configuration in all provision hosts
EOT
command :configure, provision_configure_desc,
:provisionid, :options => [MODES, FORCE] do
@common_helper.get_mode(options)
command :configure, provision_configure_desc, :provisionid, :options=>[MODES,FORCE] do
$common_helper.get_mode(options)
@provision_helper.configure(args[0], options)
$provision_helper.configure(args[0], options)
0
end
###
=begin
provision_update_desc = <<-EOT
Update the provision, adding more resources
EOT
command :update, provision_update_desc, :provisionid, :config, :options=>[CREATE_OPTIONS, INCREMENTAL] do
$common_helper.get_mode(options)
$provision_helper.update(args[0], args[1], options)
0
end
=end
###
provision_delete_desc = <<-EOT
Deletes and unprovisions all the resources
EOT
command :delete, provision_delete_desc, :provisionid,
:options => [MODES, THREADS, DELETE_ALL] do
@common_helper.get_mode(options)
command :delete, provision_delete_desc, :provisionid, :options=>[MODES,THREADS,DELETE_ALL] do
$common_helper.get_mode(options)
provision = Provision.new(args[0])
provision.refresh
provision.delete((options.key? :delete_all))
provision.delete((options.has_key? :delete_all))
0
end
@ -304,15 +311,10 @@ CommandParser::CmdParser.new(ARGV) do
List all availables clusters
EOT
command [:cluster, :list], cluster_list_desc,
:options => CommandParser::OPTIONS + CLIHelper::OPTIONS +
OpenNebulaHelper::OPTIONS +
[OpenNebulaHelper::DESCRIBE] do
columns = %w[hosts networks datastores]
command [:cluster, :list], cluster_list_desc, :options=>CommandParser::OPTIONS+CLIHelper::OPTIONS+OpenNebulaHelper::OPTIONS + [OpenNebulaHelper::DESCRIBE] do
columns = ['hosts', 'networks', 'datastores']
@cluster_helper.format_pool(options)
.show(@provision_helper.get_list(columns, false),
options)
$cluster_helper.format_pool(options).show($provision_helper.get_list(columns, false), options)
0
end
@ -323,17 +325,14 @@ CommandParser::CmdParser.new(ARGV) do
Deletes and unprovisions the given cluster
EOT
command [:cluster, :delete], cluster_delete_desc,
[:range, :clusterid_list], :options => [MODES, FORCE] do
@common_helper.get_mode(options)
command [:cluster, :delete], cluster_delete_desc, [:range,:clusterid_list], :options=>[MODES,FORCE] do
$common_helper.get_mode(options)
@cluster_helper.perform_actions(args[0],
options,
'deleted') do |cluster|
$cluster_helper.perform_actions(args[0],options,"deleted") do |cluster|
rc = cluster.delete
if OpenNebula.is_error?(rc)
@common_helper.fail(rc.message)
$common_helper.fail(rc.message)
end
end
@ -344,16 +343,31 @@ CommandParser::CmdParser.new(ARGV) do
# Host Commands
########################################################################
=begin
host_create_desc = <<-EOT.unindent
Create a single host
EOT
command [:host, :create], create_desc, :config, :options=>CREATE_OPTIONS do
$common_helper.get_mode(options)
$provision_helper.create(args[0], options)
0
end
=end
###
host_resume_desc = <<-EOT.unindent
Resume the host
EOT
command [:host, :resume], host_resume_desc,
[:range, :hostid_list], :options => MODES do
@common_helper.get_mode(options)
command [:host, :resume], host_resume_desc, [:range,:hostid_list], :options=>MODES do
$common_helper.get_mode(options)
@host_helper.perform_actions(args[0], options, 'enabled') do |host|
@host_helper.resume_host(host)
$host_helper.perform_actions(args[0],options,"enabled") do |host|
$host_helper.resume_host(host)
end
end
@ -363,12 +377,11 @@ CommandParser::CmdParser.new(ARGV) do
Power off the host
EOT
command [:host, :poweroff], host_poweroff_desc,
[:range, :hostid_list], :options => MODES do
@common_helper.get_mode(options)
command [:host, :poweroff], host_poweroff_desc, [:range,:hostid_list], :options=>MODES do
$common_helper.get_mode(options)
@host_helper.perform_actions(args[0], options, 'disabled') do |host|
@host_helper.poweroff_host(host)
$host_helper.perform_actions(args[0],options,"disabled") do |host|
$host_helper.poweroff_host(host)
end
end
@ -378,12 +391,11 @@ CommandParser::CmdParser.new(ARGV) do
Reboot the host
EOT
command [:host, :reboot], host_reboot_desc,
[:range, :hostid_list], :options => [MODES, HARD] do
@common_helper.get_mode(options)
command [:host, :reboot], host_reboot_desc, [:range,:hostid_list], :options=>[MODES, HARD] do
$common_helper.get_mode(options)
@host_helper.perform_actions(args[0], options, 'enabled') do |host|
@host_helper.reboot_host(host, options)
$host_helper.perform_actions(args[0],options,"enabled") do |host|
$host_helper.reboot_host(host, options)
end
end
@ -393,17 +405,16 @@ CommandParser::CmdParser.new(ARGV) do
Unprovisions and deletes the given Host
EOT
command [:host, :delete], host_delete_desc,
[:range, :hostid_list], :options => MODES do
@common_helper.get_mode(options)
command [:host, :delete], host_delete_desc, [:range,:hostid_list], :options=>MODES do
$common_helper.get_mode(options)
@host_helper.perform_actions(args[0], options, 'deleted') do |host|
$host_helper.perform_actions(args[0],options,"deleted") do |host|
host.info
begin
@host_helper.delete_host(host)
rescue StandardError => e
@common_helper.fail("Delete failed on exception: #{e}")
$host_helper.delete_host(host)
rescue => e
$common_helper.fail("Delete failed on exception: #{e.to_s}")
end
end
end
@ -414,12 +425,11 @@ CommandParser::CmdParser.new(ARGV) do
Run configuration on the host
EOT
command [:host, :configure], host_configure_desc,
[:range, :hostid_list], :options => [MODES, FORCE] do
@common_helper.get_mode(options)
command [:host, :configure], host_configure_desc, [:range,:hostid_list], :options=>[MODES,FORCE] do
$common_helper.get_mode(options)
@host_helper.perform_actions(args[0], options, 'configured') do |host|
@host_helper.configure_host([host], options)
$host_helper.perform_actions(args[0],options,"configured") do |host|
$host_helper.configure_host([host], options)
end
end
@ -429,10 +439,9 @@ CommandParser::CmdParser.new(ARGV) do
Establish SSH conection to the host
EOT
command [:host, :ssh], host_ssh_desc, :hostid, [:command, nil],
:options => CommandParser::OPTIONS do
@host_helper.perform_action(args[0], options, '') do |host|
@host_helper.ssh_host(host, args)
command [:host, :ssh], host_ssh_desc, :hostid, [:command, nil], :options=>CommandParser::OPTIONS do
$host_helper.perform_action(args[0],options,"") do |host|
$host_helper.ssh_host(host, args)
end
end
@ -442,15 +451,12 @@ CommandParser::CmdParser.new(ARGV) do
Lists bare metal Hosts in the pool
EOT
command [:host, :list], host_list_desc,
:options => CommandParser::OPTIONS + CLIHelper::OPTIONS +
OpenNebulaHelper::OPTIONS +
[OpenNebulaHelper::DESCRIBE] do
if !options.key? :filter
options[:filter] = ['PROVIDER!=-']
command [:host, :list], host_list_desc, :options=>CommandParser::OPTIONS+CLIHelper::OPTIONS+OpenNebulaHelper::OPTIONS + [OpenNebulaHelper::DESCRIBE] do
if !options.has_key? :filter
options.merge!(filter: ["PROVIDER!=-"])
end
@host_helper.list_pool(options)
$host_helper.list_pool(options)
end
###
@ -459,14 +465,12 @@ CommandParser::CmdParser.new(ARGV) do
Lists bare metal Hosts continuously
EOT
command [:host, :top], host_top_desc,
:options => CommandParser::OPTIONS +
CLIHelper::OPTIONS + OpenNebulaHelper::OPTIONS do
if !options.key? :filter
options[:filter] = ['PROVIDER!=-']
command [:host, :top], host_top_desc, :options=>CommandParser::OPTIONS+CLIHelper::OPTIONS+OpenNebulaHelper::OPTIONS do
if !options.has_key? :filter
options.merge!(filter: ["PROVIDER!=-"])
end
@host_helper.list_pool(options, true)
$host_helper.list_pool(options, true)
end
########################################################################
@ -477,15 +481,8 @@ CommandParser::CmdParser.new(ARGV) do
List all availables datastores
EOT
command [:datastore, :list], datastore_list_desc,
:options => CommandParser::OPTIONS +
CLIHelper::OPTIONS +
OpenNebulaHelper::OPTIONS +
[OpenNebulaHelper::DESCRIBE] do
@datastore_helper.format_pool(options)
.show(@provision_helper
.get_provision_resources(['datastores']),
options)
command [:datastore, :list], datastore_list_desc, :options=>CommandParser::OPTIONS+CLIHelper::OPTIONS+OpenNebulaHelper::OPTIONS + [OpenNebulaHelper::DESCRIBE] do
$datastore_helper.format_pool(options).show($provision_helper.get_provision_resources(['datastores']), options)
0
end
@ -496,13 +493,11 @@ CommandParser::CmdParser.new(ARGV) do
Deletes and unprovisions the given datastore
EOT
command [:datastore, :delete], datastore_delete_desc,
[:range, :datastoreid_list], :options => [MODES, FORCE] do
@common_helper.get_mode(options)
command [:datastore, :delete], datastore_delete_desc, [:range,:datastoreid_list], :options=>[MODES,FORCE] do
$common_helper.get_mode(options)
@datastore_helper
.perform_actions(args[0], options, 'deleted') do |datastore|
@logger.info("Deleting datastore #{datastore['ID']}")
$datastore_helper.perform_actions(args[0],options,"deleted") do |datastore|
$logger.info("Deleting datastore #{datastore['ID']}")
datastore.delete
end
@ -518,15 +513,8 @@ CommandParser::CmdParser.new(ARGV) do
List all availables virtual networks
EOT
command [:vnet, :list], vnet_list_desc,
:options => CommandParser::OPTIONS +
CLIHelper::OPTIONS +
OpenNebulaHelper::OPTIONS +
[OpenNebulaHelper::DESCRIBE] do
@vnet_helper.format_pool(options)
.show(@provision_helper
.get_provision_resources(['networks']),
options)
command [:vnet, :list], vnet_list_desc, :options=>CommandParser::OPTIONS+CLIHelper::OPTIONS+OpenNebulaHelper::OPTIONS + [OpenNebulaHelper::DESCRIBE] do
$vnet_helper.format_pool(options).show($provision_helper.get_provision_resources(['networks']), options)
0
end
@ -537,12 +525,11 @@ CommandParser::CmdParser.new(ARGV) do
Deletes and unprovisions the given virtual network
EOT
command [:vnet, :delete], vnet_delete_desc,
[:range, :vnetid_list], :options => [MODES, FORCE] do
@common_helper.get_mode(options)
command [:vnet, :delete], vnet_delete_desc, [:range,:vnetid_list], :options=>[MODES,FORCE] do
$common_helper.get_mode(options)
@vnet_helper.perform_actions(args[0], options, 'deleted') do |vnet|
@logger.info("Deleting vnet #{vnet['ID']}")
$vnet_helper.perform_actions(args[0],options,"deleted") do |vnet|
$logger.info("Deleting vnet #{vnet['ID']}")
vnet.delete
end

View File

@ -557,10 +557,8 @@ CommandParser::CmdParser.new(ARGV) do
EOT
command :migrate, migrate_desc, [:range, :vmid_list], :hostid,
[:datastoreid, nil], :options => [ENFORCE,
OneVMHelper::LIVE,
OneVMHelper::POFF,
OneVMHelper::POFFHARD] do
[:datastoreid, nil], :options => [ENFORCE, OneVMHelper::LIVE,
OneVMHelper::POFF, OneVMHelper::POFFHARD] do
host_id = args[1]
verbose = "migrating to #{host_id}"
@ -797,8 +795,7 @@ CommandParser::CmdParser.new(ARGV) do
if ip
if !nic_alias && !nic_name
template = "NIC = [ NETWORK_ID = #{network_id},\
IP = #{ip} ]"
template = "NIC = [ NETWORK_ID = #{network_id}, IP = #{ip} ]"
elsif !nic_alias && nic_name
template = "NIC = [ NETWORK_ID = #{network_id},
IP = #{ip},
@ -1148,8 +1145,8 @@ CommandParser::CmdParser.new(ARGV) do
state, valid states are: pending, failure, poweroff, undeploy, hold or
cloning.
This command accepts a template file or opens an editor, the full list
of configuration attributes are:
This command accepts a template file or opens an editor, the full list of
configuration attributes are:
OS = ["ARCH", "MACHINE", "KERNEL", "INITRD", "BOOTLOADER", "BOOT"]
FEATURES = ["ACPI", "PAE", "APIC", "LOCALTIME", "HYPERV", "GUEST_AGENT"]
@ -1187,8 +1184,8 @@ CommandParser::CmdParser.new(ARGV) do
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.
Aalid states are: All.
EOT