Beispiel #1
0
    def _prompt_certificate(self):
        """Ask for the key details (country, state, and location)."""
        print("The following questions affect SSL certificate generation.")
        print("If no data is provided, the default values are used.")
        newcountry = input("Country name (2 letter code) for certificate: ")
        if newcountry != '':
            if len(newcountry) == 2:
                self.country = newcountry
            else:
                while len(newcountry) != 2:
                    newcountry = input("2 letter country code (eg. US): ")
                    if len(newcountry) == 2:
                        self.country = newcountry
                        break
        else:
            self.country = 'US'

        newstate = input("State or Province Name (full name) for certificate: ")
        if newstate != '':
            self.state = newstate
        else:
            self.state = 'Illinois'

        newlocation = input("Locality Name (eg, city) for certificate: ")
        if newlocation != '':
            self.location = newlocation
        else:
            self.location = 'Argonne'
Beispiel #2
0
 def _prompt_repopath(self):
     """Ask for the repository path."""
     while True:
         newrepo = input("Location of Bcfg2 repository [%s]: " %
                         self.repopath)
         if newrepo != '':
             self.repopath = os.path.abspath(newrepo)
         if os.path.isdir(self.repopath):
             response = input("Directory %s exists. Overwrite? [y/N]:" \
                              % self.repopath)
             if response.lower().strip() == 'y':
                 break
         else:
             break
Beispiel #3
0
 def _prompt_plugins(self):
     default = input("Use default plugins? (%s) [Y/n]: " %
                     ''.join(default_plugins)).lower()
     if default != 'y' or default != '':
         while True:
             plugins_are_valid = True
             plug_str = input("Specify plugins: ")
             plugins = plug_str.split(',')
             for plugin in plugins:
                 plugin = plugin.strip()
                 if not plugin in plugin_list:
                     plugins_are_valid = False
                     print("ERROR: Plugin %s not recognized" % plugin)
             if plugins_are_valid:
                 break
Beispiel #4
0
 def RunAction(self, entry):
     """This method handles command execution and status return."""
     if not self.setup['dryrun']:
         if self.setup['interactive']:
             prompt = ('Run Action %s, %s: (y/N): ' %
                       (entry.get('name'), entry.get('command')))
             ans = input(prompt)
             if ans not in ['y', 'Y']:
                 return False
         if self.setup['servicemode'] == 'build':
             if entry.get('build', 'true') == 'false':
                 self.logger.debug("Action: Deferring execution of %s due to build mode" % (entry.get('command')))
                 return False
         self.logger.debug("Running Action %s" % (entry.get('name')))
         rc = self.cmd.run(entry.get('command'))[0]
         self.logger.debug("Action: %s got rc %s" % (entry.get('command'), rc))
         entry.set('rc', str(rc))
         if entry.get('status', 'check') == 'ignore':
             return True
         else:
             return rc == 0
     else:
         self.logger.debug("In dryrun mode: not running action: %s" %
                           (entry.get('name')))
         return False
Beispiel #5
0
    def BundleUpdated(self, bundle, states):
        """The Bundle has been updated."""
        if self.setup['servicemode'] == 'disabled':
            return

        for entry in [ent for ent in bundle if self.handlesEntry(ent)]:
            restart = entry.get("restart", "true")
            if (restart.lower() == "false" or
                (restart.lower == "interactive" and
                 not self.setup['interactive'])):
                continue

            rc = None
            if entry.get('status') == 'on':
                if self.setup['servicemode'] == 'build':
                    rc = self.stop_service(entry)
                elif entry.get('name') not in self.restarted:
                    if self.setup['interactive']:
                        prompt = ('Restart service %s?: (y/N): ' %
                                  entry.get('name'))
                        ans = input(prompt)
                        if ans not in ['y', 'Y']:
                            continue
                    rc = self.restart_service(entry)
                    if not rc:
                        self.restarted.append(entry.get('name'))
            else:
                rc = self.stop_service(entry)
            if rc:
                self.logger.error("Failed to manipulate service %s" %
                                  (entry.get('name')))
Beispiel #6
0
 def _prompt_hostname(self):
     """Ask for the server hostname."""
     data = input("What is the server's hostname [%s]: " %
                  socket.getfqdn())
     if data != '':
         self.shostname = data
     else:
         self.shostname = socket.getfqdn()
Beispiel #7
0
 def _prompt_groups(self):
     """Create the groups.xml file."""
     prompt = '''Input base Operating System for clients:\n'''
     for entry in os_list:
         prompt += "%d: %s\n" % (os_list.index(entry) + 1, entry[0])
     prompt += ': '
     while True:
         try:
             osidx = int(input(prompt))
             self.os_sel = os_list[osidx - 1][1]
             break
         except ValueError:
             continue
Beispiel #8
0
Datei: Tidy.py Projekt: m4z/bcfg2
 def __call__(self, args):
     Bcfg2.Server.Admin.Mode.__call__(self, args)
     badfiles = self.buildTidyList()
     if '-f' in args or '-I' in args:
         if '-I' in args:
             for name in badfiles[:]:
                 answer = input("Unlink file %s? [yN] " % name)
                 if answer not in ['y', 'Y']:
                     badfiles.remove(name)
         for name in badfiles:
             try:
                 os.unlink(name)
             except IOError:
                 print("Failed to unlink %s" % name)
     else:
         for name in badfiles:
             print(name)
Beispiel #9
0
def create_conf(confpath, confdata, keypath):
    # Don't overwrite existing bcfg2.conf file
    if os.path.exists(confpath):
        result = input("\nWarning: %s already exists. "
                       "Overwrite? [y/N]: " % confpath)
        if result not in ['Y', 'y']:
            print("Leaving %s unchanged" % confpath)
            return
    try:
        open(confpath, "w").write(confdata)
        os.chmod(confpath, stat.S_IRUSR | stat.S_IWUSR)  # 0600
    except Exception:
        e = sys.exc_info()[1]
        print("Error %s occured while trying to write configuration "
              "file to '%s'.\n" %
               (e, confpath))
        raise SystemExit(1)
Beispiel #10
0
    def Choose(self, choices):
        """Determine where to put pull data."""
        if self.mode == 'interactive':
            for choice in choices:
                print("Plugin returned choice:")
                if id(choice) == id(choices[0]):
                    print("(current entry) ")
                if choice.all:
                    print(" => global entry")
                elif choice.group:
                    print(" => group entry: %s (prio %d)" %
                          (choice.group, choice.prio))
                else:
                    print(" => host entry: %s" % (choice.hostname))

                ans = input("Use this entry? [yN]: ") in ['y', 'Y']
                if ans:
                    return choice
            return False
        else:
            # mode == 'force'
            if not choices:
                return False
            return choices[0]
Beispiel #11
0
 def _prompt_server(self):
     """Ask for the server name."""
     newserver = input("Input the server location [%s]: " %
                       self.server_uri)
     if newserver != '':
         self.server_uri = newserver
Beispiel #12
0
 def _prompt_config(self):
     """Ask for the configuration file path."""
     newconfig = input("Store Bcfg2 configuration in [%s]: " %
                       self.configfile)
     if newconfig != '':
         self.configfile = os.path.abspath(newconfig)