Beispiel #1
0
 def create(self):
     """ Override method for creating FormBaseNew form """
     self.add_handlers({"^T": self.quit, "^Q": self.quit})
     self.add(npyscreen.TitleFixedText, name='Logs:', value='')
     msg = 'Checking for container logs, please wait...'
     self.logs_mle = self.add(npyscreen.Pager, values=[msg])
     self.action = Action()
     response = self.action.logs()
     if response[0]:
         value = "Logs for each Vent container found:\n"
         logs = response[1]
         for container in logs:
             value += "\n Container: " + container + "\n"
             for log in logs[container]:
                 value += "    " + log + "\n"
             value += "\n"
         self.logs_mle.values = value.split("\n")
     else:
         msg = "There was an issue retrieving logs for Vent containers: "
         self.logs_mle.values = [
             msg,
             str(response[1]), "Please see vent.log for more details."
         ]
Beispiel #2
0
 def create(self):
     """ Override method for creating FormBaseNew form """
     self.add_handlers({'^T': self.quit, '^Q': self.quit})
     self.add(npyscreen.TitleFixedText, name='Logs:', value='')
     msg = 'Checking for container logs, please wait...'
     self.logs_mle = self.add(npyscreen.Pager, values=[msg])
     self.action = Action()
     response = self.action.logs()
     if response[0]:
         value = 'Logs for each Vent container found:\n'
         logs = response[1]
         for container in logs:
             value += '\n Container: ' + container + '\n'
             for log in logs[container]:
                 value += '    ' + log + '\n'
             value += '\n'
         self.logs_mle.values = value.split('\n')
     else:
         msg = 'There was an issue retrieving logs for Vent containers: '
         self.logs_mle.values = [
             msg,
             str(response[1]), 'Please see vent.log for more details.'
         ]
Beispiel #3
0
 def __init__(self, *args, **keywords):
     """ Initialize tool form objects """
     self.logger = Logger(__name__)
     self.logger.info(str(keywords['names']))
     self.api_action = Action()
     self.m_helper = MenuHelper()
     action = {'api_action': self.api_action}
     self.tools_tc = {}
     self.repo_widgets = {}
     if keywords['action_dict']:
         action.update(keywords['action_dict'])
     if keywords['names']:
         i = 1
         for name in keywords['names']:
             action['action_object' + str(i)] = getattr(
                 self.api_action, name)
             i += 1
     self.action = action
     # get list of all possible group views to display
     self.views = deque()
     possible_groups = set()
     manifest = Template(self.api_action.plugin.manifest)
     if self.action['cores']:
         tools = self.api_action.inventory(choices=['core'])[1]['core']
     else:
         tools = self.api_action.inventory(choices=['tools'])[1]['tools']
     for tool in tools:
         groups = manifest.option(tool, 'groups')[1].split(',')
         for group in groups:
             # don't do core because that's the purpose of all in views
             if group != '' and group != 'core':
                 possible_groups.add(group)
     self.manifest = manifest
     self.views += possible_groups
     self.views.append('all groups')
     self.no_instance = ['build', 'remove']
     super(ToolForm, self).__init__(*args, **keywords)
Beispiel #4
0
def test_file_queue():
    """ Tests simulation of new file """
    path_dirs = PathDirs()
    images = watch.file_queue('/tmp/foo')
    assert not images[0]
    images = watch.file_queue('host_/tmp/foo',
                              template_path=path_dirs.base_dir,
                              r_host="localhost")
    assert isinstance(images, tuple)
    assert images[0]
    assert isinstance(images[1], list)
    instance = Action()
    status = instance.add('https://github.com/cyberreboot/vent-plugins',
                          branch='master',
                          tools=[('gpu_example', '')],
                          build=True)
    assert isinstance(status, tuple)
    assert status[0]
    images = watch.file_queue('host_/tmp/foo.matrix',
                              template_path=path_dirs.base_dir,
                              r_host="localhost")
    assert isinstance(images, tuple)
    assert images[0]
    assert isinstance(images[1], list)
Beispiel #5
0
    def create(self):
        self.add_handlers({'^T': self.quit, '^Q': self.quit})
        self.add(npyscreen.Textfield,
                 value=self.n_action + ' a network tap capture container.',
                 editable=False,
                 color='STANDOUT')
        self.add(npyscreen.Textfield,
                 value='Choose a container to ' + self.n_action,
                 editable=False,
                 color='STANDOUT')

        self.nextrely += 1

        try:
            self.api_action = Action()

            # display all containers by sending a get request to ntap/list
            # nlist returns tuple and get_request returns tuple
            url = self.api_action.get_vent_tool_url('network-tap')[1] + '/list'
            request = self.api_action.get_request(url)

            # create selection for containers
            if request[0]:
                request = ast.literal_eval(str(request[1]))
                data = [d for d in list(request[1])]
                self.ms = self.add(npyscreen.TitleMultiSelect,
                                   max_height=20,
                                   name='Choose one or more containers to ' +
                                   self.n_action,
                                   values=data)

            else:
                npyscreen.notify_confirm('Failure: ' + str(request[1]))

        except Exception as e:  # pragma: no cover
            npyscreen.notify_confirm('Failure: ' + str(e))
Beispiel #6
0
def test_save_configure():
    """ Test the save_configure function """
    instance = Action()
    status = instance.save_configure(name='elasticsearch',
                                     config_val='[info]\ntesting123 = testing123')
    assert isinstance(status, tuple)
    assert status[0]
    template_path = os.path.join(instance.p_helper.path_dirs.plugins_dir,
                                 'cyberreboot', 'vent', 'vent', 'core',
                                 'elasticsearch', 'vent.template')
    with open(template_path) as f:
        assert 'testing123' in f.read()
    with open(instance.p_helper.manifest) as man:
        assert 'testing123' in man.read()

    status = instance.save_configure(name='elasticsearch',
                                     config_val='[docker]\nrandom = instance',
                                     instances=2)
    assert isinstance(status, tuple)
    assert status[0]
    with open(instance.p_helper.manifest) as man:
        man_contents = man.read()
        assert 'random' in man_contents
        assert 'elasticsearch2' in man_contents
def test_clean():
    """ Test the clean function """
    instance = Action()
    status = instance.clean()
    assert type(status) == tuple
Beispiel #8
0
def test_get_configure():
    """ Test the get_configure function """
    instance = Action()
    status = instance.get_configure(name='elasticsearch')
    assert status[0]
    assert 'Elasticsearch' in status[1]
Beispiel #9
0
def test_restore():
    """ Test the restore function """
    instance = Action()
    status = instance.restore('not a backup')
    assert isinstance(status, tuple)
    assert status[0] == False
Beispiel #10
0
def test_reset():
    """ Test the reset function """
    instance = Action()
    status = instance.reset()
    assert isinstance(status, tuple)
    assert status[0]
Beispiel #11
0
    def on_ok(self):
        """ Add the repository """
        def popup(thr, add_type, title):
            """
            Start the thread and display a popup of the plugin being cloned
            until the thread is finished
            """
            thr.start()
            tool_str = 'Cloning repository...'
            if add_type == 'image':
                tool_str = 'Pulling image...'
            npyscreen.notify_wait(tool_str, title=title)
            while thr.is_alive():
                time.sleep(1)
            return

        if self.image.value and self.link_name.value:
            api_action = Action()
            thr = threading.Thread(target=api_action.add_image,
                                   args=(),
                                   kwargs={
                                       'image': self.image.value,
                                       'link_name': self.link_name.value,
                                       'tag': self.tag.value,
                                       'registry': self.registry.value,
                                       'groups': self.groups.value
                                   })
            popup(thr, 'image', 'Please wait, adding image...')
            npyscreen.notify_confirm('Done adding image.', title='Added image')
            editor_args = {
                'tool_name': self.image.value,
                'version': self.tag.value,
                'get_configure': api_action.get_configure,
                'save_configure': api_action.save_configure,
                'restart_tools': api_action.restart_tools,
                'clean': api_action.clean,
                'prep_start': api_action.prep_start,
                'start_tools': api_action.start,
                'from_registry': True,
                'just_downloaded': True,
                'link_name': self.link_name.value,
                'groups': self.groups.value
            }
            self.parentApp.addForm("CONFIGUREIMAGE",
                                   EditorForm,
                                   name="Specify vent.template settings for "
                                   "image pulled (optional)",
                                   **editor_args)
            self.parentApp.change_form("CONFIGUREIMAGE")
        elif self.image.value:
            npyscreen.notify_confirm(
                "A name needs to be supplied for "
                "the image being added!",
                title="Specify a name for the image",
                form_color='CAUTION')
        elif self.repo.value:
            self.parentApp.repo_value['repo'] = self.repo.value.lower()
            p_helper = PluginHelper()
            thr = threading.Thread(target=p_helper.clone,
                                   args=(),
                                   kwargs={
                                       'repo': self.repo.value.lower(),
                                       'user': self.user.value,
                                       'pw': self.pw.value
                                   })
            popup(thr, 'repository', 'Please wait, adding repository...')
            self.parentApp.addForm("ADDOPTIONS",
                                   AddOptionsForm,
                                   name="Set options for new plugin"
                                   "\t\t\t\t\t\t^Q to quit",
                                   color="CONTROL")
            self.parentApp.change_form('ADDOPTIONS')
        else:
            npyscreen.notify_confirm(
                "Either a repository or an image "
                "name must be specified!",
                title="Specify plugin to add",
                form_color='CAUTION')
        return
Beispiel #12
0
def test_tool_status_checker():
    """ Test the tool_status_checker function """
    instance = Action()
    status = instance.tool_status_checker('elasticsearch')
Beispiel #13
0
def test_tool_status_output():
    """ Test the tool_status_output function """
    instance = Action()
    status = instance.tool_status_output('elasticsearch')
Beispiel #14
0
    def onStart(self):
        """ Override onStart method for npyscreen """
        curses.mousemask(0)
        self.paths.host_config()
        version = Version()

        # setup initial runtime stuff
        if self.first_time[0] and self.first_time[1] != 'exists':
            plugins = Plugin()
            actions = Action()
            thr = Thread(target=MainForm.t_status,
                         args=(),
                         kwargs={'core': True})
            thr.start()
            while thr.is_alive():
                npyscreen.notify_wait(
                    'Please wait while Vent initializes...1/4',
                    title='Setting up things...')
                time.sleep(1)
            thr.join()
            thr = Thread(target=MainForm.t_status,
                         args=(),
                         kwargs={'core': False})
            thr.start()
            while thr.is_alive():
                npyscreen.notify_wait(
                    'Please wait while Vent initializes...2/4',
                    title='Setting up things...')
                time.sleep(1)
            thr.join()
            thr = Thread(target=plugins.auto_install, args=(), kwargs={})
            thr.start()
            while thr.is_alive():
                npyscreen.notify_wait(
                    'Please wait while Vent initializes...3/4',
                    title='Setting up things...')
                time.sleep(1)
            thr.join()
            thr = Thread(target=actions.startup, args=(), kwargs={})
            thr.start()
            while thr.is_alive():
                npyscreen.notify_wait(
                    'Please wait while Vent initializes...4/4',
                    title='Setting up things...')
                time.sleep(1)
            thr.join()

        quit_s = '\t' * 4 + '^Q to quit'
        tab_esc = '\t' * 4 + 'TAB to close menu popup'
        self.addForm('MAIN',
                     MainForm,
                     name='Vent ' + version + '\t\t\t\t\t^T for help' +
                     quit_s + tab_esc,
                     color='IMPORTANT')
        self.addForm('HELP',
                     HelpForm,
                     name='Help\t\t\t\t\t\t\t\t^T to toggle previous' + quit_s,
                     color='DANGER')
        self.addForm('TUTORIALINTRO',
                     TutorialIntroForm,
                     name='Vent Tutorial' + quit_s,
                     color='DANGER')
        self.addForm('TUTORIALBACKGROUND',
                     TutorialBackgroundForm,
                     name='About Vent' + quit_s,
                     color='DANGER')
        self.addForm('TUTORIALTERMINOLOGY',
                     TutorialTerminologyForm,
                     name='About Vent' + quit_s,
                     color='DANGER')
        self.addForm('TUTORIALGETTINGSETUP',
                     TutorialGettingSetupForm,
                     name='About Vent' + quit_s,
                     color='DANGER')
        self.addForm('TUTORIALBUILDINGCORES',
                     TutorialBuildingCoresForm,
                     name='Working with Cores' + quit_s,
                     color='DANGER')
        self.addForm('TUTORIALSTARTINGCORES',
                     TutorialStartingCoresForm,
                     name='Working with Cores' + quit_s,
                     color='DANGER')
        self.addForm('TUTORIALADDINGPLUGINS',
                     TutorialAddingPluginsForm,
                     name='Working with Plugins' + quit_s,
                     color='DANGER')
        self.addForm('TUTORIALADDINGFILES',
                     TutorialAddingFilesForm,
                     name='Files' + quit_s,
                     color='DANGER')
        self.addForm('TUTORIALTROUBLESHOOTING',
                     TutorialTroubleshootingForm,
                     name='Troubleshooting' + quit_s,
                     color='DANGER')
def test_stop():
    """ Test the stop function """
    instance = Action()
    status = instance.stop()
    assert type(status) == tuple
def test_start():
    """ Test the start function """
    instance = Action()
    status = instance.start({})
    assert type(status) == tuple
    assert status[0] == True
