Enterasys-NetSight

 view release on metacpan or  search on metacpan

lib/Enterasys/NetSight.pm  view on Meta::CPAN

		foreach my $attribute(split(" ",$line))
		{
			if((my @keyval=split("=",$attribute))==2)
				{ $temp{$keyval[0]}=$keyval[1] }
			else
				{ $temp{$keyval[0]}=undef }
		}
		$table{$temp{dev}}=\%temp;
	}

	return $call->result eq ""?undef:\%table;
}
sub ipV6Enabled
{
	my ($self)=@_;
	my $call=$self->{soap}->isIpV6Enabled;

	if($call->fault) 
		{ carp($call->faultstring) && return undef }

	return $call->result eq "true"?1:0;
}
sub netSnmpEnabled
{
	my ($self)=@_;
	my $call=$self->{soap}->isNetSnmpEnabled;

	if($call->fault) 
		{ carp($call->faultstring) && return undef }

	return $call->result eq "true"?1:0;
}

# Methods for adding device data
sub addAuth
{
	my ($self, $args)=@_;
	my @params=qw(username description loginPassword enablePassword configurationPassword type);
	return _call($self, 'addAuthCredentialEx', \@params, $args);
}
sub addSnmp
{
	my ($self, $args)=@_;
	my @params=qw(name snmpVersion communityName userName authPassword authType privPassword privType);
	return _call($self, 'addCredentialEx', \@params, $args);
}
sub addDevice
{
	my ($self, $args)=@_;
	my @params=qw(ipAddress profileName snmpContext nickName);
	return _call($self, 'addDeviceEx', \@params, $args);
}
sub addProfile
{
	my ($self, $args)=@_;
	my @params=qw(name snmpVersion read write maxAccess auth);
	return _call($self, 'addProfileEx', \@params, $args);
}

# Methods for updating
sub updateAuth
{
	my ($self, $args)=@_;
	my @params=qw(username description loginPassword enablePassword configurationPassword type);
	return _call($self, 'updateAuthCredentialEx', \@params, $args);
}
sub updateSnmp
{
	my ($self, $args)=@_;
	my @params=qw(name communityName userName authPassword authType privPassword privType);
	return _call($self, 'updateCredentialEx', \@params, $args);
}
sub updateProfile
{
	my ($self, $args)=@_;
	my @params=qw(name read write maxAccess authCredName);
	return _call($self, 'updateProfileEx', \@params, $args);
}

# Methods for deleting
sub deleteDevice
{
	my ($self, $args)=@_;
	
	if(!defined $args->{host})
		{ carp("You must specify a host for deleteDevice method") && return undef }
	$args->{host}=_resolv($args->{host});
	
	my $call=$self->{soap}->deleteDeviceByIpEx($args->{host});

	if($call->fault)
		{ carp($call->faultstring) && return undef }

	if(_wsresult_error($call->result))
		{ return undef }
	else
		{ return $call->result }
}

# Private
sub _call
{
	# Internal method for making calls with multiple arguments
	# Arguments must be in the correct order and unused arguments
	# must be present but blank. The order of all args needed is specified
	# in $params array and the args specified is in the $args table
	my ($self, $method, $params, $args)=@_;
	my @data;

	foreach my $param(@$params)
		{ push(@data, SOAP::Data->name($param => $args->{$param} || "")) }

	my $call=$self->{soap}->$method(SOAP::Data->value(@data));

	if($call->fault) 
		{ carp($call->faultstring) && return undef }

	if(_wsresult_error($call->result))
		{ return undef }
	else
		{ return $call->result }
}
sub _resolv
{
	# Resolve IP for a hostname
	my ($host)=@_;
	if(eval{$host=inet_ntoa(inet_aton($host))})
		{ return $host }
	else
		{ carp("Unable to resolve host: $host") && return undef }
}
sub _wsresult_error
{



( run in 0.706 second using v1.01-cache-2.11-cpan-d7f47b0818f )