Sha256: 6e94cac75979c9e7ebf37307aa69cb7e80a6515ff74ff95c2fede4eac06a24f6

Contents?: true

Size: 1.84 KB

Versions: 2

Compression:

Stored size: 1.84 KB

Contents

#
# Authors: Christopher M Wood (<woodc@us.ibm.com>)
#		   John F Hutchinson (<jfhutchi@us.ibm.com)
# © Copyright IBM Corporation 2015.
#
# LICENSE: MIT (http://opensource.org/licenses/MIT)
# 
class Network
	attr_accessor :ip_address, :is_primary, :subnet_mask, :gateway, :dns, :given_name, :vlan_id

	def initialize(options_hash)
		#Test for the explicitly required parameters
		raise StandardError.new("A Network cannot be defined without a IP Address") if options_hash[:ip_address].nil?
		raise StandardError.new("A Network cannot be defined without a Subnet Mask") if options_hash[:subnet_mask].nil?
		raise StandardError.new("A Network cannot be defined without specifying if it is the primary network or not") if options_hash[:is_primary].nil? or (options_hash[:is_primary] != "false" and options_hash[:is_primary] != "true")
        raise StandardError.new("A Network cannot be defined without specifying a VLAN ID") if options_hash[:vlan_id].nil?

		#Test for optional parameters
		warn ("Warning: Gateway not defined") if options_hash[:gateway].nil?
		warn ("Warning: DNS not defined") if options_hash[:dns].nil?
		warn ("Warning: Given Name not defined") if options_hash[:given_name].nil?
		
		#Parameters
		@ip_address				= options_hash[:ip_address]
		@is_primary 			= options_hash[:is_primary]
		@subnet_mask			= options_hash[:subnet_mask]
		@gateway				= options_hash[:gateway]
		@dns					= options_hash[:dns]
		@given_name				= options_hash[:given_name]
		@vlan_id				= options_hash[:vlan_id]      
	end
	
	def update_dns(new_dns,old_dns=nil)
		if old_dns.nil?
			if new_dns.is_array?
				@dns = new_dns
			else
				@dns = [new_dns]
			end
		else
			#find index of old_entry in @dns
			i = @dns.index(old_dns)
			@dns[i] = new_entry
		end
	end

	def update_gateway(new_gateway)
		@gateway = new_gateway
	end
	
	def update_given_name(new_name)
		@vlan_id = new_name
	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rbvppc-1.0.2 lib/rbvppc/network.rb
rbvppc-1.0.1 lib/rbvppc/network.rb