mirror of
https://github.com/xcat2/confluent.git
synced 2024-11-25 19:10:10 +00:00
Have configbmc wait for settings to complete
There has been some confusion when configbmc changes are deferred until later. Reduce confusion by waiting for the settings to take effect, but avoiding checking each parameter to preserve most of the speedup.
This commit is contained in:
parent
e7fbbe2737
commit
184727408a
@ -111,6 +111,14 @@ class Session(object):
|
||||
self.databuffer.raw[1:self.rsp.msg.data_len])}
|
||||
return response
|
||||
|
||||
def await_config(s, bmccfg, channel):
|
||||
vlan = bmccfg.get('bmcvlan', None)
|
||||
ipv4 = bmccfg.get('bmcipv4', None)
|
||||
prefix = bmccfg.get('prefixv4', None)
|
||||
gw = bmccfg.get('bmcgw', None)
|
||||
|
||||
|
||||
|
||||
def raw_command(self,
|
||||
netfn,
|
||||
command,
|
||||
@ -217,8 +225,7 @@ def set_port_xcc(s, port, model):
|
||||
sys.stdout.write('Complete\n')
|
||||
|
||||
|
||||
def set_vlan(s, vlan, channel):
|
||||
ovlan = vlan
|
||||
def check_vlan(s, vlan, channel):
|
||||
if vlan == 'off':
|
||||
vlan = b'\x00\x00'
|
||||
else:
|
||||
@ -229,7 +236,19 @@ def set_vlan(s, vlan, channel):
|
||||
currvlan = bytes(s.raw_command(0xc, 2, bytearray([channel, 0x14 ,0, 0]))['data'][1:])
|
||||
if bytearray(currvlan)[1] & 0b10000000 == 0:
|
||||
currvlan = b'\x00\x00'
|
||||
if currvlan == vlan:
|
||||
return currvlan == vlan
|
||||
|
||||
|
||||
def set_vlan(s, vlan, channel):
|
||||
ovlan = vlan
|
||||
if vlan == 'off':
|
||||
vlan = b'\x00\x00'
|
||||
else:
|
||||
vlan = int(vlan)
|
||||
if vlan:
|
||||
vlan = vlan | 32768
|
||||
vlan = struct.pack('<H', vlan)
|
||||
if check_vlan(s, ovlan, channel):
|
||||
sys.stdout.write('VLAN already configured to "{0}"\n'.format(ovlan))
|
||||
return False
|
||||
rsp = s.raw_command(0xc, 1, bytearray([channel, 0x14]) + vlan)
|
||||
@ -237,7 +256,7 @@ def set_vlan(s, vlan, channel):
|
||||
print('VLAN configured to "{}"'.format(ovlan))
|
||||
else:
|
||||
print('Error setting vlan: ' + repr(rsp))
|
||||
return
|
||||
return True
|
||||
|
||||
|
||||
def get_lan_channel(s):
|
||||
@ -253,13 +272,18 @@ def get_lan_channel(s):
|
||||
return chan
|
||||
return 1
|
||||
|
||||
|
||||
def check_ipv4(s, ipaddr, channel):
|
||||
ipaddr = bytearray(socket.inet_aton(ipaddr))
|
||||
rsp = s.raw_command(0xc, 2, bytearray([channel, 3, 0, 0]))['data'][-4:]
|
||||
return rsp == ipaddr
|
||||
|
||||
def set_ipv4(s, ipaddr, channel):
|
||||
oipaddr = ipaddr
|
||||
ipaddr = bytearray(socket.inet_aton(ipaddr))
|
||||
rsp = s.raw_command(0xc, 2, bytearray([channel, 3, 0, 0]))['data'][-4:]
|
||||
if rsp == ipaddr:
|
||||
if check_ipv4(s, oipaddr, channel):
|
||||
print('IP Address already set to {}'.format(oipaddr))
|
||||
return
|
||||
return False
|
||||
rsp = int(s.raw_command(0xc, 2, bytearray([channel, 4, 0, 0]))['data'][1]) & 0b1111
|
||||
if rsp != 1:
|
||||
sys.stdout.write("Changing configuration to static...")
|
||||
@ -276,29 +300,47 @@ def set_ipv4(s, ipaddr, channel):
|
||||
sys.stdout.flush()
|
||||
print('Setting IP to {}'.format(oipaddr))
|
||||
s.raw_command(0xc, 1, bytearray([channel, 3]) + ipaddr)
|
||||
return True
|
||||
|
||||
|
||||
def check_subnet(s, prefix, channel):
|
||||
prefix = int(prefix)
|
||||
mask = bytearray(struct.pack('!I', (2**32 - 1) ^ (2**(32 - prefix) - 1)))
|
||||
rsp = s.raw_command(0xc, 2, bytearray([channel, 6, 0, 0]))['data'][-4:]
|
||||
return rsp == mask
|
||||
|
||||
def set_subnet(s, prefix, channel):
|
||||
oprefix = prefix
|
||||
prefix = int(prefix)
|
||||
mask = bytearray(struct.pack('!I', (2**32 - 1) ^ (2**(32 - prefix) - 1)))
|
||||
rsp = s.raw_command(0xc, 2, bytearray([channel, 6, 0, 0]))['data'][-4:]
|
||||
if rsp == mask:
|
||||
if check_subnet(s, prefix, channel):
|
||||
print('Subnet Mask already set to /{}'.format(oprefix))
|
||||
return
|
||||
return False
|
||||
print('Setting subnet mask to /{}'.format(oprefix))
|
||||
s.raw_command(0xc, 1, bytearray([channel, 6]) + mask)
|
||||
return True
|
||||
|
||||
|
||||
def check_gateway(s, gw, channel):
|
||||
gw = bytearray(socket.inet_aton(gw))
|
||||
rsp = s.raw_command(0xc, 2, bytearray([channel, 12, 0, 0]))['data'][-4:]
|
||||
return rsp == gw
|
||||
|
||||
def set_gateway(s, gw, channel):
|
||||
ogw = gw
|
||||
gw = bytearray(socket.inet_aton(gw))
|
||||
rsp = s.raw_command(0xc, 2, bytearray([channel, 12, 0, 0]))['data'][-4:]
|
||||
if rsp == gw:
|
||||
if check_gateway(s, ogw, channel):
|
||||
print('Gateway already set to {}'.format(ogw))
|
||||
return
|
||||
return False
|
||||
print('Setting gateway to {}'.format(ogw))
|
||||
s.raw_command(0xc, 1, bytearray([channel, 12]) + gw)
|
||||
return True
|
||||
|
||||
def dotwait():
|
||||
sys.stdout.write('.')
|
||||
sys.stdout.flush()
|
||||
time.sleep(0.5)
|
||||
|
||||
def main():
|
||||
a = argparse.ArgumentParser(description='Locally configure a BMC device')
|
||||
@ -341,14 +383,30 @@ def main():
|
||||
channel = set_port(s, bmccfg['bmcport'], vendor, model)
|
||||
else:
|
||||
channel = get_lan_channel(s)
|
||||
awaitvlan = False
|
||||
awaitip = False
|
||||
awaitprefix = False
|
||||
awaitgw = False
|
||||
if bmccfg.get('bmcvlan', None):
|
||||
set_vlan(s, bmccfg['bmcvlan'], channel)
|
||||
awaitvlan = set_vlan(s, bmccfg['bmcvlan'], channel)
|
||||
if bmccfg.get('bmcipv4', None):
|
||||
set_ipv4(s, bmccfg['bmcipv4'], channel)
|
||||
awaitip = set_ipv4(s, bmccfg['bmcipv4'], channel)
|
||||
if bmccfg.get('prefixv4', None):
|
||||
set_subnet(s, bmccfg['prefixv4'], channel)
|
||||
awaitprefix = set_subnet(s, bmccfg['prefixv4'], channel)
|
||||
if bmccfg.get('bmcgw', None):
|
||||
set_gateway(s, bmccfg['bmcgw'], channel)
|
||||
awaitgw = set_gateway(s, bmccfg['bmcgw'], channel)
|
||||
sys.stdout.write('Waiting for changes to take effect...')
|
||||
sys.stdout.flush()
|
||||
while awaitvlan and not check_vlan(s, bmccfg['bmcvlan'], channel):
|
||||
dotwait()
|
||||
while awaitip and not check_ipv4(s, bmccfg['bmcipv4'], channel):
|
||||
dotwait()
|
||||
while awaitprefix and not check_subnet(s, bmccfg['prefixv4'], channel):
|
||||
dotwait()
|
||||
while awaitprefix and not check_gateway(s, bmccfg['bmcgw'], channel):
|
||||
dotwait()
|
||||
sys.stdout.write('done\n')
|
||||
sys.stdout.flush()
|
||||
#await_config(s, bmccfg, channel)
|
||||
|
||||
|
||||
|
@ -111,6 +111,14 @@ class Session(object):
|
||||
self.databuffer.raw[1:self.rsp.msg.data_len])}
|
||||
return response
|
||||
|
||||
def await_config(s, bmccfg, channel):
|
||||
vlan = bmccfg.get('bmcvlan', None)
|
||||
ipv4 = bmccfg.get('bmcipv4', None)
|
||||
prefix = bmccfg.get('prefixv4', None)
|
||||
gw = bmccfg.get('bmcgw', None)
|
||||
|
||||
|
||||
|
||||
def raw_command(self,
|
||||
netfn,
|
||||
command,
|
||||
@ -217,8 +225,7 @@ def set_port_xcc(s, port, model):
|
||||
sys.stdout.write('Complete\n')
|
||||
|
||||
|
||||
def set_vlan(s, vlan, channel):
|
||||
ovlan = vlan
|
||||
def check_vlan(s, vlan, channel):
|
||||
if vlan == 'off':
|
||||
vlan = b'\x00\x00'
|
||||
else:
|
||||
@ -229,7 +236,19 @@ def set_vlan(s, vlan, channel):
|
||||
currvlan = bytes(s.raw_command(0xc, 2, bytearray([channel, 0x14 ,0, 0]))['data'][1:])
|
||||
if bytearray(currvlan)[1] & 0b10000000 == 0:
|
||||
currvlan = b'\x00\x00'
|
||||
if currvlan == vlan:
|
||||
return currvlan == vlan
|
||||
|
||||
|
||||
def set_vlan(s, vlan, channel):
|
||||
ovlan = vlan
|
||||
if vlan == 'off':
|
||||
vlan = b'\x00\x00'
|
||||
else:
|
||||
vlan = int(vlan)
|
||||
if vlan:
|
||||
vlan = vlan | 32768
|
||||
vlan = struct.pack('<H', vlan)
|
||||
if check_vlan(s, ovlan, channel):
|
||||
sys.stdout.write('VLAN already configured to "{0}"\n'.format(ovlan))
|
||||
return False
|
||||
rsp = s.raw_command(0xc, 1, bytearray([channel, 0x14]) + vlan)
|
||||
@ -237,7 +256,7 @@ def set_vlan(s, vlan, channel):
|
||||
print('VLAN configured to "{}"'.format(ovlan))
|
||||
else:
|
||||
print('Error setting vlan: ' + repr(rsp))
|
||||
return
|
||||
return True
|
||||
|
||||
|
||||
def get_lan_channel(s):
|
||||
@ -253,13 +272,18 @@ def get_lan_channel(s):
|
||||
return chan
|
||||
return 1
|
||||
|
||||
|
||||
def check_ipv4(s, ipaddr, channel):
|
||||
ipaddr = bytearray(socket.inet_aton(ipaddr))
|
||||
rsp = s.raw_command(0xc, 2, bytearray([channel, 3, 0, 0]))['data'][-4:]
|
||||
return rsp == ipaddr
|
||||
|
||||
def set_ipv4(s, ipaddr, channel):
|
||||
oipaddr = ipaddr
|
||||
ipaddr = bytearray(socket.inet_aton(ipaddr))
|
||||
rsp = s.raw_command(0xc, 2, bytearray([channel, 3, 0, 0]))['data'][-4:]
|
||||
if rsp == ipaddr:
|
||||
if check_ipv4(s, oipaddr, channel):
|
||||
print('IP Address already set to {}'.format(oipaddr))
|
||||
return
|
||||
return False
|
||||
rsp = int(s.raw_command(0xc, 2, bytearray([channel, 4, 0, 0]))['data'][1]) & 0b1111
|
||||
if rsp != 1:
|
||||
sys.stdout.write("Changing configuration to static...")
|
||||
@ -276,29 +300,47 @@ def set_ipv4(s, ipaddr, channel):
|
||||
sys.stdout.flush()
|
||||
print('Setting IP to {}'.format(oipaddr))
|
||||
s.raw_command(0xc, 1, bytearray([channel, 3]) + ipaddr)
|
||||
return True
|
||||
|
||||
|
||||
def check_subnet(s, prefix, channel):
|
||||
prefix = int(prefix)
|
||||
mask = bytearray(struct.pack('!I', (2**32 - 1) ^ (2**(32 - prefix) - 1)))
|
||||
rsp = s.raw_command(0xc, 2, bytearray([channel, 6, 0, 0]))['data'][-4:]
|
||||
return rsp == mask
|
||||
|
||||
def set_subnet(s, prefix, channel):
|
||||
oprefix = prefix
|
||||
prefix = int(prefix)
|
||||
mask = bytearray(struct.pack('!I', (2**32 - 1) ^ (2**(32 - prefix) - 1)))
|
||||
rsp = s.raw_command(0xc, 2, bytearray([channel, 6, 0, 0]))['data'][-4:]
|
||||
if rsp == mask:
|
||||
if check_subnet(s, prefix, channel):
|
||||
print('Subnet Mask already set to /{}'.format(oprefix))
|
||||
return
|
||||
return False
|
||||
print('Setting subnet mask to /{}'.format(oprefix))
|
||||
s.raw_command(0xc, 1, bytearray([channel, 6]) + mask)
|
||||
return True
|
||||
|
||||
|
||||
def check_gateway(s, gw, channel):
|
||||
gw = bytearray(socket.inet_aton(gw))
|
||||
rsp = s.raw_command(0xc, 2, bytearray([channel, 12, 0, 0]))['data'][-4:]
|
||||
return rsp == gw
|
||||
|
||||
def set_gateway(s, gw, channel):
|
||||
ogw = gw
|
||||
gw = bytearray(socket.inet_aton(gw))
|
||||
rsp = s.raw_command(0xc, 2, bytearray([channel, 12, 0, 0]))['data'][-4:]
|
||||
if rsp == gw:
|
||||
if check_gateway(s, ogw, channel):
|
||||
print('Gateway already set to {}'.format(ogw))
|
||||
return
|
||||
return False
|
||||
print('Setting gateway to {}'.format(ogw))
|
||||
s.raw_command(0xc, 1, bytearray([channel, 12]) + gw)
|
||||
return True
|
||||
|
||||
def dotwait():
|
||||
sys.stdout.write('.')
|
||||
sys.stdout.flush()
|
||||
time.sleep(0.5)
|
||||
|
||||
def main():
|
||||
a = argparse.ArgumentParser(description='Locally configure a BMC device')
|
||||
@ -341,14 +383,30 @@ def main():
|
||||
channel = set_port(s, bmccfg['bmcport'], vendor, model)
|
||||
else:
|
||||
channel = get_lan_channel(s)
|
||||
awaitvlan = False
|
||||
awaitip = False
|
||||
awaitprefix = False
|
||||
awaitgw = False
|
||||
if bmccfg.get('bmcvlan', None):
|
||||
set_vlan(s, bmccfg['bmcvlan'], channel)
|
||||
awaitvlan = set_vlan(s, bmccfg['bmcvlan'], channel)
|
||||
if bmccfg.get('bmcipv4', None):
|
||||
set_ipv4(s, bmccfg['bmcipv4'], channel)
|
||||
awaitip = set_ipv4(s, bmccfg['bmcipv4'], channel)
|
||||
if bmccfg.get('prefixv4', None):
|
||||
set_subnet(s, bmccfg['prefixv4'], channel)
|
||||
awaitprefix = set_subnet(s, bmccfg['prefixv4'], channel)
|
||||
if bmccfg.get('bmcgw', None):
|
||||
set_gateway(s, bmccfg['bmcgw'], channel)
|
||||
awaitgw = set_gateway(s, bmccfg['bmcgw'], channel)
|
||||
sys.stdout.write('Waiting for changes to take effect...')
|
||||
sys.stdout.flush()
|
||||
while awaitvlan and not check_vlan(s, bmccfg['bmcvlan'], channel):
|
||||
dotwait()
|
||||
while awaitip and not check_ipv4(s, bmccfg['bmcipv4'], channel):
|
||||
dotwait()
|
||||
while awaitprefix and not check_subnet(s, bmccfg['prefixv4'], channel):
|
||||
dotwait()
|
||||
while awaitprefix and not check_gateway(s, bmccfg['bmcgw'], channel):
|
||||
dotwait()
|
||||
sys.stdout.write('done\n')
|
||||
sys.stdout.flush()
|
||||
#await_config(s, bmccfg, channel)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user