Beispiel #1
0
    def ps(self):
        """ps will print a table of instances, including pids and names.
        """
        instance_names = self.get_instance_names()
        table = []
        for instance in self.client.instances(quiet=True, sudo=self.sudo):
            if instance.name in instance_names:
                image = os.path.basename(instance._image)
                table.append([instance.name.rjust(12), instance.pid, image])

        bot.custom(prefix="INSTANCES ", message="NAME PID     IMAGE", color="CYAN")

        bot.table(table)
Beispiel #2
0
    def logs(self, tail=0):
        '''show logs for an instance'''

        log_folder = self._get_log_folder()

        for ext in ['OUT', 'ERR']:
            logfile = os.path.join(log_folder,
                                   '%s.%s' % (self.name, ext.lower()))

            # Use Try/catch to account for not existing.
            try:
                result = self.client._run_command(['cat', logfile],
                                                  quiet=True,
                                                  sudo=self.sudo)
                if result:
                    # If the user only wants to see certain number
                    if tail > 0:
                        result = '\n'.join(result.split('\n')[-tail:])
                    bot.custom(prefix=self.name, message=ext, color='CYAN')
                    print(result)
                    bot.newline()

            except:
                pass
Beispiel #3
0
    def logs(self, tail=0):
        """show logs for an instance"""

        log_folder = self._get_log_folder()

        for ext in ["OUT", "ERR"]:
            logfile = os.path.join(log_folder,
                                   "%s.%s" % (self.name, ext.lower()))

            # Use Try/catch to account for not existing.
            try:
                result = self.client._run_command(["cat", logfile],
                                                  quiet=True,
                                                  sudo=self.sudo)
                if result:
                    # If the user only wants to see certain number
                    if tail > 0:
                        result = "\n".join(result.split("\n")[-tail:])
                    bot.custom(prefix=self.name, message=ext, color="CYAN")
                    print(result)
                    bot.newline()

            except:
                pass