Created
August 23, 2014 04:33
-
-
Save ryanrhanson/205b055e8db829b48e25 to your computer and use it in GitHub Desktop.
This horrible looking script will list all vyatta appliances on an account (from the Gateway Appliances section) along with a wealth of info about the one you select. It will also tell you the status of any vlan behind the vyatta (such as if it can support san or local disk virtual servers). Could be improved in many ways, I'm sure.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is optional and can be removed if you already have the SoftLayer | |
# directory that contains this module in your @INC path. | |
use lib 'Softlayer'; | |
my %config = do 'apiconfig.pl'; | |
use SoftLayer::API::SOAP; | |
use Data::Dumper; | |
use MIME::Base64; | |
use Data::Printer; | |
my $acctClient = SoftLayer::API::SOAP->new('SoftLayer_Account','',$config{apiUser},$config{apiKey}); | |
my $acctGateways = $acctClient->getNetworkGateways()->result; | |
print "Gateways for account " . $acctGateways->[0]->{'accountId'} . "\n"; | |
foreach $vyatta (@{$acctGateways}) { | |
print "ID: " . $vyatta->{'id'} . " - " . $vyatta->{'name'} . "\n"; | |
} | |
print "Please enter a vyatta ID from the list above: "; | |
my $vyattaId = <STDIN>; | |
chomp $vyattaId; | |
# Initialize an API client for the SoftLayer_Account service. | |
my $gwClient = SoftLayer::API::SOAP->new('SoftLayer_Network_Gateway',$vyattaId,$config{apiUser},$config{apiKey}); | |
$gwClient->setObjectMask({ | |
publicIpAddress => '', | |
privateIpAddress => '', | |
publicIpv6Address => '', | |
publicVlan => '', | |
privateVlan => '', | |
insideVlanCount => '', | |
members => { | |
hardware => { | |
operatingSystem => { | |
passwords => '', | |
}, | |
}, | |
}, | |
insideVlans => { | |
networkVlan => { | |
networkSpace => '', | |
sanStorageCapabilityFlag => '', | |
localDiskStorageCapabilityFlag => '', | |
subnets => { | |
subnetType => '', | |
}, | |
}, | |
}, | |
}); | |
# Retrieve our account record | |
my $gateway = $gwClient->getObject(); | |
if ($gateway->fault) { | |
die 'Unable to retrieve account information: ' . $gateway->faultstring; | |
} else { | |
print "Gateway Information: \n"; | |
print "Name: " . $gateway->result->{'name'} . "\n"; | |
print "Public Information: \n"; | |
print " - Public IPv4 Address: " . $gateway->result->{'publicIpAddress'}->{'ipAddress'} . " on VLAN " .$gateway->result->{'publicVlan'}->{'vlanNumber'} . "\n"; | |
print " - Private IPv4 Address: " . $gateway->result->{'privateIpAddress'}->{'ipAddress'} . " on VLAN " . $gateway->result->{'privateVlan'}->{'vlanNumber'} . "\n"; | |
if ($gateway->result->{'publicIpv6Address'}){ | |
print " - Public IPv6 Address: " . $gateway->result->{'publicIpv6Address'}->{'ipAddress'} . "\n"; | |
} | |
foreach my $member ( @{ $gateway->result->{'members'} } ) { | |
foreach my $creds ( @{ $member->{'hardware'}->{'operatingSystem'}->{'passwords'} } ) { | |
print "User: " . $creds->{'username'} . "\n"; | |
print "Password: " . $creds->{'password'} . "\n"; | |
my $base64auth = encode_base64($creds->{'username'} . ":" . $creds->{'password'}); | |
chomp $base64auth; | |
my $authstring = "\"Authorization: Basic " . $base64auth . "\""; | |
print "Auth String: " . $authstring . "\n\n" | |
} | |
} | |
print "=== INSIDE VLANS ===\n"; | |
foreach my $vlan ( @{ $gateway->result->{'insideVlans'} } ) { | |
$route = $vlan->{'bypassFlag'} ? "Bypassed" : "Routed"; | |
$cloud = $vlan->{'networkVlan'}->{'sanStorageCapabilityFlag'} ? "C" : ""; | |
$local = $vlan->{'networkVlan'}->{'localDiskStorageCapabilityFlag'} ? "L" : ""; | |
print "(".$cloud.$local.") ".$vlan->{'networkVlan'}->{'networkSpace'} . " VLAN " . $vlan->{'networkVlan'}->{'vlanNumber'} . " is currently " . $route . "\n"; | |
foreach my $subnet (@{$vlan->{'networkVlan'}->{'subnets'}}) { | |
print "\t" .$subnet->{'subnetType'} . " - " . $subnet->{'networkIdentifier'} . "/" . $subnet->{'cidr'} . "\n"; | |
} | |
print Dumper($vlan) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment