| 1 | package VMware::vCloudDirector2; | ||||||||||
| 2 | |||||||||||
| 3 | # ABSTRACT: Interface to VMWare vCloud Directory REST API | ||||||||||
| 4 | |||||||||||
| 5 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 4 | our $VERSION = '0.107'; # VERSION | |||||||||
| 9 | 4 | our $AUTHORITY = 'cpan:NIGELM'; # AUTHORITY | |||||||||
| 10 | |||||||||||
| 11 | 4 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 4 | ▶ | use Method::Signatures; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 4 | ▶ | use MooseX::Types::Path::Tiny qw/Path/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 4 | ▶ | use VMware::vCloudDirector2::API; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 4 | ▶ | use VMware::vCloudDirector2::Error; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 4 | ▶ | use VMware::vCloudDirector2::Object; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | # ------------------------------------------------------------------------ | ||||||||||
| 19 | |||||||||||
| 20 | |||||||||||
| 21 | 4 | has debug => ( is => 'rw', isa => 'Bool', default => 0 ); # Defaults to no debug info | |||||||||
| 22 | |||||||||||
| 23 | 4 | has hostname => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||
| 24 | 4 | has username => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||
| 25 | 4 | has password => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||
| 26 | 4 | has orgname => ( is => 'ro', isa => 'Str', required => 1, default => 'System' ); | |||||||||
| 27 | 4 | has ssl_verify => ( is => 'ro', isa => 'Bool', predicate => '_has_ssl_verify' ); | |||||||||
| 28 | 4 | has timeout => ( is => 'rw', isa => 'Int', predicate => '_has_timeout' ); | |||||||||
| 29 | 4 | has ssl_ca_file => ( is => 'ro', isa => Path, coerce => 1, predicate => '_has_ssl_ca_file' ); | |||||||||
| 30 | 4 | has _ua => ( is => 'ro', isa => 'LWP::UserAgent', predicate => '_has_ua' ); | |||||||||
| 31 | 4 | has _debug_trace_directory => | |||||||||
| 32 | ( is => 'ro', isa => Path, coerce => 1, predicate => '_has_debug_trace_directory' ); | ||||||||||
| 33 | |||||||||||
| 34 | 4 | has api => ( | |||||||||
| 35 | is => 'ro', | ||||||||||
| 36 | isa => 'VMware::vCloudDirector2::API', | ||||||||||
| 37 | lazy => 1, | ||||||||||
| 38 | builder => '_build_api', | ||||||||||
| 39 | handles => [qw( GET PUT POST DELETE )], | ||||||||||
| 40 | ); | ||||||||||
| 41 | |||||||||||
| 42 | 4 | ▶ | method _build_api () { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
_build_api: called CC=7 SCAR=20.6
Branch: 1 branch
| |||||||||||
| 43 | 1 | my @args = ( | |||||||||
| 44 | hostname => $self->hostname, | ||||||||||
| 45 | username => $self->username, | ||||||||||
| 46 | password => $self->password, | ||||||||||
| 47 | orgname => $self->orgname, | ||||||||||
| 48 | debug => $self->debug | ||||||||||
| 49 | ); | ||||||||||
| 50 | 1 | ▶ | push( @args, timeout => $self->timeout ) if ( $self->_has_timeout ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 1 | ▶ | push( @args, ssl_verify => $self->ssl_verify ) if ( $self->_has_ssl_verify ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 1 | ▶ | push( @args, ssl_ca_file => $self->ssl_ca_file ) if ( $self->_has_ssl_ca_file ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 1 | ▶ | push( @args, _debug_trace_directory => $self->_debug_trace_directory ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | if ( $self->_has_debug_trace_directory ); | ||||||||||
| 55 | 1 | ▶ | push( @args, _ua => $self->_ua ) if ( $self->_has_ua ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | |||||||||||
| 57 | 1 | return VMware::vCloudDirector2::API->new(@args); | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | # ------------------------------------------------------------------------ | ||||||||||
| 61 | |||||||||||
| 62 | |||||||||||
| 63 | 4 | has org_listref => ( | |||||||||
| 64 | is => 'ro', | ||||||||||
| 65 | isa => 'ArrayRef[VMware::vCloudDirector2::Object]', | ||||||||||
| 66 | lazy => 1, | ||||||||||
| 67 | builder => '_build_org_listref', | ||||||||||
| 68 | traits => ['Array'], | ||||||||||
| 69 | handles => { | ||||||||||
| 70 | org_list => 'elements', | ||||||||||
| 71 | org_map => 'map', | ||||||||||
| 72 | org_grep => 'grep', | ||||||||||
| 73 | }, | ||||||||||
| 74 | ); | ||||||||||
| 75 | 4 | ▶ | method _build_org_listref { return [ $self->api->GET('/api/org/') ]; } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
_build_org_listref: called CC=2 SCAR=7.0
Branch: 1 branch
| |||||||||||
| 76 | |||||||||||
| 77 | # ------------------------------------------------------------------------ | ||||||||||
| 78 | |||||||||||
| 79 | |||||||||||
| 80 | 4 | ▶ | method query (@args) { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
Subroutine
query: not called CC=1 SCAR=3.1
| |||||||||||
| 81 | 0 | my $uri = $self->api->query_uri->clone; | |||||||||
| 82 | 0 | $uri->query_form(@args); | |||||||||
| 83 | 0 | return $self->api->GET($uri); | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | # ------------------------------------------------------------------------ | ||||||||||
| 87 | |||||||||||
| 88 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||
| 89 | |||||||||||
| 90 | 4 | 1; | |||||||||
| 91 | |||||||||||
| 92 | __END__ | ||||||||||
| 93 | |||||||||||
| 94 | =pod | ||||||||||
| 95 | |||||||||||
| 96 | =encoding UTF-8 | ||||||||||
| 97 | |||||||||||
| 98 | =head1 NAME | ||||||||||
| 99 | |||||||||||
| 100 | VMware::vCloudDirector2 - Interface to VMWare vCloud Directory REST API | ||||||||||
| 101 | |||||||||||
| 102 | =head1 VERSION | ||||||||||
| 103 | |||||||||||
| 104 | version 0.107 | ||||||||||
| 105 | |||||||||||
| 106 | =head1 SYNOPSIS | ||||||||||
| 107 | |||||||||||
| 108 | # THIS IS AT AN EARLY STAGE OF DEVELOPMENT - PROTOTYPING REALLY | ||||||||||
| 109 | # IT MAY CHANGE DRAMATICALLY OR EAT YOUR DATA. | ||||||||||
| 110 | |||||||||||
| 111 | use VMware::vCloudDirector2 | ||||||||||
| 112 | |||||||||||
| 113 | my $vcd = VMware::vCloudDirector2->new( | ||||||||||
| 114 | hostname => $host, | ||||||||||
| 115 | username => $user, | ||||||||||
| 116 | password => $pass, | ||||||||||
| 117 | orgname => $org, | ||||||||||
| 118 | ssl_verify => 0, | ||||||||||
| 119 | ); | ||||||||||
| 120 | my @org_list = $vcd->org_list; | ||||||||||
| 121 | |||||||||||
| 122 | =head2 Attributes | ||||||||||
| 123 | |||||||||||
| 124 | =head3 hostname | ||||||||||
| 125 | |||||||||||
| 126 | Hostname of the vCloud server. Must have a vCloud instance listening for https | ||||||||||
| 127 | on port 443. | ||||||||||
| 128 | |||||||||||
| 129 | =head3 username | ||||||||||
| 130 | |||||||||||
| 131 | Username to use to login to vCloud server. | ||||||||||
| 132 | |||||||||||
| 133 | =head3 password | ||||||||||
| 134 | |||||||||||
| 135 | Password to use to login to vCloud server. | ||||||||||
| 136 | |||||||||||
| 137 | =head3 orgname | ||||||||||
| 138 | |||||||||||
| 139 | Org name to use to login to vCloud server - this defaults to C<System>. | ||||||||||
| 140 | |||||||||||
| 141 | =head3 timeout | ||||||||||
| 142 | |||||||||||
| 143 | Command timeout in seconds. Defaults to 120. | ||||||||||
| 144 | |||||||||||
| 145 | =head3 default_accept_header | ||||||||||
| 146 | |||||||||||
| 147 | The default MIME types to accept. This is automatically set based on the | ||||||||||
| 148 | information received back from the API versions. | ||||||||||
| 149 | |||||||||||
| 150 | =head3 ssl_verify | ||||||||||
| 151 | |||||||||||
| 152 | Whether to do standard SSL certificate verification. Defaults to set. | ||||||||||
| 153 | |||||||||||
| 154 | =head3 ssl_ca_file | ||||||||||
| 155 | |||||||||||
| 156 | The SSL CA set to trust packaged in a file. This defaults to those set in the | ||||||||||
| 157 | L<Mozilla::CA> | ||||||||||
| 158 | |||||||||||
| 159 | =head3 debug | ||||||||||
| 160 | |||||||||||
| 161 | Set debug level. The higher the debug level, the more chatter is exposed. | ||||||||||
| 162 | |||||||||||
| 163 | Defaults to 0 (no output) unless the environment variable C<VCLOUD_API_DEBUG> | ||||||||||
| 164 | is set to something that is non-zero. Picked up at create time in C<BUILD()> | ||||||||||
| 165 | |||||||||||
| 166 | =head2 Methods | ||||||||||
| 167 | |||||||||||
| 168 | =head3 org_list | ||||||||||
| 169 | |||||||||||
| 170 | Returns a set of L<VMware::vCloudDirector2::Object> each containing one of the | ||||||||||
| 171 | vCloud Orgs on the system (or if using this in user mode the single org you can | ||||||||||
| 172 | see). | ||||||||||
| 173 | |||||||||||
| 174 | =head3 query | ||||||||||
| 175 | |||||||||||
| 176 | Returns a L<VMware::vCloudDirector2::Object> containing the query result of the | ||||||||||
| 177 | query against the platform. | ||||||||||
| 178 | |||||||||||
| 179 | =head1 DESCRIPTION | ||||||||||
| 180 | |||||||||||
| 181 | Thinish wrapper of the VMware vCloud Director REST API. | ||||||||||
| 182 | |||||||||||
| 183 | This differs from L<VMware::vCloudDirector> in that it uses the JSON flavoured | ||||||||||
| 184 | version of the API, which has subtly different naming conventions (which is why | ||||||||||
| 185 | I didn't try to make the code handle both flavours), but is much easier to work | ||||||||||
| 186 | with when doing write operations. | ||||||||||
| 187 | |||||||||||
| 188 | It also B<can> do write operations - as well as the other issues in | ||||||||||
| 189 | L<VMware::vCloudDirector> it looks like the write operations - C<PUT>, C<POST> | ||||||||||
| 190 | and C<DELETE> have never worked! | ||||||||||
| 191 | |||||||||||
| 192 | THIS IS AT AN EARLY STAGE OF DEVELOPMENT - PROTOTYPING REALLY - AND MAY CHANGE | ||||||||||
| 193 | DRAMATICALLY OR EAT YOUR DATA. | ||||||||||
| 194 | |||||||||||
| 195 | The lack of documentation reflects the stage in development... | ||||||||||
| 196 | |||||||||||
| 197 | =head1 AUTHOR | ||||||||||
| 198 | |||||||||||
| 199 | Nigel Metheringham <nigelm@cpan.org> | ||||||||||
| 200 | |||||||||||
| 201 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 202 | |||||||||||
| 203 | This software is copyright (c) 2019 by Nigel Metheringham. | ||||||||||
| 204 | |||||||||||
| 205 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 206 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 207 | |||||||||||
| 208 | =cut | ||||||||||