def __get_tblsaffix(self, stime, etime): logger.debug("get table-saffix({0}-{1}).".format(stime, etime)) table_saffix_msg = """ <nmwg:message xmlns:nmwgt="http://ggf.org/ns/nmwg/topology/2.0/" xmlns:nmwg="http://ggf.org/ns/nmwg/base/2.0/" xmlns:select="http://ggf.org/ns/nmwg/ops/select/2.0/" type="TableSuffixRequest"> <nmwg:metadata id="m1"> <nmwg:eventType>http://ggf.org/ns/nmwg/sequel/20090610</nmwg:eventType> <nmwg:parameter name="stime">{0}</nmwg:parameter> <nmwg:parameter name="etime">{1}</nmwg:parameter> </nmwg:metadata> <nmwg:data metadataIdRef="m1"/> </nmwg:message> """.format(stime, etime) msg = self.__create_ps_msg(table_saffix_msg) logger.debug('request perfSONAR') res = self.__post_sequel_service(msg) logger.debug('response perfSONAR') if self.__check_ps_res('TableSaffixRequest', res.text) == False: logger.debug('TableSaffixRequest no resqonse text.') return None xd_root = xmltodict.parse(res.text) xd_body = xd_root['SOAP-ENV:Envelope']['SOAP-ENV:Body'] if not xd_body['nmwg:message']['nmwg:data']: logger.debug('TableSaffixRequest no data.') return None data_list = to_array( xd_body['nmwg:message']['nmwg:data']['sequel:datum']) tblsaffix_list = [] for data in data_list: tblsaffix_list.append(data['@value']) return tblsaffix_list
def __get_tblsaffix(self,stime,etime): logger.debug("get table-saffix({0}-{1}).".format(stime,etime)) table_saffix_msg = """ <nmwg:message xmlns:nmwgt="http://ggf.org/ns/nmwg/topology/2.0/" xmlns:nmwg="http://ggf.org/ns/nmwg/base/2.0/" xmlns:select="http://ggf.org/ns/nmwg/ops/select/2.0/" type="TableSuffixRequest"> <nmwg:metadata id="m1"> <nmwg:eventType>http://ggf.org/ns/nmwg/sequel/20090610</nmwg:eventType> <nmwg:parameter name="stime">{0}</nmwg:parameter> <nmwg:parameter name="etime">{1}</nmwg:parameter> </nmwg:metadata> <nmwg:data metadataIdRef="m1"/> </nmwg:message> """.format(stime,etime) msg = self.__create_ps_msg(table_saffix_msg) logger.debug('request perfSONAR') res = self.__post_sequel_service(msg) logger.debug('response perfSONAR') if self.__check_ps_res('TableSaffixRequest',res.text) == False: logger.debug('TableSaffixRequest no resqonse text.') return None xd_root = xmltodict.parse(res.text) xd_body = xd_root['SOAP-ENV:Envelope']['SOAP-ENV:Body'] if not xd_body['nmwg:message']['nmwg:data']: logger.debug('TableSaffixRequest no data.') return None data_list = to_array(xd_body['nmwg:message']['nmwg:data']['sequel:datum']) tblsaffix_list = [] for data in data_list: tblsaffix_list.append(data['@value']) return tblsaffix_list
def parse_monitoring_data_xml(logger, md_xml): try: mon_data_dict = dict() # get Xml root element in the Dictionary type. xd_root = xmltodict.parse(md_xml) # get <monitoring-data> if xd_root.has_key(const.XML_TAG_MON_DATA): xd_mon_data = xd_root[const.XML_TAG_MON_DATA] else: logger.warn('tag <{0}> is not specified.'.format( const.XML_TAG_MON_DATA)) return None # get forward flag.<monitoring-data forward=xxx> fwd_flg = False if xd_mon_data.has_key('@' + const.XML_ATTR_FWD): if xd_mon_data['@' + const.XML_ATTR_FWD].lower() == 'yes': fwd_flg = True mon_data_dict[const.XML_ATTR_FWD] = fwd_flg # get <topology-list> if xd_mon_data.has_key(const.XML_TAG_TOPOL_LIST): xd_topol_list = xd_mon_data[const.XML_TAG_TOPOL_LIST] else: logger.warn('tag <{0}> is not specified.'.format( const.XML_TAG_TOPOL_LIST)) return None # get <topology> if xd_topol_list.has_key(const.XML_TAG_TOPOL): topol_list = util.to_array(xd_topol_list[const.XML_TAG_TOPOL]) else: logger.warn('tag <{0}> is not specified.'.format( const.XML_TAG_TOPOL)) return None topol_dict_list = [] mon_data_dict[const.XML_TAG_TOPOL] = topol_dict_list for xd_topol in topol_list: topol_dict = dict() # append topology dictionary list. topol_dict_list.append(topol_dict) # get topology type.<topology type=xxx> if xd_topol.has_key('@' + const.XML_ATTR_TYPE): topol_type = xd_topol['@' + const.XML_ATTR_TYPE].lower() else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_TOPOL,const.XML_ATTR_TYPE)) return None if not topol_type == const.TYPE_NW_PHYSICAL and \ not topol_type == const.TYPE_NW_SLICE: logger.warn('attribute <{0} {1}={2}> is invalid value.'\ .format(const.XML_TAG_TOPOL,const.XML_ATTR_TYPE,topol_type)) return None topol_dict[const.XML_ATTR_TYPE] = topol_type # get topology name.<topology name=xxx> if xd_topol.has_key('@' + const.XML_ATTR_NAME): topol_name = xd_topol['@' + const.XML_ATTR_NAME].lower() else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_TOPOL,const.XML_ATTR_NAME)) return None topol_dict[const.XML_ATTR_NAME] = topol_name # get <node> node_dict_list = [] topol_dict[const.XML_TAG_NODE] = node_dict_list if xd_topol.has_key(const.XML_TAG_NODE): node_list = util.to_array(xd_topol[const.XML_TAG_NODE]) else: logger.debug('tag <{0}> is not specified.'.format( const.XML_TAG_NODE)) return None for node in node_list: # get node id<node id=xxx> node_dict = dict() if node.has_key('@' + const.XML_ATTR_ID): node_id = node['@' + const.XML_ATTR_ID] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_NODE,const.XML_ATTR_ID)) continue # get node type<node type=xxx> if node.has_key('@' + const.XML_ATTR_TYPE): node_type = node['@' + const.XML_ATTR_TYPE] if not ((topol_type == const.TYPE_NW_PHYSICAL and node_type == const.TYPE_NODE_SRV)\ or (topol_type == const.TYPE_NW_SLICE and node_type == const.TYPE_NODE_VM)): logger.warn('attribute <{0} {1}={2}> is invalid value.'\ .format(const.XML_TAG_NODE,const.XML_ATTR_TYPE,node_type)) continue else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_NODE,const.XML_ATTR_TYPE)) continue # add node name and node type node_dict[const.XML_ATTR_ID] = node_id node_dict[const.XML_ATTR_TYPE] = node_type # add parameter dictionary list. param_dict_list = [] node_dict[const.XML_TAG_PARAM] = param_dict_list # append node dictionary list. node_dict_list.append(node_dict) # get <parameter> if node.has_key(const.XML_TAG_PARAM): param_list = util.to_array(node[const.XML_TAG_PARAM]) else: logger.warn('tag <{0}> is not specified.'.format( const.XML_TAG_PARAM)) continue for param in param_list: # get parameter type<parameter type=xxx> param_dict = dict() if param.has_key('@' + const.XML_ATTR_TYPE): param_type = param['@' + const.XML_ATTR_TYPE] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_PARAM,const.XML_ATTR_TYPE)) continue # add parameter type. param_dict[const.XML_ATTR_TYPE] = param_type # add value dictionary list. value_dict_list = [] param_dict[const.XML_TAG_VAL] = value_dict_list # append parameter dictionary list. param_dict_list.append(param_dict) # get <value> if param.has_key(const.XML_TAG_VAL): val_list = util.to_array(param[const.XML_TAG_VAL]) else: logger.debug('tag <{0}> is not specified.'.format( const.XML_TAG_VAL)) continue for val in val_list: # get value timestamp<value timestamp=xxx> value_dict = dict() if val.has_key('@' + const.XML_ATTR_TIME_STAMP): time_stamp = val['@' + const.XML_ATTR_TIME_STAMP] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_VAL,const.XML_ATTR_TIME_STAMP)) continue # get value text<value>xxx</value> if val.has_key('#text'): val_text = val['#text'] else: logger.warn('text <{0}> is not specified.'.format( const.XML_TAG_VAL)) continue logger.debug('{0}={1} {2}={3} {4}={5}'.format( const.XML_ATTR_TYPE, param_type, const.XML_ATTR_TIME_STAMP, time_stamp, const.XML_TAG_VAL, val_text)) # add time stamp and value. value_dict[const.XML_ATTR_TIME_STAMP] = time_stamp value_dict[const.XML_TAG_VAL] = val_text # append value dictionary list. value_dict_list.append(value_dict) except Exception: logger.exception('parse_monitoring_data_xml') raise return mon_data_dict
def parse_node_xml(xd_root): #get node<node> node_dict_list = [] if xd_root.has_key(const.XML_TAG_NODE): node_list = util.to_array(xd_root[const.XML_TAG_NODE]) else: logger.debug('tag <{0}> is not specified.'.format(const.XML_TAG_NODE)) return None for node in node_list: #get node id<node id=xxx> node_dict = dict() if node.has_key('@'+const.XML_ATTR_ID): node_id = node['@'+const.XML_ATTR_ID] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_NODE,const.XML_ATTR_ID)) return None #get node type<node type=xxx> if node.has_key('@'+const.XML_ATTR_TYPE): node_type = node['@'+const.XML_ATTR_TYPE].lower() else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_NODE,const.XML_ATTR_TYPE)) return None if node_type == const.TYPE_NODE_SW: pass elif node_type == const.TYPE_NODE_SRV: # get vm<node>(Recursively call) sub_node_dict_list = parse_node_xml(node) if sub_node_dict_list: node_dict[const.XML_TAG_NODE] = sub_node_dict_list elif node_type == const.TYPE_NODE_VM: pass else: logger.warn('attribute <{0} {1}={2}> is invalid value.'\ .format(const.XML_TAG_NODE,const.XML_ATTR_TYPE,node_type)) return None #add node name and node type and network. node_dict[const.XML_ATTR_ID] = node_id node_dict[const.XML_ATTR_TYPE] = node_type #get management type and details mgmt_dict = dict() if node.has_key(const.XML_TAG_MGMT): mgmt_list = util.to_array(node[const.XML_TAG_MGMT]) if len(mgmt_list) > 1: logger.warn('more than one management definition. (node id={0})'.format(node_id)) mgmt = mgmt_list[1] if mgmt.has_key(const.XML_TAG_MGMT_TYPE): mgmt_dict[const.XML_TAG_MGMT_TYPE] = mgmt[const.XML_TAG_MGMT_TYPE] else: logger.warn('management definition has no type. (node id={0})'.format(node_id)) if mgmt.has_key(const.XML_TAG_MGMT_ADDRESS): mgmt_dict[const.XML_TAG_MGMT_ADDRESS] = mgmt[const.XML_TAG_MGMT_ADDRESS] if mgmt.has_key(const.XML_TAG_MGMT_PORT): mgmt_dict[const.XML_TAG_MGMT_PORT] = mgmt[const.XML_TAG_MGMT_PORT] if mgmt.has_key(const.XML_TAG_MGMT_AUTH): mgmt_dict[const.XML_TAG_MGMT_AUTH] = mgmt[const.XML_TAG_MGMT_AUTH] #add management node_dict[const.XML_TAG_MGMT] = mgmt_dict #add interface dictionary list. if_dict_list = [] node_dict[const.XML_TAG_IF] = if_dict_list #append node dictionary list. node_dict_list.append(node_dict) #get <interface> if not node.has_key(const.XML_TAG_IF): logger.debug('no interface.(node_id={0})'.format(node_id)) continue if_list = util.to_array(node[const.XML_TAG_IF]) for interface in if_list: if_dict = dict() #get interface id<interface id=xxx> if interface.has_key('@'+const.XML_ATTR_ID): if_id = interface['@'+const.XML_ATTR_ID] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_IF,const.XML_ATTR_ID)) return None #get port number<port num=xxx> if interface.has_key(const.XML_TAG_PORT): if interface[const.XML_TAG_PORT].has_key('@'+const.XML_ATTR_NUM): port_num = interface[const.XML_TAG_PORT]['@'+const.XML_ATTR_NUM] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_PORT,const.XML_ATTR_NUM)) return None #add port number. if_dict[const.XML_TAG_PORT] = port_num #add interface id. if_dict[const.XML_ATTR_ID] = if_id #create and append interface dictionary list. if_dict_list.append(if_dict) return node_dict_list
def parse_topology_xml(topology_list_xml): try: #get Xml root element in the Dictionary type. xd_root = xmltodict.parse(topology_list_xml) #get <topology_list> if xd_root.has_key(const.XML_TAG_TOPOL_LIST): xd_topol_list = xd_root[const.XML_TAG_TOPOL_LIST] else: logger.warn('tag <{0}> is not specified.'.format(const.XML_TAG_TOPOL_LIST)) return None #get <topology> if xd_topol_list.has_key(const.XML_TAG_TOPOL): topol_list = util.to_array(xd_topol_list[const.XML_TAG_TOPOL]) else: logger.warn('tag <{0}> is not specified.'.format(const.XML_TAG_TOPOL)) return None topol_dict_list = [] for xd_topol in topol_list: topol_dict = dict() #get topology type.<topology type=xxx> if xd_topol.has_key('@'+const.XML_ATTR_TYPE): topol_type = xd_topol['@'+const.XML_ATTR_TYPE].lower() else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_TOPOL,const.XML_ATTR_TYPE)) return None if not topol_type == const.TYPE_NW_PHYSICAL and \ not topol_type == const.TYPE_NW_SLICE: logger.warn('attribute <{0} {1}={2}> is invalid value.'\ .format(const.XML_TAG_TOPOL,const.XML_ATTR_TYPE,topol_type)) return None #get topology last_update_time.<topology last_update_time=xxx> if xd_topol.has_key('@'+const.XML_ATTR_LAST_UPD_TIME): topol_time = xd_topol['@'+const.XML_ATTR_LAST_UPD_TIME] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_TOPOL,const.XML_ATTR_LAST_UPD_TIME)) return None if xd_topol.has_key('@'+const.XML_ATTR_NAME): nw_name = xd_topol['@'+const.XML_ATTR_NAME] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_NW,const.XML_ATTR_NAME)) return None #In the case of slice topology, to get the status and owner. if topol_type == const.TYPE_NW_SLICE: #get network status<network status=xxx> if xd_topol.has_key('@'+const.XML_ATTR_STS): nw_sts = xd_topol['@'+const.XML_ATTR_STS] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_NW,const.XML_ATTR_STS)) return None #get network owner(=user)<network owner=xxx> if xd_topol.has_key('@'+const.XML_ATTR_OWN): nw_own = xd_topol['@'+const.XML_ATTR_OWN] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_NW,const.XML_ATTR_OWN)) return None # slice topology only. #add network status and network owner. topol_dict[const.XML_ATTR_STS] = nw_sts topol_dict[const.XML_ATTR_OWN] = nw_own # common to physical and slice topology. topol_dict[const.XML_ATTR_TYPE] = topol_type topol_dict[const.XML_ATTR_LAST_UPD_TIME] = topol_time topol_dict[const.XML_ATTR_NAME] = nw_name #get <node> node_dict_list = parse_node_xml(xd_topol) if not node_dict_list: return None #add node dictionary list. topol_dict[const.XML_TAG_NODE] = node_dict_list #get <link> link_dict_list = [] topol_dict[const.XML_TAG_LINK] = link_dict_list if xd_topol.has_key(const.XML_TAG_LINK): link_list = util.to_array(xd_topol[const.XML_TAG_LINK]) for link in link_list: #get link type<link type=xxx> link_dict = dict() if link.has_key('@'+const.XML_ATTR_TYPE): link_type = link['@'+const.XML_ATTR_TYPE].lower() else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_LINK,const.XML_ATTR_TYPE)) return None if link_type == const.TYPE_LINK_TN: # Processing for TN is T.B.D. pass elif link_type == const.TYPE_LINK_LAN: # get interface_ref<interface_ref> if link.has_key(const.XML_TAG_IF_REF): ifref_list = util.to_array(link[const.XML_TAG_IF_REF]) else: logger.warn('tag <{0}> is not specified.'.format(const.XML_TAG_IF_REF)) return None # interface_ref exist two always if len(ifref_list) != 2: logger.warn('tag <{0}> exist two always.({1})' .format(const.XML_TAG_IF_REF),len(ifref_list)) return None ifref_client_list = [] link_dict[const.XML_TAG_IF_REF] = ifref_client_list for ifref in ifref_list: #get link type<link type=xxx> if ifref.has_key('@'+const.XML_ATTR_CLIENT_ID): ifref_client_id = ifref['@'+const.XML_ATTR_CLIENT_ID] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_IF_REF,const.XML_ATTR_CLIENT_ID)) return None #add client id. ifref_client_list.append( ifref_client_id) #append link dictionary list. link_dict_list.append(link_dict) else: logger.warn('attribute <{0} {1}={2}> is invalid value.'\ .format(const.XML_TAG_LINK,const.XML_ATTR_TYPE,link_type)) return None else: logger.debug('no link.') # append topology dict topol_dict_list.append(topol_dict) except Exception: logger.exception('parse_topology_xml') return None return topol_dict_list
def parse_monitoring_data_xml(logger,md_xml): try: mon_data_dict = dict() # get Xml root element in the Dictionary type. xd_root = xmltodict.parse(md_xml) # get <monitoring-data> if xd_root.has_key(const.XML_TAG_MON_DATA): xd_mon_data = xd_root[const.XML_TAG_MON_DATA] else: logger.warn('tag <{0}> is not specified.'.format(const.XML_TAG_MON_DATA)) return None # get forward flag.<monitoring-data forward=xxx> fwd_flg = False if xd_mon_data.has_key('@'+const.XML_ATTR_FWD): if xd_mon_data['@'+const.XML_ATTR_FWD].lower() == 'yes': fwd_flg = True mon_data_dict[const.XML_ATTR_FWD] = fwd_flg # get <topology-list> if xd_mon_data.has_key(const.XML_TAG_TOPOL_LIST): xd_topol_list = xd_mon_data[const.XML_TAG_TOPOL_LIST] else: logger.warn('tag <{0}> is not specified.'.format(const.XML_TAG_TOPOL_LIST)) return None # get <topology> if xd_topol_list.has_key(const.XML_TAG_TOPOL): topol_list = util.to_array(xd_topol_list[const.XML_TAG_TOPOL]) else: logger.warn('tag <{0}> is not specified.'.format(const.XML_TAG_TOPOL)) return None topol_dict_list = [] mon_data_dict[const.XML_TAG_TOPOL] = topol_dict_list for xd_topol in topol_list: topol_dict = dict() # append topology dictionary list. topol_dict_list.append(topol_dict) # get topology type.<topology type=xxx> if xd_topol.has_key('@'+const.XML_ATTR_TYPE): topol_type = xd_topol['@'+const.XML_ATTR_TYPE].lower() else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_TOPOL,const.XML_ATTR_TYPE)) return None if not topol_type == const.TYPE_NW_PHYSICAL and \ not topol_type == const.TYPE_NW_SLICE: logger.warn('attribute <{0} {1}={2}> is invalid value.'\ .format(const.XML_TAG_TOPOL,const.XML_ATTR_TYPE,topol_type)) return None topol_dict[const.XML_ATTR_TYPE] = topol_type # get topology name.<topology name=xxx> if xd_topol.has_key('@'+const.XML_ATTR_NAME): topol_name = xd_topol['@'+const.XML_ATTR_NAME].lower() else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_TOPOL,const.XML_ATTR_NAME)) return None topol_dict[const.XML_ATTR_NAME] = topol_name # get <node> node_dict_list = [] topol_dict[const.XML_TAG_NODE] = node_dict_list if xd_topol.has_key(const.XML_TAG_NODE): node_list = util.to_array(xd_topol[const.XML_TAG_NODE]) else: logger.debug('tag <{0}> is not specified.'.format(const.XML_TAG_NODE)) return None for node in node_list: # get node id<node id=xxx> node_dict = dict() if node.has_key('@'+const.XML_ATTR_ID): node_id = node['@'+const.XML_ATTR_ID] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_NODE,const.XML_ATTR_ID)) continue # get node type<node type=xxx> if node.has_key('@'+const.XML_ATTR_TYPE): node_type = node['@'+const.XML_ATTR_TYPE] if not ((topol_type == const.TYPE_NW_PHYSICAL and node_type == const.TYPE_NODE_SRV)\ or (topol_type == const.TYPE_NW_SLICE and node_type == const.TYPE_NODE_VM)): logger.warn('attribute <{0} {1}={2}> is invalid value.'\ .format(const.XML_TAG_NODE,const.XML_ATTR_TYPE,node_type)) continue else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_NODE,const.XML_ATTR_TYPE)) continue # add node name and node type node_dict[const.XML_ATTR_ID] = node_id node_dict[const.XML_ATTR_TYPE] = node_type # add parameter dictionary list. param_dict_list = [] node_dict[const.XML_TAG_PARAM] = param_dict_list # append node dictionary list. node_dict_list.append(node_dict) # get <parameter> if node.has_key(const.XML_TAG_PARAM): param_list = util.to_array(node[const.XML_TAG_PARAM]) else: logger.warn('tag <{0}> is not specified.'.format(const.XML_TAG_PARAM)) continue for param in param_list: # get parameter type<parameter type=xxx> param_dict = dict() if param.has_key('@'+const.XML_ATTR_TYPE): param_type = param['@'+const.XML_ATTR_TYPE] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_PARAM,const.XML_ATTR_TYPE)) continue # add parameter type. param_dict[const.XML_ATTR_TYPE] = param_type # add value dictionary list. value_dict_list = [] param_dict[const.XML_TAG_VAL] = value_dict_list # append parameter dictionary list. param_dict_list.append(param_dict) # get <value> if param.has_key(const.XML_TAG_VAL): val_list = util.to_array(param[const.XML_TAG_VAL]) else: logger.debug('tag <{0}> is not specified.'.format(const.XML_TAG_VAL)) continue for val in val_list: # get value timestamp<value timestamp=xxx> value_dict = dict() if val.has_key('@'+const.XML_ATTR_TIME_STAMP): time_stamp = val['@'+const.XML_ATTR_TIME_STAMP] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_VAL,const.XML_ATTR_TIME_STAMP)) continue # get value text<value>xxx</value> if val.has_key('#text'): val_text = val['#text'] else: logger.warn('text <{0}> is not specified.'.format(const.XML_TAG_VAL)) continue logger.debug('{0}={1} {2}={3} {4}={5}' .format(const.XML_ATTR_TYPE,param_type ,const.XML_ATTR_TIME_STAMP,time_stamp ,const.XML_TAG_VAL,val_text)) # add time stamp and value. value_dict[const.XML_ATTR_TIME_STAMP] = time_stamp value_dict[const.XML_TAG_VAL] = val_text # append value dictionary list. value_dict_list.append(value_dict) except Exception: logger.exception('parse_monitoring_data_xml') raise return mon_data_dict
def __get_monitoring_data(self,node_name,port,stime,etime,tblsaffix_list): logger.debug("get monitoring-data.") sql_metaid = "(SELECT metaID FROM metaData " \ + "WHERE node_name='{0}' AND port='{1}')"\ .format(node_name,port) # search database.(data) sql_base = "(SELECT timestamp,{0} FROM {1} WHERE metaID={2}"\ + " AND timestamp >= {0}".format(stime)\ + " AND timestamp < {0})".format(etime) mon_item_list = [] for mon_item in config.ps_sdn_mon_item_list: mon_item_list.append(mon_item['data-name']) if not mon_item_list: logger.debug('monitoring-item is not specified.') return None items = ",".join(mon_item_list) sql_list = [] for tblsaffix in tblsaffix_list: sql_list.append(sql_base.format(items,'data_'+tblsaffix,sql_metaid)) if not sql_list: logger.debug('sql_list no data.') return None sql = " UNION ".join(sql_list) sql += " ORDER BY timestamp" logger.debug(sql) query_msg = """ <nmwg:message xmlns:nmwgt="http://ggf.org/ns/nmwg/topology/2.0/" xmlns:nmwg="http://ggf.org/ns/nmwg/base/2.0/" xmlns:select="http://ggf.org/ns/nmwg/ops/select/2.0/" type="QueryRequest"> <nmwg:metadata id="m1"> <nmwg:eventType>http://ggf.org/ns/nmwg/sequel/20090610</nmwg:eventType> <nmwg:parameter name="key">timestamp</nmwg:parameter> <nmwg:parameter name="query">{0}</nmwg:parameter> </nmwg:metadata> <nmwg:data metadataIdRef="m1"/> </nmwg:message> """.format(sql) msg = self.__create_ps_msg(query_msg) logger.debug('request perfSONAR') res = self.__post_sequel_service(msg) logger.debug('response perfSONAR') if self.__check_ps_res('QueryRequest',res.text) == False: logger.debug('QueryRequest no resqonse text.') return None xd_root = xmltodict.parse(res.text) xd_body = xd_root['SOAP-ENV:Envelope']['SOAP-ENV:Body'] if not xd_body['nmwg:message']['nmwg:data']: logger.debug('QueryRequest no data.') return None data_list = to_array(xd_body['nmwg:message']['nmwg:data']['nmwg:commonTime']) val_list = list() for data in data_list: val_dict = dict() datum_list = to_array(data['sequel:datum']) for datum in datum_list: if datum['@value']: val_dict[datum['@name']] = datum['@value'] val_list.append(val_dict) res_dict = {'node_name':node_name,'port':port,'val_list':val_list} return res_dict
def parse_node_xml(xd_root): #get node<node> node_dict_list = [] if xd_root.has_key(const.XML_TAG_NODE): node_list = util.to_array(xd_root[const.XML_TAG_NODE]) else: logger.debug('tag <{0}> is not specified.'.format(const.XML_TAG_NODE)) return None for node in node_list: #get node id<node id=xxx> node_dict = dict() if node.has_key('@' + const.XML_ATTR_ID): node_id = node['@' + const.XML_ATTR_ID] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_NODE,const.XML_ATTR_ID)) return None #get node type<node type=xxx> if node.has_key('@' + const.XML_ATTR_TYPE): node_type = node['@' + const.XML_ATTR_TYPE].lower() else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_NODE,const.XML_ATTR_TYPE)) return None if node_type == const.TYPE_NODE_SW: pass elif node_type == const.TYPE_NODE_SRV: # get vm<node>(Recursively call) sub_node_dict_list = parse_node_xml(node) if sub_node_dict_list: node_dict[const.XML_TAG_NODE] = sub_node_dict_list elif node_type == const.TYPE_NODE_VM: pass else: logger.warn('attribute <{0} {1}={2}> is invalid value.'\ .format(const.XML_TAG_NODE,const.XML_ATTR_TYPE,node_type)) return None #add node name and node type and network. node_dict[const.XML_ATTR_ID] = node_id node_dict[const.XML_ATTR_TYPE] = node_type #get management type and details mgmt_dict = dict() if node.has_key(const.XML_TAG_MGMT): mgmt_list = util.to_array(node[const.XML_TAG_MGMT]) if len(mgmt_list) > 1: logger.warn( 'more than one management definition. (node id={0})'. format(node_id)) mgmt = mgmt_list[1] if mgmt.has_key(const.XML_TAG_MGMT_TYPE): mgmt_dict[const.XML_TAG_MGMT_TYPE] = mgmt[ const.XML_TAG_MGMT_TYPE] else: logger.warn( 'management definition has no type. (node id={0})'.format( node_id)) if mgmt.has_key(const.XML_TAG_MGMT_ADDRESS): mgmt_dict[const.XML_TAG_MGMT_ADDRESS] = mgmt[ const.XML_TAG_MGMT_ADDRESS] if mgmt.has_key(const.XML_TAG_MGMT_PORT): mgmt_dict[const.XML_TAG_MGMT_PORT] = mgmt[ const.XML_TAG_MGMT_PORT] if mgmt.has_key(const.XML_TAG_MGMT_AUTH): mgmt_dict[const.XML_TAG_MGMT_AUTH] = mgmt[ const.XML_TAG_MGMT_AUTH] #add management node_dict[const.XML_TAG_MGMT] = mgmt_dict #add interface dictionary list. if_dict_list = [] node_dict[const.XML_TAG_IF] = if_dict_list #append node dictionary list. node_dict_list.append(node_dict) #get <interface> if not node.has_key(const.XML_TAG_IF): logger.debug('no interface.(node_id={0})'.format(node_id)) continue if_list = util.to_array(node[const.XML_TAG_IF]) for interface in if_list: if_dict = dict() #get interface id<interface id=xxx> if interface.has_key('@' + const.XML_ATTR_ID): if_id = interface['@' + const.XML_ATTR_ID] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_IF,const.XML_ATTR_ID)) return None #get port number<port num=xxx> if interface.has_key(const.XML_TAG_PORT): if interface[const.XML_TAG_PORT].has_key('@' + const.XML_ATTR_NUM): port_num = interface[const.XML_TAG_PORT][ '@' + const.XML_ATTR_NUM] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_PORT,const.XML_ATTR_NUM)) return None #add port number. if_dict[const.XML_TAG_PORT] = port_num #add interface id. if_dict[const.XML_ATTR_ID] = if_id #create and append interface dictionary list. if_dict_list.append(if_dict) return node_dict_list
def parse_topology_xml(topology_list_xml): try: #get Xml root element in the Dictionary type. xd_root = xmltodict.parse(topology_list_xml) #get <topology_list> if xd_root.has_key(const.XML_TAG_TOPOL_LIST): xd_topol_list = xd_root[const.XML_TAG_TOPOL_LIST] else: logger.warn('tag <{0}> is not specified.'.format( const.XML_TAG_TOPOL_LIST)) return None #get <topology> if xd_topol_list.has_key(const.XML_TAG_TOPOL): topol_list = util.to_array(xd_topol_list[const.XML_TAG_TOPOL]) else: logger.warn('tag <{0}> is not specified.'.format( const.XML_TAG_TOPOL)) return None topol_dict_list = [] for xd_topol in topol_list: topol_dict = dict() #get topology type.<topology type=xxx> if xd_topol.has_key('@' + const.XML_ATTR_TYPE): topol_type = xd_topol['@' + const.XML_ATTR_TYPE].lower() else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_TOPOL,const.XML_ATTR_TYPE)) return None if not topol_type == const.TYPE_NW_PHYSICAL and \ not topol_type == const.TYPE_NW_SLICE: logger.warn('attribute <{0} {1}={2}> is invalid value.'\ .format(const.XML_TAG_TOPOL,const.XML_ATTR_TYPE,topol_type)) return None #get topology last_update_time.<topology last_update_time=xxx> if xd_topol.has_key('@' + const.XML_ATTR_LAST_UPD_TIME): topol_time = xd_topol['@' + const.XML_ATTR_LAST_UPD_TIME] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_TOPOL,const.XML_ATTR_LAST_UPD_TIME)) return None if xd_topol.has_key('@' + const.XML_ATTR_NAME): nw_name = xd_topol['@' + const.XML_ATTR_NAME] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_NW,const.XML_ATTR_NAME)) return None #In the case of slice topology, to get the status and owner. if topol_type == const.TYPE_NW_SLICE: #get network status<network status=xxx> if xd_topol.has_key('@' + const.XML_ATTR_STS): nw_sts = xd_topol['@' + const.XML_ATTR_STS] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_NW,const.XML_ATTR_STS)) return None #get network owner(=user)<network owner=xxx> if xd_topol.has_key('@' + const.XML_ATTR_OWN): nw_own = xd_topol['@' + const.XML_ATTR_OWN] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_NW,const.XML_ATTR_OWN)) return None # slice topology only. #add network status and network owner. topol_dict[const.XML_ATTR_STS] = nw_sts topol_dict[const.XML_ATTR_OWN] = nw_own # common to physical and slice topology. topol_dict[const.XML_ATTR_TYPE] = topol_type topol_dict[const.XML_ATTR_LAST_UPD_TIME] = topol_time topol_dict[const.XML_ATTR_NAME] = nw_name #get <node> node_dict_list = parse_node_xml(xd_topol) if not node_dict_list: return None #add node dictionary list. topol_dict[const.XML_TAG_NODE] = node_dict_list #get <link> link_dict_list = [] topol_dict[const.XML_TAG_LINK] = link_dict_list if xd_topol.has_key(const.XML_TAG_LINK): link_list = util.to_array(xd_topol[const.XML_TAG_LINK]) for link in link_list: #get link type<link type=xxx> link_dict = dict() if link.has_key('@' + const.XML_ATTR_TYPE): link_type = link['@' + const.XML_ATTR_TYPE].lower() else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_LINK,const.XML_ATTR_TYPE)) return None if link_type == const.TYPE_LINK_TN: # Processing for TN is T.B.D. pass elif link_type == const.TYPE_LINK_LAN: # get interface_ref<interface_ref> if link.has_key(const.XML_TAG_IF_REF): ifref_list = util.to_array( link[const.XML_TAG_IF_REF]) else: logger.warn('tag <{0}> is not specified.'.format( const.XML_TAG_IF_REF)) return None # interface_ref exist two always if len(ifref_list) != 2: logger.warn( 'tag <{0}> exist two always.({1})'.format( const.XML_TAG_IF_REF), len(ifref_list)) return None ifref_client_list = [] link_dict[const.XML_TAG_IF_REF] = ifref_client_list for ifref in ifref_list: #get link type<link type=xxx> if ifref.has_key('@' + const.XML_ATTR_CLIENT_ID): ifref_client_id = ifref[ '@' + const.XML_ATTR_CLIENT_ID] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_IF_REF,const.XML_ATTR_CLIENT_ID)) return None #add client id. ifref_client_list.append(ifref_client_id) #append link dictionary list. link_dict_list.append(link_dict) else: logger.warn('attribute <{0} {1}={2}> is invalid value.'\ .format(const.XML_TAG_LINK,const.XML_ATTR_TYPE,link_type)) return None else: logger.debug('no link.') # append topology dict topol_dict_list.append(topol_dict) except Exception: logger.exception('parse_topology_xml') return None return topol_dict_list
def __get_nsi_monitoring_data(self): logger.debug("get monitoring-data from NSI.") # HTTP GET monitoring-data from NSI res = requests.get(config.nsi_uri, timeout=const.HTTP_TIME_OUT) # get Xml root element in the Dictionary type. all_nsi_md = dict() xd_root = xmltodict.parse(res.text) # get <reservationIDMaps> if not xd_root.has_key(const.NST_TAG_RESERVE_MAPS): logger.warn('tag <{0}> is not specified.'.format(const.NST_TAG_RESERVE_MAPS)) return None xd_reservationIDMaps = xd_root[const.NST_TAG_RESERVE_MAPS] # get <updateTime> if not xd_reservationIDMaps.has_key(const.NSI_TAG_UPDATE_TIME): logger.warn('tag <{0}> is not specified.'.format(const.NSI_TAG_UPDATE_TIME)) return None # convert the updateTime to UNIXTIME(UTC) dt_update_time = dateutil.parser.parse(xd_reservationIDMaps[const.NSI_TAG_UPDATE_TIME]).astimezone(pytz.timezone('UTC')) update_time = calendar.timegm(dt_update_time.timetuple()) logger.debug('update time.({0}->{1})'.format(xd_reservationIDMaps[const.NSI_TAG_UPDATE_TIME],update_time)) # get <reservationIDMap> if not xd_reservationIDMaps.has_key(const.NST_TAG_RESERVE_MAP): logger.warn('tag <{0}> is not specified.'.format(const.NST_TAG_RESERVE_MAP)) return None for xd_reservationIDMap in util.to_array(xd_reservationIDMaps[const.NST_TAG_RESERVE_MAP]): # get <resourceSet> if not xd_reservationIDMap.has_key(const.NST_TAG_RESOURCE_SET): logger.warn('tag <{0}> is not specified.'.format(const.NST_TAG_RESOURCE_SET)) continue for xd_resourceSet in util.to_array(xd_reservationIDMap[const.NST_TAG_RESOURCE_SET]): # get <networkResource> if not xd_resourceSet.has_key(const.NST_TAG_NW_RESOURCE): logger.warn('tag <{0}> is not specified.'.format(const.NST_TAG_NW_RESOURCE)) continue xd_networkResource = xd_resourceSet[const.NST_TAG_NW_RESOURCE] # check <globalReservationId> if not xd_networkResource.has_key(const.NSI_TAG_LINK_ID): logger.warn('tag <{0}> is not specified.'.format(const.NSI_TAG_LINK_ID)) continue logger.debug(xd_networkResource[const.NSI_TAG_LINK_ID]) # check <dataPlaneState> if not xd_networkResource.has_key(const.NSI_TAG_STATE): logger.warn('tag <{0}> is not specified.'.format(const.NSI_TAG_STATE)) continue md_dict = {'timestamp':update_time} # # get <provisionState> # if xd_networkResource[const.NSI_TAG_STATE] == 'PROVISIONED': # md_dict['status'] = const.MD_STATUS_UP # else: # md_dict['status'] = const.MD_STATUS_DOWN # get <dataPlaneState>isAct=false, ver=0, isConsistent=true</dataPlaneState> # create status dict. # e.g. state_list=[[dictisAct,false], [ver,0], [isConsistent,true]] state_list = [status_value_list.split("=") for status_value_list in xd_networkResource[const.NSI_TAG_STATE].split(",")] logger.debug(state_list) # e.g. status_dict={isAct:True, ver:0, isConsistent:true} state_dict = dict(state_list) logger.debug(state_dict) if not state_dict.has_key(const.NSI_ELM_STATE): logger.warn('element[{0}] is not found.'.format(const.NSI_ELM_STATE)) continue if state_dict[const.NSI_ELM_STATE].lower() == 'true': md_dict['status'] = const.MD_STATUS_UP else: md_dict['status'] = const.MD_STATUS_DOWN all_nsi_md[xd_networkResource[const.NSI_TAG_LINK_ID]] = md_dict logger.debug(all_nsi_md) return all_nsi_md
def parse_link_xml(xd_root): link_dict_list = [] if xd_root.has_key(const.XML_TAG_LINK): link_list = util.to_array(xd_root[const.XML_TAG_LINK]) else: logger.debug('no link.') return None for link in link_list: link_dict = dict() #get link id<link id=xxx> if link.has_key('@' + const.XML_ATTR_ID): #add link name. link_dict[const.XML_ATTR_ID] = link['@' + const.XML_ATTR_ID] #get link type<link type=xxx> if link.has_key('@' + const.XML_ATTR_TYPE): link_type = link['@' + const.XML_ATTR_TYPE].lower() else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_LINK,const.XML_ATTR_TYPE)) return None # get interface_ref<interface_ref> if link.has_key(const.XML_TAG_IF_REF): ifref_list = util.to_array(link[const.XML_TAG_IF_REF]) else: logger.warn('tag <{0}> is not specified.'.format( const.XML_TAG_IF_REF)) return None # interface_ref exist two always if len(ifref_list) != 2: logger.warn( 'tag <{0}> exist two always.({1})'.format( const.XML_TAG_IF_REF), len(ifref_list)) return None ifref_client_list = [] link_dict[const.XML_TAG_IF_REF] = ifref_client_list for ifref in ifref_list: #get link type<link type=xxx> if ifref.has_key('@' + const.XML_ATTR_CLIENT_ID): ifref_client_id = ifref['@' + const.XML_ATTR_CLIENT_ID] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_IF_REF,const.XML_ATTR_CLIENT_ID)) return None #add client id. ifref_client_list.append(ifref_client_id) #append link dictionary list. link_dict_list.append(link_dict) #add link type. link_dict[const.XML_ATTR_TYPE] = link_type if link_type == const.TYPE_LINK_ABST_SDN: # get abstract link.<link>(Recursively call) sub_link_dict_list = parse_link_xml(link) if sub_link_dict_list: link_dict[const.XML_TAG_LINK] = sub_link_dict_list return link_dict_list
def parse_topology_xml(topology_list_xml): try: #get Xml root element in the Dictionary type. xd_root = xmltodict.parse(topology_list_xml) #get <topology_list> if xd_root.has_key(const.XML_TAG_TOPOL_LIST): xd_topol_list = xd_root[const.XML_TAG_TOPOL_LIST] else: logger.warn('tag <{0}> is not specified.'.format( const.XML_TAG_TOPOL_LIST)) return None #get <topology> if xd_topol_list.has_key(const.XML_TAG_TOPOL): topol_list = util.to_array(xd_topol_list[const.XML_TAG_TOPOL]) else: logger.warn('tag <{0}> is not specified.'.format( const.XML_TAG_TOPOL)) return None topol_dict_list = [] for xd_topol in topol_list: topol_dict = dict() #get topology type.<topology type=xxx> if xd_topol.has_key('@' + const.XML_ATTR_TYPE): topol_type = xd_topol['@' + const.XML_ATTR_TYPE].lower() else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_TOPOL,const.XML_ATTR_TYPE)) return None if not topol_type == const.TYPE_NW_PHYSICAL and \ not topol_type == const.TYPE_NW_SLICE: logger.warn('attribute <{0} {1}={2}> is invalid value.'\ .format(const.XML_TAG_TOPOL,const.XML_ATTR_TYPE,topol_type)) return None #get topology last_update_time.<topology last_update_time=xxx> if xd_topol.has_key('@' + const.XML_ATTR_LAST_UPD_TIME): topol_time = xd_topol['@' + const.XML_ATTR_LAST_UPD_TIME] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_TOPOL,const.XML_ATTR_LAST_UPD_TIME)) return None if xd_topol.has_key('@' + const.XML_ATTR_NAME): nw_name = xd_topol['@' + const.XML_ATTR_NAME] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_NW,const.XML_ATTR_NAME)) return None #In the case of slice topology, to get the status and owner. if topol_type == const.TYPE_NW_SLICE: #get network status<network status=xxx> if xd_topol.has_key('@' + const.XML_ATTR_STS): nw_sts = xd_topol['@' + const.XML_ATTR_STS] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_NW,const.XML_ATTR_STS)) return None #get network owner(=user)<network owner=xxx> if xd_topol.has_key('@' + const.XML_ATTR_OWN): nw_own = xd_topol['@' + const.XML_ATTR_OWN] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_NW,const.XML_ATTR_OWN)) return None # slice topology only. #add network status and network owner. topol_dict[const.XML_ATTR_STS] = nw_sts topol_dict[const.XML_ATTR_OWN] = nw_own # common to physical and slice topology. topol_dict[const.XML_ATTR_TYPE] = topol_type topol_dict[const.XML_ATTR_LAST_UPD_TIME] = topol_time topol_dict[const.XML_ATTR_NAME] = nw_name #get <node> node_dict_list = parse_node_xml(xd_topol) if not node_dict_list: return None #add node dictionary list. topol_dict[const.XML_TAG_NODE] = node_dict_list #get <link> link_dict_list = parse_link_xml(xd_topol) if not link_dict_list: link_dict_list = [] #add link dictionary list. topol_dict[const.XML_TAG_LINK] = link_dict_list # append topology dict topol_dict_list.append(topol_dict) except Exception: logger.exception('parse_topology_xml') return None return topol_dict_list
def parse_link_xml(xd_root): link_dict_list = [] if xd_root.has_key(const.XML_TAG_LINK): link_list = util.to_array(xd_root[const.XML_TAG_LINK]) else: logger.debug('no link.') return None for link in link_list: link_dict = dict() #get link id<link id=xxx> if link.has_key('@'+const.XML_ATTR_ID): #add link name. link_dict[const.XML_ATTR_ID] = link['@'+const.XML_ATTR_ID] #get link type<link type=xxx> if link.has_key('@'+const.XML_ATTR_TYPE): link_type = link['@'+const.XML_ATTR_TYPE].lower() else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_LINK,const.XML_ATTR_TYPE)) return None # get interface_ref<interface_ref> if link.has_key(const.XML_TAG_IF_REF): ifref_list = util.to_array(link[const.XML_TAG_IF_REF]) else: logger.warn('tag <{0}> is not specified.'.format(const.XML_TAG_IF_REF)) return None # interface_ref exist two always if len(ifref_list) != 2: logger.warn('tag <{0}> exist two always.({1})' .format(const.XML_TAG_IF_REF),len(ifref_list)) return None ifref_client_list = [] link_dict[const.XML_TAG_IF_REF] = ifref_client_list for ifref in ifref_list: #get link type<link type=xxx> if ifref.has_key('@'+const.XML_ATTR_CLIENT_ID): ifref_client_id = ifref['@'+const.XML_ATTR_CLIENT_ID] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_IF_REF,const.XML_ATTR_CLIENT_ID)) return None #add client id. ifref_client_list.append( ifref_client_id) #append link dictionary list. link_dict_list.append(link_dict) #add link type. link_dict[const.XML_ATTR_TYPE] = link_type if link_type == const.TYPE_LINK_ABST_SDN: # get abstract link.<link>(Recursively call) sub_link_dict_list = parse_link_xml(link) if sub_link_dict_list: link_dict[const.XML_TAG_LINK] = sub_link_dict_list return link_dict_list
def parse_topology_xml(topology_list_xml): try: #get Xml root element in the Dictionary type. xd_root = xmltodict.parse(topology_list_xml) #get <topology_list> if xd_root.has_key(const.XML_TAG_TOPOL_LIST): xd_topol_list = xd_root[const.XML_TAG_TOPOL_LIST] else: logger.warn('tag <{0}> is not specified.'.format(const.XML_TAG_TOPOL_LIST)) return None #get <topology> if xd_topol_list.has_key(const.XML_TAG_TOPOL): topol_list = util.to_array(xd_topol_list[const.XML_TAG_TOPOL]) else: logger.warn('tag <{0}> is not specified.'.format(const.XML_TAG_TOPOL)) return None topol_dict_list = [] for xd_topol in topol_list: topol_dict = dict() #get topology type.<topology type=xxx> if xd_topol.has_key('@'+const.XML_ATTR_TYPE): topol_type = xd_topol['@'+const.XML_ATTR_TYPE].lower() else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_TOPOL,const.XML_ATTR_TYPE)) return None if not topol_type == const.TYPE_NW_PHYSICAL and \ not topol_type == const.TYPE_NW_SLICE: logger.warn('attribute <{0} {1}={2}> is invalid value.'\ .format(const.XML_TAG_TOPOL,const.XML_ATTR_TYPE,topol_type)) return None #get topology last_update_time.<topology last_update_time=xxx> if xd_topol.has_key('@'+const.XML_ATTR_LAST_UPD_TIME): topol_time = xd_topol['@'+const.XML_ATTR_LAST_UPD_TIME] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_TOPOL,const.XML_ATTR_LAST_UPD_TIME)) return None if xd_topol.has_key('@'+const.XML_ATTR_NAME): nw_name = xd_topol['@'+const.XML_ATTR_NAME] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_NW,const.XML_ATTR_NAME)) return None #In the case of slice topology, to get the status and owner. if topol_type == const.TYPE_NW_SLICE: #get network status<network status=xxx> if xd_topol.has_key('@'+const.XML_ATTR_STS): nw_sts = xd_topol['@'+const.XML_ATTR_STS] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_NW,const.XML_ATTR_STS)) return None #get network owner(=user)<network owner=xxx> if xd_topol.has_key('@'+const.XML_ATTR_OWN): nw_own = xd_topol['@'+const.XML_ATTR_OWN] else: logger.warn('attribute <{0} {1}> is not specified.'\ .format(const.XML_TAG_NW,const.XML_ATTR_OWN)) return None # slice topology only. #add network status and network owner. topol_dict[const.XML_ATTR_STS] = nw_sts topol_dict[const.XML_ATTR_OWN] = nw_own # common to physical and slice topology. topol_dict[const.XML_ATTR_TYPE] = topol_type topol_dict[const.XML_ATTR_LAST_UPD_TIME] = topol_time topol_dict[const.XML_ATTR_NAME] = nw_name #get <node> node_dict_list = parse_node_xml(xd_topol) if not node_dict_list: return None #add node dictionary list. topol_dict[const.XML_TAG_NODE] = node_dict_list #get <link> link_dict_list = parse_link_xml(xd_topol) if not link_dict_list: link_dict_list = [] #add link dictionary list. topol_dict[const.XML_TAG_LINK] = link_dict_list # append topology dict topol_dict_list.append(topol_dict) except Exception: logger.exception('parse_topology_xml') return None return topol_dict_list