Class: Network

Inherits:
Object
  • Object
show all
Defined in:
lib/rbvppc/network.rb

Overview

Authors: Christopher M Wood (<[email protected]>) John F Hutchinson (<[email protected]) © Copyright IBM Corporation 2015.

LICENSE: MIT (opensource.org/licenses/MIT)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options_hash) ⇒ Network

Returns a new instance of Network.

Raises:

  • (StandardError)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rbvppc/network.rb', line 11

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

Instance Attribute Details

#dnsObject

Returns the value of attribute dns.



9
10
11
# File 'lib/rbvppc/network.rb', line 9

def dns
  @dns
end

#gatewayObject

Returns the value of attribute gateway.



9
10
11
# File 'lib/rbvppc/network.rb', line 9

def gateway
  @gateway
end

#given_nameObject

Returns the value of attribute given_name.



9
10
11
# File 'lib/rbvppc/network.rb', line 9

def given_name
  @given_name
end

#ip_addressObject

Returns the value of attribute ip_address.



9
10
11
# File 'lib/rbvppc/network.rb', line 9

def ip_address
  @ip_address
end

#is_primaryObject

Returns the value of attribute is_primary.



9
10
11
# File 'lib/rbvppc/network.rb', line 9

def is_primary
  @is_primary
end

#subnet_maskObject

Returns the value of attribute subnet_mask.



9
10
11
# File 'lib/rbvppc/network.rb', line 9

def subnet_mask
  @subnet_mask
end

#vlan_idObject

Returns the value of attribute vlan_id.



9
10
11
# File 'lib/rbvppc/network.rb', line 9

def vlan_id
  @vlan_id
end

Instance Method Details

#update_dns(new_dns, old_dns = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rbvppc/network.rb', line 33

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

#update_gateway(new_gateway) ⇒ Object



47
48
49
# File 'lib/rbvppc/network.rb', line 47

def update_gateway(new_gateway)
	@gateway = new_gateway
end

#update_given_name(new_name) ⇒ Object



51
52
53
# File 'lib/rbvppc/network.rb', line 51

def update_given_name(new_name)
	@vlan_id = new_name
end