46
73
'auth_supported': get_auth() or 'none',
47
74
'mon_hosts': ' '.join(get_mon_hosts()),
48
'hostname': utils.get_unit_hostname(),
75
'hostname': get_unit_hostname(),
49
76
'version': ceph.get_ceph_version('radosgw')
52
# Check to ensure that correct version of ceph is
79
# Check to ensure that correct version of ceph is
54
if ceph.get_ceph_version('radosgw') >= "0.55":
81
if ceph.get_ceph_version('radosgw') >= "0.55":
55
82
# Add keystone configuration if found
56
83
ks_conf = get_keystone_conf()
58
85
cephcontext.update(ks_conf)
60
87
with open('/etc/ceph/ceph.conf', 'w') as cephconf:
61
cephconf.write(utils.render_template('ceph.conf', cephcontext))
88
cephconf.write(render_template('ceph.conf', cephcontext))
64
91
def emit_apacheconf():
66
"hostname": utils.unit_get('private-address')
68
with open('/etc/apache2/sites-available/rgw', 'w') as apacheconf:
69
apacheconf.write(utils.render_template('rgw', apachecontext))
93
"hostname": unit_get('private-address')
95
site_conf = '/etc/apache2/sites-available/rgw'
97
site_conf = '/etc/apache2/sites-available/rgw.conf'
98
with open(site_conf, 'w') as apacheconf:
99
apacheconf.write(render_template('rgw', apachecontext))
72
102
def apache_sites():
73
utils.juju_log('INFO', 'Begin apache_sites.')
74
subprocess.check_call(['a2dissite', 'default'])
104
subprocess.check_call(['a2dissite', '000-default'])
106
subprocess.check_call(['a2dissite', 'default'])
75
107
subprocess.check_call(['a2ensite', 'rgw'])
76
utils.juju_log('INFO', 'End apache_sites.')
79
110
def apache_modules():
80
utils.juju_log('INFO', 'Begin apache_sites.')
81
111
subprocess.check_call(['a2enmod', 'fastcgi'])
82
112
subprocess.check_call(['a2enmod', 'rewrite'])
83
utils.juju_log('INFO', 'End apache_sites.')
86
115
def apache_reload():
87
116
subprocess.call(['service', 'apache2', 'reload'])
119
@hooks.hook('upgrade-charm',
90
121
def config_changed():
91
utils.juju_log('INFO', 'Begin config-changed hook.')
94
124
install_www_scripts()
98
utils.juju_log('INFO', 'End config-changed hook.')
101
130
def get_mon_hosts():
103
for relid in utils.relation_ids('mon'):
104
for unit in utils.relation_list(relid):
132
for relid in relation_ids('mon'):
133
for unit in related_units(relid):
106
'{}:6789'.format(utils.get_host_ip(
107
utils.relation_get('private-address',
135
'{}:6789'.format(get_host_ip(
136
relation_get('private-address',
119
148
def get_conf(name):
120
for relid in utils.relation_ids('mon'):
121
for unit in utils.relation_list(relid):
122
conf = utils.relation_get(name,
149
for relid in relation_ids('mon'):
150
for unit in related_units(relid):
151
conf = relation_get(name,
128
158
def get_keystone_conf():
129
for relid in utils.relation_ids('identity-service'):
130
for unit in utils.relation_list(relid):
159
for relid in relation_ids('identity-service'):
160
for unit in related_units(relid):
132
162
'auth_type': 'keystone',
133
163
'auth_protocol': 'http',
134
'auth_host': utils.relation_get('auth_host', unit, relid),
135
'auth_port': utils.relation_get('auth_port', unit, relid),
136
'admin_token': utils.relation_get('admin_token', unit, relid),
137
'user_roles': utils.config_get('operator-roles'),
138
'cache_size': utils.config_get('cache-size'),
139
'revocation_check_interval': utils.config_get('revocation-check-interval')
164
'auth_host': relation_get('auth_host', unit, relid),
165
'auth_port': relation_get('auth_port', unit, relid),
166
'admin_token': relation_get('admin_token', unit, relid),
167
'user_roles': config('operator-roles'),
168
'cache_size': config('cache-size'),
169
'revocation_check_interval':
170
config('revocation-check-interval')
141
172
if None not in ks_auth.itervalues():
177
@hooks.hook('mon-relation-departed',
178
'mon-relation-changed')
146
179
def mon_relation():
147
utils.juju_log('INFO', 'Begin mon-relation hook.')
149
key = utils.relation_get('radosgw_key')
181
key = relation_get('radosgw_key')
151
183
ceph.import_radosgw_key(key)
152
184
restart() # TODO figure out a better way todo this
153
utils.juju_log('INFO', 'End mon-relation hook.')
187
@hooks.hook('gateway-relation-joined')
156
188
def gateway_relation():
157
utils.juju_log('INFO', 'Begin gateway-relation hook.')
158
utils.relation_set(hostname=utils.unit_get('private-address'),
160
utils.juju_log('INFO', 'Begin gateway-relation hook.')
164
utils.juju_log('INFO', 'Begin upgrade-charm hook.')
165
utils.juju_log('INFO', 'End upgrade-charm hook.')
189
relation_set(hostname=unit_get('private-address'),
169
194
subprocess.call(['service', 'radosgw', 'start'])
170
utils.expose(port=80)
174
199
subprocess.call(['service', 'radosgw', 'stop'])
175
utils.expose(port=80)
179
204
subprocess.call(['service', 'radosgw', 'restart'])
180
utils.expose(port=80)
208
@hooks.hook('identity-service-relation-joined',
209
'identity-service-relation-changed')
183
210
def identity_joined(relid=None):
184
211
if ceph.get_ceph_version('radosgw') < "0.55":
185
utils.juju_log('ERROR',
186
'Integration with keystone requires ceph >= 0.55')
212
log('Integration with keystone requires ceph >= 0.55')
189
hostname = utils.unit_get('private-address')
215
hostname = unit_get('private-address')
190
216
admin_url = 'http://{}:80/swift'.format(hostname)
191
217
internal_url = public_url = '{}/v1'.format(admin_url)
192
utils.relation_set(service='swift',
193
region=utils.config_get('region'),
194
public_url=public_url, internal_url=internal_url,
196
requested_roles=utils.config_get('operator-roles'),
218
relation_set(service='swift',
219
region=config('region'),
220
public_url=public_url, internal_url=internal_url,
222
requested_roles=config('operator-roles'),
200
226
def identity_changed():
207
'config-changed': config_changed,
208
'mon-relation-departed': mon_relation,
209
'mon-relation-changed': mon_relation,
210
'gateway-relation-joined': gateway_relation,
211
'upgrade-charm': config_changed, # same function ATM
212
'identity-service-relation-joined': identity_joined,
213
'identity-service-relation-changed': identity_changed
231
if __name__ == '__main__':
233
hooks.execute(sys.argv)
234
except UnregisteredHookError as e:
235
log('Unknown hook {} - skipping.'.format(e))