The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Rex::Commands::Cloud - Cloud Management Commands

DESCRIPTION

With this Module you can manage different Cloud services. Currently it supports Amazon EC2 and Jiffybox.

SYNOPSIS

 use Rex::Commands::Cloud;
     
 cloud_service "Amazon";
 cloud_auth "your-access-key", "your-private-access-key";
 cloud_region "ec2.eu-west-1.amazonaws.com";
    
 task "list", sub {
    print Dumper cloud_instance_list;
    print Dumper cloud_volume_list;
 };
      
 task "create", sub {
    my $vol_id = cloud_volume create => { size => 1, zone => "eu-west-1a", };
       
    cloud_instance create => {
          image_id => "ami-xxxxxxx",
          name     => "test01",
          key      => "my-key",
          volume   => $vol_id,
          zone     => "eu-west-1a",
       };
 };
     
 task "destroy", sub {
    cloud_volume detach => "vol-xxxxxxx";
    cloud_volume delete => "vol-xxxxxxx";
       
    cloud_instance terminate => "i-xxxxxxx";
 };

EXPORTED FUNCTIONS

cloud_service($cloud_service)

Define which cloud service to use.

Services
Amazon
Jiffybox
cloud_auth($param1, $param2, ...)

Set the authentication for the cloudservice.

For example for Amazon it is:

 cloud_auth($access_key, $secret_access_key);

For JiffyBox:

 cloud_auth($auth_key);
cloud_region($region)

Set the cloud region.

cloud_instance_list

Get all instances of a cloud service.

 task "list", sub {
    for my $instance (cloud_instance_list()) {
       say "Arch  : " . $instance->{"architecture"};
       say "IP    : " . $instance->{"ip"};
       say "ID    : " . $instance->{"id"};
       say "State : " . $instance->{"state"};
    }
 };
cloud_volume_list

Get all volumes of a cloud service.

 task "list-volumes", sub {
    for my $volume (cloud_volume_list()) {
       say "ID       : " . $volume->{"id"};
       say "Zone     : " . $volume->{"zone"};
       say "State    : " . $volume->{"state"};
       say "Attached : " . $volume->{"attached_to"};
    }
 };
get_cloud_instances_as_group

Get a list of all running instances of a cloud service. This can be used for a group definition.

 group fe  => "fe01", "fe02", "fe03";
 group ec2 => get_cloud_instances_as_group();
cloud_instance($action, $data)

This function controlls all aspects of a cloud instance.

create

Create a new instance.

 cloud_instance create => {
       image_id => "ami-xxxxxx",
       key      => "ssh-key",
       name     => "fe-ec2-01",   # name is not necessary
       volume   => "vol-yyyyy",   # volume is not necessary
       zone     => "eu-west-1a",  # zone is not necessary
    };
start

Start an existing instance

 cloud_instance start => "instance-id";
stop

Stop an existing instance

 cloud_instance stop => "instance-id";
terminate

Terminate an instance. This will destroy all data and remove the instance.

 cloud_instance terminate => "i-zzzzzzz";
get_cloud_regions

Returns all regions as an array.

cloud_volume($action , $data)

This function controlls all aspects of a cloud volume.

create

Create a new volume. Size is in Gigabytes.

 task "create-vol", sub {
    my $vol_id = cloud_volume create => { size => 1, zone => "eu-west-1a", };
 };
detach

Detach a volume from an instance.

 task "detach-vol", sub {
    cloud_volume detach => "vol-xxxxxx";
 };
delete

Delete a volume. This will destroy all data.

 task "delete-vol", sub {
    cloud_volume delete => "vol-xxxxxx";
 };
get_cloud_availability_zones

Returns all availability zones of a cloud services. If available.

 task "get-zones", sub {
    print Dumper get_cloud_availability_zones;
 };
get_cloud_plans

Retrieve information of the available cloud plans. If supported.

get_cloud_operating_systems

Retrieve information of the available cloud plans. If supported.