def get(key): """ API: GET: Retrun: { arr: [ tbl_interface ] }, ... ... ], error: bool, err_code: int, err_reason: string } """ _err_reason = [ '', # err_code: 0 'interface is not exist', # err_code: 1 ] obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''} if key == '' or key == 'all': arr = vcmd.get_arr('cdbctl read/cdb/interface') if arr: for item in arr: item['sort_name'] = portMap.Mapping(item['key']) item['full_name'] = portMap.Mapping(item['key'], is_sort=False) obj['arr'] = arr else: obj['error'] = True obj['err_code'] = 1 obj['err_reason'] = _err_reason[1] else: arr = vcmd.get_lines('cdbctl read/cdb/interface/%s' % key) if arr[0].find('%') >= 0: for item in arr: item['sort_name'] = portMap.Mapping(item['key']) item['full_name'] = portMap.Mapping(item['key'], is_sort=False) obj['error'] = True obj['err_code'] = 1 obj['err_reason'] = arr else: arr = vcmd.get_arr('cdbctl read/cdb/interface/%s' % key) if arr: for item in arr: item['sort_name'] = portMap.Mapping(item['key']) item['full_name'] = portMap.Mapping(item['key'], is_sort=False) obj['arr'] = arr else: obj['error'] = True obj['err_code'] = 1 obj['err_reason'] = _err_reason[1] return obj
def dot1x_load_dot1x_port_get(key): """ API: GET: Retrun: { arr: [ tbl_interface ] }, ... ... ], error: bool, err_code: int, err_reason: string } """ _err_reason = [ '', # err_code: 0 'interface is not exist', # err_code: 1 ] obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''} if key == '' or key == 'all': arr = vcmd.get_arr('cdbctl read/cdb/l2/dot1x_port/') if arr: # pre-process for front-web easy display for entry in arr: if entry['guest_vlan'] == '0': entry['guest_vlan'] = 'none' if entry['max_user'] == '0': entry['max_user'] = '******' obj['arr'] = arr # else: # obj['error'] = True # obj['err_code'] = 1 # obj['err_reason'] = _err_reason[1] else: arr = vcmd.get_lines('cdbctl read/cdb/l2/dot1x_port/%s' % key) if arr[0].find('%') >= 0: obj['error'] = True obj['err_code'] = 1 obj['err_reason'] = arr else: arr = vcmd.get_arr('cdbctl read/cdb/interface/%s' % key) if arr: obj['arr'] = arr else: obj['error'] = True obj['err_code'] = 1 obj['err_reason'] = _err_reason[1] return obj
def snmp_context_get(): _err_reason = [ '', # err_code: 0 'get snmp cfg error', # err_code: 1 ] obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''} cmd = 'cdbctl read/cdb/app/snmp_context' arr = vcmd.get_arr(cmd) if arr: for entry in arr: key = entry['key'] key = key[:(len(key))] sublist = key.split(',') entry.pop('key') entry['context'] = sublist[0] obj['cfg'] = arr else: obj['cfg'] = [] return obj
def snmp_target_addr_get(): _err_reason = [ '', # err_code: 0 'get snmp cfg error', # err_code: 1 ] obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''} cmd = 'cdbctl read/cdb/app/snmp_trap' arr = vcmd.get_arr(cmd) if arr: for entry in arr: key = entry['key'] key = key[:(len(key) - 1)] sublist = key.split(',') entry.pop('key') entry['trapaddr'] = sublist[0] entry['community'] = sublist[1] entry['port'] = sublist[2] if entry['is_inband'] == '1': entry['vrf'] = 'default' elif entry['is_inband'] == '0': entry['vrf'] = 'mgmt' obj['cfg'] = arr else: obj['cfg'] = [] return obj
def sensorGet(): """ API: GET: Retrun: { arr: [ { tbl_sensor; }, ... ... ], error: bool, err_code: int, err_reason: string } """ _err_reason = [ '', # err_code: 0 'log is null', # err_code: 1 ] obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''} arr = vcmd.get_arr('cdbctl read/cdb/sys/sensor') if arr: obj['arr'] = arr else: obj['error'] = True obj['err_code'] = 1 obj['err_reason'] = _err_reason[1] return obj
def snmp_target_params_get(): _err_reason = [ '', # err_code: 0 'get snmp cfg error', # err_code: 1 ] obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''} cmd = 'cdbctl read/cdb/app/snmp_target_params' arr = vcmd.get_arr(cmd) if arr: for entry in arr: # key = entry['key'] # key = key[:(len(key))] # sublist = key.split(',') # entry.pop('key') entry['params'] = entry['key'] entry['username'] = entry['user_name'] if entry['usm_level'] == '1': entry['selpar'] = 'noauth' elif entry['usm_level'] == '2': entry['selpar'] = 'auth' elif entry['usm_level'] == '3': entry['selpar'] = 'priv' obj['cfg'] = arr else: obj['cfg'] = [] return obj
def tap_timestamp_get(): """ TBD """ _err_reason = [ '', # err_code: 0 'cmd excute error', # err_code: 1 ] obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''} cmd = 'cdbctl read/cdb/sys/sys_global/' arr = vcmd.get_arr(cmd) if arr: # int -> hex format value = arr[0].get('ether_type') arr[0]['ether_type'] = hex(int(value)) if value.isdigit() else 0xffff obj['cfg'] = arr else: obj['cfg'] = [] return obj
def snmp_target_address_get(): _err_reason = [ '', # err_code: 0 'get snmp cfg error', # err_code: 1 ] obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''} cmd = 'cdbctl read/cdb/app/snmp_target_addr' arr = vcmd.get_arr(cmd) if arr: for entry in arr: entry['trapaddress'] = entry['key'] entry['communitys'] = entry['para_name'] entry['server'] = entry['ip_addr'] entry['traname'] = entry['tag_list'] obj['cfg'] = arr else: obj['cfg'] = [] return obj
def ntp_srv_get(): """ TBD """ _err_reason = [ '', # err_code: 0 'cmd excute error', # err_code: 1 ] obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''} cmd = 'cdbctl read/cdb/app/ntp_server' arr = vcmd.get_arr(cmd) if arr: for entry in arr: if entry['is_inband'] == '1': entry['is_inband'] = 'default' elif entry['is_inband'] == '0': entry['is_inband'] = 'mgmt' if arr: obj['cfg'] = arr else: obj['cfg'] = [] return obj
def snmp_notify_get(): _err_reason = [ '', # err_code: 0 'get snmp cfg error', # err_code: 1 ] obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''} cmd = 'cdbctl read/cdb/app/snmp_notify' arr = vcmd.get_arr(cmd) if arr: for entry in arr: #key = entry['key'] #key = key[:(len(key))] #sublist = key.split(',') #entry.pop('key') entry['notify'] = entry['key'] entry['tag'] = entry['tag_name'] if entry['notify_type'] == '0': entry['type'] = 'trap' elif entry['notify_type'] == '1': entry['type'] = 'inform' obj['cfg'] = arr else: obj['cfg'] = [] return obj
def _get_boot_info(): """get boot image infomations """ res = vcmd.get_arr('cdbctl read/cdb/sys/bootimage')[0] if res['mode'] == 'flash:': tmp = res['current_image'] tmp = tmp.replace(res['mode'], '') res['current_image'] = os.path.basename(tmp) return res
def snmp_community_get(): _err_reason = [ '', # err_code: 0 'get snmp cfg error', # err_code: 1 ] obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''} arr = vcmd.get_arr('cdbctl read/cdb/app/snmp_community') if arr: obj['cfg'] = arr else: obj['cfg'] = [] return obj
def dhcp_snooping_information_option_get(): """ API: Retrun: { if /: group_arr: [group_dict, group_dict, ...], elif /<int:git>/: group: group_dict error: bool, err_code: int, err_reason: string } group_dict { lag_name: string, protocol: 'static' | 'LACP', group_state: 'L2' | 'L3', ports_in_bundle: int, member_ports: ['eth-0-1', ...], max_ports_count: int, } """ _err_reason = [ '', # err_code: 0 'bad request', # err_code: 1 'cmd excute error', # err_code: 2 'group is not exist', # err_code: 3 ] obj = {'error': False, 'err_code': 0, 'err_reason': ''} # excute arr = vcmd.get_arr('cdbctl read/cdb/dhcp/dhcsnooping/add_agent_options') if arr: obj['add_agent_options'] = arr[0]['add_agent_options'] else: obj['error'] = True obj['err_code'] = 1 obj['err_reason'] = _err_reason[1] return obj
def get_port_split_status(): """ TBD """ _err_reason = [ '', # err_code: 0 'interface is not exist', # err_code: 1 ] obj = { 'arr': [], 'port_media_type': '', 'error': False, 'err_code': 0, 'err_reason': '' } arr = vcmd.get_arr('cdbctl show/cdb/sys/port/') split_arr = {} connection = portMap.getPortConnection() if arr: for item in arr: # 1. media type property only support 1 port eth-0-1 only in GG chip. if (item['key'] == '0'): obj['port_media_type'] = item['port_media_type'] # 2. split_type if -1 != item['name'].find(connection['sub_connection']): item['is_split'] = 'True' else: item['is_split'] = 'False' split_arr[item['name']] = { 'split_type': item['split_type'], 'is_split': item['is_split'] } obj['arr'] = split_arr else: obj['error'] = True obj['err_code'] = 1 obj['err_reason'] = _err_reason[1] return obj
def tap_group_table_get(): """ TBD """ _err_reason = [ '', # err_code: 0 'cmd excute error', # err_code: 1 ] obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''} cmd = 'cdbctl read/cdb/tap/tap_group' arr = vcmd.get_arr(cmd) if arr: obj['arr'] = arr else: obj['arr'] = [] return obj
def tap_truncation_get(): """ TBD """ _err_reason = [ '', # err_code: 0 'cmd excute error', # err_code: 1 ] obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''} cmd = 'cdbctl read/cdb/sys/sys_global/trunction_length' arr = vcmd.get_arr(cmd) if arr: obj['trunction'] = arr[0]['trunction_length'] else: obj['trunction'] = '' return obj
def tap_timestamp_del(): """ TBD """ _err_reason = [ '', # err_code: 0 'cmd excute error', # err_code: 1 ] obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''} cmd = 'cdbctl update/cdb/sys/sys_global/trunction_length/0' arr = vcmd.get_arr(cmd) if arr: obj['arr'] = arr else: obj['arr'] = [] return obj
def snmp_cfg_get(): """ TBD """ _err_reason = [ '', # err_code: 0 'get snmp cfg error', # err_code: 1 ] obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''} arr = vcmd.get_arr('cdbctl read/cdb/app/snmp_cfg/') if arr: obj['cfg'] = arr[0] else: obj['error'] = True obj['err_code'] = 1 obj['err_reason'] = _err_reason[1] return obj
def sysglobalGet(): """ API: GET: Retrun: { arr: [ { tbl_sys_global; }, ... ... ], error: bool, err_code: int, err_reason: string } """ _err_reason = [ '', # err_code: 0 'log is null', # err_code: 1 ] obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''} arr = vcmd.get_arr('cdbctl read/cdb/sys/sys_global') if arr: obj['arr'] = arr mgmt_mac = vcmd.get_showarr('cdbctl show/cdb/sys/show_management_if') if len(mgmt_mac[0]) > 1: for line in mgmt_mac: if line.find('HWaddr') >= 0: arr[0]['mgmt_routemac'] = line[line.find('HWaddr: ') + len('HWaddr: '):] break else: obj['error'] = True obj['err_code'] = 1 obj['err_reason'] = _err_reason[1] return obj
def get(file_type): """ API: GET: Retrun: { user: [ {user: string, privilege: number, password: string,}, ... ], } """ _err_reason = [ '', # err_code: 0 'cmd excute error', # err_code: 1 ] obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''} cmd = 'cdbctl read/cdb/app/user' arr = vcmd.get_arr(cmd) if arr: for entry in arr: # key = entry['key'] # key = key[:(len(key) - 1)] # entry.pop('key') entry['username'] = entry['key'] entry['privilege'] = entry['privilege'] entry['password'] = entry['passwd'] obj['cfg'] = arr else: obj['cfg'] = [] return obj
def flow_table_get(): """ TBD """ _err_reason = [ '', # err_code: 0 'cmd excute error', # err_code: 1 ] obj = { 'acl': [], 'flow': [], 'flow_match': [], 'error': False, 'err_code': 0, 'err_reason': '' } cmd = 'cdbctl read/cdb/l2/acl_config/' arr = vcmd.get_arr(cmd) # change '/key=#FLOW#flow1/' to '/key=flow1/' for entry in arr: key = entry['key'] if '#' in key: name_list = key.split('#') entry['key'] = name_list[-1] if 'FLOW' in key: obj['flow'].append(entry) else: obj['flow_match'].append(entry) else: obj['acl'].append(entry) return obj
def load_balance_tunnel_hash_get(): """ API: GET: Retrun: { arr: [group_dict, group_dict, ...], error: bool, err_code: int, err_reason: string } group_dict { load_balance: string, load_balance_inner_filed_en: '0' | '1' | '2', ... } """ _err_reason = [ '', # err_code: 0 'get tunnel hash mode cfg error', # err_code: 1 ] obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''} arr = vcmd.get_arr('cdbctl read/cdb/sys/lag_global/') if arr: obj['arr'] = arr[0] #print obj else: obj['error'] = True obj['err_code'] = 1 obj['err_reason'] = _err_reason[1] return obj
def snmp_usm_user_get(): _err_reason = [ '', # err_code: 0 'get snmp cfg error', # err_code: 1 ] obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''} cmd = 'cdbctl read/cdb/app/snmp_usm_user' arr = vcmd.get_arr(cmd) if arr: for entry in arr: # key = entry['key'] # key = key[:(len(key) - 1)] # entry.pop('key') entry['username'] = entry['key'] if entry['auth_type'] == '1': entry['authensel'] = 'md5' elif entry['auth_type'] == '2': entry['authensel'] = 'sha' entry['authenpwd'] = entry['auth_pwd'] if entry['priv_type'] == '1': entry['encrysel'] = 'des' elif entry['priv_type'] == '2': entry['encrysel'] = 'aes' entry['encrypwd'] = entry['priv_pwd'] obj['cfg'] = arr else: obj['cfg'] = [] return obj
def dhcp_get_interval(): """ API: Retrun: { database_save_interval: database_save_interval, error: bool, err_code: int, err_reason: string } """ _err_reason = [ '', # err_code: 0 'bad request', # err_code: 1 'cmd excute error', # err_code: 2 'group is not exist', # err_code: 3 ] obj = {'error': False, 'err_code': 0, 'err_reason': ''} # excute arr = vcmd.get_arr( 'cdbctl read/cdb/dhcp/dhcsnooping/database_save_interval') if arr: obj['database_save_interval'] = arr[0]['database_save_interval'] else: obj['error'] = True obj['err_code'] = 1 obj['err_reason'] = _err_reason[1] return obj
def get(key): """ API: GET: Retrun: { arr: [ tbl_interface ] }, ... ... ], error: bool, err_code: int, err_reason: string } """ _err_reason = [ '', # err_code: 0 'interface is not exist', # err_code: 1 ] obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''} if key == '' or key == 'all': arr = vcmd.get_arr('cdbctl read/cdb/interface') if arr: # process split port, assert a 'split_type' field for item in arr: if item['key'].startswith('eth-'): item['split_type'] = 'splited' if ( item['key'].find('_') != -1) else 'not_split' else: item['split_type'] = 'not_support' if item['brgif'] and item['brgif']['allowed_vlan']: # change "all5-10" to 'ALL', if exist keyword 'all', we ignore other when display item['brgif']['allowed_vlan'] = 'ALL' if ( item['brgif']['allowed_vlan'].find('all') == 0) else item['brgif']['allowed_vlan'] item['sort_name'] = portMap.Mapping(item['key']) item['full_name'] = portMap.Mapping(item['key'], is_sort=False) item['svlan_tpid_mode'] = '0x%x' % int(item['svlan_tpid']) # process split port end obj['arr'] = arr else: obj['error'] = True obj['err_code'] = 1 obj['err_reason'] = _err_reason[1] else: arr = vcmd.get_lines('cdbctl read/cdb/interface/%s' % key) if arr[0].find('%') >= 0: obj['error'] = True obj['err_code'] = 1 obj['err_reason'] = arr else: arr = vcmd.get_arr('cdbctl read/cdb/interface/%s' % key) if arr: obj['arr'] = arr else: obj['error'] = True obj['err_code'] = 1 obj['err_reason'] = _err_reason[1] return obj
def tap_entry_get(): """ TBD """ _err_reason = [ '', # err_code: 0 'cmd excute error', # err_code: 1 ] obj = { 'egress': [], 'ingress': [], 'error': False, 'err_code': 0, 'err_reason': '' } cmd = 'cdbctl read/cdb/tap/tap_group_egress/' # Get egress direction entry arr = vcmd.get_arr(cmd) if arr: for entry in arr: temp = entry.get('key') entry['name'] = temp.split('#')[0] entry['port'] = temp.split('#')[1] entry['sort_name'] = portMap.Mapping(entry['port']) entry['full_name'] = portMap.Mapping(entry['port'], is_sort=False) obj['egress'] = arr else: obj['egress'] = [] # Get in gress direction entry cmd_flow = 'cdbctl read/cdb/tap/tap_group_ingress_flow' cmd_normal = 'cdbctl read/cdb/tap/tap_group_ingress' arr_flow = vcmd.get_arr(cmd_flow) arr_normal = vcmd.get_arr(cmd_normal) arr = arr_flow + arr_normal if arr: # change 'tap2#eth-0-24#flow1' to 'tap2','eth-0-24','flow1' for entry in arr: temp = entry.get('key').split('#') if entry['ing_untag_en'] == '1': entry['untag_mode'] = 'double-vlan' elif entry['ing_untag_en'] == '2': entry['untag_mode'] = 'outer-vlan' elif entry['ing_untag_en'] == '3': entry['untag_mode'] = 'inner-vlan' else: entry['untag_mode'] = 'Disable' if len(temp) == 2: entry['name'] = temp[0] entry['port'] = temp[1] entry['sort_name'] = portMap.Mapping(entry['port']) entry['full_name'] = portMap.Mapping(entry['port'], is_sort=False) entry['flow'] = '' elif len(temp) == 5: entry['name'] = temp[0] entry['port'] = temp[1] entry['sort_name'] = portMap.Mapping(entry['port']) entry['full_name'] = portMap.Mapping(entry['port'], is_sort=False) entry['flow'] = temp[4] # only hold a place entry['ing_trunction_en'] = '0' # ingress can't support edit-pkt, only hold a place for display entry['ing_edit_dest_mac_en'] = '0' entry['ing_edit_src_mac_en'] = '0' entry['ing_edit_ipda_en'] = '0' entry['ing_edit_ipsa_en'] = '0' obj['ingress'] = arr else: obj['ingress'] = [] return obj
def ipv4_port_load_l3_port_get(key): """ API: GET: Retrun: { arr: [ tbl_interface ] }, ... ... ], error: bool, err_code: int, err_reason: string } """ _err_reason = [ '', # err_code: 0 'interface is not exist', # err_code: 1 ] obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''} entry = [] if key == '' or key == 'all': arr = vcmd.get_arr('cdbctl read/cdb/l3/route_if/') if arr: for i in range(len(arr)): ipv4 = arr[i].get('ifc_ipv4') if (isinstance(ipv4, list)): for item in ipv4: # Add option web need item['name'] = arr[i].get('key') item['ip_redirects_en'] = arr[i].get('ip_redirects_en') item['unicast_rpf_en'] = arr[i].get('unicast_rpf_en') # ',/key' --> 'key' if item.has_key(',/key'): item['ip'] = item[',/key'].split('#')[0] item['mask'] = item[',/key'].split('#')[1] del item[',/key'] if item.has_key('key'): item['ip'] = item['key'].split('#')[0] item['mask'] = item['key'].split('#')[1] del item['key'] # append to entry entry.append(item) if (isinstance(ipv4, dict)): ipv4['name'] = arr[i].get('key') ipv4['ip_redirects_en'] = arr[i].get('ip_redirects_en') ipv4['unicast_rpf_en'] = arr[i].get('unicast_rpf_en') if (ipv4.has_key('key')): item = ipv4['key'].split('#') ipv4['ip'] = item[0] ipv4['mask'] = item[1] else: ipv4['ip'] = 'N/A' ipv4['mask'] = 'N/A' entry.append(ipv4) obj['arr'] = entry else: arr = vcmd.get_lines('cdbctl read/cdb/l2/dot1x_port/%s' % key) if arr[0].find('%') >= 0: obj['error'] = True obj['err_code'] = 1 obj['err_reason'] = arr else: arr = vcmd.get_arr('cdbctl read/cdb/interface/%s' % key) if arr: obj['arr'] = arr else: obj['error'] = True obj['err_code'] = 1 obj['err_reason'] = _err_reason[1] return obj
def get(key): """ API: GET: Retrun: { if_statistic_arr: [ { ifidx: int, octets_rcv_rate: int, pkts_rcv_rate: int, octets_send_rate: int, pkts_send_rate: int, octets_rcv: int, pkts_rcv: int, uc_pkts_rcv: int, brdc_pkts_rcv: int, mc_pkts_rcv: int, oam_pkts_rcv: int, undersize_pkts: int, oversize_pkts: int, mac_rcv_error: int, bad_crc: int, frame_error: int, drop_events: int, pause_rcv: int, octets_send: int, pkts_send: int, uc_pkts_send: int, brdc_pkts_send: int, mc_pkts_send: int, oam_pkts_send: int, underruns: int, mac_transmit_err: int, pause_send: int, fcs_pkts_rcv: int, fcs_octets_rcv: int, fcs_pkts_send: int, fcs_octets_send: int, fragments_pkts: int, bad_pkts_rcv: int, bad_octets_rcv: int, ifname: string }, ... ... error: bool, err_code: int, err_reason: string } """ _err_reason = [ '', # err_code: 0 'interface statistic is not exist', # err_code: 1 ] obj = { 'if_statistic_arr': [], 'error': False, 'err_code': 0, 'err_reason': '' } arr_if = vcmd.get_arr('cdbctl read/cdb/interface') if key == '' or key == 'all': arr = vcmd.get_arr('cdbctl read/cdb/sys/port_stats') if arr: for i in arr: tmp = {} tmp['ifidx'] = i.get('key') if arr_if: for j in arr_if: if j.get('ifindex') == i.get('key'): tmp['ifname'] = j.get('key') tmp['sort_name'] = portMap.Mapping(tmp['ifname']) tmp['full_name'] = portMap.Mapping(tmp['ifname'], is_sort=False) break else: tmp['ifname'] = '' if j.get('ifg_stats_en') == "1": octets_rcv = str( int(i.get('octets_rcv')) + int(i.get('pkts_rcv')) * 20) tmp['octets_rcv'] = octets_rcv else: tmp['octets_rcv'] = i.get('octets_rcv') tmp['pkts_rcv'] = i.get('pkts_rcv') tmp['uc_pkts_rcv'] = i.get('uc_pkts_rcv') tmp['brdc_pkts_rcv'] = i.get('brdc_pkts_rcv') tmp['mc_pkts_rcv'] = i.get('mc_pkts_rcv') tmp['oam_pkts_rcv'] = i.get('oam_pkts_rcv') tmp['undersize_pkts'] = i.get('undersize_pkts') tmp['oversize_pkts'] = i.get('oversize_pkts') tmp['mac_rcv_error'] = i.get('mac_rcv_error') tmp['bad_crc'] = i.get('bad_crc') tmp['frame_error'] = i.get('frame_error') tmp['drop_events'] = i.get('drop_events') tmp['pause_rcv'] = i.get('pause_rcv') if j.get('ifg_stats_en') == "1": octets_send = str( int(i.get('octets_send')) + int(i.get('pkts_send')) * 20) tmp['octets_send'] = octets_send else: tmp['octets_send'] = i.get('octets_send') tmp['pkts_send'] = i.get('pkts_send') tmp['uc_pkts_send'] = i.get('uc_pkts_send') tmp['brdc_pkts_send'] = i.get('brdc_pkts_send') tmp['mc_pkts_send'] = i.get('mc_pkts_send') tmp['oam_pkts_send'] = i.get('oam_pkts_send') tmp['underruns'] = i.get('underruns') tmp['mac_transmit_err'] = i.get('mac_transmit_err') tmp['pause_send'] = i.get('pause_send') tmp['fcs_pkts_rcv'] = i.get('fcs_pkts_rcv') tmp['fcs_octets_rcv'] = i.get('fcs_octets_rcv') tmp['fcs_pkts_send'] = i.get('fcs_pkts_send') tmp['fcs_octets_send'] = i.get('fcs_octets_send') tmp['fragments_pkts'] = i.get('fragments_pkts') tmp['bad_pkts_rcv'] = i.get('bad_pkts_rcv') tmp['bad_octets_rcv'] = i.get('bad_octets_rcv') if arr_if: for j in arr_if: if j.get('ifindex') == i.get('key'): tmp['ifname'] = j.get('key') tmp['sort_name'] = portMap.Mapping(tmp['ifname']) tmp['full_name'] = portMap.Mapping(tmp['ifname'], is_sort=False) break else: tmp['ifname'] = '' arr_rate = vcmd.get_arr('cdbctl read/cdb/sys/port_stats_rate') if arr_rate: for j in arr_rate: if j.get('key') == i.get('key'): tmp['octets_rcv_rate'] = j.get('octets_rcv_rate') tmp['pkts_rcv_rate'] = j.get('pkts_rcv_rate') tmp['octets_send_rate'] = j.get('octets_send_rate') tmp['pkts_send_rate'] = j.get('pkts_send_rate') break else: tmp['octets_rcv_rate'] = 0 tmp['pkts_rcv_rate'] = 0 tmp['octets_send_rate'] = 0 tmp['pkts_send_rate'] = 0 obj['if_statistic_arr'].append(tmp) else: obj['error'] = True obj['err_code'] = 1 obj['err_reason'] = _err_reason[1] else: arr = vcmd.get_lines('cdbctl read/cdb/sys/port_stats/%s' % key) status, lines = vcmd.get_status_lines() if arr[0].find('%') >= 0: obj['error'] = True obj['err_code'] = 1 obj['err_reason'] = arr else: arr = vcmd.get_arr('cdbctl read/cdb/sys/port_stats/%s' % key) if arr: for i in arr: tmp = {} tmp['ifidx'] = i.get('key') #tmp['octets_rcv_rate'] = i.get('octets_rcv_rate') #tmp['pkts_rcv_rate'] = i.get('pkts_rcv_rate') #tmp['octets_send_rate'] = i.get('octets_send_rate') #tmp['pkts_send_rate'] = i.get('pkts_send_rate') tmp['octets_rcv'] = i.get('octets_rcv') tmp['pkts_rcv'] = i.get('pkts_rcv') tmp['uc_pkts_rcv'] = i.get('uc_pkts_rcv') tmp['brdc_pkts_rcv'] = i.get('brdc_pkts_rcv') tmp['mc_pkts_rcv'] = i.get('mc_pkts_rcv') tmp['oam_pkts_rcv'] = i.get('oam_pkts_rcv') tmp['undersize_pkts'] = i.get('undersize_pkts') tmp['oversize_pkts'] = i.get('oversize_pkts') tmp['mac_rcv_error'] = i.get('mac_rcv_error') tmp['bad_crc'] = i.get('bad_crc') tmp['frame_error'] = i.get('frame_error') tmp['drop_events'] = i.get('drop_events') tmp['pause_rcv'] = i.get('pause_rcv') tmp['octets_send'] = i.get('octets_send') tmp['pkts_send'] = i.get('pkts_send') tmp['uc_pkts_send'] = i.get('uc_pkts_send') tmp['brdc_pkts_send'] = i.get('brdc_pkts_send') tmp['mc_pkts_send'] = i.get('mc_pkts_send') tmp['oam_pkts_send'] = i.get('oam_pkts_send') tmp['underruns'] = i.get('underruns') tmp['mac_transmit_err'] = i.get('mac_transmit_err') tmp['pause_send'] = i.get('pause_send') tmp['fcs_pkts_rcv'] = i.get('fcs_pkts_rcv') tmp['fcs_octets_rcv'] = i.get('fcs_octets_rcv') tmp['fcs_pkts_send'] = i.get('fcs_pkts_send') tmp['fcs_octets_send'] = i.get('fcs_octets_send') tmp['fragments_pkts'] = i.get('fragments_pkts') tmp['bad_pkts_rcv'] = i.get('bad_pkts_rcv') tmp['bad_octets_rcv'] = i.get('bad_octets_rcv') if arr_if: for j in arr_if: if j.get('ifindex') == i.get('key'): tmp['ifname'] = j.get('key') tmp['sort_name'] = portMap.Mapping( tmp['ifname']) tmp['full_name'] = portMap.Mapping( tmp['ifname'], is_sort=False) break else: tmp['ifname'] = '' arr_rate = vcmd.get_arr( 'cdbctl read/cdb/sys/port_stats_rate/%s' % key) if arr_rate: for j in arr_rate: if j.get('key') == j.get('key'): tmp['octets_rcv_rate'] = j.get( 'octets_rcv_rate') tmp['pkts_rcv_rate'] = j.get('pkts_rcv_rate') tmp['octets_send_rate'] = j.get( 'octets_send_rate') tmp['pkts_send_rate'] = j.get('pkts_send_rate') break else: tmp['octets_rcv_rate'] = 0 tmp['pkts_rcv_rate'] = 0 tmp['octets_send_rate'] = 0 tmp['pkts_send_rate'] = 0 obj['if_statistic_arr'].append(tmp) else: obj['error'] = True obj['err_code'] = 1 obj['err_reason'] = _err_reason[1] return obj
def get(key): """ API: GET: Retrun: { arr: [ tbl_interface ] }, ... ... ], error: bool, err_code: int, err_reason: string } """ _err_reason = [ '', # err_code: 0 'interface is not exist', # err_code: 1 ] obj = {'arr': [], 'error': False, 'err_code': 0, 'err_reason': ''} if key == '' or key == 'all': arr = vcmd.get_arr('cdbctl read/cdb/sys/fiber/') if arr: newArr = [] for map in arr: m = {} for key, value in map.items(): if key == 'interface_name': m['interface_name'] = str(value) m['sort_name'] = portMap.Mapping(m['interface_name']) m['full_name'] = portMap.Mapping(m['interface_name'], is_sort=False) if key == 'fiber_type_name': m['fiber_type_name'] = str(value) if key == 'name': m['name'] = str(value) if key == 'pn': m['pn'] = str(value) if key == 'sn': m['sn'] = str(value) newArr.append(m) obj['arr'] = newArr else: obj['error'] = True obj['err_code'] = 1 obj['err_reason'] = _err_reason[1] else: arr = vcmd.get_lines('cdbctl read/cdb/sys/fiber/%s' % key) if arr[0].find('%') >= 0: obj['error'] = True obj['err_code'] = 1 obj['err_reason'] = arr else: arr = vcmd.get_arr('cdbctl read/cdb/sys/fiber/%s' % key) if arr: obj['arr'] = arr else: obj['error'] = True obj['err_code'] = 1 obj['err_reason'] = _err_reason[1] return obj