~cbjchen/charms/trusty/cinder/remove_stale_key

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/contrib/openstack/context.py

  • Committer: James Page
  • Date: 2014-03-31 11:11:01 UTC
  • mfrom: (27.5.8 cinder)
  • mto: This revision was merged to the branch mainline in revision 33.
  • Revision ID: james.page@canonical.com-20140331111101-rg38s7pc2zbm8hk8
[yolanda] Add support for postgresql
Refactor templates to use includes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
147
147
                    'database_host': rdata.get('db_host'),
148
148
                    'database': self.database,
149
149
                    'database_user': self.user,
150
 
                    'database_password': rdata.get(password_setting)
 
150
                    'database_password': rdata.get(password_setting),
 
151
                    'database_type': 'mysql'
151
152
                }
152
153
                if context_complete(ctxt):
153
154
                    db_ssl(rdata, ctxt, self.ssl_dir)
155
156
        return {}
156
157
 
157
158
 
 
159
class PostgresqlDBContext(OSContextGenerator):
 
160
    interfaces = ['pgsql-db']
 
161
 
 
162
    def __init__(self, database=None):
 
163
        self.database = database
 
164
 
 
165
    def __call__(self):
 
166
        self.database = self.database or config('database')
 
167
        if self.database is None:
 
168
            log('Could not generate postgresql_db context. '
 
169
                'Missing required charm config options. '
 
170
                '(database name)')
 
171
            raise OSContextError
 
172
        ctxt = {}
 
173
 
 
174
        for rid in relation_ids(self.interfaces[0]):
 
175
            for unit in related_units(rid):
 
176
                ctxt = {
 
177
                    'database_host': relation_get('host', rid=rid, unit=unit),
 
178
                    'database': self.database,
 
179
                    'database_user': relation_get('user', rid=rid, unit=unit),
 
180
                    'database_password': relation_get('password', rid=rid, unit=unit),
 
181
                    'database_type': 'postgresql',
 
182
                }
 
183
                if context_complete(ctxt):
 
184
                    return ctxt
 
185
        return {}
 
186
 
 
187
 
158
188
def db_ssl(rdata, ctxt, ssl_dir):
159
189
    if 'ssl_ca' in rdata and ssl_dir:
160
190
        ca_path = os.path.join(ssl_dir, 'db-client.ca')