VMware-LabManager
view release on metacpan or search on metacpan
lib/VMware/LabManager.pm view on Meta::CPAN
my $org = shift; # LM organization name
my $debug = shift; # enable debug, off by default
# Set the debug option if passed to the constructor.
if ( defined $debug && ( $debug eq 'debug' ) )
{
eval("use SOAP::Lite +trace => 'debug'");
} else
{
eval("use SOAP::Lite");
}
my $self = {
Username => $uname,
Password => $pass,
Hostname => $host,
Organization => $org
};
bless( $self, $class );
return $self;
}
=head2 get_soap
This method is primary used internally, but there are situations where it could
be used for other SOAP methods that have not been exposed by this module. This
method returns SOAP::Lite object & sets the readable option on. You can use this
in conjunction with Authentication header, which you can get from get_auth_header()
method.
NOTE: Usage of this method outside the scope of this API is not recommended.
=cut
sub get_soap
{
my $self = shift;
my $soap = SOAP::Lite->on_action(
sub {
return "http://vmware.com/labmanager/" . $_[1];
}
)->default_ns('http://vmware.com/labmanager')
->proxy(
'https://' . $self->{Hostname} . '/LabManager/SOAP/LabManager.asmx' );
$soap->readable(1);
return $soap;
}
=head2 get_auth_header
This method returns an authentication header wrapper that is needed for each
SOAP call that you make to Lab Manager. It uses the options you provided in the
new() method to build this header.
=cut
sub get_auth_header
{
my $self = shift;
my $auth_header = SOAP::Header->new(
name => 'AuthenticationHeader',
attr => { xmlns => "http://vmware.com/labmanager" },
value => {
username => $self->{Username},
password => $self->{Password},
organizationname => $self->{Organization},
},
);
return $auth_header;
}
=head2 deploy_config
This method is tailored for automation. During automation, one primarily cares about
deploying a library image. A single method call to encapsulate the whole set of
operations is more deirable.
This method requires a config name (make sure it is unique in the system), which
it uses to:
=over 4
=item * Checkout the config to your default workspace with a random name.
=item * Deploy the confignation in fenced mode.
=item * Return the unique numeric Config ID of the deployed config.
=back
You have to use this config ID to undeploy & delete it at at later stage.
=cut
sub deploy_config
{
my $self = shift;
my $config_name = shift; # library config name
my $soap = $self->get_soap();
my $auth_header = $self->get_auth_header();
my $res;
# Get Configuration by Name
$res = $soap->GetConfigurationByName(
$auth_header,
SOAP::Data->name(
'name' => $config_name
)->type('s:string')
);
#check for error ... there's more in the faultdetail hash, could use Dumper to examine it
if ( $res->fault )
{
return
join( ': ',
'LabManager SOAP error', $res->faultcode,
$res->faultstring, $res->faultdetail );
}
( run in 1.885 second using v1.01-cache-2.11-cpan-e1769b4cff6 )