コード例 #1
0
    def while_waiting(self):
        """ Update fields periodically if nothing is happening """
        # give a little extra time for file descriptors to close
        time.sleep(0.1)

        self.addfield.value = Timestamp()
        self.addfield.display()
        self.addfield2.value = Uptime()
        self.addfield2.display()
        self.addfield3.value = str(len(Containers())) + ' running'
        if len(Containers()) > 0:
            self.addfield3.labelColor = 'GOOD'
        else:
            self.addfield3.labelColor = 'DEFAULT'
        self.addfield3.display()

        # if file drop location changes deal with it
        logger = Logger(__name__)
        if self.file_drop.value != DropLocation()[1]:
            logger.info('Starting: file drop restart')
            try:
                self.file_drop.value = DropLocation()[1]
                logger.info('Path given: ' + str(self.file_drop.value))
            except Exception as e:  # pragma no cover
                logger.error('file drop restart failed with error: ' + str(e))
            logger.info('Finished: file drop restart')
        self.file_drop.display()
        return
コード例 #2
0
 def set_instances(template, section, built, image_id=None):
     """ Set build information for multiple instances """
     i = 2
     while True:
         addtl_section = section.rsplit(':', 2)
         addtl_section[0] += str(i)
         addtl_section = ':'.join(addtl_section)
         if template.section(addtl_section)[0]:
             template.set_option(addtl_section, 'built', built)
             if image_id:
                 template.set_option(addtl_section, 'image_id',
                                     image_id)
             template.set_option(addtl_section, 'last_updated',
                                 Timestamp())
         else:
             break
         i += 1
コード例 #3
0
ファイル: plugins.py プロジェクト: NikolaJankovic/vent
 def set_instances(template, section, built, image_id=None):
     """ Set build information for multiple instances """
     self.logger.info("entering set_instances")
     i = 2
     while True:
         addtl_section = section.rsplit(':', 2)
         addtl_section[0] += str(i)
         addtl_section = ':'.join(addtl_section)
         self.logger.info(addtl_section)
         if template.section(addtl_section)[0]:
             template.set_option(addtl_section, "built", built)
             if image_id:
                 template.set_option(addtl_section, "image_id",
                                     image_id)
             template.set_option(addtl_section, "last_updated",
                                 Timestamp())
         else:
             break
         i += 1
コード例 #4
0
ファイル: system.py プロジェクト: swipswaps/vent
    def backup(self):
        """
        Saves the configuration information of the current running vent
        instance to be used for restoring at a later time
        """
        status = (True, None)
        # initialize all needed variables (names for backup files, etc.)
        backup_name = ('.vent-backup-' + '-'.join(Timestamp().split(' ')))
        backup_dir = join(expanduser('~'), backup_name)
        backup_manifest = join(backup_dir, 'backup_manifest.cfg')
        backup_vcfg = join(backup_dir, 'backup_vcfg.cfg')
        manifest = self.manifest

        # create new backup directory
        try:
            mkdir(backup_dir)
        except Exception as e:  # pragma: no cover
            self.logger.error(str(e))
            return (False, str(e))
        # create new files in backup directory
        try:
            # backup manifest
            with open(backup_manifest, 'w') as bmanifest:
                with open(manifest, 'r') as manifest_file:
                    bmanifest.write(manifest_file.read())
            # backup vent.cfg
            with open(backup_vcfg, 'w') as bvcfg:
                with open(self.vent_config, 'r') as vcfg_file:
                    bvcfg.write(vcfg_file.read())
            self.logger.info('Backup information written to ' + backup_dir)
            status = (True, backup_dir)
        except Exception as e:  # pragma: no cover
            self.logger.error("Couldn't backup vent: " + str(e))
            status = (False, str(e))
        # TODO #266
        return status
コード例 #5
0
def test_timestamp():
    """ Test the timestamp function """
    timestamp = Timestamp()
    assert isinstance(timestamp, str)
コード例 #6
0
ファイル: main.py プロジェクト: rubiruchi/vent
    def while_waiting(self):
        """ Update fields periodically if nothing is happening """
        # give a little extra time for file descriptors to close
        time.sleep(0.1)

        self.addfield.value = Timestamp()
        self.addfield.display()
        self.addfield2.value = Uptime()
        self.addfield2.display()
        self.addfield3.value = str(len(Containers())) + ' running'
        if len(Containers()) > 0:
            self.addfield3.labelColor = 'GOOD'
        else:
            self.addfield3.labelColor = 'DEFAULT'
        self.addfield3.display()

        # update core tool status
        self.addfield5.value, values = MainForm.t_status(True)
        if values[0] + values[1] == 0:
            color = 'DANGER'
            self.addfield4.labelColor = 'CAUTION'
            self.addfield4.value = 'Idle'
        elif values[0] >= int(values[2]):
            color = 'GOOD'
            self.addfield4.labelColor = color
            self.addfield4.value = 'Ready to start jobs'
        else:
            color = 'CAUTION'
            self.addfield4.labelColor = color
            self.addfield4.value = 'Ready to start jobs'
        self.addfield5.labelColor = color

        # update plugin tool status
        plugin_str, values = MainForm.t_status(False)
        plugin_str += ', ' + str(values[3]) + ' plugin(s) installed'
        self.addfield6.value = plugin_str

        # get jobs
        jobs = Jobs()

        # number of jobs, number of tool containers
        self.addfield7.value = str(jobs[0]) + ' jobs running (' + str(jobs[1])
        self.addfield7.value += ' tool containers), ' + str(jobs[2])
        self.addfield7.value += ' completed jobs'

        if jobs[0] > 0:
            self.addfield4.labelColor = 'GOOD'
            self.addfield4.value = 'Processing jobs'
            self.addfield7.labelColor = 'GOOD'
        else:
            self.addfield7.labelColor = 'DEFAULT'
        self.addfield4.display()
        self.addfield5.display()
        self.addfield6.display()
        self.addfield7.display()

        # if file drop location changes deal with it
        logger = Logger(__name__)
        status = (False, None)
        if self.file_drop.value != DropLocation()[1]:
            logger.info('Starting: file drop restart')
            try:
                self.file_drop.value = DropLocation()[1]
                logger.info('Path given: ' + str(self.file_drop.value))
                # restart if the path is valid
                if DropLocation()[0]:
                    status = self.api_action.clean(name='file_drop')
                    status = self.api_action.prep_start(name='file_drop')
                else:
                    logger.error('file drop path name invalid' +
                                 DropLocation()[1])
                if status[0]:
                    tool_d = status[1]
                    status = self.api_action.start(tool_d)
                    logger.info('Status of file drop restart: ' +
                                str(status[0]))
            except Exception as e:  # pragma no cover
                logger.error('file drop restart failed with error: ' + str(e))
            logger.info('Finished: file drop restart')
        self.file_drop.display()
        return
