Skip to content

Instantly share code, notes, and snippets.

@scottdware
Created March 17, 2015 15:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottdware/931e1e722e4d26111713 to your computer and use it in GitHub Desktop.
Save scottdware/931e1e722e4d26111713 to your computer and use it in GitHub Desktop.
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