~bcsaller/charms/trusty/cloudfoundry/progressbar

« back to all changes in this revision

Viewing changes to cloudfoundry/contexts.py

  • Committer: Benjamin Saller
  • Date: 2014-11-06 00:47:41 UTC
  • mfrom: (154.1.2 reconciler-integration)
  • Revision ID: benjamin.saller@canonical.com-20141106004741-6fyd10onis9dwvcv
merge ri shadow trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
                                               rid=rid, unit=unit))
32
32
        return list(units)
33
33
 
 
34
    def get_first(self, key=None):
 
35
        data = self[self.name][0]
 
36
        return data[key] if key is not None else data
 
37
 
 
38
    def get_all(self, key):
 
39
        return [u[key] for u in self[self.name]]
 
40
 
34
41
 
35
42
class StoredContext(dict):
36
43
    """
100
107
    def get_data(self):
101
108
        RelationContext.get_data(self)
102
109
        if self.is_ready():
103
 
            for unit in self['db']:
 
110
            for unit in self[self.name]:
104
111
                if 'port' not in unit:
105
112
                    unit['port'] = '3306'
106
113
                unit['dsn'] = self.dsn_template.format(**unit)
114
121
 
115
122
class UAARelation(RelationContext):
116
123
    name = 'uaa'
117
 
    interface = 'http'
 
124
    interface = 'uaa'
118
125
    required_keys = ['login_client_secret', 'admin_client_secret', 'cc_client_secret', 'cc_token_secret',
119
126
                     'service_broker_client_secret', 'servicesmgmt_client_secret', 'port']
120
127
    port = 8081
168
175
        }
169
176
 
170
177
 
 
178
class UAADBRelation(MysqlRelation):
 
179
    name = 'uaadb'
 
180
 
 
181
    def provide_data(self, manager, service_name, rel_id):
 
182
        data = {}
 
183
        if manager.is_ready(service_name):
 
184
            # proxy data from the MysqlRelation to this relation
 
185
            mysql = MysqlRelation()
 
186
            data = mysql.get_first()
 
187
        return data
 
188
 
 
189
 
171
190
class LoginRelation(RelationContext):
172
191
    name = 'login'
173
192
    interface = 'http'
362
381
        }
363
382
 
364
383
 
365
 
class CloudControllerDBRelation(RelationContext):
366
 
    name = 'cc-db'
367
 
    interface = 'controller-db'
368
 
    required_keys = MysqlRelation.required_keys
 
384
class CloudControllerDBRelation(MysqlRelation):
 
385
    name = 'ccdb'
369
386
 
370
 
    @classmethod
371
 
    def send_data(cls, job_name):
372
 
        # using send_data instead of provide_data to delay it until data_ready
373
 
        data = MysqlRelation()['db'][0]
374
 
        for rid in hookenv.relation_ids(cls.name):
375
 
            hookenv.relation_set(rid, data)
 
387
    def provide_data(self, manager, service_name, rel_id):
 
388
        data = {}
 
389
        if manager.is_ready(service_name):
 
390
            # proxy data from the MysqlRelation to this relation
 
391
            mysql = MysqlRelation()
 
392
            data = mysql.get_first()
 
393
        return data
376
394
 
377
395
    def is_ready(self):
378
396
        is_ready = super(CloudControllerDBRelation, self).is_ready()