Skip to content
This repository has been archived by the owner on Mar 13, 2022. It is now read-only.

Commit

Permalink
Initial grouped environment support
Browse files Browse the repository at this point in the history
  • Loading branch information
major committed May 5, 2014
1 parent dba8eda commit 6ad37d2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
15 changes: 11 additions & 4 deletions supernova/executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,17 @@ def run_supernova():
print msg % rwrap('Missing novaclient arguments')
sys.exit(1)

setup_supernova_env(s, supernova_args.env)

# All of the remaining arguments should be handed off to nova
return s.run_novaclient(nova_args, supernova_args)
# Is our environment argument a single environment or a supernova group?
if s.is_valid_group(supernova_args.env):
# We were handed a valid supernova group
envs = s.get_envs_in_group(supernova_args.env)
for env in envs:
setup_supernova_env(s, env)
s.run_novaclient(nova_args, supernova_args)
else:
# It's not a group -- let's assume we were passed a single environment
setup_supernova_env(s, supernova_args.env)
s.run_novaclient(nova_args, supernova_args)


def run_supernova_keyring():
Expand Down
37 changes: 34 additions & 3 deletions supernova/supernova.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def __init__(self):
self.nova_env = None
self.env = os.environ.copy()

# Check for preset environment variables that could cause problems
self.check_environment_presets()

def check_deprecated_options(self):
"""
Hunts for deprecated configuration options from previous SuperNova
Expand All @@ -57,6 +60,15 @@ def check_environment_presets(self):
print " - %s" % preset
print "_" * 80

def get_envs_in_group(self, group_name):
envs = []
for section in self.nova_creds.sections():
if (self.nova_creds.has_option(section, 'SUPERNOVA_GROUP') and
self.nova_creds.get(section,
'SUPERNOVA_GROUP') == group_name):
envs.append(section)
return envs

def get_nova_creds(self):
"""
Reads the supernova config file from the current directory or the
Expand All @@ -81,6 +93,22 @@ def is_valid_environment(self):
valid_envs = self.get_nova_creds().sections()
return self.nova_env in valid_envs

def is_valid_group(self, group_name):
"""
Checks to see if the configuration file contains a SUPERNOVA_GROUP
configuration option.
"""
valid_groups = []
for section in self.nova_creds.sections():
if self.nova_creds.has_option(section, 'SUPERNOVA_GROUP'):
valid_groups.append(self.nova_creds.get(section,
'SUPERNOVA_GROUP'))
valid_groups = list(set(valid_groups))
if group_name in valid_groups:
return True
else:
return False

def prep_nova_creds(self):
"""
Finds relevant config options in the supernova config and cleans them
Expand Down Expand Up @@ -132,6 +160,7 @@ def prep_shell_environment(self):
"""
Appends new variables to the current shell environment temporarily.
"""
self.env = os.environ.copy()
for k, v in self.prep_nova_creds():
self.env[k] = v

Expand All @@ -140,9 +169,6 @@ def run_novaclient(self, nova_args, supernova_args):
Sets the environment variables for novaclient, runs novaclient, and
prints the output.
"""
# Check for preset environment variables that could cause problems
self.check_environment_presets()

# Get the environment variables ready
self.prep_shell_environment()

Expand All @@ -157,6 +183,11 @@ def run_novaclient(self, nova_args, supernova_args):
except KeyError:
pass

# Print a small message for the user
msg = "Running %s against %s..." % (supernova_args.executable,
self.nova_env)
print "[SUPERNOVA] %s " % msg

# Call novaclient and connect stdout/stderr to the current terminal
# so that any unicode characters from novaclient's list will be
# displayed appropriately.
Expand Down

0 comments on commit 6ad37d2

Please sign in to comment.