Rex::Cloud::OpenNebula::CloudLayer - Cloud layer for Rex
This module is a layer between the Rex::Cloud::OpenNebula Module and the Rex::Cloud API.
use Rex::Cloud::OpenNebula::CloudLayer; use Rex::Commands::Cloud; use Rex::Cloud::OpenNebula; use Data::Dumper; cloud_service "OpenNebula"; cloud_auth "user", "password"; cloud_region "http://172.16.120.131:2633/RPC2"; task "list-os", sub { print Dumper get_cloud_operating_systems; }; task "create", sub { my $params = shift; my $vm = cloud_instance create => { image => "template-1", name => $params->{name}, }; print Dumper($vm); }; task "start", sub { my $params = shift; cloud_instance start => $params->{name}; }; task "stop", sub { my $params = shift; cloud_instance stop => $params->{name}; }; task "terminate", sub { my $params = shift; cloud_instance terminate => $params->{name}; }; task "list", sub { print Dumper cloud_instance_list; };
Constructor.
If you want to use the OO Interface:
my $obj = Rex::Cloud::OpenNebula::CloudLayer->new(
endpoint => "http://your-opennebula-server/RPC2:2633",
user => "username",
password => "password"
);Set the authentication.
cloud_auth "user", "password"; Or, if you want to use the OO Interface:
$obj->set_auth($user, $password);
list_operating_systems()List all available templates.
my @oses = get_cloud_operating_systems;
Or, if you want to use the OO interface:
my @oses = $obj->list_operating_systems();
run_instance(%data)Create an instance and start it.
You have to define an image_id (or template_id) to use and a name. You can also use the name of the template. Than you have to define the template property or image property.
my $vm = cloud_instance create => {
image_id => 5,
name => $params->{name},
}; my $vm = cloud_instance create => {
image => "template-name",
name => $params->{name},
};Or, if you want to call it via its OO Interface:
$obj->run_instance( iamge => "template-name", name => "myinstance01", );
terminate_instance(%data)Terminate and remove an instance.
cloud_instance terminate => "vmname";
Or, if you want to use the OO Interface:
$obj->terminate_instance(instance_id => "vmname or vmid");
start_instance(%data)Start a stopped instance.
cloud_instance start => "vmname";
Or, if you want to use the OO Interface:
$obj->start_instance(name => "vmname or vmid");
stop_instance(%data)Stop a running instance.
cloud_instance stop => "vmname";
Or, if you want to use the OO Interface:
$obj->stop_instance(name => "vmname or vmid");
list_instances()List your instances. Returns an array of hashes.
print Dumper cloud_instance_list;
Or, if you want to use the OO Interface:
my @instances = $obj->list_instances();
list_running_instances()List your running instances.
group opennebula_vms => get_cloud_instances_as_group();
Or, if you want to use the OO Interface:
my @instances = $obj->list_running_instances();