~jimbaker/pyjuju/ssh-known_hosts

« back to all changes in this revision

Viewing changes to juju/environment/config.py

  • Committer: Gustavo Niemeyer
  • Date: 2011-09-16 00:37:59 UTC
  • mfrom: (348.1.13 the-big-renaming)
  • Revision ID: gustavo@niemeyer.net-20110916003759-bx3vsznroj4gv7w7
Merging the-big-renaming branch! Say hello to juju!

This is a massive change renaming and fixing several things
on the way. Unfortunately my day is finishing and I didn't
manage to get 100% of the tests passing, but there's very
few things broken right now, and I don't want to keep such
a massive change flying around.

We'll sort any details out tomorrow.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
import yaml
3
3
import uuid
4
4
 
5
 
from ensemble.lib.schema import (SchemaError, KeyDict, Dict, String,
 
5
from juju.lib.schema import (SchemaError, KeyDict, Dict, String,
6
6
                                 Constant, OneOf, SelectDict)
7
 
from ensemble.errors import (
8
 
    FileNotFound, FileAlreadyExists, InvalidEnsembleHeaderValue)
9
 
 
10
 
from ensemble.environment.environment import Environment
11
 
from ensemble.environment.errors import EnvironmentsConfigError
12
 
 
13
 
 
14
 
DEFAULT_CONFIG_PATH = "~/.ensemble/environments.yaml"
 
7
from juju.errors import FileNotFound, FileAlreadyExists
 
8
 
 
9
from juju.environment.environment import Environment
 
10
from juju.environment.errors import EnvironmentsConfigError
 
11
 
 
12
 
 
13
DEFAULT_CONFIG_PATH = "~/.juju/environments.yaml"
15
14
 
16
15
SAMPLE_CONFIG = """\
17
 
ensemble: environments
18
 
 
19
16
environments:
20
17
  sample:
21
18
    type: ec2
25
22
 
26
23
 
27
24
SCHEMA = KeyDict({
28
 
    "ensemble": Constant("environments"),
29
25
    "default": String(),
30
26
    "environments": Dict(String(), SelectDict("type", {
31
27
        "ec2": KeyDict({"control-bucket": String(),
82
78
        """Load an enviornment configuration file.
83
79
 
84
80
        @param path: An optional environment configuration file path.
85
 
            Defaults to ~/.ensemble/environments.yaml
 
81
            Defaults to ~/.juju/environments.yaml
86
82
 
87
83
        This method will call the C{parse()} method with the content
88
84
        of the loaded file.
100
96
        @param path: An optional environment configuration file path, used
101
97
            when raising errors.
102
98
 
103
 
        @raise InvalidEnsembleHeaderValue: If 'ensemble:' is not set to
104
 
               'environments'.
105
99
        @raise EnvironmentsConfigError: On other issues.
106
100
        """
107
101
        if not isinstance(content, basestring):
115
109
        if not isinstance(config, dict):
116
110
            self._fail("Configuration must be a dictionary", path, content)
117
111
 
118
 
        found_value = config.get("ensemble")
119
 
        expected_value = "environments"
120
 
        if found_value != expected_value:
121
 
            raise InvalidEnsembleHeaderValue(path, expected_value, found_value)
122
112
        try:
123
113
            config = SCHEMA.coerce(config, [])
124
114
        except SchemaError, error:
182
172
        """Write down a sample configuration file.
183
173
 
184
174
        @param path: An optional environment configuration file path.
185
 
            Defaults to ~/.ensemble/environments.yaml
 
175
            Defaults to ~/.juju/environments.yaml
186
176
        """
187
177
        path = self._get_path(path)
188
178
        dirname = os.path.dirname(path)
192
182
            os.makedirs(dirname)
193
183
 
194
184
        defaults = {
195
 
            "control-bucket": "ensemble-%s" % (uuid.uuid4().hex),
 
185
            "control-bucket": "juju-%s" % (uuid.uuid4().hex),
196
186
            "admin-secret": "%s" % (uuid.uuid4().hex)}
197
187
 
198
188
        with open(path, "w") as file: