Module: TestLab::Network::Status

Included in:
TestLab::Network
Defined in:
lib/testlab/network/status.rb

Instance Method Summary collapse

Instance Method Details

#broadcastObject

Returns the broadcast address



60
61
62
# File 'lib/testlab/network/status.rb', line 60

def broadcast
  TestLab::Utility.broadcast(self.address)
end

#cidrInteger

Network CIDR

Returns the CIDR of the network bridge.

Returns:

  • (Integer)

    The network bridge CIDR address.



45
46
47
# File 'lib/testlab/network/status.rb', line 45

def cidr
  TestLab::Utility.cidr(self.address)
end

#def_tagObject

Debian Network ‘interfaces’ Start Definition Tag



22
23
24
# File 'lib/testlab/network/status.rb', line 22

def def_tag
  "#TESTLAB-DEF-#{self.bridge.to_s.upcase}"
end

#end_tagObject

Debian Network ‘interfaces’ End Definition Tag



27
28
29
# File 'lib/testlab/network/status.rb', line 27

def end_tag
  "#TESTLAB-END-#{self.bridge.to_s.upcase}"
end

#ipString

Network IP

Returns the IP of the network bridge.

Returns:

  • (String)

    The network bridge IP address.



36
37
38
# File 'lib/testlab/network/status.rb', line 36

def ip
  TestLab::Utility.ip(self.address)
end

#netmaskObject

Returns the network mask



50
51
52
# File 'lib/testlab/network/status.rb', line 50

def netmask
  TestLab::Utility.netmask(self.address)
end

#networkObject

Returns the network address



55
56
57
# File 'lib/testlab/network/status.rb', line 55

def network
  TestLab::Utility.network(self.address)
end

#stateObject

Network Bridge State



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/testlab/network/status.rb', line 65

def state
  if self.node.dead?
    :unknown
  else
    exit_code = self.node.exec(%(sudo brctl show #{self.bridge} 2>&1 | grep -i 'No such device'), :ignore_exit_status => true).exit_code
    if (exit_code == 0)
      :not_created
    else
      output = self.node.exec(%(sudo ifconfig #{self.bridge} 2>&1 | grep 'MTU'), :ignore_exit_status => true).output
      if ((output =~ /UP/) || (output =~ /RUNNING/))
        :running
      else
        :stopped
      end
    end
  end
end

#statusObject

Network status



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/testlab/network/status.rb', line 7

def status
  interface = "#{bridge}:#{self.address}"
  {
    :id => self.id,
    :node_id => self.node.id,
    :state => self.state,
    :interface => interface,
    :broadcast => self.broadcast,
    :network => self.network,
    :netmask => self.netmask,
    :provisioners => self.provisioners.map(&:to_s).collect{ |p| p.split('::').last }.join(','),
  }
end