Ejemplo n.º 1
0
    def __init__(self, options):
        """
        Constructor
        """
        readline.parse_and_bind("tab: complete")
        readline.set_completer(self.complete)
        readline.set_completion_display_matches_hook(self.completer_print)
        try:
            readline.read_history_file(CLI_HISTORY)
        except IOError:
            pass
        readline.set_history_length(CLI_MAX_CMD_HISTORY)

        if not os.path.isdir(CLI_RESULT_HISTORY_FOLDER):
            os.system('rm -rf %s' % os.path.dirname(CLI_RESULT_HISTORY_FOLDER))
            os.system('mkdir -p %s' % os.path.dirname(CLI_RESULT_HISTORY_FOLDER))

        try:
            self.hd = filedb.FileDB(CLI_RESULT_HISTORY_KEY, is_abs_path=True)
        except:
            os.system('rm -rf %s' % CLI_RESULT_HISTORY_KEY)
            self.hd = filedb.FileDB(CLI_RESULT_HISTORY_KEY, is_abs_path=True)
            print "\nRead history file: %s error. Has recreate it.\n" % CLI_RESULT_HISTORY_KEY

        self.start_key = 'start_key'
        self.last_key = 'last_key'
        self.cli_cmd_func = {'help': self.show_help,
                             'history': self.show_help,
                             'more': self.show_more,
                             'quit': sys.exit,
                             'exit': sys.exit,
                             'save': self.save_json_to_file}
        self.cli_cmd = self.cli_cmd_func.keys()

        self.raw_words_db = self._parse_api_name(inventory.api_names)
        self.words_db = list(self.raw_words_db)
        self.words_db.extend(self.cli_cmd)
        self.words = list(self.words_db)
        self.is_cmd = False
        self.curr_pattern = None
        self.matching_words = None
        self.api_class_params = {}
        self.build_api_parameters()
        self.api = None
        self.account_name = None
        self.user_name = None
        self.session_uuid = None
        if os.path.exists(SESSION_FILE):
            session_file_reader = open(SESSION_FILE, 'r')
            self.session_uuid = session_file_reader.readline().rstrip()
            try:
                self.account_name = session_file_reader.readline().rstrip()
                self.user_name = session_file_reader.readline().rstrip()
            except EOFError:
                pass

        self.hostname = options.host
        self.port = options.port
        self.no_secure = options.no_secure
        self.api = api.Api(host=self.hostname, port=self.port)
Ejemplo n.º 2
0
def async_call(http_server_ip, apicmd, session_uuid):
    api_instance = api.Api(host = http_server_ip, port = '8080')
    api_instance.set_session_to_api_message(apicmd, session_uuid)
    (name, event) = api_instance.async_call_wait_for_complete(apicmd)
    if not event.success: raise api.ApiError("Async call at %s: [%s] meets error: %s." % (http_server_ip, apicmd.__class__.__name__, api.error_code_to_string(reply.error)))
    print("[Async call at %s]: [%s] Success" % (http_server_ip, apicmd.__class__.__name__))
    return event
Ejemplo n.º 3
0
def sync_call(http_server_ip, apicmd, session_uuid):
    api_instance = api.Api(host = http_server_ip, port = '8080')
    if session_uuid:
        api_instance.set_session_to_api_message(apicmd, session_uuid)
    (name, reply) = api_instance.sync_call(apicmd)
    if not reply.success: raise api.ApiError("Sync call at %s: [%s] meets error: %s." % (http_server_ip, apicmd.__class__.__name__, api.error_code_to_string(reply.error)))
    print("[Sync call at %s]: [%s] Success" % (http_server_ip, apicmd.__class__.__name__))
    return reply
Ejemplo n.º 4
0
def is_management_node_ready(node_uuid):
    try:
        apicmd = inventory.APIIsReadyToGoMsg()
        api_client = api.Api(
            host=os.environ.get('ZSTACK_BUILT_IN_HTTP_SERVER_IP'))
        api_client.managementNodeId = node_uuid
        (name, event) = api_client.async_call_wait_for_complete(
            apicmd, exception_on_error=False, interval=1000)
        if not event.success:
            print('management node is still not ready ...')
        else:
            print('management node is ready !')

        return event.success
    except socket.error as e:
        print('%s, tomcat is still starting ... ' % str(e))
        return False
Ejemplo n.º 5
0
 def test_login(self):
     binding = api.Api(os.path.abspath('test/jsontemplates'))
     session = binding.login_as_admin()
     print session
Ejemplo n.º 6
0
def _sync_api_call(action):
    api_client = api.Api()
    session_uuid = api_client.login_as_admin()
    api_client.set_session_to_api_message(action, session_uuid)
    return api_client.sync_call(action)
Ejemplo n.º 7
0
def _async_api_call(action):
    api_client = api.Api()
    session_uuid = api_client.login_as_admin()
    api_client.set_session_to_api_message(action, session_uuid)
    return api_client.async_call_wait_for_complete(action)