コード例 #7
0
ファイル: main.py プロジェクト: rubiruchi/vent
    def create(self):
        """ Override method for creating FormBaseNewWithMenu form """
        try:
            self.api_action = Action()

        except DockerException as de:  # pragma: no cover
            notify_confirm(str(de),
                           title='Docker Error',
                           form_color='DANGER',
                           wrap=True)
            MainForm.exit()

        self.add_handlers({'^T': self.help_form, '^Q': MainForm.exit})
        # all forms that can toggle view by group
        self.view_togglable = [
            'inventory', 'remove', 'update', 'enable', 'disable', 'build'
        ]

        #######################
        # MAIN SCREEN WIDGETS #
        #######################

        self.addfield = self.add(npyscreen.TitleFixedText,
                                 name='Date:',
                                 labelColor='DEFAULT',
                                 value=Timestamp())
        self.addfield2 = self.add(npyscreen.TitleFixedText,
                                  name='Uptime:',
                                  labelColor='DEFAULT',
                                  value=Uptime())
        self.cpufield = self.add(npyscreen.TitleFixedText,
                                 name='Logical CPUs:',
                                 labelColor='DEFAULT',
                                 value=Cpu())
        self.gpufield = self.add(npyscreen.TitleFixedText,
                                 name='GPUs:',
                                 labelColor='DEFAULT',
                                 value=Gpu()[1])
        self.location = self.add(npyscreen.TitleFixedText,
                                 name='User Data:',
                                 value=PathDirs().meta_dir,
                                 labelColor='DEFAULT')
        self.file_drop = self.add(npyscreen.TitleFixedText,
                                  name='File Drop:',
                                  value=DropLocation()[1],
                                  labelColor='DEFAULT')
        self.addfield3 = self.add(npyscreen.TitleFixedText,
                                  name='Containers:',
                                  labelColor='DEFAULT',
                                  value='0 ' + ' running')
        self.addfield4 = self.add(npyscreen.TitleFixedText,
                                  name='Status:',
                                  labelColor='CAUTION',
                                  value='Idle')
        self.addfield5 = self.add(npyscreen.TitleFixedText,
                                  name='Core Tools:',
                                  labelColor='DANGER',
                                  value='Not built')
        self.addfield6 = self.add(npyscreen.TitleFixedText,
                                  name='Plugin Tools:',
                                  labelColor='DEFAULT',
                                  value='Not built')
        self.addfield7 = self.add(npyscreen.TitleFixedText,
                                  name='Jobs:',
                                  value='0 jobs running (0 tool containers),'
                                  ' 0 completed jobs',
                                  labelColor='DEFAULT')
        self.multifield1 = self.add(npyscreen.MultiLineEdit,
                                    max_height=22,
                                    editable=False,
                                    value="""

            '.,
              'b      *
               '$    #.
                $:   #:
                *#  @):
                :@,@):   ,.**:'
      ,         :@@*: ..**'
       '#o.    .:(@'.@*"'
          'bq,..:,@@*'   ,*
          ,p$q8,:@)'  .p*'
         '    '@@Pp@@*'
               Y7'.'
              :@):.
             .:@:'.
           .::(@:.
                       _
      __   _____ _ __ | |_
      \ \ / / _ \ '_ \| __|
       \ V /  __/ | | | |_
        \_/ \___|_| |_|\__|
                           """)

        ################
        # MENU OPTIONS #
        ################

        # Core Tools Menu Items
        self.m2 = self.add_menu(name='Core Tools', shortcut='c')
        self.m2.addItem(text='Add all latest core tools',
                        onSelect=MainForm.core_tools,
                        arguments=['install'],
                        shortcut='i')
        self.m2.addItem(text='Build core tools',
                        onSelect=self.perform_action,
                        arguments=['build_core'],
                        shortcut='b')
        self.m2.addItem(text='Clean core tools',
                        onSelect=self.perform_action,
                        arguments=['clean_core'],
                        shortcut='c')
        self.m2.addItem(text='Configure core tools',
                        onSelect=self.perform_action,
                        arguments=['configure_core'],
                        shortcut='t')
        self.m2.addItem(text='Disable core tools',
                        onSelect=self.perform_action,
                        arguments=['disable_core'],
                        shortcut='d')
        self.m2.addItem(text='Enable core tools',
                        onSelect=self.perform_action,
                        arguments=['enable_core'],
                        shortcut='e')
        self.m2.addItem(text='Inventory of core tools',
                        onSelect=self.perform_action,
                        arguments=['inventory_core'],
                        shortcut='v')
        self.m2.addItem(text='Remove core tools',
                        onSelect=self.perform_action,
                        arguments=['remove_core'],
                        shortcut='r')
        self.m2.addItem(text='Start core tools',
                        onSelect=self.perform_action,
                        arguments=['start_core'],
                        shortcut='s')
        self.m2.addItem(text='Stop core tools',
                        onSelect=self.perform_action,
                        arguments=['stop_core'],
                        shortcut='p')
        self.m2.addItem(text='Update core tools',
                        onSelect=self.perform_action,
                        arguments=['update_core'],
                        shortcut='u')

        # Plugin Menu Items
        self.m3 = self.add_menu(name='Plugins', shortcut='p')
        self.m3.addItem(text='Add new plugin',
                        onSelect=self.perform_action,
                        arguments=['add'],
                        shortcut='a')
        self.m3.addItem(text='Build plugin tools',
                        onSelect=self.perform_action,
                        arguments=['build'],
                        shortcut='b')
        self.m3.addItem(text='Clean plugin tools',
                        onSelect=self.perform_action,
                        arguments=['clean'],
                        shortcut='c')
        self.m3.addItem(text='Configure plugin tools',
                        onSelect=self.perform_action,
                        arguments=['configure'],
                        shortcut='t')
        self.m3.addItem(text='Disable plugin tools',
                        onSelect=self.perform_action,
                        arguments=['disable'],
                        shortcut='d')
        self.m3.addItem(text='Enable plugin tools',
                        onSelect=self.perform_action,
                        arguments=['enable'],
                        shortcut='e')
        self.m3.addItem(text='Inventory of installed plugins',
                        onSelect=self.perform_action,
                        arguments=['inventory'],
                        shortcut='i')
        self.m3.addItem(text='Remove plugins',
                        onSelect=self.perform_action,
                        arguments=['remove'],
                        shortcut='r')
        self.m3.addItem(text='Start plugin tools',
                        onSelect=self.perform_action,
                        arguments=['start'],
                        shortcut='s')
        self.m3.addItem(text='Stop plugin tools',
                        onSelect=self.perform_action,
                        arguments=['stop'],
                        shortcut='p')
        self.m3.addItem(text='Update plugins',
                        onSelect=self.perform_action,
                        arguments=['update'],
                        shortcut='u')

        # Log Menu Items
        self.m4 = self.add_menu(name='Logs', shortcut='l')
        self.m4.addItem(text='Get container logs',
                        arguments=['logs'],
                        onSelect=self.perform_action)

        # Services Menu Items
        self.m5 = self.add_menu(name='Services Running', shortcut='s')
        self.m5.addItem(text='Core Services',
                        onSelect=self.perform_action,
                        arguments=['services_core'],
                        shortcut='c')
        self.m5.addItem(text='External Services',
                        onSelect=self.perform_action,
                        arguments=['services_external'],
                        shortcut='e')
        self.m5.addItem(text='Plugin Services',
                        onSelect=self.perform_action,
                        arguments=['services'],
                        shortcut='p')

        # System Commands Menu Items
        self.m6 = self.add_menu(name='System Commands', shortcut='y')
        self.m6.addItem(text='Backup',
                        onSelect=self.system_commands,
                        arguments=['backup'],
                        shortcut='b')
        self.m6.addItem(text='Change vent configuration',
                        onSelect=self.system_commands,
                        arguments=['configure'],
                        shortcut='c')
        self.m6.addItem(text='Detect GPUs',
                        onSelect=self.system_commands,
                        arguments=['gpu'],
                        shortcut='g')
        self.m6.addItem(text='Enable Swarm Mode (To Be Implemented...)',
                        onSelect=self.system_commands,
                        arguments=['swarm'],
                        shortcut='s')
        self.m6.addItem(text='Factory reset',
                        onSelect=self.system_commands,
                        arguments=['reset'],
                        shortcut='r')
        self.s6 = self.m6.addNewSubmenu(name='Network Tap Interface',
                                        shortcut='n')
        self.m6.addItem(text='Restore',
                        onSelect=self.system_commands,
                        arguments=['restore'],
                        shortcut='t')
        self.m6.addItem(text='Upgrade (To Be Implemented...)',
                        onSelect=self.system_commands,
                        arguments=['upgrade'],
                        shortcut='u')
        self.s6.addItem(text='Create',
                        onSelect=self.system_commands,
                        shortcut='c',
                        arguments=['ntapcreate'])
        self.s6.addItem(text='Delete',
                        onSelect=self.system_commands,
                        shortcut='d',
                        arguments=['ntapdelete'])
        self.s6.addItem(text='List',
                        onSelect=self.system_commands,
                        shortcut='l',
                        arguments=['ntaplist'])
        self.s6.addItem(text='NICs',
                        onSelect=self.system_commands,
                        shortcut='n',
                        arguments=['ntapnics'])
        self.s6.addItem(text='Start',
                        onSelect=self.system_commands,
                        shortcut='s',
                        arguments=['ntapstart'])
        self.s6.addItem(text='Stop',
                        onSelect=self.system_commands,
                        shortcut='t',
                        arguments=['ntapstop'])

        # Tutorial Menu Items
        self.m7 = self.add_menu(name='Tutorials', shortcut='t')
        self.s1 = self.m7.addNewSubmenu(name='About Vent', shortcut='v')
        self.s1.addItem(text='Background',
                        onSelect=self.switch_tutorial,
                        arguments=['background'],
                        shortcut='b')
        self.s1.addItem(text='Terminology',
                        onSelect=self.switch_tutorial,
                        arguments=['terminology'],
                        shortcut='t')
        self.s1.addItem(text='Getting Setup',
                        onSelect=self.switch_tutorial,
                        arguments=['setup'],
                        shortcut='s')
        self.s2 = self.m7.addNewSubmenu(name='Working with Cores',
                                        shortcut='c')
        self.s2.addItem(text='Building Cores',
                        onSelect=self.switch_tutorial,
                        arguments=['building_cores'],
                        shortcut='b')
        self.s2.addItem(text='Starting Cores',
                        onSelect=self.switch_tutorial,
                        arguments=['starting_cores'],
                        shortcut='c')
        self.s3 = self.m7.addNewSubmenu(name='Working with Plugins',
                                        shortcut='p')
        self.s3.addItem(text='Adding Plugins',
                        onSelect=self.switch_tutorial,
                        arguments=['adding_plugins'],
                        shortcut='a')
        self.s4 = self.m7.addNewSubmenu(name='Files', shortcut='f')
        self.s4.addItem(text='Adding Files',
                        onSelect=self.switch_tutorial,
                        arguments=['adding_files'],
                        shortcut='a')
        self.s5 = self.m7.addNewSubmenu(name='Help', shortcut='s')
        self.s5.addItem(text='Basic Troubleshooting',
                        onSelect=self.switch_tutorial,
                        arguments=['basic_troubleshooting'],
                        shortcut='t')
