OpenNebula/Cluster.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 59 CC 4 SCAR 21.5
CC
4
Cov
0%
_do
20.0
create
2.0
add
2.0
CRAP 8.5
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4 # vim: set ts=3 sw=3 tw=0:
5 # vim: set expandtab:
6 #
7 # !no_doc!
8 use strict;
9 use warnings;
10  
11 package Net::OpenNebula::Cluster;
12 $Net::OpenNebula::Cluster::VERSION = '0.317.0';
13 use Net::OpenNebula::RPC;
14 push our @ISA , qw(Net::OpenNebula::RPC);
15  
16 use constant ONERPC => 'cluster';
17  
18 sub create {
19 my ($self, $name) = @_;
20 return $self->_allocate([ string => $name ]);
21 }
22  
23 # add something to this cluster
24 # eg add host with hostid 123
25 # $cluster->_do('add, 'host', 123)
26 # or pass Net::OpenNebula::Host instance as "resource" (no id needed)
27 sub _do
28 {
29 my ($self, $action, $resource, $id) = @_;
30  
31 if ($action ne 'add' && $action ne 'del') {
32 $self->error("Invalid cluster action $action");
33 return;
34 }
35  
36 my $ref = ref($resource);
37 if ($ref =~ m/^Net::OpenNebula::(\w+)/) {
38 $id = $resource->id;
39 $resource = lc($1);
40 }
41 my $msg = "Cluster action $action for instance $ref resource $resource id $id";
42 if (grep {$resource eq $_} qw(host datastore vnet)) {
43 $self->info($msg);
44 return $self->_onerpc("$action$resource", [int => $self->id], [int => $id]);
45 } else {
46 $self->error("$msg: unsupported resource");
47 return;
48 }
49 }
50  
51 sub add
52 {
53 my ($self, @args) = @_;
54 return $self->_do('add', @args);
55 }
56  
57 sub del
58 {
59 my ($self, @args) = @_;
60 return $self->_do('del', @args);
61 }
62  
63  
64 1;