NAME

Rex::Commands::Box - Functions / Class to manage Virtual Machines

DESCRIPTION

This is a Module to manage Virtual Machines or Cloud Instances in a simple way. Currently it supports only VirtualBox.

SYNOPSIS

task mytask => sub {
   
   box {
      my ($box) = @_;
      $box->name("vmname");
      $box->url("http://box.rexify.org/box/base-image.box");
         
      $box->network(1 => {
        type => "nat",
      });
          
      $box->network(1 => {
        type => "bridged",
        bridge => "eth0",
      });
         
      $box->forward_port(ssh => [2222, 22]);
         
      $box->share_folder(myhome => "/home/myuser");
         
      $box->auth(
        user => "root",
        password => "box",
      );
        
      $box->setup(qw/task_to_customize_box/);
      
   };
   
};

EXPORTED FUNCTIONS

new(name => $vmname)

Constructor if used in OO mode.

my $box = Rex::Commands::Box->new(name => "vmname");
name($vmname)

Sets the name of the virtual machine.

setup(@tasks)

Sets the tasks that should be executed as soon as the VM is available throu SSH.

stop()

Stops the VM.

start()

Starts the VM.

provision([@tasks])

Execute's the given tasks on the VM.

cpus($count)

Set the amount of CPUs for the VM.

forward_port(%option)

Set ports to be forwarded to the VM. This only work with VirtualBox in NAT network mode.

$box->forward_port(
   name => [$from_host_port, $to_vm_port],
   name2 => [$from_host_port_2, $to_vm_port_2],
   ...
);
share_folder(%option)

Creates a shared folder inside the VM with the content from a folder from the Host machine. This only works with VirtualBox.

$box->share_folder(
   name => "/path/on/host",
   name2 => "/path_2/on/host",
);
memory($memory_size)

Sets the memory of a VM in megabyte.

network(%option)

Configure the network for a VM.

Currently it supports 2 modes. nat and bridged. Currently it supports only one network card.

$box->network(
   1 => {
      type => "nat",
   },
}
   
$box->network(
   1 => {
      type => "bridged",
      bridge => "eth0",
   },
);
url($url)

The URL where to download the Base VM Image. You can use self-made images or prebuild images from http://box.rexify.org/.

auth(%option)

Configure the authentication to the VM.

$box->auth(
   user => $user,
   password => $password,
   private_key => $private_key,
   public_key => $public_key,
);