Merge pull request #208 from MalteJ/master
Expose parameter to set interface MAC address
This commit is contained in:
commit
0a5fde25c5
|
@ -328,7 +328,7 @@ func TestCreateBridgeWithMac(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestSetMACAddress(t *testing.T) {
|
||||
func TestSetMacAddress(t *testing.T) {
|
||||
if testing.Short() {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -68,6 +68,14 @@ func SetDefaultGateway(ip, ifaceName string) error {
|
|||
return netlink.AddDefaultGw(ip, ifaceName)
|
||||
}
|
||||
|
||||
func SetInterfaceMac(name string, macaddr string) error {
|
||||
iface, err := net.InterfaceByName(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return netlink.NetworkSetMacAddress(iface, macaddr)
|
||||
}
|
||||
|
||||
func SetInterfaceIp(name string, rawIp string) error {
|
||||
iface, err := net.InterfaceByName(name)
|
||||
if err != nil {
|
||||
|
|
|
@ -17,6 +17,9 @@ type Network struct {
|
|||
// Prefix for the veth interfaces.
|
||||
VethPrefix string `json:"veth_prefix,omitempty"`
|
||||
|
||||
// MacAddress contains the MAC address to set on the network interface
|
||||
MacAddress string `json:"mac_address,omitempty"`
|
||||
|
||||
// Address contains the IPv4 and mask to set on the network interface
|
||||
Address string `json:"address,omitempty"`
|
||||
|
||||
|
|
|
@ -60,6 +60,11 @@ func (v *Veth) Initialize(config *Network, networkState *NetworkState) error {
|
|||
if err := ChangeInterfaceName(vethChild, defaultDevice); err != nil {
|
||||
return fmt.Errorf("change %s to %s %s", vethChild, defaultDevice, err)
|
||||
}
|
||||
if config.MacAddress != "" {
|
||||
if err := SetInterfaceMac(defaultDevice, config.MacAddress); err != nil {
|
||||
return fmt.Errorf("set %s mac %s", defaultDevice, err)
|
||||
}
|
||||
}
|
||||
if err := SetInterfaceIp(defaultDevice, config.Address); err != nil {
|
||||
return fmt.Errorf("set %s ip %s", defaultDevice, err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue