Exemplo n.º 1
0
    def cliHelp(self, helpWanted=None):
        knownTopics = ("cli, criteria, filter, help," +
                       "report, sources, topics, values")
        basicHelp = ("Enter exit|quit|bye to quit,\n" +
                     "or help cli for how to use the cli")

        if helpWanted is None:
            print basicHelp
            return

        helpWanted = helpWanted.strip()
        if helpWanted == "cli":
            print "Enter one of the following:"
            print ""
            print "exit|quit|bye to quit,"
            print "filter <expr> where expr is a comma-separated list"
            print "   of assertions, to display a list of hosts matching"
            print "   the filter,"
            print "report <expr> where expr is a comma-separated list"
            print "   of reqirements, to display a report of hosts in those"
            print "   sources and values matching the requirement,"
            print "flush to discard all host source lists; they will be"
            print "   reloaded for the next filter or report"
            print "verbose to display various messages during processing,"
            print "noverbose to turn that off,"
            print "settings to show current settings,"
            print "hosts <expr> to change the value of the hosts option"
            print "   (applies to filters and reports),"
            print "nohosts to unset that,"
            print "set <sourcename> to set a setting for a source (you"
            print "   will be prompted for a setting, enter <setting> <value>"
            print "   for one of host, path, db, user, password,"
            print "   depending on what settings are valid for that source),"
            print "unset <sourcename> to set a setting for a source to"
            print "   '' (you will be prompted for a settingname, enter one"
            print "   of host, path, db, user, password, depending on what"
            print "   settings are valid for that source),"
            print "timeout <int> to set the timeout for remote commands to this"
            print "   many seconds (applies to filters and reports),"
            print "help <topicname> for detailed help on a topic."
            print ""
            print "Known help topics:"
            print knownTopics
        elif helpWanted == "filter":
            print HHelp.getFilterHelp(self.knownSources)
        elif helpWanted == "report":
            print HHelp.getReportHelp(self.knownSources)
        elif helpWanted == "sources":
            print HHelp.getSourcesHelp(self.knownSources)
        elif helpWanted == "criteria":
            print HHelp.getCriteriaHelp()
        elif helpWanted == "values":
            print HHelp.getCriteriaValuesHelp()
        elif helpWanted == "topics":
            print "Enter help <topicname> for detailed help on a topic."
            print "Known topics:"
            print knownTopics
        else:
            print "Unknown help topic <%s>.  Known topics:" % helpWanted
            print knownTopics
Exemplo n.º 2
0
    def cliHelp(self, helpWanted=None):
        knownTopics = ("cli, criteria, filter, help," +
                       "report, sources, topics, values")
        basicHelp = ("Enter exit|quit|bye to quit,\n" +
                     "or help cli for how to use the cli")

        if helpWanted is None:
            print basicHelp
            return

        helpWanted = helpWanted.strip()
        if helpWanted == "cli":
            print "Enter one of the following:"
            print ""
            print "exit|quit|bye to quit,"
            print "filter <expr> where expr is a comma-separated list"
            print "   of assertions, to display a list of hosts matching"
            print "   the filter,"
            print "report <expr> where expr is a comma-separated list"
            print "   of reqirements, to display a report of hosts in those"
            print "   sources and values matching the requirement,"
            print "flush to discard all host source lists; they will be"
            print "   reloaded for the next filter or report"
            print "verbose to display various messages during processing,"
            print "noverbose to turn that off,"
            print "settings to show current settings,"
            print "hosts <expr> to change the value of the hosts option"
            print "   (applies to filters and reports),"
            print "nohosts to unset that,"
            print "set <sourcename> to set a setting for a source (you"
            print "   will be prompted for a setting, enter <setting> <value>"
            print "   for one of host, path, db, user, password,"
            print "   depending on what settings are valid for that source),"
            print "unset <sourcename> to set a setting for a source to"
            print "   '' (you will be prompted for a settingname, enter one"
            print "   of host, path, db, user, password, depending on what"
            print "   settings are valid for that source),"
            print "timeout <int> to set the timeout for remote commands to this"
            print "   many seconds (applies to filters and reports),"
            print "help <topicname> for detailed help on a topic."
            print ""
            print "Known help topics:"
            print knownTopics
        elif helpWanted == "filter":
            print HHelp.getFilterHelp(self.knownSources)
        elif helpWanted == "report":
            print HHelp.getReportHelp(self.knownSources)
        elif helpWanted == "sources":
            print HHelp.getSourcesHelp(self.knownSources)
        elif helpWanted == "criteria":
            print HHelp.getCriteriaHelp()
        elif helpWanted == "values":
            print HHelp.getCriteriaValuesHelp()
        elif helpWanted == "topics":
            print "Enter help <topicname> for detailed help on a topic."
            print "Known topics:"
            print knownTopics
        else:
            print "Unknown help topic <%s>.  Known topics:" % helpWanted
            print knownTopics
Exemplo n.º 3
0
 def cliDoUnset(self, command):
     sourceName = command.split()[1]
     if sourceName not in self.knownSources:
         print "Unknown source"
         print HHelp.getSourcesHelp(self.knownSources)
     else:
         setting = raw_input("setting: ")
         setting = setting.strip()
         if ' ' in setting:
             print "Bad setting format; expecting setting-name"
         # update both hr and hf sources
         elif not self.hf.sources[sourceName].update(
                 setting, "", emptyOk=True):
             print "Bad setting for source"
         elif not self.hr.sources[sourceName].update(
                 setting, "", emptyOk=True):
             print "Bad setting for source"
Exemplo n.º 4
0
 def cliDoUnset(self, command):
     sourceName = command.split()[1]
     if sourceName not in self.knownSources:
         print "Unknown source"
         print HHelp.getSourcesHelp(self.knownSources)
     else:
         setting = raw_input("setting: ")
         setting = setting.strip()
         if ' ' in setting:
             print "Bad setting format; expecting setting-name"
         # update both hr and hf sources
         elif not self.hf.sources[sourceName].update(setting,
                                                     "", emptyOk=True):
             print "Bad setting for source"
         elif not self.hr.sources[sourceName].update(setting,
                                                     "", emptyOk=True):
             print "Bad setting for source"
Exemplo n.º 5
0
 def getValueExprs(self, sourceNameAndValues):
     if '=' not in sourceNameAndValues:
         sourceName = sourceNameAndValues
         values = None
     else:
         sourceName, values = sourceNameAndValues.split('=', 1)
         values = [v for v in values.split(';') if v]
         if not len(values):
             values = None
     if sourceName[-1] == '!':
         realSourceName = sourceName[:-1]
     else:
         realSourceName = sourceName
     # fixme do we still need this?
     if realSourceName not in self.sourcesClasses:
         print HHelp.usage("Unknown source %s for report\n" % realSourceName)
         return None, None
     else:
         return sourceName, values
Exemplo n.º 6
0
 def cliDoSet(self, setCommand):
     sourceName = setCommand.split()[1]
     if sourceName not in self.knownSources:
         print "Unknown source"
         print HHelp.getSourcesHelp(self.knownSources)
     else:
         setting = raw_input("setting: ")
         setting = setting.strip()
         if ' ' not in setting:
             print ("Bad setting format;" +
                    "expecting setting-name whitespace value")
         # fixme this and the below set of splits is inconsistent
         # and dangerous
         # update both the hf and hr sources
         elif (not self.hf.sources[sourceName].update(
                 setting.split(" ", 1))):
             print "Bad setting for source"
         elif (not self.hr.sources[sourceName].update(
                 setting.split(" ", 1))):
             print "Bad setting for source"
         else:
             print ("setting", setting.split()[0], "updated to",
                    setting.split()[1])
Exemplo n.º 7
0
 def cliDoSet(self, setCommand):
     sourceName = setCommand.split()[1]
     if sourceName not in self.knownSources:
         print "Unknown source"
         print HHelp.getSourcesHelp(self.knownSources)
     else:
         setting = raw_input("setting: ")
         setting = setting.strip()
         if ' ' not in setting:
             print("Bad setting format;" +
                   "expecting setting-name whitespace value")
         # fixme this and the below set of splits is inconsistent
         # and dangerous
         # update both the hf and hr sources
         elif (not self.hf.sources[sourceName].update(setting.split(" ",
                                                                    1))):
             print "Bad setting for source"
         elif (not self.hr.sources[sourceName].update(setting.split(" ",
                                                                    1))):
             print "Bad setting for source"
         else:
             print("setting",
                   setting.split()[0], "updated to",
                   setting.split()[1])
Exemplo n.º 8
0
                     "--puppetcerts": PuppetCerts,
                     "-s": PuppetStoredConfigs,
                     "--storedconfigs": PuppetStoredConfigs,
                     "-n": Dns, "--dns": Dns}

    try:
        (options, remainder) = getopt.gnu_getopt(
            sys.argv[1:], "f:CR:d:D:r:p:P:n:l:Q:s:H:c:t:vVhe",
            ["filter=", "report=", "cli", "dhcp=", "dsh=",
             "decomracktables=", "decompuppet=", "puppet=",
             "dns=", "logpuppet=", "puppetcerts=",
             "storedconfigs=", "hosts=", "config=", "timeout=",
             "verbose", "version", "help", "extendedhelp",
             "debug"])
    except getopt.GetoptError as err:
        HHelp.usage("Unknown option specified: " + str(err))

    for (opt, val) in options:
        if opt in ["-f", "--filter"]:
            filterExpr = val
        elif opt in ["-C", "--cli"]:
            cli = True
        elif opt in ["-R", "--report"]:
            reportArg = val
        elif opt in optsToClasses:
            configInfo[optsToClasses[opt].getSourceName()] = (
                optsToClasses[opt].getArgs(val))
        elif opt in ["-H", "--hosts"]:
            hostExprs = val
        elif opt in ["-c", "--config"]:
            configfile = val