Esempio n. 1
0
 def auto_complete_command(self, chosen_command, line, last_arg=None):
     obj = None
     files = None
     smgr_dict = self.parent_app.get_smgr_config()
     ip = smgr_dict["smgr_ip"]
     port = smgr_dict["smgr_port"]
     rest_api_params = None
     return_list = list()
     if chosen_command in ['reimage', 'provision']:
         obj = 'image'
         rest_api_params = {
             'object': "image",
             'select': "id,category"
         }
     else:
         files = self.auto_complete_file_list(last_arg)
     if obj:
         rest_api_params["match_key"] = None
         rest_api_params["match_value"] = None
         resp = smgrutils.send_REST_request(ip, port, rest_api_params=rest_api_params, detail=False, method="GET")
         if resp:
             json_dict = ast.literal_eval(resp)
             new_json_dict = dict()
             new_json_dict[obj] = list()
             for data_dict in json_dict[obj]:
                 new_dict = dict()
                 data_dict = dict(data_dict)
                 if (data_dict["category"] == "image" and chosen_command == "reimage") or \
                         (data_dict["category"] == "package" and chosen_command == "provision"):
                     new_dict["id"] = data_dict["id"]
                     new_json_dict[obj].append(new_dict)
             auto_fill_list = smgrutils.convert_json_to_list(obj=obj, json_resp=new_json_dict)
             return_list = [
                 str(str(line).rsplit(' ', 1)[0] + " " + af_option)
                 for af_option in auto_fill_list
                 if str(str(line).rsplit(' ', 1)[0] + " " + af_option).startswith(line)
             ]
     elif files:
         return_list = [
             str(str(line).rsplit(' ', 1)[0] + " " + f)
             for f in files
             if str(str(line).rsplit(' ', 1)[0] + " " + f).startswith(line)
         ]
     return return_list
Esempio n. 2
0
 def auto_complete_sub_option(self, chosen_sub_option, chosen_sub_command, line, last_arg=None):
     obj = None
     files = None
     smgr_dict = self.parent_app.get_smgr_config()
     ip = smgr_dict["smgr_ip"]
     port = smgr_dict["smgr_port"]
     rest_api_params = None
     return_list = list()
     if chosen_sub_option in ['--server_id']:
         obj = 'server'
         rest_api_params = {
             'object': "server",
             'select': "id"
         }
     elif chosen_sub_option in ['--tag']:
         obj = 'tag'
         rest_api_params = {
             'object': "tag",
             'select': None
         }
     elif chosen_sub_option in ['--cluster_id']:
         obj = 'cluster'
         rest_api_params = {
             'object': "cluster",
             'select': None
         }
     elif chosen_sub_option in ['--image_id', '--package_image_id']:
         obj = 'image'
         rest_api_params = {
             'object': "image",
             'select': None
         }
     elif chosen_sub_option in ['--mac']:
         obj = 'mac'
         rest_api_params = {
             'object': "server",
             'select': "mac_address"
         }
     elif chosen_sub_option in ['--ip']:
         obj = 'ip'
         rest_api_params = {
             'object': "server",
             'select': "ip_address"
         }
     elif chosen_sub_option in ['-f', '--file_name']:
         files = self.auto_complete_file_list(last_arg)
     else:
         return []
     if obj:
         rest_api_params["match_key"] = None
         rest_api_params["match_value"] = None
         resp = smgrutils.send_REST_request(ip, port, rest_api_params=rest_api_params, method="GET")
         if resp:
             json_dict = ast.literal_eval(str(resp))
             auto_fill_list = smgrutils.convert_json_to_list(obj=obj, json_resp=json_dict)
             return_list = [
                 str(str(line).rsplit(' ', 1)[0] + " " + af_option)
                 for af_option in auto_fill_list
                 if str(str(line).rsplit(' ', 1)[0] + " " + af_option).startswith(line)
             ]
     elif files:
         return_list = [
             str(str(line).rsplit(' ', 1)[0] + " " + f)
             for f in files
             if str(str(line).rsplit(' ', 1)[0] + " " + f).startswith(line)
         ]
     return return_list