42 lines
2.2 KiB
Go
42 lines
2.2 KiB
Go
package template
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// UbuntuNetworkConfig renders a cloud-init network configuration (version 2)
|
|
// for an Ubuntu node: the management NIC with its static address and no
|
|
// gateway or DNS, and every data NIC renamed to its device name without an
|
|
// address. A template adds the addresses of its variant to the data NICs
|
|
// itself. Interfaces are matched by MAC, because a VM names its NICs by PCI
|
|
// slot.
|
|
func UbuntuNetworkConfig(node PlannedNode) string {
|
|
var text strings.Builder
|
|
text.WriteString("version: 2\nethernets:\n")
|
|
fmt.Fprintf(&text, " eth0:\n match:\n macaddress: %q\n set-name: eth0\n dhcp4: false\n dhcp6: false\n accept-ra: false\n addresses:\n - %s\n",
|
|
node.ManagementMAC, node.Management.String())
|
|
for _, nic := range node.Interfaces {
|
|
fmt.Fprintf(&text, " %s:\n match:\n macaddress: %q\n set-name: %s\n dhcp4: false\n dhcp6: false\n accept-ra: false\n",
|
|
nic.Device, nic.MAC, nic.Device)
|
|
}
|
|
return text.String()
|
|
}
|
|
|
|
// RouterOSManagementScript renders the RouterOS commands that give a
|
|
// MikroTik node its management address and restrict the API services to the
|
|
// host side of the management bridge. A template appends its variant
|
|
// configuration. RouterOS matches interfaces by MAC in upper case.
|
|
func RouterOSManagementScript(node PlannedNode) string {
|
|
var text strings.Builder
|
|
fmt.Fprintf(&text, "/interface ethernet set [find mac-address=%q] name=mgmt\n", strings.ToUpper(node.ManagementMAC))
|
|
for _, nic := range node.Interfaces {
|
|
fmt.Fprintf(&text, "/interface ethernet set [find mac-address=%q] name=%s\n", strings.ToUpper(nic.MAC), nic.Device)
|
|
}
|
|
fmt.Fprintf(&text, "/ip address add address=%s interface=mgmt comment=lincodex-management\n", node.Management.String())
|
|
host := node.ManagementHost.String() + "/32"
|
|
fmt.Fprintf(&text, "/ip service set api address=%s\n/ip service set api-ssl address=%s\n/ip service set ssh address=%s\n", host, host, host)
|
|
text.WriteString("/ip service set telnet disabled=yes\n/ip service set ftp disabled=yes\n/ip service set www disabled=yes\n/ip service set www-ssl disabled=yes\n/ip service set winbox disabled=yes\n")
|
|
return text.String()
|
|
}
|