| 1 | package VMware::vCloudDirector; | ||||||||||
| 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.007'; # 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 Path::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 4 | ▶ | use VMware::vCloudDirector::API; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 4 | ▶ | use VMware::vCloudDirector::Error; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 4 | ▶ | use VMware::vCloudDirector::Object; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | # ------------------------------------------------------------------------ | ||||||||||
| 20 | |||||||||||
| 21 | |||||||||||
| 22 | 4 | has debug => ( is => 'rw', isa => 'Bool', default => 0 ); # Defaults to no debug info | |||||||||
| 23 | |||||||||||
| 24 | 4 | has hostname => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||
| 25 | 4 | has username => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||
| 26 | 4 | has password => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||
| 27 | 4 | has orgname => ( is => 'ro', isa => 'Str', required => 1, default => 'System' ); | |||||||||
| 28 | 4 | has ssl_verify => ( is => 'ro', isa => 'Bool', predicate => '_has_ssl_verify' ); | |||||||||
| 29 | 4 | has timeout => ( is => 'rw', isa => 'Int', predicate => '_has_timeout' ); | |||||||||
| 30 | 4 | has ssl_ca_file => ( is => 'ro', isa => Path, coerce => 1, predicate => '_has_ssl_ca_file' ); | |||||||||
| 31 | 4 | has _ua => ( is => 'ro', isa => 'LWP::UserAgent', predicate => '_has_ua' ); | |||||||||
| 32 | 4 | has _debug_trace_directory => | |||||||||
| 33 | ( is => 'ro', isa => Path, coerce => 1, predicate => '_has_debug_trace_directory' ); | ||||||||||
| 34 | |||||||||||
| 35 | 4 | has api => ( | |||||||||
| 36 | is => 'ro', | ||||||||||
| 37 | isa => 'VMware::vCloudDirector::API', | ||||||||||
| 38 | lazy => 1, | ||||||||||
| 39 | builder => '_build_api' | ||||||||||
| 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::vCloudDirector::API->new(@args); | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | # ------------------------------------------------------------------------ | ||||||||||
| 61 | 4 | has org_listref => ( | |||||||||
| 62 | is => 'ro', | ||||||||||
| 63 | isa => 'ArrayRef[VMware::vCloudDirector::Object]', | ||||||||||
| 64 | lazy => 1, | ||||||||||
| 65 | builder => '_build_org_listref', | ||||||||||
| 66 | traits => ['Array'], | ||||||||||
| 67 | handles => { | ||||||||||
| 68 | org_list => 'elements', | ||||||||||
| 69 | org_map => 'map', | ||||||||||
| 70 | org_grep => 'grep', | ||||||||||
| 71 | }, | ||||||||||
| 72 | ); | ||||||||||
| 73 | 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
| |||||||||||
| 74 | |||||||||||
| 75 | # ------------------------------------------------------------------------ | ||||||||||
| 76 | 4 | ▶ | method query (@args) { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
Subroutine
query: not called CC=1 SCAR=3.1
| |||||||||||
| 77 | 0 | my $uri = $self->api->query_uri->clone; | |||||||||
| 78 | 0 | $uri->query_form(@args); | |||||||||
| 79 | 0 | return $self->api->GET($uri); | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | # ------------------------------------------------------------------------ | ||||||||||
| 83 | |||||||||||
| 84 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||
| 85 | |||||||||||
| 86 | 4 | 1; | |||||||||
| 87 | |||||||||||
| 88 | __END__ | ||||||||||
| 89 | |||||||||||
| 90 | =pod | ||||||||||
| 91 | |||||||||||
| 92 | =encoding UTF-8 | ||||||||||
| 93 | |||||||||||
| 94 | =head1 NAME | ||||||||||
| 95 | |||||||||||
| 96 | VMware::vCloudDirector - Interface to VMWare vCloud Directory REST API | ||||||||||
| 97 | |||||||||||
| 98 | =head1 VERSION | ||||||||||
| 99 | |||||||||||
| 100 | version 0.007 | ||||||||||
| 101 | |||||||||||
| 102 | =head1 SYNOPSIS | ||||||||||
| 103 | |||||||||||
| 104 | # THIS IS AT AN EARLY STAGE OF DEVELOPMENT - PROTOTYPING REALLY | ||||||||||
| 105 | # IT MAY CHANGE DRAMATICALLY OR EAT YOUR DATA. | ||||||||||
| 106 | |||||||||||
| 107 | use VMware::vCloudDirector | ||||||||||
| 108 | |||||||||||
| 109 | my $vcd = VMware::vCloudDirector->new( | ||||||||||
| 110 | hostname => $host, | ||||||||||
| 111 | username => $user, | ||||||||||
| 112 | password => $pass, | ||||||||||
| 113 | orgname => $org, | ||||||||||
| 114 | ssl_verify => 0, | ||||||||||
| 115 | ); | ||||||||||
| 116 | my @org_list = $vcd->org_list; | ||||||||||
| 117 | |||||||||||
| 118 | =head2 Attributes | ||||||||||
| 119 | |||||||||||
| 120 | =head3 hostname | ||||||||||
| 121 | |||||||||||
| 122 | Hostname of the vCloud server. Must have a vCloud instance listening for https | ||||||||||
| 123 | on port 443. | ||||||||||
| 124 | |||||||||||
| 125 | =head3 username | ||||||||||
| 126 | |||||||||||
| 127 | Username to use to login to vCloud server. | ||||||||||
| 128 | |||||||||||
| 129 | =head3 password | ||||||||||
| 130 | |||||||||||
| 131 | Password to use to login to vCloud server. | ||||||||||
| 132 | |||||||||||
| 133 | =head3 orgname | ||||||||||
| 134 | |||||||||||
| 135 | Org name to use to login to vCloud server - this defaults to C<System>. | ||||||||||
| 136 | |||||||||||
| 137 | =head3 timeout | ||||||||||
| 138 | |||||||||||
| 139 | Command timeout in seconds. Defaults to 120. | ||||||||||
| 140 | |||||||||||
| 141 | =head3 default_accept_header | ||||||||||
| 142 | |||||||||||
| 143 | The default MIME types to accept. This is automatically set based on the | ||||||||||
| 144 | information received back from the API versions. | ||||||||||
| 145 | |||||||||||
| 146 | =head3 ssl_verify | ||||||||||
| 147 | |||||||||||
| 148 | Whether to do standard SSL certificate verification. Defaults to set. | ||||||||||
| 149 | |||||||||||
| 150 | =head3 ssl_ca_file | ||||||||||
| 151 | |||||||||||
| 152 | The SSL CA set to trust packaged in a file. This defaults to those set in the | ||||||||||
| 153 | L<Mozilla::CA> | ||||||||||
| 154 | |||||||||||
| 155 | =head2 debug | ||||||||||
| 156 | |||||||||||
| 157 | Set debug level. The higher the debug level, the more chatter is exposed. | ||||||||||
| 158 | |||||||||||
| 159 | Defaults to 0 (no output) unless the environment variable C<VCLOUD_API_DEBUG> | ||||||||||
| 160 | is set to something that is non-zero. Picked up at create time in C<BUILD()> | ||||||||||
| 161 | |||||||||||
| 162 | =head1 DESCRIPTION | ||||||||||
| 163 | |||||||||||
| 164 | Thinish wrapper of the VMware vCloud Director REST API. | ||||||||||
| 165 | |||||||||||
| 166 | THIS IS AT AN EARLY STAGE OF DEVELOPMENT - PROTOTYPING REALLY - AND MAY CHANGE | ||||||||||
| 167 | DRAMATICALLY OR EAT YOUR DATA. | ||||||||||
| 168 | |||||||||||
| 169 | The target application is to read information from a vCloud instance, so the | ||||||||||
| 170 | ability to change or write data to the vCloud system has not been implemented | ||||||||||
| 171 | as yet... | ||||||||||
| 172 | |||||||||||
| 173 | =head1 AUTHOR | ||||||||||
| 174 | |||||||||||
| 175 | Nigel Metheringham <nigelm@cpan.org> | ||||||||||
| 176 | |||||||||||
| 177 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 178 | |||||||||||
| 179 | This software is copyright (c) 2017 by Nigel Metheringham. | ||||||||||
| 180 | |||||||||||
| 181 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 182 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 183 | |||||||||||
| 184 | =cut | ||||||||||