コード例 #8
0
ファイル: system.py プロジェクト: swipswaps/vent
    def save_configure(self,
                       repo=None,
                       name=None,
                       groups=None,
                       config_val='',
                       from_registry=False,
                       main_cfg=False,
                       instances=1):
        """
        Save changes made to vent.template through npyscreen to the template
        and to plugin_manifest
        """
        def template_to_manifest(vent_template, manifest, tool, instances):
            """
            Helper function to transfer information from vent.template
            to plugin_manifest
            """
            sections = vent_template.sections()
            if sections[0]:
                for section in sections[1]:
                    section_dict = {}
                    if section == 'settings':
                        section_dict.update({'instances': str(instances)})
                    options = vent_template.options(section)
                    if options[0]:
                        for option in options[1]:
                            option_name = option
                            if option == 'name':
                                option_name = 'link_name'
                            opt_val = vent_template.option(section,
                                                           option)[1]
                            section_dict[option_name] = opt_val
                    if section_dict:
                        manifest.set_option(tool, section,
                                            json.dumps(section_dict))
                    elif manifest.option(tool, section)[0]:
                        manifest.del_option(tool, section)

        constraints = locals()
        del constraints['config_val']
        del constraints['from_registry']
        del constraints['main_cfg']
        del constraints['instances']
        del constraints['template_to_manifest']
        status = (True, None)
        fd = None
        # ensure instances is an int and remove instances from config_val to
        # ensure correct info
        instances = int(instances)
        config_val = re.sub(r'instances\ *=\ *\d+\n', '', config_val)
        api_system = System()
        manifest = api_system.manifest
        if not main_cfg:
            if not from_registry:
                # creating new instances
                if instances > 1:
                    fd, template_path = tempfile.mkstemp(suffix='.template')
                    # scrub name for clean section name
                    if re.search(r'\d+$', name):
                        name = re.sub(r'\d+$', '', name)
                    t_identifier = {'name': name,
                                    'branch': branch,
                                    'version': version}
                    result = Template(manifest).constrain_opts(
                        t_identifier, [])
                    tools = result[0]
                    tool = list(tools.keys())[0]
                else:
                    options = ['path', 'multi_tool', 'name']
                    tools, _ = Template(manifest).constrain_opts(
                        constraints, options)
                    # only one tool in tools because perform this function for
                    # every tool
                    if tools:
                        tool = list(tools.keys())[0]
                        if ('multi_tool' in tools[tool] and
                                tools[tool]['multi_tool'] == 'yes'):
                            name = tools[tool]['name']
                            if name == 'unspecified':
                                name = 'vent'
                            template_path = join(tools[tool]['path'],
                                                 name+'.template')
                        else:
                            template_path = join(tools[tool]['path'],
                                                 'vent.template')
                    else:
                        status = (False, "Couldn't save configuration")
            else:
                fd, template_path = tempfile.mkstemp(suffix='.template')
                options = ['namespace']
                constraints.update({'type': 'registry'})
                tools, _ = Template(manifest).constrain_opts(constraints,
                                                             options)
                if tools:
                    tool = list(tools.keys())[0]
                else:
                    status = (False, "Couldn't save configuration")
            if status[0]:
                try:
                    # save in vent.template
                    with open(template_path, 'w') as f:
                        f.write(config_val)
                    # save in plugin_manifest
                    vent_template = Template(template_path)
                    manifest = Template(manifest)
                    if instances > 1:
                        # add instances as needed
                        for i in range(1, instances + 1):
                            i_section = tool.rsplit(':', 2)
                            i_section[0] += str(i) if i != 1 else ''
                            i_section = ':'.join(i_section)
                            if not manifest.section(i_section)[0]:
                                manifest.add_section(i_section)
                                for val_pair in manifest.section(tool)[1]:
                                    name = val_pair[0]
                                    val = val_pair[1]
                                    if name == 'name':
                                        val += str(i)
                                    elif name == 'last_updated':
                                        val = Timestamp()
                                    elif name == 'running':
                                        val = 'no'
                                    manifest.set_option(i_section, name, val)
                                template_to_manifest(vent_template, manifest,
                                                     i_section, instances)
                            else:
                                settings = manifest.option(i_section,
                                                           'settings')
                                if settings[0]:
                                    settings_dict = json.loads(settings[1])
                                    settings_dict['instances'] = str(instances)
                                    manifest.set_option(i_section, 'settings',
                                                        json.dumps(
                                                            settings_dict))
                                else:
                                    inst = str(instances)
                                    settings_dict = {'instances': inst}
                                    manifest.set_option(i_section, 'settings',
                                                        json.dumps(
                                                            settings_dict))
                    else:
                        try:
                            settings_str = manifest.option(tool, 'settings')[1]
                            settings_dict = json.loads(settings_str)
                            old_instances = int(settings_dict['instances'])
                        except Exception:
                            old_instances = 1
                        template_to_manifest(vent_template, manifest,
                                             tool, old_instances)
                    manifest.write_config()
                    status = (True, manifest)
                except Exception as e:  # pragma: no cover
                    self.logger.error('save_configure error: ' + str(e))
                    status = (False, str(e))
            # close os file handle and remove temp file
            if from_registry or instances > 1:
                try:
                    close(fd)
                    remove(template_path)
                except Exception as e:  # pragma: no cover
                    self.logger.error('save_configure error: ' + str(e))
        else:
            with open(self.vent_config, 'w') as f:
                f.write(config_val)
        return status
