mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-23 22:50:09 +03:00
B OpenNebula/one#810: add append opt to update AR (#22)
- Add option to append attributes to the AR - Add option to read from file and append or replace it - Code small polishments (cherry picked from commit 3f31b7f5c6d4f39c6929411e1daf8216325adbe1)
This commit is contained in:
parent
9ff02bac52
commit
ad9a698681
@ -13,7 +13,6 @@
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'one_helper'
|
||||
require 'one_helper/onevm_helper'
|
||||
|
||||
@ -215,6 +214,71 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
|
||||
orphans
|
||||
end
|
||||
|
||||
# Update VNet address range
|
||||
#
|
||||
# @param vnet_id [Intenger] Virtual Network ID
|
||||
# @param ar_id [Intenger] Address Range ID
|
||||
# @param file [String] Path to file to read
|
||||
# @param options [Hash] User CLI options
|
||||
def update_ar(vnet_id, ar_id, file, options)
|
||||
perform_action(vnet_id, options, 'AR updated') do |obj|
|
||||
rc = obj.info
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
STDERR.puts rc.message
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
obj.delete_element("AR_POOL/AR[AR_ID!=#{ar_id}]")
|
||||
obj.delete_element('AR_POOL/AR/LEASES')
|
||||
obj.delete_element('AR_POOL/AR/USED_LEASES')
|
||||
obj.delete_element('AR_POOL/AR/MAC_END')
|
||||
obj.delete_element('AR_POOL/AR/IP_END')
|
||||
obj.delete_element('AR_POOL/AR/IP6_ULA')
|
||||
obj.delete_element('AR_POOL/AR/IP6_ULA_END')
|
||||
obj.delete_element('AR_POOL/AR/IP6_GLOBAL')
|
||||
obj.delete_element('AR_POOL/AR/IP6_GLOBAL_END')
|
||||
|
||||
if obj.template_like_str('AR_POOL').empty?
|
||||
STDERR.puts "Address Range #{ar_id} does not exist for " \
|
||||
"Virtual Network #{vnet_id}"
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
xpath = "AR_POOL/AR[AR_ID=#{ar_id}]"
|
||||
|
||||
if options[:append]
|
||||
str = OpenNebulaHelper.append_template(vnet_id,
|
||||
obj,
|
||||
file,
|
||||
xpath)
|
||||
else
|
||||
str = OpenNebulaHelper.update_template(vnet_id,
|
||||
obj,
|
||||
file,
|
||||
xpath)
|
||||
end
|
||||
|
||||
if options[:append]
|
||||
# Insert element in current template
|
||||
parts = obj.template_like_str('AR_POOL').split("\n")
|
||||
|
||||
# Insert it in second position, OpenNebula will sort it
|
||||
parts.insert(1, "#{str.strip},")
|
||||
|
||||
parts = parts.join("\n")
|
||||
str = parts
|
||||
else
|
||||
# Use the information from user
|
||||
unless str.gsub(' ', '').match(/AR=\[/)
|
||||
str = "AR=[\n#{str.split("\n").join(",\n")}]"
|
||||
end
|
||||
end
|
||||
|
||||
obj.update_ar(str)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def factory(id=nil)
|
||||
|
@ -350,43 +350,9 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
Update Address Range variables. SIZE, IP, MAC and TYPE cannot be updated
|
||||
EOT
|
||||
|
||||
command :updatear, update_ar_desc, :vnetid, :ar_id, [:file, nil] do
|
||||
helper.perform_action(args[0], options, 'modified') do |obj|
|
||||
rc = obj.info
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
puts rc.message
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
obj.delete_element("AR_POOL/AR[AR_ID!=#{args[1]}]")
|
||||
obj.delete_element('AR_POOL/AR/LEASES')
|
||||
obj.delete_element('AR_POOL/AR/USED_LEASES')
|
||||
obj.delete_element('AR_POOL/AR/MAC_END')
|
||||
obj.delete_element('AR_POOL/AR/IP_END')
|
||||
obj.delete_element('AR_POOL/AR/IP6_ULA')
|
||||
obj.delete_element('AR_POOL/AR/IP6_ULA_END')
|
||||
obj.delete_element('AR_POOL/AR/IP6_GLOBAL')
|
||||
obj.delete_element('AR_POOL/AR/IP6_GLOBAL_END')
|
||||
|
||||
if obj.template_like_str('AR_POOL').empty?
|
||||
puts "Address Range #{args[1]} does not exist for " \
|
||||
"Virtual Network #{args[0]}"
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
str = OpenNebulaHelper.update_template_helper(false,
|
||||
args[0],
|
||||
obj,
|
||||
args[2],
|
||||
'AR_POOL',
|
||||
false)
|
||||
|
||||
helper.set_client(options)
|
||||
obj = helper.retrieve_resource(obj.id)
|
||||
|
||||
obj.update_ar(str)
|
||||
end
|
||||
command :updatear, update_ar_desc, :vnetid, :ar_id, [:file, nil],
|
||||
:options => OpenNebulaHelper::APPEND do
|
||||
helper.update_ar(args[0], args[1], args[2], options)
|
||||
end
|
||||
|
||||
rename_desc = <<-EOT.unindent
|
||||
|
Loading…
x
Reference in New Issue
Block a user