This def has too many IF, i don't know how to optimize this code for more simplier and professional.
Please take a look.
def cfg_wlan(self, wlan_cfg):
"""
Configure a new wlan for Zone Director.
Input: a dictionary, supplied in DUT.py
Output: none
"""
if wlan_cfg['auth'] == "PSK":
auth = "open"
else:
auth = wlan_cfg['auth']
auth_server = ""
vlan_id = ""
acl_name = ""
uplink_rate_limit = ""
downlink_rate_limit = ""
use_web_auth = False
use_hide_ssid = False
use_guest_access = False
use_client_isolation = False
use_zero_it = False
use_dynamic_psk = False
do_tunnel = False
if auth == "EAP":
if wlan_cfg['use_radius']:
auth_server = wlan_cfg['ras_addr']
else:
if wlan_cfg.has_key('use_web_auth'):
if wlan_cfg['use_web_auth']:
use_web_auth = wlan_cfg['use_web_auth']
if wlan_cfg['ras_addr']:
auth_server = wlan_cfg['ras_addr']
elif wlan_cfg['ad_addr']:
auth_server = wlan_cfg['ad_addr']
if wlan_cfg.has_key('use_guest_access'):
use_guest_access = wlan_cfg['use_guest_access']
if wlan_cfg.has_key('use_client_isolation'):
use_client_isolation = wlan_cfg['use_client_isolation']
if wlan_cfg.has_key('acl_name'):
acl_name = wlan_cfg['acl_name']
if wlan_cfg.has_key('use_hide_ssid'):
use_hide_ssid = wlan_cfg['use_hide_ssid']
if wlan_cfg.has_key('vlan_id'):
vlan_id = wlan_cfg['vlan_id']
if wlan_cfg.has_key('uplink_rate_limit'):
uplink_rate_limit = wlan_cfg['uplink_rate_limit']
if wlan_cfg.has_key('downlink_rate_limit'):
downlink_rate_limit = wlan_cfg['downlink_rate_limit']
if wlan_cfg.has_key('use_zero_it'):
use_zero_it = wlan_cfg['use_zero_it']
if wlan_cfg.has_key('use_dynamic_psk'):
use_dynamic_psk = wlan_cfg['use_dynamic_psk']
if wlan_cfg.has_key('do_tunnel'):
do_tunnel = wlan_cfg['do_tunnel']
try:
self._create_wlan(wlan_cfg['ssid'], auth, wlan_cfg['encryption'],
wlan_cfg['wpa_ver'], wlan_cfg['key_string'],
wlan_cfg['key_index'], auth_server,
use_web_auth, use_guest_access, acl_name, use_hide_ssid,
vlan_id, uplink_rate_limit, downlink_rate_limit,
use_client_isolation, use_zero_it,
use_dynamic_psk, do_tunnel)
except:
raise