ros7api

package module
v0.0.0-...-271b61c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2021 License: Apache-2.0 Imports: 0 Imported by: 0

README

ros7api

Experimental (don't use!) Mikrotik RouterOS 7 REST client for Go.

Attempting to autogenerate as much as possible - see gen/kinds.proto and gen/types.text.pb.

Regenerating

$ nix-shell
$ rm ros/zz*
$ go generate

Bazel Integration

Soon, probably in hscloud.

Documentation

Overview

Package ros7api implements a client for the ROS7 (Mikrotik RouterOS 7) REST API (https://help.mikrotik.com/docs/display/ROS/REST+API).

The API types are autogenerated from a high-level description. The main client and generated types are in the ros subpackage.

The gen subpackage contains the code generator used to generate the API client types from a Protobuf description contained in gen/types.text.pb.

Example
ctx := context.Background()
c := ros.Client{
	Username: "admin",
	Password: os.Getenv("ROS7API_EXAMPLE_PASSWORD"),
	Address:  os.Getenv("ROS7API_EXAMPLE_ADDRESS"),
	HTTP:     ros.LetsEncryptClient,
}

// Get all VLANs.
vlist, err := c.InterfaceBridgeVlanList(ctx)
if err != nil {
	log.Fatalf("Could not list vlans: %v", err)
}

// Find VLAN 3005.
var vl3005 *ros.InterfaceBridgeVlan
for _, vlan := range vlist {
	if vlan.VlanIDs != 3005 {
		continue
	}
	vlan := vlan
	vl3005 = &vlan
}
if vl3005 == nil {
	log.Fatalf("No vlan 3005")
}

// Add ether8 if needed.
add := true
tagged := vl3005.Tagged
for _, t := range tagged {
	if t == "ether8" {
		add = false
		break
	}
}

if add {
	tagged = append(tagged, "ether8")
	_, err = c.InterfaceBridgeVlanPatch(ctx, vl3005.ID, &ros.InterfaceBridgeVlan_Update{
		Tagged: &tagged,
	})
	if err != nil {
		log.Fatalf("Could not update vlan: %v", err)
	}
}
Output:

Directories

Path Synopsis
package main implements a ROS7 REST API client generator.
package main implements a ROS7 REST API client generator.
Package ros implements a Mikrotik RouterOS 7 REST API client.
Package ros implements a Mikrotik RouterOS 7 REST API client.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL