Esempio n. 1
0
 def do_sync(self, args):
     """
     Asks cloudmonkey to discovery and sync apis available on user specified
     CloudStack host server which has the API discovery plugin, on failure
     it rollbacks last datastore or api precached datastore.
     """
     response = self.make_request("listApis")
     self.apicache = monkeycache(response)
     if response is None:
         monkeyprint("Failed to sync apis, check your config")
         return
     savecache(self.apicache, self.cache_file)
     self.loadcache()
Esempio n. 2
0
    def __init__(self, pname):
        self.program_name = pname
        self.config_options = read_config(self.get_attr, self.set_attr)
        self.loadcache()
        self.prompt = self.prompt.strip() + " "  # Cosmetic fix for prompt

        logging.basicConfig(filename=self.log_file,
                            level=logging.DEBUG, format=log_fmt)
        logger.debug("Loaded config fields:\n%s" % map(lambda x: "%s=%s" %
                                                       (x, getattr(self, x)),
                                                       self.config_options))
        cmd.Cmd.__init__(self)

        try:
            if os.path.exists(self.history_file):
                readline.read_history_file(self.history_file)
            atexit.register(readline.write_history_file, self.history_file)
        except IOError:
            monkeyprint("Error: history support")
 def do_sync(self, args):
     """
     Asks cloudmonkey to discovery and sync apis available on user specified
     CloudStack host server which has the API discovery plugin, on failure
     it rollbacks last datastore or api precached datastore.
     """
     response = self.make_request("listApis")
     if not response:
         monkeyprint("Failed to sync apis, please check your config?")
         monkeyprint("Note: `sync` requires api discovery service enabled" + " on the CloudStack management server")
         return
     self.apicache = monkeycache(response)
     savecache(self.apicache, self.cache_file)
     monkeyprint("%s APIs discovered and cached" % self.apicache["count"])
     self.loadcache()
Esempio n. 4
0
 def do_sync(self, args):
     """
     Asks cloudmonkey to discovery and sync apis available on user specified
     CloudStack host server which has the API discovery plugin, on failure
     it rollbacks last datastore or api precached datastore.
     """
     response = self.make_request("listApis")
     if not response:
         monkeyprint("Failed to sync apis, please check your config?")
         monkeyprint("Note: `sync` requires api discovery service enabled" +
                     " on the CloudStack management server")
         return
     self.apicache = monkeycache(response)
     savecache(self.apicache, self.cache_file)
     monkeyprint("%s APIs discovered and cached" % self.apicache["count"])
     self.loadcache()
Esempio n. 5
0
            grammar_handler.__doc__ = "%ss resources" % verb.capitalize()
            grammar_handler.__name__ = 'do_' + str(verb)
            setattr(self.__class__, grammar_handler.__name__, grammar_handler)

    def monkeyprint(self, *args):
        output = ""
        try:
            for arg in args:
                if isinstance(type(arg), types.NoneType):
                    continue
                output += str(arg)
        except Exception, e:
            print(e)

        if self.color == 'true':
            monkeyprint(output)
        else:
            print(output)

    def print_result(self, result, result_filter=None):
        if result is None or len(result) == 0:
            return

        def printer_helper(printer, toprow):
            if printer:
                self.monkeyprint(printer)
            return PrettyTable(toprow)

        def print_result_tabular(result, result_filter=None):
            toprow = None
            printer = None
Esempio n. 6
0
    def monkeyprint(self, *args):
        output = u""
        try:
            for arg in args:
                if isinstance(type(arg), types.NoneType) or not arg:
                    continue
                if not (isinstance(arg, str) or isinstance(arg, unicode)):
                    arg = unicode(arg)
                output += arg
        except Exception, e:
            print(str(e))

        output = output.encode("utf-8")
        if self.color == 'true':
            monkeyprint(output)
        else:
            if output.startswith("Error"):
                sys.stderr.write(output + "\n")
                sys.stderr.flush()
            else:
                print output

    def print_result(self, result, result_filter=[]):
        if not result or len(result) == 0:
            return

        def printer_helper(printer, toprow):
            if printer:
                self.monkeyprint(printer.get_string())
            return PrettyTable(toprow)
Esempio n. 7
0
 def monkeyprint(self, *args):
     monkeyprint((self.color == 'true'), *args)