Move IP creation/removal to common function

This commit is contained in:
Joshua Boniface 2018-10-27 16:31:31 -04:00
parent a5be42908d
commit d8796fd6d6
3 changed files with 37 additions and 65 deletions

View File

@ -294,20 +294,7 @@ class NodeInstance(object):
), ),
state='o' state='o'
) )
common.run_os_command( common.createIPAddress(self.vni_ipaddr, self.vni_cidrnetmask, self.vni_dev)
'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
)
# Upstream floating IP # Upstream floating IP
self.logger.out( self.logger.out(
'Creating floating upstream IP {}/{} on interface {}'.format( 'Creating floating upstream IP {}/{} on interface {}'.format(
@ -317,20 +304,7 @@ class NodeInstance(object):
), ),
state='o' state='o'
) )
common.run_os_command( common.createIPAddress(self.upstream_ipaddr, self.upstream_cidrnetmask, self.upstream_dev)
'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
)
def removeFloatingAddresses(self): def removeFloatingAddresses(self):
# VNI floating IP # VNI floating IP
@ -342,13 +316,7 @@ class NodeInstance(object):
), ),
state='o' state='o'
) )
common.run_os_command( common.removeIPAddress(self.vni_ipaddr, self.vni_cidrnetmask, self.vni_dev)
'ip address delete {}/{} dev {}'.format(
self.vni_ipaddr,
self.vni_cidrnetmask,
self.vni_dev
)
)
# Upstream floating IP # Upstream floating IP
self.logger.out( self.logger.out(
'Removing floating upstream IP {}/{} from interface {}'.format( 'Removing floating upstream IP {}/{} from interface {}'.format(
@ -358,13 +326,7 @@ class NodeInstance(object):
), ),
state='o' state='o'
) )
common.run_os_command( common.removeIPAddress(self.upstream_ipaddr, self.upstream_cidrnetmask, self.upstream_dev)
'ip address delete {}/{} dev {}'.format(
self.upstream_ipaddr,
self.upstream_cidrnetmask,
self.upstream_dev
)
)
# Flush all VMs on the host # Flush all VMs on the host
def flush(self): def flush(self):

View File

@ -331,27 +331,15 @@ add rule inet filter input meta iifname {bridgenic} counter drop
def createGatewayAddress(self): def createGatewayAddress(self):
if self.this_node.router_state == 'primary': if self.this_node.router_state == 'primary':
self.logger.out( self.logger.out(
'Creating gateway {} on interface {}'.format( 'Creating gateway {}/{} on interface {}'.format(
self.ip_gateway, self.ip_gateway,
self.ip_cidrnetmask,
self.bridge_nic self.bridge_nic
), ),
prefix='VNI {}'.format(self.vni), prefix='VNI {}'.format(self.vni),
state='o' state='o'
) )
common.run_os_command( common.createIPAddress(self.ip_gateway, self.ip_cidrnetmask, self.bridge_nic)
'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
)
def startDHCPServer(self): def startDHCPServer(self):
if self.this_node.router_state == 'primary': if self.this_node.router_state == 'primary':
@ -454,20 +442,15 @@ add rule inet filter input meta iifname {bridgenic} counter drop
def removeGatewayAddress(self): def removeGatewayAddress(self):
self.logger.out( self.logger.out(
'Removing gateway {} from interface {}'.format( 'Removing gateway {}/{} from interface {}'.format(
self.ip_gateway, self.ip_gateway,
self.ip_cidrnetmask,
self.bridge_nic self.bridge_nic
), ),
prefix='VNI {}'.format(self.vni), prefix='VNI {}'.format(self.vni),
state='o' state='o'
) )
common.run_os_command( common.removeIPAddress(self.ip_gateway, self.ip_cidrnetmask, self.bridge_nic)
'ip address delete {}/{} dev {}'.format(
self.ip_gateway,
self.ip_cidrnetmask,
self.bridge_nic
)
)
def stopDHCPServer(self): def stopDHCPServer(self):
if self.dhcp_server_daemon: if self.dhcp_server_daemon:

View File

@ -88,3 +88,30 @@ def reload_firewall_rules(logger, rules_file):
retcode, stdout, stderr = run_os_command('/usr/sbin/nft -f {}'.format(rules_file)) retcode, stdout, stderr = run_os_command('/usr/sbin/nft -f {}'.format(rules_file))
if retcode != 0: if retcode != 0:
logger.out('Failed to reload configuration: {}'.format(stderr), state='e') 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
)
)