| 1 | package Ovirt::Cluster; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use v5.10; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | with 'Ovirt'; | |||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | Ovirt::Cluster - Bindings for oVirt Cluster API | ||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | Version 0.01 | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | use Ovirt::Cluster; | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | my %con = ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | username => 'admin', | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | password => 'password', | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | manager => 'ovirt-mgr.example.com', | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | cluster_output_attrs => 'id,name,cpu_id,cpu_arch,description', # optional | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | my $cluster = Ovirt::Cluster->new(%con); | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # return xml output | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | print $cluster->list_xml; | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # list cluster attributes | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | print $cluster->list; | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # the output also available in hash | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # for example to print all cluster name | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | my $hash = $cluster->hash_output; | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | for my $array (keys $hash->{cluster}) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | print $hash->{cluster}[$array]->{name}; | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # we can also specify specific cluster 'id' when initiating an object | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # so we can direct access the element for specific cluster | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | print $cluster->hash_output->{name}; | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | print $cluster->hash_output->{cluster}->{id}; | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | =head1 Attributes | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | Other attributes is also inherited from Ovirt.pm | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | Check 'perldoc Ovirt' for detail | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | notes : | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | ro = read only, can be specified only during initialization | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | rw = read write, user can set this attribute | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | rwp = read write protected, for internal class | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | cluster_url = (ro) store default cluster url path | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | cluster_output_attrs = (rw) store cluster attributes to be returned, default is (id, name, description) | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | supported attributes : | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | id name | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | cpu_id description | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | cpu_arch datacenter_id | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | ver_major ver_minor | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | sched_name sched_policy | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | cluster_output_delimiter = (rw) specify output delimiter between attribute, default is '||' | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | has 'cluster_url' => ( is => 'ro', default => '/api/clusters' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | has 'cluster_output_attrs' => ( is => 'rw', default => 'id,name,description', | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | isa => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # store all output attribute into array split by ',' | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # $_[0] is the arguments spefied during initialization | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my @attrs = split ',' => $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | croak "cluster_output_attrs can't be empty" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | unless @attrs; | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # check if provided attribute is valid / supported | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my @supported_attr = qw | | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | id name | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | cpu_id description | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | cpu_arch datacenter_id | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | ver_major ver_minor | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | sched_name sched_policy | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |; | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | for my $attr (@attrs) { | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $attr = lc ($attr); | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | $attr = Ovirt->trim($attr); | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | croak "Attribute $attr is not valid / supported" | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | unless grep { /\b$attr\b/ } @supported_attr; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | }); | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | has 'cluster_output_delimiter' => ( is => 'rw', default => '||' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | =head1 SUBROUTINES/METHODS | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | =head2 BUILD | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | The Constructor, build logging, call pass_log_obj method | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | Built root_url with cluster_url | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | set output with get_api_response method from Ovirt.pm | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $self->pass_log_obj; | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if ($self->id) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | $self->_set_root_url($self->cluster_url. '/' . $self->id); | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $self->_set_root_url($self->cluster_url); | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $self->get_api_response(); | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | =head2 list | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | return cluster's attributes text output from hash_output attribute | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | if no argument specified, it will return all cluster attributes (based on cluster_output_attrs) | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | argument supported is 'cluster id' | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | example : | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | $cluster->list('c4738b0f-b73d-4a66-baa8-2ba465d63132'); | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | sub list { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list: not called CC=21 SCAR=61.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | my $clusterid = shift || undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || undef
MC/DC0%0/1
shift() || undef
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # store the output and return it at the end | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | my $output; | |||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # store each attribute to array to be looped | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my @attrs = split ',' => $self->cluster_output_attrs; | |||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # store the last element to escape the cluster_output_delimeter | ||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | my $last_element = pop (@attrs); | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | $self->log->debug("last element = $last_element"); | |||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # if the id is defined during initialization | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # the rest api output will only contain attributes for this id | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | # so it's not necessary to loop on cluster element | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | if ($self->id) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | for my $attr (@attrs) { | |||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | $self->log->debug("requesting attribute $attr"); | |||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | my $attr_output = $self->get_cluster_by_self_id($attr) || $self->not_available; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->get_cluster_by_self_id($attr) || $self->not_available
MC/DC0%0/2
$self->get_cluster_by_self_id($attr) || $self->not_available
$self->get_cluster_by_self_id($attr)
$self->not_available
Truth table0%0/3
A || B
A= $self->get_cluster_by_self_id($attr)B= $self->not_available
| |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | $output .= $attr_output . $self->cluster_output_delimiter; | |||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | $self->log->debug("output for attribute $attr = " . $attr_output); | |||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | #handle last element or the only element | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | $self->log->debug("requesting attribute $last_element"); | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | if (my $last_output = $self->get_cluster_by_self_id($last_element) || $self->not_available) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->get_cluster_by_self_id($last_element) || $self->not_available
MC/DC0%0/2
$self->get_cluster_by_self_id($last_element) || $self->not_available
$self->get_cluster_by_self_id($last_element)
$self->not_available
Truth table0%0/3
A || B
A= $self->get_cluster_by_self_id($last_element)B= $self->not_available
| |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | $output .= $last_output; | |||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | $self->log->debug("output for attribute $last_element = " . $last_output); | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | $output .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | elsif ($clusterid) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | #store clusterid element | ||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | my $clusterid_element; | |||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | $clusterid = $self->trim($clusterid); | |||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | for my $element_id ( 0 .. $#{ $self->hash_output->{cluster} } ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | next unless $self->hash_output->{cluster}[$element_id]->{id} eq $clusterid; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | $clusterid_element = $element_id; | |||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | croak "cluster id not found" unless $clusterid_element >= 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | for my $attr (@attrs) { | |||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | $self->log->debug("requesting attribute $attr for element $clusterid_element"); | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | my $attr_output = $self->get_cluster_by_element_id($clusterid_element, $attr) || $self->not_available; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->get_cluster_by_element_id($clusterid_element, $attr) || $self->not_available
MC/DC0%0/2
$self->get_cluster_by_element_id($clusterid_element, $attr) || $self->not_available
$self->get_cluster_by_element_id($clusterid_element, $attr)
$self->not_available
Truth table0%0/3
A || B
A= $self->get_cluster_by_element_id($clusterid_element, $attr)B= $self->not_available
| |||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | $output .= $attr_output . $self->cluster_output_delimiter; | |||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | $self->log->debug("output for attribute $attr element $clusterid_element = " . $attr_output); | |||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||
| 193 | #handle last element or the only element | ||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | $self->log->debug("requesting attribute $last_element for element $clusterid_element"); | |||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | if (my $last_output = $self->get_cluster_by_element_id($clusterid_element, $last_element) || $self->not_available) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->get_cluster_by_element_id($clusterid_element, $last_element) || $self->not_available
MC/DC0%0/2
$self->get_cluster_by_element_id($clusterid_element, $last_element) || $self->not_available
$self->get_cluster_by_element_id($clusterid_element, $last_element)
$self->not_available
Truth table0%0/3
A || B
A= $self->get_cluster_by_element_id($clusterid_element, $last_element)B= $self->not_available
| |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | $output .= $last_output; | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | $self->log->debug("output for attribute $last_element element $clusterid_element = " . $last_output); | |||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | $output .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 203 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | for my $element_id ( 0 .. $#{ $self->hash_output->{vm} } ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # in case there's no any element left, the last element become the only attribute requested | ||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | if (@attrs) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | for my $attr (@attrs) { | |||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | $self->log->debug("requesting attribute $attr for element $element_id"); | |||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | my $attr_output = $self->get_cluster_by_element_id($element_id, $attr) || $self->not_available; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->get_cluster_by_element_id($element_id, $attr) || $self->not_available
MC/DC0%0/2
$self->get_cluster_by_element_id($element_id, $attr) || $self->not_available
$self->get_cluster_by_element_id($element_id, $attr)
$self->not_available
Truth table0%0/3
A || B
A= $self->get_cluster_by_element_id($element_id, $attr)B= $self->not_available
| |||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | $output .= $attr_output . $self->cluster_output_delimiter; | |||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | $self->log->debug("output for attribute $attr element $element_id = " . $attr_output); | |||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||
| 219 | #handle last element or the only element | ||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | $self->log->debug("requesting attribute $last_element for element $element_id"); | |||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | if (my $last_output = $self->get_cluster_by_element_id($element_id, $last_element) || $self->not_available) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->get_cluster_by_element_id($element_id, $last_element) || $self->not_available
MC/DC0%0/2
$self->get_cluster_by_element_id($element_id, $last_element) || $self->not_available
$self->get_cluster_by_element_id($element_id, $last_element)
$self->not_available
Truth table0%0/3
A || B
A= $self->get_cluster_by_element_id($element_id, $last_element)B= $self->not_available
| |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | $output .= $last_output; | |||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | $self->log->debug("output for attribute $last_element element $element_id = " . $last_output); | |||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | $output .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | return $output; | |||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | =head2 get_cluster_by_element_id | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||
| 236 | This method is used by list method to list all cluster attributes requested | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | An array element id and attribute name is required | ||||||||||||||||||||||||||||||||||||||||||||||
| 238 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | sub get_cluster_by_element_id { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_cluster_by_element_id: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | my ($element_id, $attr) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | croak "hash output is not defined" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 246 | unless $self->hash_output; | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | $attr = $self->trim($attr); | |||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | $self->log->debug("element id = $element_id, attribute = $attr"); | |||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | if ($attr eq 'id') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 10 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | return $self->hash_output->{cluster}[$element_id]->{id}; | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 254 | elsif ($attr eq 'name') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | return $self->hash_output->{cluster}[$element_id]->{name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 257 | elsif ($attr eq 'description') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | return $self->hash_output->{cluster}[$element_id]->{description}; | |||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 260 | elsif ($attr eq 'cpu_arch') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | return $self->hash_output->{cluster}[$element_id]->{cpu}->{architecture}; | |||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 263 | elsif ($attr eq 'cpu_id') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | return $self->hash_output->{cluster}[$element_id]->{cpu}->{id}; | |||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 266 | elsif ($attr eq 'datacenter_id') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | return $self->hash_output->{cluster}[$element_id]->{data_center}->{id}; | |||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 269 | elsif ($attr eq 'sched_name') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | return $self->hash_output->{cluster}[$element_id]->{scheduling_policy}->{name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 272 | elsif ($attr eq 'sched_policy') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | return $self->hash_output->{cluster}[$element_id]->{scheduling_policy}->{policy}; | |||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 275 | elsif ($attr eq 'ver_major') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | return $self->hash_output->{cluster}[$element_id]->{version}->{major}; | |||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 278 | elsif ($attr eq 'ver_minor') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | return $self->hash_output->{cluster}[$element_id]->{version}->{minor}; | |||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||
| 283 | =head2 get_cluster_by_self_id | ||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | This method is used by list method if $self->id is defined | ||||||||||||||||||||||||||||||||||||||||||||||
| 286 | The id is set during initialization (id => 'clusterid') | ||||||||||||||||||||||||||||||||||||||||||||||
| 287 | attribute name is required | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | sub get_cluster_by_self_id { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_cluster_by_self_id: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | my $attr = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | croak "hash output is not defined" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 296 | unless $self->hash_output; | ||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | $attr = $self->trim($attr); | |||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | $self->log->debug("attribute = $attr"); | |||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | if ($attr eq 'id') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 10 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | return $self->hash_output->{id}; | |||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 304 | elsif ($attr eq 'name') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | return $self->hash_output->{name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 307 | elsif ($attr eq 'description') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | return $self->hash_output->{description}; | |||||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 310 | elsif ($attr eq 'cpu_arch') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | return $self->hash_output->{cpu}->{architecture}; | |||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 313 | elsif ($attr eq 'cpu_id') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | return $self->hash_output->{cpu}->{id}; | |||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 316 | elsif ($attr eq 'datacenter_id') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | return $self->hash_output->{data_center}->{id}; | |||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 319 | elsif ($attr eq 'sched_name') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | return $self->hash_output->{scheduling_policy}->{name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 322 | elsif ($attr eq 'sched_policy') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | return $self->hash_output->{scheduling_policy}->{policy}; | |||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 325 | elsif ($attr eq 'ver_major') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | return $self->hash_output->{version}->{major}; | |||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 328 | elsif ($attr eq 'ver_minor') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | return $self->hash_output->{version}->{minor}; | |||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||
| 333 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||
| 335 | "Heince Kurniawan", C<< <"heince at cpan.org"> >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||
| 337 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||
| 339 | Please report any bugs or feature requests to C<bug-ovirt at rt.cpan.org>, or through | ||||||||||||||||||||||||||||||||||||||||||||||
| 340 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Ovirt::Cluster>. I will be notified, and then you'll | ||||||||||||||||||||||||||||||||||||||||||||||
| 341 | automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||
| 343 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||
| 345 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||
| 347 | perldoc Ovirt::Cluster | ||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||
| 349 | You can also look for information at: | ||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||
| 351 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||
| 354 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||
| 356 | Copyright 2015 "Heince Kurniawan". | ||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||
| 358 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||||||
| 359 | under the terms of the the Artistic License (2.0). You may obtain a | ||||||||||||||||||||||||||||||||||||||||||||||
| 360 | copy of the full license at: | ||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||
| 362 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||
| 364 | Any use, modification, and distribution of the Standard or Modified | ||||||||||||||||||||||||||||||||||||||||||||||
| 365 | Versions is governed by this Artistic License. By using, modifying or | ||||||||||||||||||||||||||||||||||||||||||||||
| 366 | distributing the Package, you accept this license. Do not use, modify, | ||||||||||||||||||||||||||||||||||||||||||||||
| 367 | or distribute the Package, if you do not accept this license. | ||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||
| 369 | If your Modified Version has been derived from a Modified Version made | ||||||||||||||||||||||||||||||||||||||||||||||
| 370 | by someone other than you, you are nevertheless required to ensure that | ||||||||||||||||||||||||||||||||||||||||||||||
| 371 | your Modified Version complies with the requirements of this license. | ||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||
| 373 | This license does not grant you the right to use any trademark, service | ||||||||||||||||||||||||||||||||||||||||||||||
| 374 | mark, tradename, or logo of the Copyright Holder. | ||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||
| 376 | This license includes the non-exclusive, worldwide, free-of-charge | ||||||||||||||||||||||||||||||||||||||||||||||
| 377 | patent license to make, have made, use, offer to sell, sell, import and | ||||||||||||||||||||||||||||||||||||||||||||||
| 378 | otherwise transfer the Package with respect to any patent claims | ||||||||||||||||||||||||||||||||||||||||||||||
| 379 | licensable by the Copyright Holder that are necessarily infringed by the | ||||||||||||||||||||||||||||||||||||||||||||||
| 380 | Package. If you institute patent litigation (including a cross-claim or | ||||||||||||||||||||||||||||||||||||||||||||||
| 381 | counterclaim) against any party alleging that the Package constitutes | ||||||||||||||||||||||||||||||||||||||||||||||
| 382 | direct or contributory patent infringement, then this Artistic License | ||||||||||||||||||||||||||||||||||||||||||||||
| 383 | to you shall terminate on the date that such litigation is filed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||
| 385 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||||||||||||||||||||||||||||||||||||||||||||||
| 386 | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||||||||||||||||||||||||||||||||||||||||||||||
| 387 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||||||||||||||||||||||||||||||||||||||||||||||
| 388 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||||||||||||||||||||||||||||||||||||||||||||||
| 389 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||||||||||||||||||||||||||||||||||||||||||||||
| 390 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||||||||||||||||||||||||||||||||||||||||||||||
| 391 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||||||||||||||||||||||||||||||||||||||||||||||
| 392 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||
| 395 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||