Commit ace7f39b authored by Paul Graydon's avatar Paul Graydon

software/wendelin-telecom: Rework slave instances for use by ORS

parent d79bc190
...@@ -4,4 +4,4 @@ md5sum = 79e4a9d4c632eaf0472929464a12e768 ...@@ -4,4 +4,4 @@ md5sum = 79e4a9d4c632eaf0472929464a12e768
[template-wendelin-telecom] [template-wendelin-telecom]
filename = instance-wendelin-telecom.cfg.in filename = instance-wendelin-telecom.cfg.in
md5sum = eb17784ee1a9d1f5bf8f5741cd733446 md5sum = 5ed2d5da369b5b73eabf8045666ebebc
...@@ -2,25 +2,10 @@ ...@@ -2,25 +2,10 @@
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "http://json-schema.org/draft-07/schema#",
"type": "object", "type": "object",
"properties": { "properties": {
"project-title": {
"description": "Title of the ORS client project to register",
"title": "Client Project Title",
"type": "string"
},
"client-username": {
"description": "Username for the client project's user account",
"title": "Client Project Account Username",
"type": "string"
},
"ors-tag": { "ors-tag": {
"description": "Fluentbit tag of the ORS to register to the client project", "description": "Fluentbit tag of the ORS to register",
"title": "ORS Tag", "title": "ORS Tag",
"type": "string" "type": "string"
},
"ors-title": {
"description": "Title of the ORS to register to the client project",
"title": "ORS Title",
"type": "string"
} }
} }
} }
...@@ -2,18 +2,5 @@ ...@@ -2,18 +2,5 @@
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "http://json-schema.org/draft-07/schema#",
"description": "Values returned by Wendelin Telecom", "description": "Values returned by Wendelin Telecom",
"type": "object", "type": "object",
"properties": { "properties": {}
"ors-wendelin-homepage": {
"description": "URL to the homepage of the Wendelin Telecom platform",
"type": "string"
},
"username": {
"description": "Username for the project's user account",
"type": "string"
},
"init-password": {
"description": "Initial password for the project's user account",
"type": "string"
}
}
} }
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "http://json-schema.org/draft-07/schema#",
"type": "object", "type": "object",
"properties": { "properties": {}
"client-frontend-url": {
"description": "Base URL of the Wendelin Telecom frontend instance intended for use by the clients.",
"type": "string"
}
}
} }
...@@ -3,23 +3,17 @@ extends = ...@@ -3,23 +3,17 @@ extends =
{{ instance_erp5 }} {{ instance_erp5 }}
parts += parts +=
ors-client-project-register ors-register
[directory] [ors-register]
ors-client-project-register = ${:etc}/ors-client-project-register
[ors-client-project-register]
recipe = slapos.recipe.build recipe = slapos.recipe.build
slave-instance-list = {{ dumps(slave_instance_list) }} slave-instance-list = {{ dumps(slave_instance_list) }}
ors-client-project-register-path = ${directory:ors-client-project-register} site-id = ${publish:site-id}
backend-url = ${publish:family-default-v6}
client-frontend-url = {{ slapparameter_dict.get('client-frontend-url', '')}}
inituser-login = ${publish:inituser-login} inituser-login = ${publish:inituser-login}
inituser-password = ${publish-early:inituser-password} inituser-password = ${publish-early:inituser-password}
update = update =
import json import json
import logging import logging
import os
import requests import requests
import slapos import slapos
...@@ -31,7 +25,6 @@ update = ...@@ -31,7 +25,6 @@ update =
self.computer_id = slap_connection['computer-id'] self.computer_id = slap_connection['computer-id']
self.computer_partition_id = slap_connection['partition-id'] self.computer_partition_id = slap_connection['partition-id']
self.server_url = slap_connection['server-url'] self.server_url = slap_connection['server-url']
self.software_release_url = slap_connection['software-release-url']
self.key_file = slap_connection.get('key-file') self.key_file = slap_connection.get('key-file')
self.cert_file = slap_connection.get('cert-file') self.cert_file = slap_connection.get('cert-file')
self.slave_instance_list = list(options['slave-instance-list']) self.slave_instance_list = list(options['slave-instance-list'])
...@@ -40,68 +33,41 @@ update = ...@@ -40,68 +33,41 @@ update =
slap.initializeConnection(self.server_url, self.key_file, self.cert_file) slap.initializeConnection(self.server_url, self.key_file, self.cert_file)
computer_partition = slap.registerComputerPartition(self.computer_id, self.computer_partition_id) computer_partition = slap.registerComputerPartition(self.computer_id, self.computer_partition_id)
ors_client_project_register_path = options['ors-client-project-register-path'] request_balancer = self.buildout['request-balancer']
wendelin_telecom_backend_url = options['backend-url'] zope_family_name_list = ['ingestion', 'web', 'default']
wendelin_telecom_client_frontend_url = options['client-frontend-url'] wendelin_telecom_backend_url = None
inituser_login = options['inituser-login'] for family_name in zope_family_name_list:
inituser_password = options['inituser-password'] connection_name = 'connection-%s-v6' % family_name
if connection_name in request_balancer:
for slave in self.slave_instance_list: wendelin_telecom_backend_url = request_balancer[connection_name]
slave_reference = slave['slave_reference'] break
if not wendelin_telecom_backend_url:
try: log.fatal("Wendelin Telecom backend URL not found, cannot register")
project_title = slave['project-title'] else:
project_reference = project_title.replace(" ", "_").lower() wendelin_telecom_site_id = options['site-id']
client_username = slave['client-username'] inituser_login = options['inituser-login']
ors_tag = slave['ors-tag'] inituser_password = options['inituser-password']
ors_title = slave['ors-title']
except KeyError as e: for slave in self.slave_instance_list:
log.fatal("%s: Parameter %s not found, skipping registration" % (slave_reference, e)) slave_reference = slave['slave_reference']
continue
try:
register_file = os.path.join(ors_client_project_register_path, '%s.json' % slave_reference) ors_tag = slave['ors-tag']
except KeyError as err:
connection_dict = {} log.fatal("%s: Parameter %s not found, skipping registration" % (slave_reference, err))
if not os.path.exists(register_file):
with open(register_file, 'w') as file:
json.dump(connection_dict, file)
else:
with open(register_file, 'r') as file:
connection_dict = json.load(file)
request_url = "%s/erp5/Base_registerOrsClientProject?project_reference=%s&project_title=%s&client_username=%s&ors_tag=%s&ors_title=%s" \
% (wendelin_telecom_backend_url, project_reference, project_title, client_username, ors_tag, ors_title)
response = requests.get(request_url, verify=False, auth=(inituser_login, inituser_password))
response = response.json()
error_msg_key = "error_msg"
if error_msg_key in response:
error_msg = response[error_msg_key]
log.info(error_msg)
else:
if "username" in response and "init_password" in response:
connection_dict = {
"username": response['username'],
"init-password": response['init_password']
}
with open(register_file, 'w') as file:
json.dump(connection_dict, file)
log.info("ORS client project successfully registered: %s" % slave_reference)
else:
log.fatal("Error while fetching client user account credentials")
continue continue
no_client_frontend_url_msg = "Wendelin Telecom website has not been configured." request_url = "%s/%s/ERP5Site_registerOrs?ors_tag=%s" % (wendelin_telecom_backend_url, wendelin_telecom_site_id, ors_tag)
connection_dict['wendelin-telecom-homepage'] = wendelin_telecom_client_frontend_url or no_client_frontend_url_msg
try: response = requests.get(request_url, verify=False, auth=(inituser_login, inituser_password))
log.info("Update parameters for client project %s" % slave_reference) response = response.json()
computer_partition.setConnectionDict(connection_dict, slave_reference) error_msg_key = "error_msg"
except Exception: if error_msg_key in response:
log.fatal("Error while sending slave %s information: %s", error_msg = response[error_msg_key]
slave_reference, traceback.format_exc()) log.info(error_msg)
else:
log.info("ORS successfully registered: %s" % slave_reference)
[publish] [publish]
slave-amount = {{ len(slave_instance_list) }} slave-amount = {{ len(slave_instance_list) }}
...@@ -34,7 +34,7 @@ depends = ...@@ -34,7 +34,7 @@ depends =
<= erp5 <= erp5
repository = https://lab.nexedi.com/paul.graydon/wendelin-telecom.git repository = https://lab.nexedi.com/paul.graydon/wendelin-telecom.git
branch = master branch = master
revision = 71d02c8d6cce7e9970b1371d149622f201440fda revision = d29e4e3ede129af6b2ba2726e0b4b4e1f324ea0d
[local-bt5-repository] [local-bt5-repository]
list += ${wendelin-telecom:location}/bt5 list += ${wendelin-telecom:location}/bt5
...@@ -42,6 +42,11 @@ list += ${wendelin-telecom:location}/bt5 ...@@ -42,6 +42,11 @@ list += ${wendelin-telecom:location}/bt5
[erp5_repository_list] [erp5_repository_list]
repository_id_list += wendelin-telecom repository_id_list += wendelin-telecom
[default-bt5]
list =
erp5_full_text_mroonga_catalog
wendelin_telecom_configurator
[template] [template]
output = ${buildout:directory}/template-base.cfg output = ${buildout:directory}/template-base.cfg
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
}, },
"default-slave": { "default-slave": {
"title": "Default (Shared)", "title": "Default (Shared)",
"description": "ORS Client Project Registration", "description": "ORS Registration",
"software-type": "default", "software-type": "default",
"request": "instance-shared-input-schema.json", "request": "instance-shared-input-schema.json",
"response": "instance-shared-output-schema.json", "response": "instance-shared-output-schema.json",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment