diff --git a/src/cli/one_helper/onevnet_helper.rb b/src/cli/one_helper/onevnet_helper.rb index a8db52d5ab..c2bdc898a2 100644 --- a/src/cli/one_helper/onevnet_helper.rb +++ b/src/cli/one_helper/onevnet_helper.rb @@ -18,6 +18,22 @@ require 'one_helper' require 'one_helper/onevm_helper' class OneVNetHelper < OpenNebulaHelper::OneHelper + AR = { + :name => "ar_id", + :short => "-a ar_id", + :large => "--address_range ar_id", + :format => Integer, + :description => "ID of the address range" + } + + MAC = { + :name => "mac", + :short => "-m mac", + :large => "--mac mac", + :format => String, + :description => "MAC address" + } + def self.rname "VNET" end @@ -26,12 +42,6 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper "onevnet.yaml" end - def self.type_to_str(id) - id = id.to_i - type_str = VirtualNetwork::VN_TYPES[id] - return VirtualNetwork::SHORT_VN_TYPES[type_str] - end - def format_pool(options) config_file = self.class.table_conf @@ -59,10 +69,6 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper OpenNebulaHelper.cluster_str(d["CLUSTER"]) end - column :TYPE, "Type of Virtual Network", :size=>6 do |d| - OneVNetHelper.type_to_str(d["TYPE"]) - end - column :SIZE, "Size of the Virtual Network", :size=>5 do |d| d["SIZE"] end diff --git a/src/cli/onevnet b/src/cli/onevnet index 4c5ee447e2..886dcbaf66 100755 --- a/src/cli/onevnet +++ b/src/cli/onevnet @@ -47,6 +47,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS CREATE_OPTIONS = [OneClusterHelper::CLUSTER] + STD_OPTIONS = CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS ######################################################################## # Formatters for arguments @@ -127,9 +128,17 @@ cmd=CommandParser::CmdParser.new(ARGV) do Holds a Virtual Network lease, marking it as used EOT - command :hold, hold_desc, :vnetid, :ip do + command :hold, hold_desc, :vnetid, :ip, + :options=>STD_OPTIONS + [OneVNetHelper::MAC, OneVNetHelper::AR] do helper.perform_action(args[0],options,"lease on hold") do |vn| - vn.hold(args[1]) + ar = options[:ar_id] || -1 + mac = options[:mac] || "" + + if mac.empty? + vn.hold(args[1], ar) + else + vn.hold_by_mac(mac, ar) + end end end @@ -137,9 +146,17 @@ cmd=CommandParser::CmdParser.new(ARGV) do Releases a Virtual Network lease on hold EOT - command :release, release_desc, :vnetid, :ip do + command :release, release_desc, :vnetid, :ip, + :options=>STD_OPTIONS + [OneVNetHelper::MAC, OneVNetHelper::AR] do helper.perform_action(args[0],options,"lease released") do |vn| - vn.release(args[1]) + ar = options[:ar_id] || -1 + mac = options[:mac] || "" + + if mac.empty? + vn.release(args[1], ar) + else + vn.release_by_mac(mac, ar) + end end end diff --git a/src/oca/ruby/opennebula/virtual_network.rb b/src/oca/ruby/opennebula/virtual_network.rb index 11ac90feb8..c7ca4cd36e 100644 --- a/src/oca/ruby/opennebula/virtual_network.rb +++ b/src/oca/ruby/opennebula/virtual_network.rb @@ -38,13 +38,6 @@ module OpenNebula :rename => "vn.rename" } - VN_TYPES=%w{RANGED FIXED} - - SHORT_VN_TYPES={ - "RANGED" => "R", - "FIXED" => "F" - } - # Creates a VirtualNetwork description with just its identifier # this method should be used to create plain VirtualNetwork objects. # +id+ the id of the network @@ -142,12 +135,16 @@ module OpenNebula return rc end - # Holds a virtual network Lease as used + # Holds a virtual network address # @param ip [String] IP to hold - def hold(ip) + # @param ar_id [Integer] The address range to hold the lease. If not set + # the lease will be held from all possible address ranges + def hold(ip, ar_id=-1) return Error.new('ID not defined') if !@pe_id - lease_template = "LEASES = [ IP = #{ip} ]" + lease_template = "LEASES = [ IP = #{ip}" + lease_template << ", AR_ID = #{ar_id}" if ar_id != -1 + lease_template << "]" rc = @client.call(VN_METHODS[:hold], @pe_id, lease_template) rc = nil if !OpenNebula.is_error?(rc) @@ -155,12 +152,50 @@ module OpenNebula return rc end - # Releases a virtual network Lease on hold - # @param ip [String] IP to release - def release(ip) + # Holds a virtual network address by its MAC + # @param mac [String] MAC to hold + # @param ar_id [Integer] The address range to hold the lease. If not set + # the lease will be held from all possible address ranges + def hold_by_mac(mac, ar_id=-1) return Error.new('ID not defined') if !@pe_id - lease_template = "LEASES = [ IP = #{ip} ]" + lease_template = "LEASES = [ MAC = #{mac}" + lease_template << ", AR_ID = #{ar_id}" if ar_id != -1 + lease_template << "]" + + rc = @client.call(VN_METHODS[:hold], @pe_id, lease_template) + rc = nil if !OpenNebula.is_error?(rc) + + return rc + end + + # Releases an address on hold + # @param ip [String] IP to release + # @param ar_id [Integer] The address range to release the lease. If not + # set the lease will be freed from all possible address ranges + def release(ip, ar_id=-1) + return Error.new('ID not defined') if !@pe_id + + lease_template = "LEASES = [ IP = #{ip}" + lease_template << ", AR_ID = #{ar_id}" if ar_id != -1 + lease_template << "]" + + rc = @client.call(VN_METHODS[:release], @pe_id, lease_template) + rc = nil if !OpenNebula.is_error?(rc) + + return rc + end + + # Releases an addres on hold by its MAC + # @param mac [String] MAC to release + # @param ar_id [Integer] The address range to release the lease. If not + # set the lease will be freed from all possible address ranges + def release_by_mac(mac, ar_id=-1) + return Error.new('ID not defined') if !@pe_id + + lease_template = "LEASES = [ MAC = #{mac}" + lease_template << ", AR_ID = #{ar_id}" if ar_id != -1 + lease_template << "]" rc = @client.call(VN_METHODS[:release], @pe_id, lease_template) rc = nil if !OpenNebula.is_error?(rc) @@ -198,7 +233,7 @@ module OpenNebula super(VN_METHODS[:chmod], owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a) end - + # Renames this virtual network # # @param name [String] New name for the virtual network. @@ -219,21 +254,6 @@ module OpenNebula self['GID'].to_i end - # Returns the type of the Virtual Network (numeric value) - def type - self['TYPE'].to_i - end - - # Returns the type of the Virtual Network (string value) - def type_str - VN_TYPES[type] - end - - # Returns the state of the Virtual Network (string value) - def short_type_str - SHORT_VN_TYPES[type_str] - end - def public? if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1" true