~james-page/charms/trusty/neutron-openvswitch/lp1531102-trunk

« back to all changes in this revision

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

  • Committer: james.page at ubuntu
  • Date: 2015-08-10 16:36:25 UTC
  • Revision ID: james.page@ubuntu.com-20150810163625-dsckfsvgdpjbexd1
Tags: 15.07
[gnuoy] 15.07 Charm release

Show diffs side-by-side

added added

removed removed

Lines of Context:
122
122
         of specifying multiple key value pairs within the same string. For
123
123
         example, a string in the format of 'key1=value1, key2=value2' will
124
124
         return a dict of:
125
 
         {'key1': 'value1',
126
 
          'key2': 'value2'}.
 
125
 
 
126
             {'key1': 'value1',
 
127
              'key2': 'value2'}.
127
128
 
128
129
      2. A string in the above format, but supporting a comma-delimited list
129
130
         of values for the same key. For example, a string in the format of
130
131
         'key1=value1, key2=value3,value4,value5' will return a dict of:
131
 
         {'key1', 'value1',
132
 
          'key2', 'value2,value3,value4'}
 
132
 
 
133
             {'key1', 'value1',
 
134
              'key2', 'value2,value3,value4'}
133
135
 
134
136
      3. A string containing a colon character (:) prior to an equal
135
137
         character (=) will be treated as yaml and parsed as such. This can be
136
138
         used to specify more complex key value pairs. For example,
137
139
         a string in the format of 'key1: subkey1=value1, subkey2=value2' will
138
140
         return a dict of:
139
 
         {'key1', 'subkey1=value1, subkey2=value2'}
 
141
 
 
142
             {'key1', 'subkey1=value1, subkey2=value2'}
140
143
 
141
144
    The provided config_flags string may be a list of comma-separated values
142
145
    which themselves may be comma-separated list of values.
240
243
        if self.relation_prefix:
241
244
            password_setting = self.relation_prefix + '_password'
242
245
 
243
 
        for rid in relation_ids('shared-db'):
 
246
        for rid in relation_ids(self.interfaces[0]):
244
247
            for unit in related_units(rid):
245
248
                rdata = relation_get(rid=rid, unit=unit)
246
249
                host = rdata.get('db_host')
891
894
        return ctxt
892
895
 
893
896
    def __call__(self):
894
 
        self._ensure_packages()
895
 
 
896
897
        if self.network_manager not in ['quantum', 'neutron']:
897
898
            return {}
898
899
 
1050
1051
        :param config_file : Service's config file to query sections
1051
1052
        :param interface   : Subordinate interface to inspect
1052
1053
        """
1053
 
        self.service = service
1054
1054
        self.config_file = config_file
1055
 
        self.interface = interface
 
1055
        if isinstance(service, list):
 
1056
            self.services = service
 
1057
        else:
 
1058
            self.services = [service]
 
1059
        if isinstance(interface, list):
 
1060
            self.interfaces = interface
 
1061
        else:
 
1062
            self.interfaces = [interface]
1056
1063
 
1057
1064
    def __call__(self):
1058
1065
        ctxt = {'sections': {}}
1059
 
        for rid in relation_ids(self.interface):
 
1066
        rids = []
 
1067
        for interface in self.interfaces:
 
1068
            rids.extend(relation_ids(interface))
 
1069
        for rid in rids:
1060
1070
            for unit in related_units(rid):
1061
1071
                sub_config = relation_get('subordinate_configuration',
1062
1072
                                          rid=rid, unit=unit)
1068
1078
                            'setting from %s' % rid, level=ERROR)
1069
1079
                        continue
1070
1080
 
1071
 
                    if self.service not in sub_config:
1072
 
                        log('Found subordinate_config on %s but it contained'
1073
 
                            'nothing for %s service' % (rid, self.service),
1074
 
                            level=INFO)
1075
 
                        continue
1076
 
 
1077
 
                    sub_config = sub_config[self.service]
1078
 
                    if self.config_file not in sub_config:
1079
 
                        log('Found subordinate_config on %s but it contained'
1080
 
                            'nothing for %s' % (rid, self.config_file),
1081
 
                            level=INFO)
1082
 
                        continue
1083
 
 
1084
 
                    sub_config = sub_config[self.config_file]
1085
 
                    for k, v in six.iteritems(sub_config):
1086
 
                        if k == 'sections':
1087
 
                            for section, config_dict in six.iteritems(v):
1088
 
                                log("adding section '%s'" % (section),
1089
 
                                    level=DEBUG)
1090
 
                                ctxt[k][section] = config_dict
1091
 
                        else:
1092
 
                            ctxt[k] = v
1093
 
 
 
1081
                    for service in self.services:
 
1082
                        if service not in sub_config:
 
1083
                            log('Found subordinate_config on %s but it contained'
 
1084
                                'nothing for %s service' % (rid, service),
 
1085
                                level=INFO)
 
1086
                            continue
 
1087
 
 
1088
                        sub_config = sub_config[service]
 
1089
                        if self.config_file not in sub_config:
 
1090
                            log('Found subordinate_config on %s but it contained'
 
1091
                                'nothing for %s' % (rid, self.config_file),
 
1092
                                level=INFO)
 
1093
                            continue
 
1094
 
 
1095
                        sub_config = sub_config[self.config_file]
 
1096
                        for k, v in six.iteritems(sub_config):
 
1097
                            if k == 'sections':
 
1098
                                for section, config_list in six.iteritems(v):
 
1099
                                    log("adding section '%s'" % (section),
 
1100
                                        level=DEBUG)
 
1101
                                    if ctxt[k].get(section):
 
1102
                                        ctxt[k][section].extend(config_list)
 
1103
                                    else:
 
1104
                                        ctxt[k][section] = config_list
 
1105
                            else:
 
1106
                                ctxt[k] = v
1094
1107
        log("%d section(s) found" % (len(ctxt['sections'])), level=DEBUG)
1095
1108
        return ctxt
1096
1109