DMTF-WSMan

 view release on metacpan or  search on metacpan

lib/DMTF/WSMan.pm  view on Meta::CPAN

package DMTF::WSMan;

use warnings;
use strict;

use version; 
our $VERSION = qv('0.05');
use LWP;
use LWP::Authen::Digest;
use Data::UUID;
use Carp;

# Module implementation here
# We make our own specialization of LWP::UserAgent that 
# uses the correct user ID and password
{
    package DMTF::WSMan::PRIVATE::RequestAgent;
    our @ISA = qw(LWP::UserAgent);

    sub new
    {
		my $class=shift;
		my $awo=shift;
		my $self = LWP::UserAgent::new($class, @_);
		$self->{ASSOCIATED_WSMAN_OBJECT}=$awo;
		return($self);
    }

    sub get_basic_credentials
    {
		my $self=shift;
		return($self->{ASSOCIATED_WSMAN_OBJECT}{Context}{user},$self->{ASSOCIATED_WSMAN_OBJECT}{Context}{pass});
    }
}

sub new
{
	my $self={};
	$self->{CLASS} = shift;
	my %args=@_;
	$self->{Context} = {
		user=>'Administrator',
		# password
		# host
		port=>623,
		protocol=>'http',
		xmlns=>{
			soap=>{prefix=>'s', uri=>'http://www.w3.org/2003/05/soap-envelope'},
			addressing=>{prefix=>'a', uri=>'http://schemas.xmlsoap.org/ws/2004/08/addressing'},
			enumeration=>{prefix=>'n', uri=>'http://schemas.xmlsoap.org/ws/2004/09/enumeration'},
			wsman=>{prefix=>'w', uri=>'http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd'},
			cim=>{prefix=>'c', uri=>'http://schemas.dmtf.org/wbem/wsman/1/cimbinding.xsd'}
		}
	};
	$self->{Context}{user} = $args{user} if(defined $args{user});
	$self->{Context}{port} = $args{port} if(defined $args{port});
	$self->{Context}{protocol} = $args{protocol} if(defined $args{protocol});
	$self->{Context}{pass} = $args{pass} if(defined $args{pass});
	$self->{Context}{host} = $args{host} if(defined $args{host});
	$self->{RA} = DMTF::WSMan::PRIVATE::RequestAgent->new($self, keep_alive=>1);
	$self->{challenge_str}=undef;
	$self->{UUID} = Data::UUID->new();
	bless($self, $self->{CLASS});
	return($self);
}

sub invoke
{
	my $self=shift;
	my %args=@_;
	if(!defined $args{epr}) {
		carp "No EPR specified";
		return;
	}
	my $postdata;

	if(defined $args{method}) {
		$postdata=$self->_genheaders($args{epr}{ResourceURI}."/".$args{method},$args{epr});
	}
	else {
		$postdata=$self->_genheaders($args{epr}{ResourceURI},$args{epr});
	}
	$postdata .= "<$self->{Context}{xmlns}{soap}{prefix}:Body>";
	$postdata .= $args{body};
	$postdata .= "</$self->{Context}{xmlns}{soap}{prefix}:Body></$self->{Context}{xmlns}{soap}{prefix}:Envelope>";

	my $res = $self->_request($postdata);
	return $res->content;
}



( run in 1.514 second using v1.01-cache-2.11-cpan-39bf76dae61 )