Exemplo n.º 1
0
def get_config(runner, reset=False):
    #===============================================================================
    """
    Utility function to look for and validate a set of configuration properties.
    """
    config = Configuration()
    missing = []
    defaults = []
    msgblocks = []
    for name in sorted(Global.config_properties.keys()):
        config_property = Global.config_properties[name]
        key = config_key(name)
        value = runner.config.get(key)
        if not value or reset:
            if config_property.default is None:
                missing.append(name)
                runner.config.set_permanent(key, '')
            else:
                defaults.append(name)
                value = Global.config_properties[name].default
                runner.config.set_permanent(key, value)
                setattr(config, name, value)
        else:
            # Use an existing config value.
            config[name] = value
    samples = []
    if not reset and missing:
        table = [(name, Global.config_properties[name].description)
                 for name in missing]
        msgblocks.append([
            'The following settings must be configured before proceeding:', '',
            utility.format_table(table,
                                 headings=['PROPERTY', 'DESCRIPTION'],
                                 indent=3,
                                 separator='  ')
        ])
        samples.extend(missing)
        config = None
    if defaults:
        msgblocks.append([
            'The following setting defaults were applied and saved permanently:',
            '',
            utility.format_table(
                [(name, Global.config_properties[name].default)
                 for name in defaults],
                indent=3,
                separator='  ',
                headings=['PROPERTY', 'VALUE'])
        ])
    if reset:
        config = None
    elif config is None:
        msgblocks.append([config_help(samples=samples)])
    if msgblocks:
        for msgblock in msgblocks:
            print ''
            for msg in msgblock:
                print msg
        print ''
    return config
Exemplo n.º 2
0
def inspect(runner):
    response = runner.call_proc('@SystemInformation',
                                [VOLT.FastSerializer.VOLTTYPE_STRING],
                                ['LICENSE'])
    print(response.table(0).format_table(caption='License Information'))
    for tuple in response.table(0).tuples():
        if tuple[0] == 'EXPIRATION':
            expiration = datetime.datetime.strptime(tuple[1], "%a %b %d, %Y")
            daysUntilExpiration = expiration - datetime.datetime.today()
            print("License expires on " + tuple[1] + " (" +
                  str(daysUntilExpiration.days) + " days remaining).")

    response2 = runner.call_proc('@SystemInformation',
                                 [VOLT.FastSerializer.VOLTTYPE_STRING],
                                 ['DEPLOYMENT'])
    filtered = filter_tuples(response2.table(0), 0,
                             ('hostcount', 'sitesperhost', 'kfactor'))
    print(
        utility.format_table(filtered,
                             caption='Deployment Information',
                             headings=('PROPERTY', 'VALUE')))

    response3 = runner.call_proc('@SystemInformation',
                                 [VOLT.FastSerializer.VOLTTYPE_STRING],
                                 ['OVERVIEW'])
    filtered = filter_tuples(
        response3.table(0), 1,
        ('VERSION', 'UPTIME', 'REPLICATIONROLE', 'CPUCORES', 'CPUTHREADS',
         'MEMORY', 'KUBERNETES'))
    squashed = squash_same_values(approx_uptime(filtered))
    print(
        utility.format_table(squashed,
                             caption='Configuration Information',
                             headings=('PROPERTY', 'VALUE', 'HOST ID')))
    print('')
Exemplo n.º 3
0
def get_config(runner, reset = False):
#===============================================================================
    """
    Utility function to look for and validate a set of configuration properties.
    """
    config = Configuration()
    missing = []
    defaults = []
    msgblocks = []
    for name in sorted(Global.config_properties.keys()):
        config_property = Global.config_properties[name]
        key = config_key(name)
        value = runner.config.get(key)
        if not value or reset:
            if config_property.default is None:
                missing.append(name)
                runner.config.set_permanent(key, '')
            else:
                defaults.append(name)
                value = Global.config_properties[name].default
                runner.config.set_permanent(key, value)
                setattr(config, name, value)
        else:
            # Use an existing config value.
            config[name] = value
    samples = []
    if not reset and missing:
        table = [(name, Global.config_properties[name].description) for name in missing]
        msgblocks.append([
            'The following settings must be configured before proceeding:',
            '',
            utility.format_table(table, headings=['PROPERTY', 'DESCRIPTION'],
                                        indent=3, separator='  ')
        ])
        samples.extend(missing)
        config = None
    if defaults:
        msgblocks.append([
            'The following setting defaults were applied and saved permanently:',
            '',
            utility.format_table(
                [(name, Global.config_properties[name].default) for name in defaults],
                indent=3, separator='  ', headings=['PROPERTY', 'VALUE'])
        ])
    if reset:
        config = None
    elif config is None:
        msgblocks.append([config_help(samples=samples)])
    if msgblocks:
        for msgblock in msgblocks:
            print ''
            for msg in msgblock:
                print msg
        print ''
    return config
Exemplo n.º 4
0
 def _format_verb_list(self):
     rows1 = []
     rows2 = []
     for verb_name in self.verb_names:
         verb = self.verbs[verb_name]
         if not verb.cli_spec.hideverb:
             if verb.cli_spec.baseverb:
                 rows2.append((get_verb_usage(verb), verb.cli_spec.description))
             else:
                 rows1.append((get_verb_usage(verb), verb.cli_spec.description))
     table1 = utility.format_table(rows1, caption = 'Verb Descriptions', separator = '  ')
     table2 = utility.format_table(rows2, caption = 'Common Verbs', separator = '  ')
     return '%s\n%s' % (table1, table2)
Exemplo n.º 5
0
 def _format_verb_list(self):
     rows1 = []
     rows2 = []
     for verb_name in self.verb_names:
         verb = self.verbs[verb_name]
         if not verb.cli_spec.hideverb:
             usage = self._get_verb_usage(verb, brief=True)
             if verb.cli_spec.baseverb:
                 rows2.append((usage, verb.cli_spec.description))
             else:
                 rows1.append((usage, verb.cli_spec.description))
     table1 = utility.format_table(rows1, caption = 'Verb Descriptions', separator = '  ')
     table2 = utility.format_table(rows2, caption = 'Common Verbs', separator = '  ')
     return '%s\n%s' % (table1, table2)
Exemplo n.º 6
0
 def _format_verb_list(self):
     rows1 = []
     rows2 = []
     for verb_name in self.verb_names:
         verb = self.verbs[verb_name]
         if not verb.cli_spec.hideverb:
             usage = self._get_verb_usage(verb, brief=True)
             if verb.cli_spec.baseverb:
                 rows2.append((usage, verb.cli_spec.description))
             else:
                 rows1.append((usage, verb.cli_spec.description))
     table1 = utility.format_table(rows1, caption="Verb Descriptions", separator="  ")
     table2 = utility.format_table(rows2, caption="Common Verbs", separator="  ")
     return "%s\n%s" % (table1, table2)
Exemplo n.º 7
0
 def __init__(self, name, function, **kwargs):
     CommandVerb.__init__(self, name, function, **kwargs)
     self.modifiers = utility.kwargs_get_list(kwargs, 'modifiers', default = [])
     if not self.modifiers:
         utility.abort('Multi-command "%s" must provide a "modifiers" list.' % self.name)
     valid_modifiers = '|'.join([mod.name for mod in self.modifiers])
     has_args = 0
     rows = []
     for mod in self.modifiers:
         if mod.arg_name:
             usage = '%s %s [ %s ... ]' % (self.name, mod.name, mod.arg_name)
             has_args += 1
         else:
             usage = '%s %s' % (self.name, mod.name)
         rows.append((usage, mod.description))
     caption = '"%s" Command Variations' % self.name
     other_info = utility.format_table(rows, caption = caption, separator = '  ')
     self.set_defaults(other_info = other_info.strip())
     args = [
         cli.StringArgument('modifier',
                            'command modifier (valid modifiers: %s)' % valid_modifiers)]
     if has_args > 0:
         if has_args == len(self.modifiers):
             arg_desc = 'optional arguments(s)'
         else:
             arg_desc = 'optional arguments(s) (where applicable)'
         args.append(cli.StringArgument('arg', arg_desc, min_count = 0, max_count = None))
     self.add_arguments(*args)
