File Coverage

blib/lib/VMware/vCloudDirector.pm
Criterion Covered Total %
statement 19 21 90.4
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 26 28 92.8


line stmt bran cond sub pod time code
1             package VMware::vCloudDirector;
2              
3             # ABSTRACT: Interface to VMWare vCloud Directory REST API
4              
5 3     3   57020 use strict;
  3         25  
  3         109  
6 3     3   20 use warnings;
  3         9  
  3         180  
7              
8             our $VERSION = '0.005'; # VERSION
9             our $AUTHORITY = 'cpan:NIGELM'; # AUTHORITY
10              
11 3     3   1286 use Moose;
  3         895733  
  3         27  
12 3     3   21797 use Method::Signatures;
  3         100687  
  3         27  
13 3     3   2390 use MooseX::Types::Path::Tiny qw/Path/;
  3         993241  
  3         37  
14 3     3   7684 use Path::Tiny;
  3         8  
  3         184  
15 3     3   1293 use VMware::vCloudDirector::API;
  0            
  0            
16             use VMware::vCloudDirector::Error;
17             use VMware::vCloudDirector::Object;
18              
19             # ------------------------------------------------------------------------
20              
21              
22             has debug => ( is => 'rw', isa => 'Bool', default => 0 ); # Defaults to no debug info
23              
24             has hostname => ( is => 'ro', isa => 'Str', required => 1 );
25             has username => ( is => 'ro', isa => 'Str', required => 1 );
26             has password => ( is => 'ro', isa => 'Str', required => 1 );
27             has orgname => ( is => 'ro', isa => 'Str', required => 1, default => 'System' );
28             has ssl_verify => ( is => 'ro', isa => 'Bool', predicate => '_has_ssl_verify' );
29             has timeout => ( is => 'rw', isa => 'Int', predicate => '_has_timeout' );
30             has ssl_ca_file => ( is => 'ro', isa => Path, coerce => 1, predicate => '_has_ssl_ca_file' );
31             has _ua => ( is => 'ro', isa => 'LWP::UserAgent', predicate => '_has_ua' );
32             has _debug_trace_directory =>
33             ( is => 'ro', isa => Path, coerce => 1, predicate => '_has_debug_trace_directory' );
34              
35             has api => (
36             is => 'ro',
37             isa => 'VMware::vCloudDirector::API',
38             lazy => 1,
39             builder => '_build_api'
40             );
41              
42             method _build_api () {
43             my @args = (
44             hostname => $self->hostname,
45             username => $self->username,
46             password => $self->password,
47             orgname => $self->orgname,
48             debug => $self->debug
49             );
50             push( @args, timeout => $self->timeout ) if ( $self->_has_timeout );
51             push( @args, ssl_verify => $self->ssl_verify ) if ( $self->_has_ssl_verify );
52             push( @args, ssl_ca_file => $self->ssl_ca_file ) if ( $self->_has_ssl_ca_file );
53             push( @args, _debug_trace_directory => $self->_debug_trace_directory )
54             if ( $self->_has_debug_trace_directory );
55             push( @args, _ua => $self->_ua ) if ( $self->_has_ua );
56              
57             return VMware::vCloudDirector::API->new(@args);
58             }
59              
60             # ------------------------------------------------------------------------
61             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             method _build_org_listref { return [ $self->api->GET('/api/org/') ]; }
74              
75             # ------------------------------------------------------------------------
76             method query (@args) {
77             my $uri = $self->api->query_uri->clone;
78             $uri->query_form(@args);
79             return $self->api->GET($uri);
80             }
81              
82             # ------------------------------------------------------------------------
83              
84             __PACKAGE__->meta->make_immutable;
85              
86             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.005
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