diff options
Diffstat (limited to 'utils/lab-reconfiguration/reconfigUcsNet.py')
-rwxr-xr-x | utils/lab-reconfiguration/reconfigUcsNet.py | 47 |
1 files changed, 41 insertions, 6 deletions
diff --git a/utils/lab-reconfiguration/reconfigUcsNet.py b/utils/lab-reconfiguration/reconfigUcsNet.py index 8adace00b..282eca0cf 100755 --- a/utils/lab-reconfiguration/reconfigUcsNet.py +++ b/utils/lab-reconfiguration/reconfigUcsNet.py @@ -30,6 +30,7 @@ import getpass import optparse import platform import yaml +import time from UcsSdk import * from collections import defaultdict @@ -53,6 +54,14 @@ def get_servers(handle=None): if server.Type == 'instance' and "POD-2" in server.Dn: yield server + +def ack_pending(handle=None, server=None): + """ + Acknowledge pending state of server + """ + handle.AddManagedObject(server, LsmaintAck.ClassId(), {LsmaintAck.DN: server.Dn + "/ack", LsmaintAck.DESCR:"", LsmaintAck.ADMIN_STATE:"trigger-immediate", LsmaintAck.SCHEDULER:"", LsmaintAck.POLICY_OWNER:"local"}, True) + + def get_vnics(handle=None, server=None): """ Return list of vnics for given server @@ -66,6 +75,7 @@ def get_network_config(handle=None): Print current network config """ print "\nCURRENT NETWORK CONFIG:" + print " d - default, t - tagged" for server in get_servers(handle): print ' {}'.format(server.Name) for vnic in get_vnics(handle, server): @@ -73,10 +83,13 @@ def get_network_config(handle=None): print ' {}'.format(vnic.Addr) vnicIfs = handle.ConfigResolveChildren(VnicEtherIf.ClassId(), vnic.Dn, None, YesOrNo.TRUE) for vnicIf in vnicIfs.OutConfigs.GetChild(): - print ' Vlan: {}'.format(vnicIf.Vnet) + if vnicIf.DefaultNet == 'yes': + print ' Vlan: {}d'.format(vnicIf.Vnet) + else: + print ' Vlan: {}t'.format(vnicIf.Vnet) -def add_interface(handle=None, lsServerDn=None, vnicEther=None, templName=None, order=None): +def add_interface(handle=None, lsServerDn=None, vnicEther=None, templName=None, order=None, macAddr=None): """ Add interface to server specified by server.DN name """ @@ -91,6 +104,7 @@ def add_interface(handle=None, lsServerDn=None, vnicEther=None, templName=None, VnicEther.ORDER: order, "adminHostPort": "ANY", VnicEther.ADMIN_VCON: "any", + VnicEther.ADDR: macAddr, VnicEther.NW_TEMPL_NAME: templName, VnicEther.MTU: "1500"} handle.AddManagedObject(obj, VnicEther.ClassId(), params, True) @@ -119,12 +133,11 @@ def set_network(handle=None, yamlFile=None): Configure VLANs on POD according specified network """ # add interfaces and bind them with vNIC templates - # TODO: make sure MAC address for admin is still same print "\nRECONFIGURING VNICs..." network = read_yaml_file(yamlFile) - for server in get_servers(handle): + for index, server in enumerate(get_servers(handle)): for iface, data in network.iteritems(): - add_interface(handle, server.Dn, iface, data['template'], data['order']) + add_interface(handle, server.Dn, iface, data['template'], data['order'], data['mac-list'][index]) # Remove other interfaces which have not assigned required vnic template vnics = get_vnics(handle, server) for vnic in vnics: @@ -164,9 +177,31 @@ if __name__ == "__main__": handle.Login(options.ip, options.userName, options.password) + # Change vnic template if specified in cli option if (options.yamlFile != None): - print options.yamlFile set_network(handle, options.yamlFile) + + time.sleep(3) + + print "\nCheck if acknowledge is needed..." + for server in get_servers(handle): + print " {}: {}".format(server.Dn, server.OperState) + if server.OperState == "pending-reboot": + ack_pending(handle,server) + print " Acknowledged." + + print "\nWait until Overall Status of all nodes is OK..." + timeout = time.time() + 60*5 #5 minutes timeout + while True: + list_of_states = [] + for server in get_servers(handle): + list_of_states.append(server.OperState) + print " {}".format(list_of_states) + if all(state == "ok" for state in list_of_states) or time.time() > timeout: + break + time.sleep(2) + + # Show current vnic MACs and VLANs get_network_config(handle) handle.Logout() |