Repository: nanovms/ops
Pull request #960 (2021-03-11 10:24:54)

Rename IPAddr -> IPAddress
https://github.com/nanovms/ops-documentation/issues/176#issuecomment-796609494

am11: @fabioDMFerreira, should we rename this as well https://github.com/nanovms/ops/blob/134ea4645201cd283ad47e3ca00814d1fac331bc/fs/manifest.go#L45-L46
fabioDMFerreira: > @fabioDMFerreira, should we rename this as well
> 
> https://github.com/nanovms/ops/blob/134ea4645201cd283ad47e3ca00814d1fac331bc/fs/manifest.go#L45-L46

please don't change `m.root["ipaddr"]` as this is read by nanos
am11: ok, i haven't change it.
fabioDMFerreira: Seems good to me. We can merge it after updating the documentation.

Patch:
diff --git a/cmd/flags_run_local_instance_image.go b/cmd/flags_run_local_instance_image.go
index 90063a6..0638cc8 100644
--- a/cmd/flags_run_local_instance_image.go
+++ b/cmd/flags_run_local_instance_image.go
@@ -89,16 +89,16 @@ func (flags *RunLocalInstanceCommandFlags) MergeToConfig(c *types.Config) (err e
 	c.Force = flags.Force
 
 	if flags.IPAddress != "" && isIPAddressValid(flags.IPAddress) {
-		c.RunConfig.IPAddr = flags.IPAddress
+		c.RunConfig.IPAddress = flags.IPAddress
 	}
 
-	ipaddr := c.RunConfig.IPAddr
+	ipaddress := c.RunConfig.IPAddress
 	gateway := flags.Gateway
 	netmask := flags.Netmask
 
-	if ipaddr != "" && (gateway == "" || !isIPAddressValid(gateway)) {
+	if ipaddress != "" && (gateway == "" || !isIPAddressValid(gateway)) {
 		// assumes the default gateway is the first or last IP in the network range
-		ip := net.ParseIP(ipaddr).To4()
+		ip := net.ParseIP(ipaddress).To4()
 
 		if ip[3] == byte(1) {
 			ip[3] = byte(254)
@@ -107,13 +107,13 @@ func (flags *RunLocalInstanceCommandFlags) MergeToConfig(c *types.Config) (err e
 		}
 
 		c.RunConfig.Gateway = ip.String()
-	} else if ipaddr != "" {
+	} else if ipaddress != "" {
 		c.RunConfig.Gateway = gateway
 	}
 
-	if ipaddr != "" && (netmask == "" || !isIPAddressValid(netmask)) {
+	if ipaddress != "" && (netmask == "" || !isIPAddressValid(netmask)) {
 		c.RunConfig.NetMask = "255.255.255.0"
-	} else if ipaddr != "" {
+	} else if ipaddress != "" {
 		c.RunConfig.NetMask = netmask
 	}
 
diff --git a/cmd/run_local_instance.go b/cmd/run_local_instance.go
index 5efeff0..99b63ab 100644
--- a/cmd/run_local_instance.go
+++ b/cmd/run_local_instance.go
@@ -19,7 +19,7 @@ func RunLocalInstance(c *types.Config) (err error) {
 
 	tapDeviceName := c.RunConfig.TapName
 	bridged := c.RunConfig.Bridged
-	ipaddr := c.RunConfig.IPAddr
+	ipaddress := c.RunConfig.IPAddress
 	netmask := c.RunConfig.NetMask
 
 	bridgeName := c.RunConfig.BridgeName
@@ -30,7 +30,7 @@ func RunLocalInstance(c *types.Config) (err error) {
 	networkService := network.NewIprouteNetworkService()
 
 	if tapDeviceName != "" {
-		err = network.SetupNetworkInterfaces(networkService, tapDeviceName, bridgeName, ipaddr, netmask)
+		err = network.SetupNetworkInterfaces(networkService, tapDeviceName, bridgeName, ipaddress, netmask)
 		if err != nil {
 			return
 		}
diff --git a/lepton/image.go b/lepton/image.go
index b44b51a..ebc72a0 100644
--- a/lepton/image.go
+++ b/lepton/image.go
@@ -289,9 +289,9 @@ func setManifestFromConfig(m *fs.Manifest, c *types.Config) error {
 		m.AddMount(k, v)
 	}
 
-	if c.RunConfig.IPAddr != "" {
+	if c.RunConfig.IPAddress != "" {
 		m.AddNetworkConfig(&fs.ManifestNetworkConfig{
-			IP:      c.RunConfig.IPAddr,
+			IP:      c.RunConfig.IPAddress,
 			Gateway: c.RunConfig.Gateway,
 			NetMask: c.RunConfig.NetMask,
 		})
@@ -320,9 +320,9 @@ func BuildManifest(c *types.Config) (*fs.Manifest, error) {
 		m.AddLibrary(libpath)
 	}
 
-	if c.RunConfig.IPAddr != "" {
+	if c.RunConfig.IPAddress != "" {
 		m.AddNetworkConfig(&fs.ManifestNetworkConfig{
-			IP:      c.RunConfig.IPAddr,
+			IP:      c.RunConfig.IPAddress,
 			Gateway: c.RunConfig.Gateway,
 			NetMask: c.RunConfig.NetMask,
 		})
diff --git a/network/setup_network_interfaces.go b/network/setup_network_interfaces.go
index df0712b..eb3460a 100644
--- a/network/setup_network_interfaces.go
+++ b/network/setup_network_interfaces.go
@@ -24,7 +24,7 @@ type Service interface {
 }
 
 // SetupNetworkInterfaces changes network configuration to support requirements
-func SetupNetworkInterfaces(network Service, tapDeviceName string, bridgeName string, ipaddr string, netmask string) error {
+func SetupNetworkInterfaces(network Service, tapDeviceName string, bridgeName string, ipaddress string, netmask string) error {
 	tapExists, err := network.CheckNetworkInterfaceExists(tapDeviceName)
 	if err != nil {
 		return errors.New("Not able to check tap exists")
@@ -51,8 +51,8 @@ func SetupNetworkInterfaces(network Service, tapDeviceName string, bridgeName st
 			}
 		}
 
-		if ipaddr != "" {
-			ip := net.ParseIP(ipaddr).To4()
+		if ipaddress != "" {
+			ip := net.ParseIP(ipaddress).To4()
 			ip[3] = byte(66) // 66 is a random IP
 			bridgeIP := ip.String()
 
diff --git a/types/config.go b/types/config.go
index 6edc730..0efd460 100644
--- a/types/config.go
+++ b/types/config.go
@@ -160,8 +160,8 @@ type RunConfig struct {
 	// InstanceName
 	InstanceName string
 
-	// IPAddr
-	IPAddr string
+	// IPAddress
+	IPAddress string
 
 	// Klibs
 	Klibs []string


Test patch:
diff --git a/cmd/flags_run_local_instance_test.go b/cmd/flags_run_local_instance_test.go
index 488bac2..b71e846 100644
--- a/cmd/flags_run_local_instance_test.go
+++ b/cmd/flags_run_local_instance_test.go
@@ -57,7 +57,7 @@ func TestRunLocalInstanceFlagsMergeToConfig(t *testing.T) {
 			Debug:      false,
 			Gateway:    "192.168.1.254",
 			GdbPort:    1234,
-			IPAddr:     "192.168.0.1",
+			IPAddress:  "192.168.0.1",
 			Mounts:     []string(nil),
 			NetMask:    "255.255.0.0",
 			Ports:      []string{"80", "81", "82-85"},