def bindings(self): """Returns the system level yaml bindings. This is spinnaker.yml with spinnaker-local imposed on top of it. """ if self.__bindings is None: self.__bindings = yaml_util.load_bindings( self.installation_config_dir, self.user_config_dir) return self.__bindings
def __init__(self, installation_parameters=None, bindings=None): """Constructor Args: installation_parameters [InstallationParameters] if None then use default bindings [YamlBindings] Allows bindings to be explicitly injected for testing. Otherwise they are loaded on demand. """ if not installation_parameters: installation_parameters = InstallationParameters() if os.geteuid(): # If we are not running as root and there is an installation on # this machine as well as a user/.spinnaker directory then it is # ambiguous which we are validating. For saftey we'll force this # to be the normal system installation. Warn that we are doing this. installed_bindings = yaml_util.load_bindings( installation_parameters.INSTALLED_CONFIG_DIR, installation_parameters.USER_CONFIG_DIR, only_if_local=True) user_config = os.path.join(os.environ['HOME'], '.spinnaker') personal_path = os.path.join(user_config, 'spinnaker-local.yml') deck_dir = installation_parameters.DECK_INSTALL_DIR if os.path.exists(personal_path): if installed_bindings is not None: sys.stderr.write( 'WARNING: You have both personal and system Spinnaker' ' configurations on this machine.\n' 'Choosing the personal configuration in "{path}".\n' .format(path=user_config)) deck_dir = os.path.join(os.environ.get('PWD', '.'), 'deck') if not os.path.exists(deck_dir): raise RuntimeError( 'To use a personal configuration, this program must be' ' run from your top-level build directory that you' ' cloned the repositories to.\n' 'We assume you are a developer since you have a' ' $HOME/.spinnaker directory. If you meant to operate on' ' the installed Spinnaker, run this with sudo.') # If we are not root, allow for a non-standard installation location. installation_parameters.INSTALLED_CONFIG_DIR = os.path.abspath( os.path.join(os.path.dirname(__file__), '../../config')) installation_parameters.USER_CONFIG_DIR = user_config installation_parameters.DECK_INSTALL_DIR = deck_dir self.__installation = installation_parameters self.__bindings = bindings # Either injected or loaded on demand. self.load_environment_variables()