def do_alias(self, line):
        from utils import refresh_alias_json_db
        from utils import config_json_read 
        from utils import config_json_write
        from global_value import CONF_PATH 
        #read and mode and write json db
        file_path = CONF_PATH+"/"+self.controller_uid+".json"
        try :
            read_json = config_json_read(file_path)
            for dpid_list in read_json['controllers']['switchs']:
                if dpid_list['dpid'] == self.dpid:
                    #line command check
                    dpid_list['sw_alias'] = line
                    print "change switch alias"
                    break
            print self.hp_sw_alias_db
            config_json_write(file_path, read_json)
            refresh_alias_json_db(self.ip, self.port, self.token, None, None)
            self.sw_name = line
        except Exception:
            traceback.print_exc()
            return None

        #check line
        self.prompt = "Controller("+line+"): " 
        print "change datapath name",line
    def do_alias(self, cmd_line):
        from utils import refresh_alias_json_db
        from utils import config_json_write
        from utils import config_json_read
        from global_value import CONF_PATH 
        
        reg_cont = Registered_controller()
        file_path = CONF_PATH+"/"+self.controller_uid+".json"
        try :
            read_json = config_json_read(file_path)
            read_json['controllers']['con_alias'] = cmd_line
            config_json_write(file_path, read_json)
            refresh_alias_json_db(self.ip, self.port, self.token, None, None)
            self.prompt = cmd_line
            self.prompt = "Controller("+cmd_line+"): " 
            reg_cont.search_controller(self.ip, self.port, cmd_line)

        except Exception:
            traceback.print_exc()
            return None
    def init_value(self):
        from utils import refresh_alias_json_db
        from utils import mac_db 
        from utils import sw_alias_db 
        self.sw_alias = []

        self.controller_uid = refresh_alias_json_db(self.ip, self.port, self.token, None, None)
        self.hp_mac_db = mac_db
        self.hp_sw_alias_db = sw_alias_db 

        for sw_list in self.hp_sw_alias_db:
            tmp_sw_list = self.hp_sw_alias_db[sw_list]
            self.sw_alias_tuple[tmp_sw_list] = sw_list
            self.sw_alias.append(tmp_sw_list)
    def __call__(self, *args):
        from utils import mac_db 
        from utils import sw_alias_db 
        from utils import g_controller_uid 
        from utils import refresh_alias_json_db
        from hp_controller_api import show_openflow_switch_info

        self.ip = args[0]
        self.port = args[1]
        self.token = args[2]
        self.dpid = args[3]
        self.sw_name = args[4]

        self.controller_uid = refresh_alias_json_db(self.ip, self.port, self.token, None, None)
        self.hp_mac_db = mac_db
        self.hp_sw_alias_db = sw_alias_db