DOKK / manpages / debian 12 / rex / Rex::Commands::Cloud.3pm.en
Rex::Commands::Cloud(3pm) User Contributed Perl Documentation Rex::Commands::Cloud(3pm)

Rex::Commands::Cloud - Cloud Management Commands

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

Version <= 1.0: All these functions will not be reported.

 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";
 };

Define which cloud service to use.

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);

For OpenStack:

 cloud_auth(
  tenant_name => 'tenant',
  username    => 'user',
  password    => 'password',
 );

Set the cloud region.

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"};
   }
 };

There are some parameters for this function that can change the gathering of ip addresses for some cloud providers (like OpenStack).

 task "list", sub {
   my @instances = cloud_instance_list 
                      private_network => 'private',
                      public_network  => 'public',
                      public_ip_type  => 'floating',
                      private_ip_type => 'fixed';
 };

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 all networks of a cloud service.

 task "network-list", sub {
   for my $network (cloud_network_list()) {
     say "network  : " . $network->{network};
     say "name    : " . $network->{name};
     say "id     : " . $network->{id};
   }
 };

Get a list of all available cloud images.

Upload public SSH key to cloud provider

 private_key '~/.ssh/mykey
 public_key  '~/.ssh/mykey.pub';
 
 task "cloudprovider", sub {
   cloud_upload_key;
   cloud_instance create => {
     ...
   };
 };

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();

This function controls all aspects of a cloud instance.

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
     floating_ip  => "89.39.38.160" # floating_ip is not necessary
   };

Start an existing instance

 cloud_instance start => "instance-id";

Stop an existing instance

 cloud_instance stop => "instance-id";

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

 cloud_instance terminate => "i-zzzzzzz";

Returns all regions as an array.

This function controls all aspects of a cloud volume.

Create a new volume. Size is in Gigabytes.

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

Attach a volume to an instance.

 task "attach-vol", sub {
   cloud_volume attach => "vol-xxxxxx", to => "server-id";
 };

Detach a volume from an instance.

 task "detach-vol", sub {
   cloud_volume detach => "vol-xxxxxx", from => "server-id";
 };

Delete a volume. This will destroy all data.

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

Returns first available floating IP

 task "get_floating_ip", sub {
   my $ip = get_cloud_floating_ip;
   my $instance = cloud_instance create => {
      image_id => 'edffd57d-82bf-4ffe-b9e8-af22563741bf',
      name => 'instance1',
      plan_id => 17,
      floating_ip => $ip
    };
 };

Create a new network.

 task "create-net", sub {
   my $net_id = cloud_network create => { cidr => '192.168.0.0/24', name => "mynetwork", };
 };

Delete a network.

 task "delete-net", sub {
   cloud_network delete => '18a4ccf8-f14a-a10d-1af4-4ac7fee08a81';
 };

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

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

Retrieve information of the available cloud plans. If supported.

Retrieve information of the available cloud plans. If supported.

Returns the cloud object itself.

2023-03-06 perl v5.36.0