9
from charmhelpers.core import unitdata
10
from charmhelpers.core.hookenv import (
23
UnregisteredHookError,
31
from charmhelpers.core.host import (
40
from charmhelpers.core.templating import (
44
from configurationSteps.nedgeConfigurator import (
45
NedgeBaseConfigurator,
46
NedgeGatewayConfigurator
49
from configurationSteps.utils import (
53
configure_replicast_interface,
58
hook_data = unitdata.HookData()
61
@hooks.hook('install')
65
log('Bundles has copied')
66
replicast_eth = config('replicast_eth')
67
configure_replicast_interface(replicast_eth)
69
public_ip = unit_public_ip()
71
log('replicast interface {} has been created'.format(replicast_eth))
72
log('Node public ip is {}'.format(public_ip))
74
'node_public_ip' : public_ip,
75
'replicast_eth' : replicast_eth,
76
'profile' : config('profile'),
77
'nodocker' : config('nodocker'),
78
'exclude' : config('exclude'),
79
'reserved' : config('reserved')
82
configurator = NedgeGatewayConfigurator(environment)
83
if not configurator.configure():
84
log('NEDGE swift gateway node configuration failed.', level=ERROR)
88
@hooks.hook('swift-gw-relation-joined')
91
#send node sid to mgmt to create new service
92
data = {'gw_info' : {'sid':get_sid(), 'unit_id':local_unit(), 'service_name':service_name()}}
93
log("send gw_info:{} to MGMT".format(data))
94
relation_set(relation_settings=data)
96
@hooks.hook('swift-gw-relation-departed')
97
def on_mgmt_departed():
98
#mark service as detached
99
context = db.get('swift-context', record=True)
101
context['state'] = 'detached'
102
log("context data is {}".format(context))
103
db.set('swift-context', context)
105
@hooks.hook('swift-gw-relation-changed')
106
def on_swift_gateway_data_changed():
107
#recive and parse message from mgmt
108
context = relation_get('swift-context')
109
log("[SWIFT GW] data recived from MGMT: {}".format(context))
111
context = ast.literal_eval(context)
112
if context['sid'] == get_sid() and context['state'] == 'incomplete':
114
#include gw related data to context
115
#context['nder-data']['nexenta_rest_address'] = unit_public_ip()
116
#context['cinder-data']['nexenta_client_address']= unit_public_ip()
117
context['state'] = 'complete'
119
db.set('swift-context', context)
120
for relid in relation_ids('cinder-nedge'):
121
send_data_to_keystone(relid)
123
log("WRONG data: {}".format(context))
126
@hooks.hook('identity-service-relation-joined')
127
def identity_joined(relid=None):
128
log("keysone identity service joined")
129
# send data to keystone
131
if __name__ == '__main__':
134
hooks.execute(sys.argv)
135
except UnregisteredHookError as e:
136
log('Unknown hook {} - skipping.'.format(e))