Create a gist now

Instantly share code, notes, and snippets.

@scottdware /azureip.go Secret
Created Mar 17, 2015

What would you like to do?
Azure IPs added to Junos Space
package main
import (
"encoding/xml"
"flag"
"fmt"
"github.com/scottdware/go-junos"
"io/ioutil"
"log"
"os"
"time"
)
type AzurePublicIPAddresses struct {
Region []Region `xml:"Region"`
}
type Region struct {
Name string `xml:"Name,attr"`
Subnets []Subnet `xml:"IpRange"`
}
type Subnet struct {
Subnet string `xml:"Subnet,attr"`
}
var (
server = flag.String("server", "", "Junos Space server")
user = flag.String("user", "", "Username")
password = flag.String("password", "", "Password")
source = flag.String("source", "", "XML file with Azure subnets")
)
func main() {
flag.Parse()
var azure AzurePublicIPAddresses
space := junos.NewServer(*server, *user, *password)
x, err := ioutil.ReadFile(*source)
if err != nil {
log.Fatal(err)
}
if err := xml.Unmarshal(x, &azure); err != nil {
log.Fatal(err)
}
for _, r := range azure.Region {
gName := fmt.Sprintf("Azure_%s", r.Name)
desc := fmt.Sprintf("Azure IPs - %s", r.Name)
space.AddGroup(true, gName, desc)
for _, s := range r.Subnets {
addrName := fmt.Sprintf("AzureSubnet_%s", s.Subnet)
space.AddAddress(addrName, s.Subnet, "")
time.Sleep(time.Millisecond * 250)
space.ModifyObject(true, "add", gName, addrName)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment