lib/testlab.rb in testlab-0.7.6 vs lib/testlab.rb in testlab-0.8.0
- old
+ new
@@ -15,57 +15,89 @@
# in general where you want to spin up alot of servers but do not want the
# overhead of virtualization. At it's core TestLab uses Linux Containers (LXC)
# to accomplish this.
#
# @example Sample Labfile:
-# shell_provision_script = <<-EOF
-# set -x
-# apt-get -y update
-# apt-get -y install dnsutils
-# EOF
+# node 'vagrant' do
#
-# config Hash[
-# :domain => "default.zone",
-# :repo => File.join(ENV['HOME'], "code", "personal", "testlab-repo")
-# ]
+# provider TestLab::Provider::Vagrant
+# provisioners [
+# TestLab::Provisioner::Raring,
+# TestLab::Provisioner::Bind
+# ]
#
-# node :localhost do
-# components %w(resolv bind)
-# route true
-#
-# provider TestLab::Provider::Vagrant
-# config Hash[
+# config ({
# :vagrant => {
-# :id => "mytestlab-#{ENV['USER']}".downcase,
-# :ip => "192.168.13.37",
-# :user => "vagrant",
-# :port => 22,
-# :cpus => 8,
-# :memory => 16384,
-# :box => 'raring64'
+# :id => "chef-rubygem-#{TestLab.hostname}".downcase,
+# :cpus => ZTK::Parallel::MAX_FORKS.div(2), # use half of the available processors
+# :memory => ZTK::Parallel::MAX_MEMORY.div(3).div(1024 * 1024), # use a third of available RAM
+# :box => 'raring64',
+# :box_url => 'https://dl.dropboxusercontent.com/u/22904185/boxes/raring64.box',
+# :file => File.dirname(__FILE__)
+# },
+# :bind => {
+# :domain => "default.zone"
# }
-# ]
+# })
#
-# network :east do
-# address '10.10.0.1/16'
-# bridge :br0
+# network 'labnet' do
+# provisioners [TestLab::Provisioner::Route]
+# address '10.10.0.1/16'
+# bridge :br0
# end
#
-# container "server-east-1" do
-# domain "east.zone"
+# container "chef-server" do
+# distro "ubuntu"
+# release "precise"
#
+# provisioners [
+# TestLab::Provisioner::Resolv,
+# TestLab::Provisioner::AptCacherNG,
+# TestLab::Provisioner::Apt,
+# TestLab::Provisioner::Chef::RubyGemServer
+# ]
+#
+# user 'deployer' do
+# password 'deployer'
+# identity File.join(ENV['HOME'], '.ssh', 'id_rsa')
+# public_identity File.join(ENV['HOME'], '.ssh', 'id_rsa.pub')
+# uid 2600
+# gid 2600
+# end
+#
+# interface do
+# network_id 'labnet'
+# name :eth0
+# address '10.10.0.254/16'
+# mac '00:00:5e:63:b5:9f'
+# end
+# end
+#
+# container "chef-client" do
# distro "ubuntu"
# release "precise"
#
-# provisioner TestLab::Provisioner::Shell
-# config Hash[:setup => shell_provision_script]
+# provisioners [
+# TestLab::Provisioner::Resolv,
+# TestLab::Provisioner::AptCacherNG,
+# TestLab::Provisioner::Apt,
+# TestLab::Provisioner::Chef::RubyGemClient
+# ]
#
+# user 'deployer' do
+# password 'deployer'
+# identity File.join(ENV['HOME'], '.ssh', 'id_rsa')
+# public_identity File.join(ENV['HOME'], '.ssh', 'id_rsa.pub')
+# uid 2600
+# gid 2600
+# end
+#
# interface do
-# name :eth0
-# network_id :east
-# address '10.10.0.254/16'
-# mac '00:00:5e:b7:e5:15'
+# network_id 'labnet'
+# name :eth0
+# address '10.10.0.20/16'
+# mac '00:00:5e:b7:e5:15'
# end
# end
#
# end
#
@@ -76,12 +108,12 @@
# testlab = TestLab.new(:ui => ui)
#
# @example We can control things via code easily as well:
# testlab.create # creates the lab
# testlab.up # ensures the lab is up and running
-# testlab.setup # setup the lab, creating all networks and containers
-# testlab.teardown # teardown the lab, destroy all networks and containers
+# testlab.build # build the lab, creating all networks and containers
+# testlab.demolish # demolish the lab, destroy all networks and containers
#
# @author Zachary Patten <zachary AT jovelabs DOT com>
class TestLab
# TestLab Error Class
@@ -113,15 +145,20 @@
@config_dir = File.expand_path(options[:config_dir] || File.join(@repo_dir, ".testlab-#{TestLab.hostname}"))
File.exists?(@config_dir) or FileUtils.mkdir_p(@config_dir)
labfile_path = (options[:labfile_path] || File.join(@repo_dir, 'Labfile'))
@labfile_path = File.expand_path(ZTK::Locator.find(labfile_path))
+ end
+ # Boot TestLab
+ #
+ # Change to the defined repository directory and load the *Labfile*.
+ #
+ # @return [Boolean] True if successful.
+ def boot
@labfile = TestLab::Labfile.load(labfile_path)
@labfile.testlab = self
-
- Dir.chdir(@repo_dir)
end
# Test Lab Nodes
#
# Returns an array of our defined nodes.
@@ -184,10 +221,34 @@
# @return [Boolean] False is all nodes are running; true otherwise.
def dead?
!alive?
end
+ # Test Lab Create
+ #
+ # Attempts to create our lab topology. This calls the create method on all of
+ # our nodes.
+ #
+ # @return [Boolean] True if successful.
+ def create
+ method_proxy(:create)
+
+ true
+ end
+
+ # Test Lab Destroy
+ #
+ # Attempts to destroy our lab topology. This calls the destroy method on all of
+ # our nodes.
+ #
+ # @return [Boolean] True if successful.
+ def destroy
+ reverse_method_proxy(:destroy)
+
+ true
+ end
+
# Test Lab Up
#
# Attempts to up our lab topology. This calls the up method on all of
# our nodes.
#
@@ -240,9 +301,21 @@
# all of our nodes, networks and containers.
#
# @return [Boolean] True if successful.
def build
method_proxy(:build)
+
+ true
+ end
+
+ # Test Lab Demolish
+ #
+ # Attempts to demolish our lab topology. This calls various methods on
+ # all of our nodes, networks and containers.
+ #
+ # @return [Boolean] True if successful.
+ def demolish
+ reverse_method_proxy(:demolish)
true
end
# Node Method Proxy