Ejemplo n.º 1
0
 def get_env_conf(self):
     """Get the environment config file.
     """
     conf = os.path.join(self.juju_home, 'environments.yaml')
     if not os.path.exists(conf):
         raise ConfigError("Juju environments.yaml not found %s" % conf)
     return conf
Ejemplo n.º 2
0
 def check_preconditions(self):
     """Check for provider and configured environments.yaml.
     """
     env_name = self.config.get_env_name()
     with open(self.config.get_env_conf()) as handle:
         conf = yaml.safe_load(handle.read())
         if 'environments' not in conf:
             raise ConfigError(
                 "Invalid environments.yaml, no 'environments' section")
         if env_name not in conf['environments']:
             raise ConfigError("Environment %r not in environments.yaml" %
                               env_name)
         env = conf['environments'][env_name]
         if not env['type'] in ('null', 'manual'):
             raise ConfigError(
                 "Environment %r provider type is %r must be 'null'" %
                 (env_name, env['type']))
         if env['bootstrap-host']:
             raise ConfigError(
                 "Environment %r already has a bootstrap-host" % (env_name))
Ejemplo n.º 3
0
    def get_config(cls):
        provider_conf = {}

        access_key = os.environ.get('SCALEWAY_ACCESS_KEY')
        if access_key:
            provider_conf['access_key'] = access_key

        secret_key = os.environ.get('SCALEWAY_SECRET_KEY')
        if secret_key:
            provider_conf['secret_key'] = secret_key

        if 'access_key' not in provider_conf or \
           'secret_key' not in provider_conf:
            raise ConfigError("Missing Scaleway api credentials")
        return provider_conf
Ejemplo n.º 4
0
    def get_env_name(self):
        """Get the environment name.
        """
        if self.options.environment:
            return self.options.environment
        elif os.environ.get("JUJU_ENV"):
            return os.environ['JUJU_ENV']

        env_ptr = os.path.join(self.juju_home, "current-environment")
        if os.path.exists(env_ptr):
            with open(env_ptr) as handle:
                return handle.read().strip()

        with open(self.get_env_conf()) as handle:
            conf = yaml.safe_load(handle.read())
            if 'default' not in conf:
                raise ConfigError("No Environment specified")
            return conf['default']