def __call__(self, parser, *args, **kwargs): """Lists are configured supernova environments.""" for nova_env in config.nova_creds.sections(): envheader = "-- %s " % gwrap(nova_env) print envheader.ljust(86, "-") for param, value in sorted(config.nova_creds.items(nova_env)): print " %s: %s" % (param.upper().ljust(21), value) parser.exit()
def get_user_password(args): """ Allows the user to print the credential for a particular keyring entry to the screen """ username = '******' % (args.env, args.parameter) warnstring = rwrap("__ WARNING ".ljust(80, '_')) print """ %s If this operation is successful, the credential stored for this username will be displayed in your terminal as PLAIN TEXT: %s Seriously. It will just be hanging out there for anyone to see. If you have any concerns about having this credential displayed on your screen, press CTRL-C right now. %s """ % (warnstring, username, warnstring) print "If you are completely sure you want to display it, type 'yes' and "\ "press enter:", try: confirm = raw_input('') except: print "" sys.exit() if confirm != 'yes': print "\n[%s] Your keyring was not read or altered." % ( rwrap("Canceled")) return False try: password = password_get(username) except: password = None if password: print """ [%s] Found credentials for %s: %s """ % ( gwrap("Success"), username, password) return True else: print """ [%s] Unable to retrieve credentials for %s. It's likely that there aren't any credentials stored for this environment and parameter combination. If you want to set a credential, just run this command: supernova-keyring -s %s %s """ % (rwrap("Failed"), username, args.env, args.parameter) return False
def set_user_password(args): """ Sets a user's password in the keyring storage """ print """ [%s] Preparing to set a password in the keyring for: - Environment : %s - Parameter : %s If this is correct, enter the corresponding credential to store in your keyring or press CTRL-D to abort:""" % (gwrap("Keyring operation"), args.env, args.parameter) # Prompt for a password and catch a CTRL-D try: password = getpass.getpass('') except: password = None print # Did we get a password from the prompt? if not password or len(password) < 1: print "\n[%s] No data was altered in your keyring.\n" % ( rwrap("Canceled")) sys.exit() # Try to store the password username = '******' % (args.env, args.parameter) try: store_ok = password_set(username, password) except: store_ok = False if store_ok: print "[%s] Successfully stored credentials for %s under the " \ "supernova service.\n" % (gwrap("Success"), username) else: print "[%s] Unable to store credentials for %s under the " \ "supernova service.\n" % (rwrap("Failed"), username)
def run_novaclient(self, nova_args, supernova_args): """ Sets the environment variables for novaclient, runs novaclient, and prints the output. """ # Get the environment variables ready self.prep_shell_environment() # Check for a debug override if supernova_args.debug: nova_args.insert(0, '--debug') # Check for OS_EXECUTABLE try: if self.env['OS_EXECUTABLE']: supernova_args.executable = self.env['OS_EXECUTABLE'] except KeyError: pass # Print a small message for the user (very helpful for groups) msg = "Running %s against %s..." % (supernova_args.executable, self.nova_env) print "[%s] %s " % (gwrap('SUPERNOVA'), msg) # Call novaclient and connect stdout/stderr to the current terminal # so that any unicode characters from novaclient's list will be # displayed appropriately. # # In other news, I hate how python 2.6 does unicode. process = subprocess.Popen([supernova_args.executable] + nova_args, stdout=sys.stdout, stderr=sys.stderr, env=self.env) # Don't exit until we're sure the subprocess has exited return process.wait()
def print_valid_envs(valid_envs): """ Prints the available environments. """ print "[%s] Your valid environments are:" % (gwrap('Found environments')) print "%r" % valid_envs