mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
Merge branch 'feature-3203'
This commit is contained in:
commit
feddcaad77
@ -26,6 +26,12 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
|
||||
:description => "ID of the address range"
|
||||
}
|
||||
|
||||
SHOW_AR = {
|
||||
:name => "show_ar",
|
||||
:large => "--show-ar",
|
||||
:description => "Show also AR templates"
|
||||
}
|
||||
|
||||
MAC = {
|
||||
:name => "mac",
|
||||
:short => "-m mac",
|
||||
@ -163,6 +169,19 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
|
||||
table
|
||||
end
|
||||
|
||||
def show_ar(vn, ar_id)
|
||||
CLIHelper.print_header("%-80s" % ["TEMPLATE FOR AR #{ar_id}"], false)
|
||||
|
||||
begin
|
||||
template = vn.template_like_str("AR_POOL/AR[AR_ID=#{ar_id}]")
|
||||
rescue
|
||||
STDERR.puts "Can not get template for AR #{ar_id}"
|
||||
return
|
||||
end
|
||||
|
||||
puts template
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def factory(id=nil)
|
||||
@ -179,6 +198,8 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
|
||||
end
|
||||
|
||||
def format_resource(vn, options = {})
|
||||
vn_hash = vn.to_hash
|
||||
|
||||
str_h1="%-80s"
|
||||
CLIHelper.print_header(str_h1 %
|
||||
["VIRTUAL NETWORK #{vn.id.to_s} INFORMATION"])
|
||||
@ -217,8 +238,8 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
|
||||
|
||||
CLIHelper.print_header(str_h1 % ["ADDRESS RANGE POOL"], false)
|
||||
|
||||
if !vn.to_hash['VNET']['AR_POOL']['AR'].nil?
|
||||
arlist = [vn.to_hash['VNET']['AR_POOL']['AR']].flatten
|
||||
if !vn_hash['VNET']['AR_POOL']['AR'].nil?
|
||||
arlist = [vn_hash['VNET']['AR_POOL']['AR']].flatten
|
||||
end
|
||||
|
||||
CLIHelper::ShowTable.new(nil, self) do
|
||||
@ -255,12 +276,16 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
|
||||
puts
|
||||
CLIHelper.print_header(str_h1 % ["LEASES"], false)
|
||||
|
||||
if !vn.to_hash['VNET']['AR_POOL']['AR'].nil?
|
||||
lease_list = [vn.to_hash['VNET']['AR_POOL']['AR']].flatten
|
||||
ar_list = []
|
||||
|
||||
if !vn_hash['VNET']['AR_POOL']['AR'].nil?
|
||||
lease_list = [vn_hash['VNET']['AR_POOL']['AR']].flatten
|
||||
leases = Array.new
|
||||
|
||||
lease_list.each do |ar|
|
||||
id = ar['AR_ID']
|
||||
ar_list << id
|
||||
|
||||
if ar['LEASES'] && !ar['LEASES']['LEASE'].nil?
|
||||
lease = [ar['LEASES']['LEASE']].flatten
|
||||
lease.each do |l|
|
||||
@ -298,5 +323,12 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
|
||||
d["IP6_GLOBAL"]||"-"
|
||||
end
|
||||
end.show(leases, {})
|
||||
|
||||
if options[:show_ar]
|
||||
ar_list.each do |ar_id|
|
||||
puts
|
||||
show_ar(vn, ar_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -112,43 +112,49 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Adds an address range to the Virtual Network
|
||||
EOT
|
||||
|
||||
command :addar, addar_desc, :vnetid,
|
||||
command :addar, addar_desc, :vnetid, [:file, nil],
|
||||
:options => STD_OPTIONS + OneVNetHelper::ADDAR_OPTIONS do
|
||||
helper.perform_action(args[0],options,"lease added") do |vn|
|
||||
ar = "AR = [ "
|
||||
|
||||
if options[:ip]
|
||||
if options[:ip6_global] || options[:ip6_ula]
|
||||
ar << "TYPE=\"IP4_6\""
|
||||
else
|
||||
ar << "TYPE=\"IP4\""
|
||||
end
|
||||
if args[1]
|
||||
ar = File.read(args[1])
|
||||
else
|
||||
if options[:ip6_global] || options[:ip6_ula]
|
||||
ar << "TYPE=\"IP6\""
|
||||
ar = "AR = [ "
|
||||
|
||||
if options[:ip]
|
||||
if options[:ip6_global] || options[:ip6_ula]
|
||||
ar << "TYPE=\"IP4_6\""
|
||||
else
|
||||
ar << "TYPE=\"IP4\""
|
||||
end
|
||||
else
|
||||
ar << "TYPE=\"ETHER\""
|
||||
if options[:ip6_global] || options[:ip6_ula]
|
||||
ar << "TYPE=\"IP6\""
|
||||
else
|
||||
ar << "TYPE=\"ETHER\""
|
||||
end
|
||||
end
|
||||
|
||||
if options[:size]
|
||||
ar << ", SIZE = " << options[:size]
|
||||
else
|
||||
STDERR.puts "Address range needs to specify size (-s size)"
|
||||
exit -1
|
||||
end
|
||||
|
||||
ar << ", IP = " << options[:ip] if options[:ip]
|
||||
ar << ", MAC = " << options[:mac] if options[:mac]
|
||||
ar << ", GLOBAL_PREFIX = " <<
|
||||
options[:ip6_global] if options[:ip6_global]
|
||||
ar << ", ULA_PREFIX = " <<
|
||||
options[:ip6_ula] if options[:ip6_ula]
|
||||
ar << ", GATEWAY = " << options[:gateway] if options[:gateway]
|
||||
ar << ", MASK = " << options[:netmask] if options[:netmask]
|
||||
ar << ", VLAN = YES" if options[:vlan]
|
||||
ar << ", VLAN_ID = " << options[:vlanid] if options[:vlanid]
|
||||
|
||||
ar << "]"
|
||||
end
|
||||
|
||||
if options[:size]
|
||||
ar << ", SIZE = " << options[:size]
|
||||
else
|
||||
STDERR.puts "Address range needs to specify size (-s size)"
|
||||
exit -1
|
||||
end
|
||||
|
||||
ar << ", IP = " << options[:ip] if options[:ip]
|
||||
ar << ", MAC = " << options[:mac] if options[:mac]
|
||||
ar << ", GLOBAL_PREFIX = " << options[:ip6_global] if options[:ip6_global]
|
||||
ar << ", ULA_PREFIX = " << options[:ip6_ula] if options[:ip6_ula]
|
||||
ar << ", GATEWAY = " << options[:gateway] if options[:gateway]
|
||||
ar << ", MASK = " << options[:netmask] if options[:netmask]
|
||||
ar << ", VLAN = YES" if options[:vlan]
|
||||
ar << ", VLAN_ID = " << options[:vlanid] if options[:vlanid]
|
||||
|
||||
ar << "]"
|
||||
|
||||
vn.add_ar(ar)
|
||||
end
|
||||
end
|
||||
@ -299,7 +305,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :show, show_desc, :vnetid,
|
||||
:options=>OpenNebulaHelper::XML do
|
||||
:options=>[OpenNebulaHelper::XML, OneVNetHelper::SHOW_AR] do
|
||||
helper.show_resource(args[0],options)
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user