##############################################################################
############################################################################## # 练习网络配置 API 的示例 Perl 脚本 # CA ############################################################################## # ############################################################################## # 注意:请修改 $url,以指向 ADA 控制台的承载位置 ############################################################################## # ############################################################################## #!/usr/local/bin/perl use Data::Dump qw(dump); use SOAP::Lite ( # +trace => all, maptype => {} ); $SOAP::Constants::DO_NOT_USE_CHARSET = 1; # # ############################################################################## my $uri = "http://www.netqos.com/networkconfig"; my $url = "http://localhost/SuperAgentWebService/NetworkConfigService.asmx"; # my ($method, $result, $networks, @nodes, @params); my ($clientId, $description, $subnetCidr, $regionCount, $networkType); # sub SOAP::Transport::HTTP::Client::get_basic_credentials { return $user => $pass; } # ############################################################################## my $soap = SOAP::Lite -> uri($uri) -> on_action( sub { join '/', @_ } ) -> proxy($url); # # ############################################################################## # NetworkDefinitionsList ############################################################################## $method = SOAP::Data->name('NetworkDefinitionsList')->attr({xmlns => $uri}); $networks = $soap->call($method); print "\nNetworkDefinitionsList:\n"; if ($networks->fault) { print join ', ', $result->faultcode, $result->faultstring, $result->faultdetail; } else { if ($networks->dataof('//NetworkDefinitionsList')->{_attr}->{Status} eq "False") { print $network->dataof('//NetworkDefinitionsList')->{_attr}->{Message}, "\n"; } else { print "\n\nClientID\tDescription\tSubnet\t\tRegions\t\tNetworkType\n"; @nodes = $networks->valueof('//Network'); foreach $n (@nodes) { print $n->{'ClientId'}, "\t", $n->{'Description'},"\t\t", $n->{'Subnet'},"\t\t", $n->{'Regions'}, $n->{'NetworkType'},"\t", "\n"; } } } # ############################################################################## # UpdateNetworkDefinition ############################################################################## print "\n\nUpdateNetworkDefinition:\n"; $method = SOAP::Data->name('UpdateNetworkDefinition')->attr({xmlns => $uri}); $clientId = $networks->valueof('//Network/ClientId'); $description = $networks->valueof('//Network/Description') . " UPDATED"; $description = substr($description, 0, 50); $regionCount = $networks->valueof('//Network/Regions'); $networkType = "未分配"; @params = ( SOAP::Data->name(ClientId => $clientId), SOAP::Data->name(Description => $description), SOAP::Data->name(Regions => $regionCount), SOAP::Data->name(NetworkType => $networkType) ); $result = $soap->call($method => @params); if ($result->fault) { print join ', ', $result->faultcode, $result->faultstring, $result->faultdetail; } else { if ($result->dataof('//UpdateNetworkDefinition')->{_attr}->{Status} eq "False") { print $result->dataof('//UpdateNetworkDefinition')->{_attr}->{Message}; } else { print "UpdateNetworkDefinition($clientId, $description, $regionCount, $networkType):\n"; print dump($result->result), "\n"; } } # ############################################################################## # DeleteNetworkDefinition ############################################################################## print "\n\nDeleteNetworkDefinition:\n"; $method = SOAP::Data->name('DeleteNetworkDefinition')->attr({xmlns => $uri}); $clientId = $networks->valueof('//Network/ClientId'); $description = $networks->valueof('//Network/Description'); @params = (SOAP::Data->name(ClientId => $clientId)->attr({xmlns => $uri})); $result = $soap->call($method => @params); if ($result->fault) { print join ', ', $result->faultcode, $result->faultstring, $result->faultdetail; } else { if ($result->dataof('//DeleteNetworkDefinition')->{_attr}->{Status} eq "False") { print $result->dataof('//DeleteNetworkDefinition')->{_attr}->{Message}; } else { print "DeleteNetworkDefinition($clientId, $description):\n"; print dump($result->result), "\n"; } } # ############################################################################## # InsertNetworkDefinition ############################################################################## print "\n\nInsertNetworkDefinition:\n"; $method = SOAP::Data->name('InsertNetworkDefinition')->attr({xmlns => $uri}); $description = $networks->valueof('//Network/Description'); $subnetCidr = $networks->valueof('//Network/Subnet'); $regionCount = $networks->valueof('//Network/Regions'); $networkType = "未分配"; @params = ( SOAP::Data->name(Description => $description), SOAP::Data->name(Subnet => $subnetCidr), SOAP::Data->name(Regions => $regionCount), SOAP::Data->name(NetworkType => $networkType) ); $result = $soap->call($method => @params); if ($result->fault) { print join ', ', $result->faultcode, $result->faultstring, $result->faultdetail; } else { if ($result->dataof('//InsertNetworkDefinition')->{_attr}->{Status} eq "False") { print $result->dataof('//InsertNetworkDefinition')->{_attr}->{Message}; } else { print "InsertNetworkDefinition($description, $subnetCidr, $regionCount, $networkType):\n"; print dump($result->result), "\n"; } } # # ############################################################################## # ReloadCollectors ############################################################################## $method = SOAP::Data->name('ReloadCollectors')->attr({xmlns => $uri}); print "\n\nReloadCollectors():....\n"; $result = $soap->call($method); if ($result->fault) { print join ', ', $result->faultcode, $result->faultstring, $result->faultdetail; } else { if ($result->dataof('//ReloadCollectors')->{_attr}->{Status} eq "False") { print $result->dataof('//ReloadCollectors')->{_attr}->{Message}; } else { @nodes = $result->valueof('//Collector'); foreach $node (@nodes) { print $node->{'Address'}, "\t", $node->{'Status'}, "\t",$node->{'Info'}, "\n"; } } } # # ############################################################################## # ShowVersion ############################################################################## $method = SOAP::Data->name('ShowVersion')->attr({xmlns => $uri}); print "\n\nShowVersion():\n"; $result = $soap->call($method); if ($result->fault) { print join ', ', $result->faultcode, $result->faultstring, $result->faultdetail; } else { print $result->result, "\n"; }
#
版权所有 © 2014 CA Technologies。
保留所有权利。
|
|