Fix up a few more issues

This commit is contained in:
Joshua Boniface 2018-09-23 22:47:24 -04:00
parent b3259a3dcc
commit 2ea0b0b740
1 changed files with 15 additions and 10 deletions

View File

@ -56,14 +56,14 @@ class VXNetworkInstance():
# Zookeper handlers for changed states # Zookeper handlers for changed states
@zk_conn.DataWatch('/networks/{}'.format(self.vni)) @zk_conn.DataWatch('/networks/{}'.format(self.vni))
def watch_network_description(data, stat, event=''): def watch_network_description(data, stat, event=''):
if self.description != data.decode('ascii'): if data != None and self.description != data.decode('ascii'):
self.old_description = self.description self.old_description = self.description
self.description = data.decode('ascii') self.description = data.decode('ascii')
self.watch_change = True self.watch_change = True
@zk_conn.DataWatch('/networks/{}/ip_network'.format(self.vni)) @zk_conn.DataWatch('/networks/{}/ip_network'.format(self.vni))
def watch_network_ip_network(data, stat, event=''): def watch_network_ip_network(data, stat, event=''):
if self.ip_network != data.decode('ascii'): if data != None and self.ip_network != data.decode('ascii'):
ip_network = data.decode('ascii') ip_network = data.decode('ascii')
self.ip_network = ip_network self.ip_network = ip_network
self.ip_cidrnetmask = ip_network.split('/')[-1] self.ip_cidrnetmask = ip_network.split('/')[-1]
@ -71,24 +71,28 @@ class VXNetworkInstance():
@zk_conn.DataWatch('/networks/{}/ip_gateway'.format(self.vni)) @zk_conn.DataWatch('/networks/{}/ip_gateway'.format(self.vni))
def watch_network_gateway(data, stat, event=''): def watch_network_gateway(data, stat, event=''):
if self.ip_gateway != data.decode('ascii'): if data != None and self.ip_gateway != data.decode('ascii'):
self.ip_gateway = data.decode('ascii') self.ip_gateway = data.decode('ascii')
self.watch_change = True self.watch_change = True
@zk_conn.DataWatch('/networks/{}/dhcp_flag'.format(self.vni)) @zk_conn.DataWatch('/networks/{}/dhcp_flag'.format(self.vni))
def watch_network_dhcp_status(data, stat, event=''): def watch_network_dhcp_status(data, stat, event=''):
if self.dhcp_flag != data.decode('ascii'): if data != None and self.dhcp_flag != data.decode('ascii'):
self.dhcp_flag = ( data.decode('ascii') == 'True' ) self.dhcp_flag = ( data.decode('ascii') == 'True' )
self.watch_change = True self.watch_change = True
def createCorosyncResource(self): def createCorosyncResource(self):
ansiiprint.echo('Creating Corosync resource for network {} gateway {} on VNI {}'.format(self.description, self.ip_gateway, self.vni), '', 'o') ansiiprint.echo('Creating Corosync resource for network {} gateway {} on VNI {}'.format(self.description, self.ip_gateway, self.vni), '', 'o')
common.run_os_command(""" common.run_os_command('crm configure primitive vnivip_{0} ocf:heartbeat:IPaddr2 params ip={1} cidr_netmask={2} nic={3} op monitor interval=1s meta target-role=Stopped'.format(
crm configure self.description,
primitive vnivip_{} ocf:heartbeat:IPaddr2 self.ip_gateway,
params ip={} cidr_netmask={} nic={} self.ip_cidrnetmask,
op monitor interval=1s self.bridge_nic
""".format( self.description, self.ip_gateway, self.ip_cidrnetmask, self.bridge_nic)) ))
common.run_os_command('crm configure location lvnivip_{0} vnivip_{0} 100: test-dcr1'.format(self.description))
common.run_os_command('crm resource start vnivip_{0}'.format(self.description))
common.run_os_command('crm resource refresh'.format(self.description))
self.watch_change = False self.watch_change = False
self.corosync_provisioned = True self.corosync_provisioned = True
@ -124,6 +128,7 @@ class VXNetworkInstance():
def provision(self): def provision(self):
self.update_timer.start() self.update_timer.start()
self.createNetwork() self.createNetwork()
time.sleep(0.1)
self.createCorosyncResource() self.createCorosyncResource()
def deprovision(self): def deprovision(self):