F #1884: Bug Fixes, minor changes

=================================

F #1884: show header (CLI)

F #1884: new list format for vCenter importer

F #1884: Bug fixex for importing networks

F #1884: fixing network opts importation

F #1884: import_bulk added! solve rollback bug

F #1884: improve rollback
This commit is contained in:
semedi committed 2018-04-18 11:04:08 +02:00
1 parent 29ebb3f191
commit dfcebe882c
8 files changed
+137 -84

No files matched your search

+40 -51
View File
@@ -29,19 +29,19 @@ class OneVcenterHelper < OpenNebulaHelper::OneHelper
TABLE = {
VOBJECT::DATASTORE => {
:struct => ["DATASTORE_LIST", "DATASTORE"],
:columns => {:IMID => 10, :REF => 10, :VCENTER => 10, :NAME => 10, :CLUSTERS => 10},
:columns => {:IMID => 5, :REF => 15, :NAME => 25, :CLUSTERS => 10},
:cli => [:host],
:dialogue => ->(arg){}
},
VOBJECT::TEMPLATE => {
:struct => ["TEMPLATE_LIST", "TEMPLATE"],
:columns => {:IMID => 10, :REF => 10, :VCENTER => 10, :NAME => 10 , :CLUSTERS => 10},
:columns => {:IMID => 5, :REF => 10, :NAME => 35},
:cli => [:host],
:dialogue => ->(arg){ OneVcenterHelper.template_dialogue(arg) }
},
VOBJECT::NETWORK => {
:struct => ["NETWORK_LIST", "NETWORK"],
:columns => {:IMID => 10, :REF => 10, :VCENTER => 10 , :NAME => 10},
:columns => {:IMID => 5, :REF => 15, :NAME => 10},
:cli => [:host],
:dialogue => ->(arg){ OneVcenterHelper.network_dialogue(arg) }
},
@@ -55,7 +55,7 @@ class OneVcenterHelper < OpenNebulaHelper::OneHelper
#######################
# CLI
# CLI ARGS
########################
def datastore(arg)
ds = VCenterDriver::VIHelper.one_item(OpenNebula::Datastore, arg)
@@ -70,6 +70,16 @@ class OneVcenterHelper < OpenNebulaHelper::OneHelper
end
########################
def show_header(vcenter_host)
CLIHelper.scr_bold
CLIHelper.scr_underline
puts "# vCenter: #{vcenter_host}".ljust(50)
CLIHelper.scr_restore
puts
end
def set_object(type)
type = type.downcase
if (type == "datastores")
@@ -104,8 +114,12 @@ class OneVcenterHelper < OpenNebulaHelper::OneHelper
end
def list_object(options, list)
list = cli_format(list)
vcenter_host = list.keys[0]
list = cli_format(list.values.first)
table = format_list()
show_header(vcenter_host)
table.show(list)
end
@@ -117,12 +131,12 @@ class OneVcenterHelper < OpenNebulaHelper::OneHelper
set_object(opts[:object])
res = {}
TABLE[@vobject][:cli].each do |arg|
raise "#{arg} it's mandadory for this op" if opts[arg].nil?
res[arg] = self.method(arg).call(opts[arg])
end
return res
end
@@ -137,10 +151,6 @@ class OneVcenterHelper < OpenNebulaHelper::OneHelper
d[:ref]
end
column :VCENTER, "vCenter", :left, :size=>config[:VCENTER] || 20 do |d|
d[:vcenter]
end
column :NAME, "Name", :left, :size=>config[:NAME] || 20 do |d|
d[:name] || d[:simple_name]
end
@@ -264,79 +274,58 @@ class OneVcenterHelper < OpenNebulaHelper::OneHelper
return answer
}
size="255"
ar_type="ether"
first_ip=""
first_mac=""
slaac=""
global_prefix=""
ula_prefix=""
ip6_address = ""
prefix_length = ""
opts = { size: "255", type: "ether" }
question = " How many VMs are you planning"\
" to fit into this network [255]? "
size = ask.call(question, "255")
opts[:size] = ask.call(question, "255")
question = " What type of Virtual Network"\
" do you want to create (IPv[4],IPv[6], [E]thernet)?"
type_answer = ask.call(question, "ether")
if ["4","6","ether", "e", "ip4", "ip6" ].include?(type_answer.downcase)
ar_type = type_answer.downcase
else
ar_type = "ether"
supported_types = ["4","6","ether", "e", "ip4", "ip6" ]
if !supported_types.include?(type_answer)
type_answer = 'e'
STDOUT.puts " Type [#{type_answer}] not supported,"\
" defaulting to Ethernet."
end
end
question_ip = " Please input the first IP in the range: "
question_mac = " Please input the first MAC in the range [Enter for default]: "
case ar_type.downcase
case type_answer.downcase
when "4", "ip4"
first_ip = ask.call(question_ip)
firts_mac = ask.call(question_mac)
opts[:ip] = ask.call(question_ip)
opts[:mac] = ask.call(question_mac)
opts[:type] = "ip"
when "6", "ip6"
firts_mac = ask.call(question_mac)
opts[:mac] = ask.call(question_mac)
question = " Do you want to use SLAAC "\
"Stateless Address Autoconfiguration? ([y]/n): "
slaac_answer = ask.call(question)
slaac_answer = ask.call(question, 'y').downcase
if slaac_answer == 'n'
slaac = false
question = " Please input the IPv6 address (cannot be empty): "
ip6_address = ask.call(question)
opts[:ip6] = ask.call(question)
question = " Please input the Prefix length (cannot be empty): "
prefix_length = ask.call(question)
ar_type = "ip6"
opts[:prefix_length] = ask.call(question)
opts[:type] = 'ip6_static'
else
slaac = true
question = " Please input the GLOBAL PREFIX "\
"[Enter for default]: "
gp_answer = ask.call(question)
opts[:global_prefix] = ask.call(question)
question= " Please input the ULA PREFIX "\
"[Enter for default]: "
ula_answer = ask.call(question)
ar_type = "ip6_static"
opts[:ula_prefix] = ask.call(question)
opts[:type] = 'ip6'
end
when "e", "ether"
first_mac = ask.call(question_mac)
opts[:mac] = ask.call(question_mac)
end
opts = {
size: size,
type: ar_type,
ip: first_ip,
mac: first_mac,
slaac: slaac,
global_prefix: global_prefix,
ula_refix: ula_prefix,
ip6: ip6_address,
prefix_length: prefix_length
}
return opts
end
end
+1 -1
View File
@@ -154,4 +154,4 @@ cmd = CommandParser::CmdParser.new(ARGV) do
exit_code 0
end
end
end
end
+27 -1
View File
@@ -98,6 +98,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do
:format => String
}
ALL = {
:name => "all",
:large => "--all",
:description => "Import all list",
:format => String
}
############################################################################
# Global Options
############################################################################
@@ -123,6 +130,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
importer = VCenterDriver::VcImporter.new_child(helper.client, vi_client, options[:object])
list = importer.get_list(args)
helper.list_object(options, list)
else
puts "for the moment is not supported without the proper authentication"
@@ -134,7 +142,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
Import the the desired vCenter object
EOT
command :import, import_desc, :oid, :options=>[ OBJECT, HOST, DATASTORE, VCENTER, USER, PASS, USE_DEFAULTS ] do
command :import, import_desc, :oid, :options=>[ OBJECT, HOST, DATASTORE ] do
indexes = args.first
if options[:host] && options[:object]
@@ -155,6 +163,24 @@ cmd=CommandParser::CmdParser.new(ARGV) do
exit 0
end
command :import_defaults, import_desc, :options=>[ OBJECT, HOST, DATASTORE ] do
if options[:host] && options[:object]
args = helper.parse_opts(options)
vi_client = VCenterDriver::VIClient.new_from_host(options[:host])
importer = VCenterDriver::VcImporter.new_child(helper.client, vi_client, options[:object])
importer.get_list(args)
importer.import_bulk
importer.stdout
else
puts "for the moment is not supported without the proper authentication"
end
exit 0
end
############################################################################
# Import clusters
############################################################################