Sha256: d5e23b5cc1dd267529c844e5c5df4d16f15ea1f9bc495e726a7ad2a13632f6ec

Contents?: true

Size: 1.54 KB

Versions: 9

Compression:

Stored size: 1.54 KB

Contents

class TestLab
  class Network

    module Status

      # Network status
      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

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

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

      # Returns the network mask
      def netmask
        TestLab::Utility.netmask(self.address)
      end

      # Returns the network address
      def network
        TestLab::Utility.network(self.address)
      end

      # Returns the broadcast address
      def broadcast
        TestLab::Utility.broadcast(self.address)
      end

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

    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
testlab-0.9.1 lib/testlab/network/status.rb
testlab-0.9.0 lib/testlab/network/status.rb
testlab-0.8.6 lib/testlab/network/status.rb
testlab-0.8.5 lib/testlab/network/status.rb
testlab-0.8.4 lib/testlab/network/status.rb
testlab-0.8.3 lib/testlab/network/status.rb
testlab-0.8.2 lib/testlab/network/status.rb
testlab-0.8.1 lib/testlab/network/status.rb
testlab-0.8.0 lib/testlab/network/status.rb