Created
December 1, 2012 15:49
-
-
Save sergiopena/4182963 to your computer and use it in GitHub Desktop.
# Abiquo Infrastructure Grapher
This file contains 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
#!/usr/bin/perl | |
# | |
# Abiquo Infrastructure Grapher | |
# | |
# Sergio Pena 1.12.2012 | |
# | |
# | |
use GraphViz; | |
use DBI; | |
use Data::Dumper; | |
$DBI = "localhost"; | |
$port = "3306"; | |
$database = "kinton"; | |
$user = "root"; | |
$password = ""; | |
$dsn = "DBI:mysql:database=$database;host=$host;port=$port"; | |
$dbh = DBI->connect($dsn, $user, $password); | |
my $g = GraphViz->new(layout => 'twopi', directed => 0, overlap => 'escalexy', node => {shape => 'circle'}); | |
# | |
# Print node of Abiquo AEE | |
$aee = 'Abiquo'; | |
$g->add_node($aee); | |
# | |
# Gather all remote services | |
# | |
$sth = $dbh->prepare("SELECT * FROM datacenter"); | |
$sth->execute(); | |
while (my $ref = $sth->fetchrow_hashref()){ | |
# | |
# Add datacenter node | |
$datacenter_uid = "DC_".$ref->{'idDataCenter'}; | |
$g->add_node( $datacenter_uid, label => $ref->{'name'} ); | |
# | |
# Add conexion from AEE | |
$g->add_edge($aee => $datacenter_uid); | |
} | |
# | |
# RACK | |
$sth = $dbh->prepare("SELECT * FROM rack"); | |
$sth->execute(); | |
while ( my $ref = $sth->fetchrow_hashref() ) { | |
# | |
# Add racks | |
$rack_uid = "RACK_".$ref->{'idRack'}; | |
$g->add_node( $rack_uid); | |
# | |
# Add conections to datacenters | |
$g->add_edge( "DC_".$ref->{'idDataCenter'} => $rack_uid); | |
} | |
# | |
# Physical machines for every rack | |
$sth = $dbh->prepare("SELECT * FROM physicalmachine"); | |
$sth->execute(); | |
while ( my $ref = $sth->fetchrow_hashref() ) { | |
# | |
# Add physical machines | |
$pm_uui = "PM_".$ref->{'idPhysicalMachine'}; | |
$g->add_node ( $pm_uui ); | |
# | |
# Add connections from rack to physicalmachines | |
$g->add_edge( "RACK_".$ref->{'idRack'} => $pm_uui ); | |
} | |
# | |
# Virtual Machines | |
$sth = $dbh->prepare("SELECT pm.idPhysicalMachine, vm.idVM FROM virtualmachine vm, hypervisor hyp, physicalmachine pm WHERE vm.idHypervisor = hyp.id AND hyp.idPhysicalMachine = pm.idPhysicalMachine"); | |
$sth->execute(); | |
while ( my $ref = $sth->fetchrow_hashref() ) { | |
# | |
# Add virtual machines | |
$vm_uui = "VM_".$ref->{'idVM'}; | |
$g->add_node ( $vm_uui, shape => 'point' ); | |
# | |
# Add connections from rack to physicalmachines | |
$g->add_edge( "PM_".$ref->{'idPhysicalMachine'} => $vm_uui ); | |
} | |
print $g->as_svg; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment