Hi,
I recently had to import 60 VLANs (each a /24 networks) into our two XCP pools in order to be able to import client VMs in to them. I'm putting my quick and dirty perl code here in case it helps anyone else, perl is installed on the XCP hosts by default, best run on the master of the pool.
You will need your data formatted like this one vlan/network per line into a file I called "in.txt" . The "IP Range" is only used to be tagged to the end of the description . As you can tell this was a straight export out of our CMDB as an HTML table.
<tr><td>Network Name</td><td>VLAN ID</td><td>IP Range</td><td>Description</td></tr>
<tr><td>PI External 223.0</td><td>1032</td><td>8.8.8.0/25</td><td>PI Space</td></tr>
# UUIDS of host PIFs that you want this vlan presented on, can be bonded or not.
# UUID of PIF of master host in pool MUST be the first one
my @pif_uuids = ('MASTERUUID','NEXTUUID','NEXTUUID');
open (IN,"in.txt");
while (<IN>) {
chomp $_;
my @array = split(/<\/td><td>/,$_);
$array[0] =~ s/<tr><td>//;
$array[3] =~ s/<\/td><\/tr>//;
# First create the base network and get the network UUID back
my $uuid = `xe network-create name-label='$array[0]' name-description='$array[3] - $array[2]'`;
chomp($uuid);
my $string = "VLANS created ";
# Now iterate over the PIFs of the hosts attaching the VLAN to the network.
foreach my $pifuuid (@pif_uuids) {
my $command = "xe vlan-create network-uuid=$uuid pif-uuid=$pifuuid vlan=$array[1]";
my $vlanuuid= `$command`;
chomp $vlanuuid;
$string .= $vlanuuid .' ';
}
print $string . " for VLAN " . $array[1] ."\n";
sleep 2;
}
Hope this helps someone
Regards
Paul