def update_flow_cookie_hash(): """ The formatter keeps a map for static flow entries. """ # iterate through all the static flows and get their hashes once flow_map = {} prime = 211 for sf in sdnsh.get_table_from_store("flow-entry"): flow_hash = 2311 for i in range(0, len(sf['name'])): flow_hash = flow_hash * prime + ord(sf['name'][i]) flow_hash = flow_hash & ( (1 << 20) - 1) flow_map[flow_hash] = sf['name'] fmtcnv.update_alias_dict("staticflow", flow_map) fmtcnv.callout_flow_encoders(sdnsh)
def update_flow_cookie_hash(): """ The formatter keeps a map for static flow entries. """ # iterate through all the static flows and get their hashes once flow_map = {} prime = 211 for sf in sdnsh.get_table_from_store("flow-entry"): flow_hash = 2311 for i in range(0, len(sf['name'])): flow_hash = flow_hash * prime + ord(sf['name'][i]) flow_hash = flow_hash & ((1 << 20) - 1) flow_map[flow_hash] = sf['name'] fmtcnv.update_alias_dict("staticflow", flow_map) fmtcnv.callout_flow_encoders(sdnsh)
def update_show_alias(obj_type): """ Update alias associations for the pretty printer, used for the 'show' of tables """ if obj_type in mi.alias_obj_type_xref: for alias in mi.alias_obj_type_xref[obj_type]: field = mi.alias_obj_type_field(alias) if not field: print sdnsh.error_msg("update show alias alias_obj_type_field") return try: table = sdnsh.get_table_from_store(alias) except Exception, e: table = [] new_dict = {} key = mi.pk(alias) # (foreign_obj, foreign_field) = \ # mi.foreign_key_references(alias, field) for row in table: new_dict[row[field]] = row[key] fmtcnv.update_alias_dict(obj_type, new_dict)
errors = None switch_port_to_name_dict = {} try: ports = rest_to_model.get_model_from_url('interfaces', {}) except Exception, e: errors = sdnsh.rest_error_to_dict(e) if errors: print sdnsh.rest_error_dict_to_message(errors) return for port in ports: key_string = port['switch'] + "." + "%s" % port['portNumber'] switch_port_to_name_dict[key_string] = port['portName'] fmtcnv.update_alias_dict("portNames", switch_port_to_name_dict) # # -------------------------------------------------------------------------------- def update_host_alias_cache(): """ Update the cliModeInfo prettyprinting host table """ return update_show_alias('host-config') # # -------------------------------------------------------------------------------- # update_flow_cookie_hash
errors = None switch_port_to_name_dict = {} try: ports = rest_to_model.get_model_from_url('interfaces', {}) except Exception, e: errors = sdnsh.rest_error_to_dict(e) if errors: print sdnsh.rest_error_dict_to_message(errors) return for port in ports: key_string = port['switch'] + "." + "%d" % port['portNumber'] switch_port_to_name_dict[key_string] = port['portName'] fmtcnv.update_alias_dict("portNames", switch_port_to_name_dict) # # -------------------------------------------------------------------------------- def update_host_alias_cache(): """ Update the cliModeInfo prettyprinting host table """ return update_show_alias('host-config') # # --------------------------------------------------------------------------------