functions

The Fool guy's FAAS
git clone git://git.lair.cx/functions
Log | Files | Refs | README

net.go (825B)


      1 package vmutils
      2 
      3 import (
      4 	"net"
      5 
      6 	firecracker "github.com/firecracker-microvm/firecracker-go-sdk"
      7 )
      8 
      9 // GetNetworkInfo returns the network information for the given machine.
     10 // Note that this function assumes that the machine has a single network interface.
     11 func GetNetworkInfo(machine *firecracker.Machine) (ip, gateway net.IP, err error) {
     12 	if len(machine.Cfg.NetworkInterfaces) == 0 {
     13 		err = ErrNoNetworkInterfaces
     14 		return
     15 	}
     16 
     17 	networkInterface := machine.Cfg.NetworkInterfaces[0]
     18 
     19 	if networkInterface.CNIConfiguration == nil {
     20 		err = ErrNonCniNetworkInterface
     21 		return
     22 	}
     23 
     24 	if networkInterface.StaticConfiguration == nil {
     25 		err = ErrMachineNotStarted
     26 		return
     27 	}
     28 
     29 	ip = networkInterface.StaticConfiguration.IPConfiguration.IPAddr.IP
     30 	gateway = networkInterface.StaticConfiguration.IPConfiguration.Gateway
     31 	return
     32 }