Beispiel #17
0
def test_get_vent_tool_url():
    """ Test the get_vent_tool_url function """
    instance = Action()
    status = instance.get_vent_tool_url('elasticsearch')
Beispiel #18
0
    def onStart(self):
        """ Override onStart method for npyscreen """
        curses.mousemask(0)
        self.paths.host_config()
        version = Version()

        # setup initial runtime stuff
        if self.first_time[0] and self.first_time[1] != "exists":
            plugins = Plugin()
            actions = Action()
            thr = Thread(target=MainForm.t_status,
                         args=(),
                         kwargs={'core': True})
            thr.start()
            while thr.is_alive():
                npyscreen.notify_wait(
                    "Please wait while Vent initializes...1/4",
                    title="Setting up things...")
                time.sleep(1)
            thr.join()
            thr = Thread(target=MainForm.t_status,
                         args=(),
                         kwargs={'core': False})
            thr.start()
            while thr.is_alive():
                npyscreen.notify_wait(
                    "Please wait while Vent initializes...2/4",
                    title="Setting up things...")
                time.sleep(1)
            thr.join()
            thr = Thread(target=plugins.auto_install, args=(), kwargs={})
            thr.start()
            while thr.is_alive():
                npyscreen.notify_wait(
                    "Please wait while Vent initializes...3/4",
                    title="Setting up things...")
                time.sleep(1)
            thr.join()
            thr = Thread(target=actions.startup, args=(), kwargs={})
            thr.start()
            while thr.is_alive():
                npyscreen.notify_wait(
                    "Please wait while Vent initializes...4/4",
                    title="Setting up things...")
                time.sleep(1)
            thr.join()

        quit_s = "\t" * 4 + "^Q to quit"
        tab_esc = "\t" * 4 + "TAB to close menu popup"
        self.addForm("MAIN",
                     MainForm,
                     name="Vent " + version + "\t\t\t\t\t^T for help" +
                     quit_s + tab_esc,
                     color="IMPORTANT")
        self.addForm("HELP",
                     HelpForm,
                     name="Help\t\t\t\t\t\t\t\t^T to toggle previous" + quit_s,
                     color="DANGER")
        self.addForm("TUTORIALINTRO",
                     TutorialIntroForm,
                     name="Vent Tutorial" + quit_s,
                     color="DANGER")
        self.addForm("TUTORIALBACKGROUND",
                     TutorialBackgroundForm,
                     name="About Vent" + quit_s,
                     color="DANGER")
        self.addForm("TUTORIALTERMINOLOGY",
                     TutorialTerminologyForm,
                     name="About Vent" + quit_s,
                     color="DANGER")
        self.addForm("TUTORIALGETTINGSETUP",
                     TutorialGettingSetupForm,
                     name="About Vent" + quit_s,
                     color="DANGER")
        self.addForm("TUTORIALBUILDINGCORES",
                     TutorialBuildingCoresForm,
                     name="Working with Cores" + quit_s,
                     color="DANGER")
        self.addForm("TUTORIALSTARTINGCORES",
                     TutorialStartingCoresForm,
                     name="Working with Cores" + quit_s,
                     color="DANGER")
        self.addForm("TUTORIALADDINGPLUGINS",
                     TutorialAddingPluginsForm,
                     name="Working with Plugins" + quit_s,
                     color="DANGER")
        self.addForm("TUTORIALADDINGFILES",
                     TutorialAddingFilesForm,
                     name="Files" + quit_s,
                     color="DANGER")
        self.addForm("TUTORIALTROUBLESHOOTING",
                     TutorialTroubleshootingForm,
                     name="Troubleshooting" + quit_s,
                     color="DANGER")
Beispiel #19
0
def test_add_image():
    """ Test the add image function """
    instance = Action()
    status = instance.add_image('alpine', 'alpine')
    assert isinstance(status, tuple)
    assert status[0] == True
Beispiel #20
0
    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')
def test_update():
    """ Test the update function """
    instance = Action()
    status = instance.update(name='elasticsearch', branch='master')
    assert type(status) == tuple
Beispiel #22
0
def test_start():
    """ Test the start function """
    instance = Action()
    status = instance.start({})
    assert isinstance(status, tuple)
    assert status[0] == True
Beispiel #23
0
def test_stop():
    """ Test the stop function """
    instance = Action()
    status = instance.stop()
    assert isinstance(status, tuple)
Beispiel #24
0
 def __init__(self, **kargs):
     self.api_action = Action(**kargs)
     self.plugin = self.api_action.plugin
     self.p_helper = self.api_action.p_helper
     self.logger = Logger(__name__)
Beispiel #25
0
    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