diff --git a/node-daemon/pvcd/NodeInstance.py b/node-daemon/pvcd/NodeInstance.py index 3418e678..33e3b430 100644 --- a/node-daemon/pvcd/NodeInstance.py +++ b/node-daemon/pvcd/NodeInstance.py @@ -294,20 +294,7 @@ class NodeInstance(object): ), state='o' ) - common.run_os_command( - 'ip address add {}/{} dev {}'.format( - self.vni_ipaddr, - self.vni_cidrnetmask, - self.vni_dev - ) - ) - common.run_os_command( - 'arping -A -c2 -I {} {}'.format( - self.vni_dev, - self.vni_ipaddr - ), - background=True - ) + common.createIPAddress(self.vni_ipaddr, self.vni_cidrnetmask, self.vni_dev) # Upstream floating IP self.logger.out( 'Creating floating upstream IP {}/{} on interface {}'.format( @@ -317,20 +304,7 @@ class NodeInstance(object): ), state='o' ) - common.run_os_command( - 'ip address add {}/{} dev {}'.format( - self.upstream_ipaddr, - self.upstream_cidrnetmask, - self.upstream_dev - ) - ) - common.run_os_command( - 'arping -A -c2 -I {} {}'.format( - self.upstream_dev, - self.upstream_ipaddr - ), - background=True - ) + common.createIPAddress(self.upstream_ipaddr, self.upstream_cidrnetmask, self.upstream_dev) def removeFloatingAddresses(self): # VNI floating IP @@ -342,13 +316,7 @@ class NodeInstance(object): ), state='o' ) - common.run_os_command( - 'ip address delete {}/{} dev {}'.format( - self.vni_ipaddr, - self.vni_cidrnetmask, - self.vni_dev - ) - ) + common.removeIPAddress(self.vni_ipaddr, self.vni_cidrnetmask, self.vni_dev) # Upstream floating IP self.logger.out( 'Removing floating upstream IP {}/{} from interface {}'.format( @@ -358,13 +326,7 @@ class NodeInstance(object): ), state='o' ) - common.run_os_command( - 'ip address delete {}/{} dev {}'.format( - self.upstream_ipaddr, - self.upstream_cidrnetmask, - self.upstream_dev - ) - ) + common.removeIPAddress(self.upstream_ipaddr, self.upstream_cidrnetmask, self.upstream_dev) # Flush all VMs on the host def flush(self): diff --git a/node-daemon/pvcd/VXNetworkInstance.py b/node-daemon/pvcd/VXNetworkInstance.py index 4fcde209..e0335fc3 100644 --- a/node-daemon/pvcd/VXNetworkInstance.py +++ b/node-daemon/pvcd/VXNetworkInstance.py @@ -331,27 +331,15 @@ add rule inet filter input meta iifname {bridgenic} counter drop def createGatewayAddress(self): if self.this_node.router_state == 'primary': self.logger.out( - 'Creating gateway {} on interface {}'.format( + 'Creating gateway {}/{} on interface {}'.format( self.ip_gateway, + self.ip_cidrnetmask, self.bridge_nic ), prefix='VNI {}'.format(self.vni), state='o' ) - common.run_os_command( - 'ip address add {}/{} dev {}'.format( - self.ip_gateway, - self.ip_cidrnetmask, - self.bridge_nic - ) - ) - common.run_os_command( - 'arping -A -c2 -I {} {}'.format( - self.bridge_nic, - self.ip_gateway - ), - background=True - ) + common.createIPAddress(self.ip_gateway, self.ip_cidrnetmask, self.bridge_nic) def startDHCPServer(self): if self.this_node.router_state == 'primary': @@ -454,20 +442,15 @@ add rule inet filter input meta iifname {bridgenic} counter drop def removeGatewayAddress(self): self.logger.out( - 'Removing gateway {} from interface {}'.format( + 'Removing gateway {}/{} from interface {}'.format( self.ip_gateway, + self.ip_cidrnetmask, self.bridge_nic ), prefix='VNI {}'.format(self.vni), state='o' ) - common.run_os_command( - 'ip address delete {}/{} dev {}'.format( - self.ip_gateway, - self.ip_cidrnetmask, - self.bridge_nic - ) - ) + common.removeIPAddress(self.ip_gateway, self.ip_cidrnetmask, self.bridge_nic) def stopDHCPServer(self): if self.dhcp_server_daemon: diff --git a/node-daemon/pvcd/common.py b/node-daemon/pvcd/common.py index ebf63ce4..5f7a5185 100644 --- a/node-daemon/pvcd/common.py +++ b/node-daemon/pvcd/common.py @@ -88,3 +88,30 @@ def reload_firewall_rules(logger, rules_file): retcode, stdout, stderr = run_os_command('/usr/sbin/nft -f {}'.format(rules_file)) if retcode != 0: logger.out('Failed to reload configuration: {}'.format(stderr), state='e') + +# Create IP address +def createIPAddress(ipaddr, cidrnetmask, dev): + run_os_command( + 'ip address add {}/{} dev {}'.format( + ipaddr, + cidrnetmask, + dev + ) + ) + run_os_command( + 'arping -A -c2 -I {} {}'.format( + dev, + ipaddr + ), + background=True + ) + +# Remove IP address +def removeIPAddress(ipaddr, cidrnetmask, dev): + run_os_command( + 'ip address delete {}/{} dev {}'.format( + ipaddr, + cidrnetmask, + dev + ) + )