Exemplo n.º 8
0
 def on_format_epilog(self):
     if not self.verb:
         return self._format_verb_list()
     if self.verb.get_argument_count() == 0:
         return ''
     rows = [(get_argument_usage(a), a.help) for a in self.verb.iter_arguments()]
     return '\nArguments:\n%s\n' % utility.format_table(rows, indent = 2)
Exemplo n.º 9
0
 def on_format_epilog(self):
     if not self.verb:
         return self._format_verb_list()
     if self.verb.get_argument_count() == 0:
         return ''
     rows = [(get_argument_usage(a), a.help)
             for a in self.verb.iter_arguments()]
     return '\nArguments:\n%s\n' % utility.format_table(rows, indent=2)
Exemplo n.º 10
0
 def on_format_epilog(self):
     if not self.verb:
         return self._format_verb_list()
     if self.verb.get_argument_count() == 0:
         return ''
     rows = [(get_argument_usage(a), a.help) for a in self.verb.iter_arguments()]
     lines = ['Arguments:', utility.format_table(rows, indent = 2)]
     description2 = self.verb.cli_spec.get_attr('description2', None)
     if description2:
         lines.extend(('', description2))
     return '\n%s\n' % ('\n'.join(lines))
Exemplo n.º 11
0
 def on_format_epilog(self):
     if not self.verb:
         return self._format_verb_list()
     if self.verb.get_argument_count() == 0:
         return ''
     rows = [(get_argument_usage(a), a.help)
             for a in self.verb.iter_arguments()]
     lines = ['Arguments:', utility.format_table(rows, indent=2)]
     description2 = self.verb.cli_spec.get_attr('description2', None)
     if description2:
         lines.extend(('', description2))
     return '\n%s\n' % ('\n'.join(lines))
Exemplo n.º 12
0
 def on_format_epilog(self):
     if not self.verb:
         return self._format_verb_list()
     blocks = []
     if self.verb.get_argument_count() > 0:
         rows = [(get_argument_usage(a), a.help) for a in self.verb.iter_arguments()]
         blocks.append('\n'.join(['Arguments:', utility.format_table(rows, indent = 2)]))
     # other_info is used for the multi-verb variation list.
     other_info = self.verb.cli_spec.get_attr('other_info', None)
     if other_info:
         blocks.append(other_info.strip())
     # Automatically wrap description2 as a paragraph.
     description2 = self.verb.cli_spec.get_attr('description2', None)
     if description2:
         blocks.append(utility.paragraph(description2))
     return '\n%s' % '\n\n'.join(blocks)
Exemplo n.º 13
0
 def on_format_epilog(self):
     if not self.verb:
         return self._format_verb_list()
     blocks = []
     if self.verb.get_argument_count() > 0:
         rows = [(get_argument_usage(a), a.help) for a in self.verb.iter_arguments()]
         blocks.append('\n'.join(['Arguments:', utility.format_table(rows, indent = 2)]))
     # other_info is used for the multi-verb variation list.
     other_info = self.verb.cli_spec.get_attr('other_info', None)
     if other_info:
         blocks.append(other_info.strip())
     # Automatically wrap description2 as a paragraph.
     description2 = self.verb.cli_spec.get_attr('description2', None)
     if description2:
         blocks.append(utility.paragraph(description2))
     return '\n%s' % '\n\n'.join(blocks)