-
-
Save scottdware/931e1e722e4d26111713 to your computer and use it in GitHub Desktop.
Azure IPs added to Junos Space
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
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