module TestLab::Container::Status

Public Instance Methods

alive?() click to toggle source

Container Alive?

Is the container alive and running?

@return [Boolean] True if the container is running; False otherwise.

# File lib/testlab/container/status.rb, line 49
def alive?
  (self.state == :running)
end
cidr() click to toggle source

Container CIDR

Returns the CIDR of the container.

@return [Integer] The containers CIDR address.

# File lib/testlab/container/status.rb, line 20
def cidr
  TestLab::Utility.cidr(self.primary_interface.address)
end
cpu_usage() click to toggle source

Container CPU Time

# File lib/testlab/container/status.rb, line 91
def cpu_usage
  if self.node.dead?
    0
  else
    self.lxc.cpu_usage
  end
end
disk_usage() click to toggle source

Container Disk Usage

# 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
fqdn() click to toggle source

Container FQDN

Returns the FQDN for the container.

@return [String] The containers FQDN.

# File lib/testlab/container/status.rb, line 38
def fqdn
  self.domain ||= self.node.domain

  [self.id, self.domain].join('.')
end
importable?() click to toggle source

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. @return [Boolean] True if the container has a non-nil sc_url attribute,

False otherwise.
# File lib/testlab/container/status.rb, line 144
def importable?
  !self.sc_url.nil?
end
ip() click to toggle source

Container IP

Returns the IP of the container.

@return [String] The containers IP address.

# File lib/testlab/container/status.rb, line 11
def ip
  TestLab::Utility.ip(self.primary_interface.address)
end
memory_usage() click to toggle source

Container Memory Usage

# 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
mode() click to toggle source

Container Mode

What mode the container is in. @return [Symbol] A symbol indicating the mode of the container.

# 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
ptr() click to toggle source

Container BIND PTR Record

Returns a BIND reverse-DNS PTR record.

@return [String] The containers ARPA PTR record.

# File lib/testlab/container/status.rb, line 29
def ptr
  TestLab::Utility.ptr(self.primary_interface.address)
end
state() click to toggle source

Container State

What state the container is in.

@return [Symbol] A symbol indicating the state of the container.

# File lib/testlab/container/status.rb, line 113
def state
  if self.node.dead?
    :unknown
  else
    self.lxc.state
  end
end
status() click to toggle source

Container Status

Returns a hash of status information for the container.

@return [Hash] A hash of status information for the container.

# 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