lib/testlab/container/lxc.rb in testlab-0.0.4 vs lib/testlab/container/lxc.rb in testlab-0.1.0
- old
+ new
@@ -9,10 +9,22 @@
# container.
def lxc
@lxc ||= self.node.lxc.container(self.id)
end
+ # SSH to the container
+ def ssh(options={})
+ self.node.container_ssh(self, options)
+ end
+
+ # Does the container exist?
+ def exists?
+ @ui.logger.debug { "Container Exists?: #{self.id} " }
+
+ self.lxc.exists?
+ end
+
# Returns arguments for lxc-create based on our distro
#
# @return [Array] An array of arguments for lxc-create
def create_args
case self.distro.downcase
@@ -33,9 +45,31 @@
when "ubuntu" then
((self.node.arch =~ /x86_64/) ? "amd64" : "i386")
when "fedora" then
((self.node.arch =~ /x86_64/) ? "amd64" : "i686")
end
+ end
+
+ # Builds an array of hashes containing the lxc configuration options for
+ # our networks
+ def build_lxc_network_conf(interfaces)
+ networks = Array.new
+
+ interfaces.each do |network, network_config|
+ networks << Hash[
+ 'lxc.network.type' => :veth,
+ 'lxc.network.flags' => :up,
+ 'lxc.network.link' => TestLab::Network.first(network).bridge,
+ 'lxc.network.name' => network_config[:name],
+ 'lxc.network.hwaddr' => network_config[:mac],
+ 'lxc.network.ipv4' => network_config[:ip]
+ ]
+ if (network_config[:primary] == true) || (interfaces.count == 1)
+ networks.last.merge!('lxc.network.ipv4.gateway' => :auto)
+ end
+ end
+
+ networks
end
end
end