forked from extremenetworks/ExtremeScripting
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsessionManage.pl
More file actions
137 lines (61 loc) · 2.32 KB
/
Copy pathsessionManage.pl
File metadata and controls
137 lines (61 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
sub opensession {
# usage: opensession(switch, username, password)
# return value, session id if successful, null otherwise.
my $host = shift();
my $username = shift();
my $passwd = shift();
# print "Debug: $host, $username, $passwd.\n";
# form the request to initiate connection
my $connection = SOAP::Lite
-> proxy("http://$username\@$host/xmlservice", timeout => 15)
-> ns("http://www.extremenetworks.com/XMLSchema/xos/common", "com") # namespace and prefix for operation
-> autotype(0)
-> envprefix('SOAP-ENV');
my $method = SOAP::Data->name("com:openSessionRequest");
my @params = (SOAP::Data->name("session" =>
(SOAP::Data->name("session"=>
\SOAP::Data->value(
SOAP::Data->name("username" => $username),
SOAP::Data->name("password" => $passwd),
SOAP::Data->name("sessionId" => ""),
SOAP::Data->name("timeout" => "30"),
SOAP::Data->name("appName" => "perlEx")
)
)
)
)
);
# now send the request
$result = $connection->call($method => @params);
# errorhandling:
if ($result->fault) {
print "Error: ",$result->faultcode, " ", $result->faultstring, "\n";
return null;
}
# if successful, return the sessionId:
$rethash = $result->valueof('//session/sessionId');
return $rethash;
}
sub closesession{
my $sessionId=shift();
my $host = shift();
my $username = shift();
# debug
# print "Closing session id $sessionId...\n";
# set up connection
my $connection = SOAP::Lite
-> proxy("http://$username\@$host/xmlservice", timeout=>10)
-> ns("http://www.extremenetworks.com/XMLSchema/xos/common", "com")
-> autotype(0)
-> envprefix('SOAP-ENV');
my $method = SOAP::Data->name("com:closeSessionRequest");
my @params = (SOAP::Data->name("sessionId" =>$sessionId));
# send request
$result = $connection->call($method =>@params);
# handle error
if ($result->fault) {
print $result->faultcode, " ", $result->faultstring, "\n";
}
}
# crucial that the required file returns true:
1;