コード例 #9
0
def test_timestamp():
    """ Test the timestamp function """
    timestamp = Timestamp()
    assert type(timestamp) == str
コード例 #10
0
    def create(self):
        """ Override method for creating FormBaseNewWithMenu form """
        try:
            self.api_action = System()
        except DockerException as de:  # pragma: no cover
            notify_confirm(str(de),
                           title='Docker Error',
                           form_color='DANGER',
                           wrap=True)
            MainForm.exit()

        self.add_handlers({'^T': self.help_form, '^Q': MainForm.exit})
        # all forms that can toggle view by group
        self.view_togglable = ['inventory', 'remove']

        #######################
        # MAIN SCREEN WIDGETS #
        #######################

        self.addfield = self.add(npyscreen.TitleFixedText,
                                 name='Date:',
                                 labelColor='DEFAULT',
                                 value=Timestamp())
        self.addfield2 = self.add(npyscreen.TitleFixedText,
                                  name='Uptime:',
                                  labelColor='DEFAULT',
                                  value=Uptime())
        self.cpufield = self.add(npyscreen.TitleFixedText,
                                 name='Logical CPUs:',
                                 labelColor='DEFAULT',
                                 value=Cpu())
        self.gpufield = self.add(npyscreen.TitleFixedText,
                                 name='GPUs:',
                                 labelColor='DEFAULT',
                                 value=Gpu()[1])
        self.location = self.add(npyscreen.TitleFixedText,
                                 name='User Data:',
                                 value=PathDirs().meta_dir,
                                 labelColor='DEFAULT')
        self.file_drop = self.add(npyscreen.TitleFixedText,
                                  name='File Drop:',
                                  value=DropLocation()[1],
                                  labelColor='DEFAULT')
        self.addfield3 = self.add(npyscreen.TitleFixedText,
                                  name='Containers:',
                                  labelColor='DEFAULT',
                                  value='0 ' + ' running')
        self.multifield1 = self.add(npyscreen.MultiLineEdit,
                                    max_height=22,
                                    editable=False,
                                    value="""

            '.,
              'b      *
               '$    #.
                $:   #:
                *#  @):
                :@,@):   ,.**:'
      ,         :@@*: ..**'
       '#o.    .:(@'.@*"'
          'bq,..:,@@*'   ,*
          ,p$q8,:@)'  .p*'
         '    '@@Pp@@*'
               Y7'.'
              :@):.
             .:@:'.
           .::(@:.
                       _
      __   _____ _ __ | |_
      \ \ / / _ \ '_ \| __|
       \ V /  __/ | | | |_
        \_/ \___|_| |_|\__|
                           """)

        ################
        # MENU OPTIONS #
        ################

        # Tool Menu Items
        self.m3 = self.add_menu(name='Tools', shortcut='p')
        self.m3.addItem(text='Add New Tool',
                        onSelect=self.perform_action,
                        arguments=['add'],
                        shortcut='a')
        self.m3.addItem(text='Configure Tools',
                        onSelect=self.perform_action,
                        arguments=['configure'],
                        shortcut='t')
        self.m3.addItem(text='Inventory',
                        onSelect=self.perform_action,
                        arguments=['inventory'],
                        shortcut='i')
        self.m3.addItem(text='Remove Tools',
                        onSelect=self.perform_action,
                        arguments=['remove'],
                        shortcut='r')
        self.m3.addItem(text='Start Tools',
                        onSelect=self.perform_action,
                        arguments=['start'],
                        shortcut='s')
        self.m3.addItem(text='Stop Tools',
                        onSelect=self.perform_action,
                        arguments=['stop'],
                        shortcut='p')

        # Services Menu Items
        self.m5 = self.add_menu(name='Services Running', shortcut='s')
        self.m5.addItem(text='External Services',
                        onSelect=self.perform_action,
                        arguments=['services_external'],
                        shortcut='e')
        self.m5.addItem(text='Tool Services',
                        onSelect=self.perform_action,
                        arguments=['services'],
                        shortcut='t')

        # System Commands Menu Items
        self.m6 = self.add_menu(name='System Commands', shortcut='y')
        self.m6.addItem(text='Backup',
                        onSelect=self.system_commands,
                        arguments=['backup'],
                        shortcut='b')
        self.m6.addItem(text='Change Vent Configuration',
                        onSelect=self.system_commands,
                        arguments=['configure'],
                        shortcut='c')
        self.m6.addItem(text='Detect GPUs',
                        onSelect=self.system_commands,
                        arguments=['gpu'],
                        shortcut='g')
        self.m6.addItem(text='Factory Reset',
                        onSelect=self.system_commands,
                        arguments=['reset'],
                        shortcut='r')
        self.m6.addItem(text='Restore (To Be Implemented...',
                        onSelect=self.system_commands,
                        arguments=['restore'],
                        shortcut='t')

        # TODO this should be either or depending on whether or not it's running already
        self.m6.addItem(text='Start',
                        onSelect=self.system_commands,
                        arguments=['start'],
                        shortcut='s')
        self.m6.addItem(text='Stop',
                        onSelect=self.system_commands,
                        arguments=['stop'],
                        shortcut='o')

        self.m6.addItem(text='Upgrade (To Be Implemented...)',
                        onSelect=self.system_commands,
                        arguments=['upgrade'],
                        shortcut='u')

        # Tutorial Menu Items
        self.m7 = self.add_menu(name='Tutorials', shortcut='t')
        self.s1 = self.m7.addNewSubmenu(name='About Vent', shortcut='v')
        self.s1.addItem(text='Background',
                        onSelect=self.switch_tutorial,
                        arguments=['background'],
                        shortcut='b')
        self.s1.addItem(text='Terminology',
                        onSelect=self.switch_tutorial,
                        arguments=['terminology'],
                        shortcut='t')
        self.s1.addItem(text='Getting Setup',
                        onSelect=self.switch_tutorial,
                        arguments=['setup'],
                        shortcut='s')
        self.s2 = self.m7.addNewSubmenu(name='Working with Tools',
                                        shortcut='c')
        self.s2.addItem(text='Starting Tools',
                        onSelect=self.switch_tutorial,
                        arguments=['starting_tools'],
                        shortcut='s')
        self.s3 = self.m7.addNewSubmenu(name='Working with Plugins',
                                        shortcut='p')
        self.s3.addItem(text='Adding Tools',
                        onSelect=self.switch_tutorial,
                        arguments=['adding_tools'],
                        shortcut='a')
        self.s4 = self.m7.addNewSubmenu(name='Files', shortcut='f')
        self.s4.addItem(text='Adding Files',
                        onSelect=self.switch_tutorial,
                        arguments=['adding_files'],
                        shortcut='a')
        self.s5 = self.m7.addNewSubmenu(name='Help', shortcut='s')
        self.s5.addItem(text='Basic Troubleshooting',
                        onSelect=self.switch_tutorial,
                        arguments=['basic_troubleshooting'],
                        shortcut='t')
