Module: TestLab::Container::Status

Included in:
TestLab::Container
Defined in:
lib/testlab/container/status.rb

Instance Method Summary collapse

Instance Method Details

#alive?Boolean

Container Alive?

Is the container alive and running?

Returns:

  • (Boolean)

    True if the container is running; False otherwise.



49
50
51
# File 'lib/testlab/container/status.rb', line 49

def alive?
  (self.state == :running)
end

#cidrInteger

Container CIDR

Returns the CIDR of the container.

Returns:

  • (Integer)

    The containers CIDR address.



20
21
22
# File 'lib/testlab/container/status.rb', line 20

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

#cpu_usageObject

Container CPU Time



91
92
93
94
95
96
97
# File 'lib/testlab/container/status.rb', line 91

def cpu_usage
  if self.node.dead?
    0
  else
    self.lxc.cpu_usage
  end
end

#disk_usageObject

Container Disk Usage



100
101
102
103
104
105
106
# File 'lib/testlab/container/status.rb', line 100

def disk_usage
  if self.node.dead?
    0
  else
    self.lxc.disk_usage / (1024 * 1024)
  end
end

#fqdnString

Container FQDN

Returns the FQDN for the container.

Returns:

  • (String)

    The containers FQDN.



38
39
40
41
42
# File 'lib/testlab/container/status.rb', line 38

def fqdn
  self.domain ||= self.node.domain

  [self.id, self.domain].join('.')
end

#importable?Boolean

Container Importable

If the container has a non-nil sc_url value, we assume since we can supposedly download a shipping container image for the container that it is therefore importable.

Returns:

  • (Boolean)

    True if the container has a non-nil sc_url attribute, False otherwise.



144
145
146
# File 'lib/testlab/container/status.rb', line 144

def importable?
  !self.sc_url.nil?
end

#ipString

Container IP

Returns the IP of the container.

Returns:

  • (String)

    The containers IP address.



11
12
13
# File 'lib/testlab/container/status.rb', line 11

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

#memory_usageObject

Container Memory Usage



82
83
84
85
86
87
88
# File 'lib/testlab/container/status.rb', line 82

def memory_usage
  if self.node.dead?
    0
  else
    self.lxc.memory_usage / (1024 * 1024)
  end
end

#modeSymbol

Container Mode

What mode the container is in.

Returns:

  • (Symbol)

    A symbol indicating the mode of the container.



125
126
127
128
129
130
131
132
133
134
135
# File 'lib/testlab/container/status.rb', line 125

def mode
  if self.node.dead?
    :unknown
  else
    if self.is_ephemeral?
      :ephemeral
    else
      :persistent
    end
  end
end

#ptrString

Container BIND PTR Record

Returns a BIND reverse-DNS PTR record.

Returns:

  • (String)

    The containers ARPA PTR record.



29
30
31
# File 'lib/testlab/container/status.rb', line 29

def ptr
  TestLab::Utility.ptr(self.primary_interface.address)
end

#stateSymbol

Container State

What state the container is in.

Returns:

  • (Symbol)

    A symbol indicating the state of the container.



113
114
115
116
117
118
119
# File 'lib/testlab/container/status.rb', line 113

def state
  if self.node.dead?
    :unknown
  else
    self.lxc.state
  end
end

#statusHash

Container Status

Returns a hash of status information for the container.

Returns:

  • (Hash)

    A hash of status information for the container.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/testlab/container/status.rb', line 58

def status
  interfaces = self.interfaces.collect do |interface|
    "#{interface.network_id}:#{interface.name}:#{interface.ip}/#{interface.cidr}"
  end.join(', ')

  {
    :id => self.id,
    :mode => self.mode,
    :fqdn => self.fqdn,
    :state => self.state,
    :memory_usage => "#{self.memory_usage}M",
    :cpu_time => "#{self.cpu_usage}s",
    :disk_usage => "#{self.disk_usage}MB",
    :distro => self.distro,
    :release => self.release,
    :interfaces => interfaces,
    :provisioners => self.provisioners.map(&:to_s).collect{ |p| p.split('::').last }.join(','),
    :node_id => self.node.id,
    :inherited => (self.inherit.nil? ? 'none' : self.inherit),
    :priority => self.priority
  }
end