Serge Bazanski | 8d7843c | 2018-10-04 10:37:36 +0100 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "flag" |
| 5 | "io/ioutil" |
| 6 | |
Serge Bazanski | 28f4907 | 2018-10-06 11:31:18 +0100 | [diff] [blame^] | 7 | //"github.com/digitalocean/go-netbox/netbox" |
| 8 | //"github.com/digitalocean/go-netbox/netbox/client" |
| 9 | //"github.com/digitalocean/go-netbox/netbox/client/dcim" |
| 10 | |
Serge Bazanski | 8d7843c | 2018-10-04 10:37:36 +0100 | [diff] [blame] | 11 | "github.com/golang/glog" |
| 12 | "github.com/golang/protobuf/proto" |
| 13 | |
Serge Bazanski | 28f4907 | 2018-10-06 11:31:18 +0100 | [diff] [blame^] | 14 | "code.hackerspace.pl/q3k/topo/graph" |
Serge Bazanski | 8d7843c | 2018-10-04 10:37:36 +0100 | [diff] [blame] | 15 | confpb "code.hackerspace.pl/q3k/topo/proto/config" |
| 16 | ) |
| 17 | |
| 18 | var ( |
Serge Bazanski | 88b572d | 2018-10-05 16:35:01 -0700 | [diff] [blame] | 19 | flagConfigPath string |
| 20 | flagNetboxHost string |
| 21 | flagNetboxAPIKey string |
Serge Bazanski | 8d7843c | 2018-10-04 10:37:36 +0100 | [diff] [blame] | 22 | ) |
| 23 | |
| 24 | func init() { |
| 25 | flag.Set("logtostderr", "true") |
| 26 | } |
| 27 | |
| 28 | func main() { |
| 29 | flag.StringVar(&flagConfigPath, "config_path", "./topo.pb.text", "Text proto configuration of Topo (per config.proto)") |
Serge Bazanski | 88b572d | 2018-10-05 16:35:01 -0700 | [diff] [blame] | 30 | flag.StringVar(&flagNetboxHost, "netbox_host", "nebtox.bgp.wtf", "Netbox host") |
| 31 | flag.StringVar(&flagNetboxAPIKey, "netbox_api_key", "", "Netbox API key") |
Serge Bazanski | 8d7843c | 2018-10-04 10:37:36 +0100 | [diff] [blame] | 32 | flag.Parse() |
| 33 | |
| 34 | data, err := ioutil.ReadFile(flagConfigPath) |
| 35 | if err != nil { |
| 36 | glog.Exitf("Could not read config: %v", err) |
| 37 | } |
| 38 | |
| 39 | config := confpb.Config{} |
| 40 | proto.UnmarshalText(string(data), &config) |
Serge Bazanski | 88b572d | 2018-10-05 16:35:01 -0700 | [diff] [blame] | 41 | |
Serge Bazanski | 28f4907 | 2018-10-06 11:31:18 +0100 | [diff] [blame^] | 42 | gr := graph.New() |
| 43 | err = gr.LoadConfig(&config) |
| 44 | if err != nil { |
| 45 | glog.Exitf("Initial config load failed: %v", err) |
Serge Bazanski | 88b572d | 2018-10-05 16:35:01 -0700 | [diff] [blame] | 46 | } |
Serge Bazanski | 28f4907 | 2018-10-06 11:31:18 +0100 | [diff] [blame^] | 47 | |
| 48 | //client.DefaultSchemes = []string{"https"} |
| 49 | //nb := netbox.NewNetboxWithAPIKey(flagNetboxHost, flagNetboxAPIKey) |
| 50 | //req := &dcim.DcimInterfaceConnectionsListParams{ |
| 51 | // Device: swag.String("bc01n01"), |
| 52 | // Context: context.Background(), |
| 53 | //} |
| 54 | //res, err := nb.Dcim.DcimInterfaceConnectionsList(req, nil) |
| 55 | //glog.Infof("%+v, %v", res, err) |
Serge Bazanski | 8d7843c | 2018-10-04 10:37:36 +0100 | [diff] [blame] | 56 | } |