コード例 #11
0
ファイル: main.py プロジェクト: cprafullchandra/vent
    def while_waiting(self):
        """ Update fields periodically if nothing is happening """
        def popup(message):
            npyscreen.notify_confirm(str(message),
                                     title="Docker Error",
                                     form_color='DANGER',
                                     wrap=True)
            self.exit()

        # clean up forms with dynamic data
        self.parentApp.remove_forms()
        self.parentApp.add_forms()

        if not self.triggered:
            self.triggered = True
            try:
                self.api_action = Action()
            except DockerException as de:  # pragma: no cover
                popup(de)

        # give a little extra time for file descriptors to close
        time.sleep(0.1)

        try:
            current_path = os.getcwd()
        except Exception as e:  # pragma: no cover
            self.exit()
        self.addfield.value = Timestamp()
        self.addfield.display()
        self.addfield2.value = Uptime()
        self.addfield2.display()
        self.addfield3.value = str(len(Containers())) + " running"
        if len(Containers()) > 0:
            self.addfield3.labelColor = "GOOD"
        else:
            self.addfield3.labelColor = "DEFAULT"
        self.addfield3.display()

        # set core value string
        core = Core()
        installed = 0
        custom_installed = 0
        built = 0
        custom_built = 0
        running = 0
        custom_running = 0
        normal = str(len(core['normal']))
        for tool in core['running']:
            if tool in core['normal']:
                running += 1
            else:
                custom_running += 1
        for tool in core['built']:
            if tool in core['normal']:
                built += 1
            else:
                custom_built += 1
        for tool in core['installed']:
            if tool in core['normal']:
                installed += 1
            else:
                custom_installed += 1
        core_str = str(running + custom_running) + "/" + normal + " running"
        if custom_running > 0:
            core_str += " (" + str(custom_running) + " custom)"
        core_str += ", " + str(built + custom_built) + "/" + normal + " built"
        if custom_built > 0:
            core_str += " (" + str(custom_built) + " custom)"
        core_str += ", " + str(installed +
                               custom_installed) + "/" + normal + " installed"
        if custom_built > 0:
            core_str += " (" + str(custom_installed) + " custom)"
        self.addfield5.value = core_str
        if running + custom_running == 0:
            color = "DANGER"
            self.addfield4.labelColor = "CAUTION"
            self.addfield4.value = "Idle"
        elif running >= int(normal):
            color = "GOOD"
            self.addfield4.labelColor = color
            self.addfield4.value = "Ready to start jobs"
        else:
            color = "CAUTION"
            self.addfield4.labelColor = color
            self.addfield4.value = "Ready to start jobs"
        self.addfield5.labelColor = color

        # get jobs
        jobs = Jobs()
        # number of jobs, number of tool containers
        self.addfield6.value = str(jobs[0]) + " jobs running (" + str(
            jobs[1]) + " tool containers), " + str(jobs[2]) + " completed jobs"

        # TODO check if there are jobs running and update addfield4
        if jobs[0] > 0:
            self.addfield4.labelColor = "GOOD"
            self.addfield4.value = "Processing jobs"
            self.addfield6.labelColor = "GOOD"
        else:
            self.addfield6.labelColor = "DEFAULT"
        self.addfield4.display()
        self.addfield5.display()
        self.addfield6.display()

        os.chdir(current_path)
        return
コード例 #12
0
ファイル: main.py プロジェクト: cprafullchandra/vent
    def create(self):
        """ Override method for creating FormBaseNewWithMenu form """
        self.add_handlers({"^T": self.change_forms, "^Q": self.exit})

        #######################
        # MAIN SCREEN WIDGETS #
        #######################

        self.addfield = self.add(npyscreen.TitleFixedText,
                                 name='Date:',
                                 labelColor='DEFAULT',
                                 value=Timestamp())
        self.addfield2 = self.add(npyscreen.TitleFixedText,
                                  name='Uptime:',
                                  labelColor='DEFAULT',
                                  value=Uptime())
        self.cpufield = self.add(npyscreen.TitleFixedText,
                                 name='Logical CPUs:',
                                 labelColor='DEFAULT',
                                 value=Cpu())
        self.gpufield = self.add(npyscreen.TitleFixedText,
                                 name='GPUs:',
                                 labelColor='DEFAULT',
                                 value=Gpu())
        self.addfield3 = self.add(npyscreen.TitleFixedText,
                                  name='Containers:',
                                  labelColor='DEFAULT',
                                  value="0 " + " running")
        self.addfield4 = self.add(npyscreen.TitleFixedText,
                                  name='Status:',
                                  labelColor='CAUTION',
                                  value="Idle")
        self.addfield5 = self.add(npyscreen.TitleFixedText,
                                  name='Core Tools:',
                                  labelColor='DANGER',
                                  value="Not built")
        self.addfield6 = self.add(
            npyscreen.TitleFixedText,
            name='Jobs:',
            value="0 jobs running (0 tool containers), 0 completed jobs",
            labelColor='DEFAULT')
        self.multifield1 = self.add(npyscreen.MultiLineEdit,
                                    max_height=22,
                                    editable=False,
                                    value="""

            '.,
              'b      *
               '$    #.
                $:   #:
                *#  @):
                :@,@):   ,.**:'
      ,         :@@*: ..**'
       '#o.    .:(@'.@*"'
          'bq,..:,@@*'   ,*
          ,p$q8,:@)'  .p*'
         '    '@@Pp@@*'
               Y7'.'
              :@):.
             .:@:'.
           .::(@:.
                       _
      __   _____ _ __ | |_
      \ \ / / _ \ '_ \| __|
       \ V /  __/ | | | |_
        \_/ \___|_| |_|\__|
                           """)

        ################
        # MENU OPTIONS #
        ################

        # Core Tools Menu Items
        self.m2 = self.add_menu(name="Core Tools", shortcut="c")
        self.m2.addItem(text='Add all latest core tools',
                        onSelect=self.core_tools,
                        arguments=['install'],
                        shortcut='i')
        self.m2.addItem(text='Build core tools',
                        onSelect=self.core_tools,
                        arguments=['build'],
                        shortcut='b')
        self.m2.addItem(text='Clean core tools',
                        onSelect=self.core_tools,
                        arguments=['clean'],
                        shortcut='c')
        self.m2.addItem(text='Inventory of core tools',
                        onSelect=self.core_tools,
                        arguments=['inventory'],
                        shortcut='v')
        self.m2.addItem(text='Remove core tools',
                        onSelect=self.core_tools,
                        arguments=['remove'],
                        shortcut='r')
        self.m2.addItem(text='Start core tools',
                        onSelect=self.core_tools,
                        arguments=['start'],
                        shortcut='s')
        self.m2.addItem(text='Stop core tools',
                        onSelect=self.core_tools,
                        arguments=['stop'],
                        shortcut='p')
        self.m2.addItem(text='Update core tools',
                        onSelect=self.core_tools,
                        arguments=['update'],
                        shortcut='u')

        # Plugin Menu Items
        self.m3 = self.add_menu(name="Plugins", shortcut="p")
        self.m3.addItem(text='Add new plugin',
                        onSelect=self.perform_action,
                        arguments=['add'],
                        shortcut='a')
        self.m3.addItem(text='Build plugin tools',
                        onSelect=self.perform_action,
                        arguments=['build'],
                        shortcut='b')
        self.m3.addItem(text='Clean plugin tools',
                        onSelect=self.perform_action,
                        arguments=['clean'],
                        shortcut='c')
        self.m3.addItem(text='Inventory of installed plugins',
                        onSelect=self.perform_action,
                        arguments=['inventory'],
                        shortcut='i')
        self.m3.addItem(text='Remove plugins',
                        onSelect=self.perform_action,
                        arguments=['remove'],
                        shortcut='r')
        self.m3.addItem(text='Start plugin tools',
                        onSelect=self.perform_action,
                        arguments=['start'],
                        shortcut='s')
        self.m3.addItem(text='Stop plugin tools',
                        onSelect=self.perform_action,
                        arguments=['stop'],
                        shortcut='p')
        self.m3.addItem(text='Update plugins',
                        onSelect=self.perform_action,
                        arguments=['update'],
                        shortcut='u')

        # Log Menu Items
        self.m4 = self.add_menu(name="Logs", shortcut="l")
        self.m4.addItem(text='Get container logs',
                        arguments=[],
                        onSelect=self.logs_form)

        # Services Menu Items
        self.m5 = self.add_menu(name="Services Running", shortcut='s')
        self.m5.addItem(text='Core Services',
                        onSelect=self.services_form,
                        arguments=['core'],
                        shortcut='c')
        self.m5.addItem(text='Plugin Services (To be implemented...)',
                        onSelect=self.services_form,
                        arguments=['plugins'],
                        shortcut='p')

        # System Commands Menu Items
        self.m6 = self.add_menu(name="System Commands")
        self.m6.addItem(text='Factory reset',
                        onSelect=self.system_commands,
                        arguments=['reset'],
                        shortcut='r')
        self.m6.addItem(text='Upgrade (To Be Implemented...)',
                        onSelect=self.system_commands,
                        arguments=['upgrade'],
                        shortcut='u')

        # Tutorial Menu Items
        self.m7 = self.add_menu(name="Tutorials", shortcut="t")
        self.s1 = self.m7.addNewSubmenu(name="About Vent", shortcut='v')
        self.s1.addItem(text="Background",
                        onSelect=self.perform_action,
                        arguments=['background'],
                        shortcut='b')
        self.s1.addItem(text="Terminology",
                        onSelect=self.perform_action,
                        arguments=['terminology'],
                        shortcut='t')
        self.s1.addItem(text="Getting Setup",
                        onSelect=self.perform_action,
                        arguments=['setup'],
                        shortcut='s')
        self.s2 = self.m7.addNewSubmenu(name="Working with Cores",
                                        shortcut='c')
        self.s2.addItem(text="Building Cores",
                        onSelect=self.perform_action,
                        arguments=['building_cores'],
                        shortcut='b')
        self.s2.addItem(text="Starting Cores",
                        onSelect=self.perform_action,
                        arguments=['starting_cores'],
                        shortcut='c')
        self.s3 = self.m7.addNewSubmenu(name="Working with Plugins",
                                        shortcut='p')
        self.s3.addItem(text="Adding Plugins",
                        onSelect=self.perform_action,
                        arguments=['adding_plugins'],
                        shortcut='a')
        self.s4 = self.m7.addNewSubmenu(name="Files", shortcut='f')
        self.s4.addItem(text="Adding Files",
                        onSelect=self.perform_action,
                        arguments=['adding_files'],
                        shortcut='a')
        self.s5 = self.m7.addNewSubmenu(name="Services", shortcut='s')
        self.s5.addItem(text="Setting up Services",
                        onSelect=self.perform_action,
                        arguments=['setting_up_services'],
                        shortcut='s')