Merge branch 'develop' into dist/risotto/risotto-2.8.0/develop

This commit is contained in:
Emmanuel Garette 2021-04-26 17:57:38 +02:00
commit 326af0cd5c
3 changed files with 28 additions and 16 deletions

View File

@ -71,7 +71,7 @@ organizations:
zones: [internet] zones: [internet]
servers: servers:
- name: dns.cadoles.com - name: dns.cadoles.com
cluster: cluster.cadoles.com cluster: hapy.ac-test.fr
zones: [internet] zones: [internet]
servermodel: unbound_etab1 servermodel: unbound_etab1
settings: settings:

View File

@ -5,8 +5,9 @@ from sys import exit, argv
from yaml import load, SafeLoader, YAMLError from yaml import load, SafeLoader, YAMLError
from time import sleep from time import sleep
from os.path import isfile from os.path import isfile
from json import dumps
from cucchiaiata import Configuration from cucchiaiata import Configuration, JsonError, config
from cucchiaiata.common import Common from cucchiaiata.common import Common
from cucchiaiata.i18n import _ from cucchiaiata.i18n import _
@ -43,13 +44,13 @@ class Import(Common):
'cluster', 'cluster',
cluster, cluster,
zone_name=cluster['zone'], zone_name=cluster['zone'],
zones_name=cluster['zones'],
) )
for node in cluster.get('nodes', []): for node in cluster.get('nodes', []):
self.configuration('infra', self.configuration('infra',
'cluster.node', 'cluster.node',
node, node,
cluster_name=cluster['name'], cluster_name=cluster['name'],
zones_name=node['zones'],
) )
self.send('v1.infra.cluster.deploy', self.send('v1.infra.cluster.deploy',
cluster_name=cluster['name'], cluster_name=cluster['name'],
@ -99,9 +100,12 @@ class Import(Common):
if 'settings' in dico: if 'settings' in dico:
#FIXME #FIXME
sleep(1) sleep(1)
try:
self.apply_settings(element, self.apply_settings(element,
dico, dico,
) )
except JsonError as err:
raise Exception(f'unable to configure {element} "{dico["name"]}": {err.message["reason"]}')
def apply_settings(self, def apply_settings(self,
element: str, element: str,
@ -138,10 +142,10 @@ class Import(Common):
value = [value] value = [value]
tiramisu.option(key).value.set(value) tiramisu.option(key).value.set(value)
except ValueError as err: except ValueError as err:
print(_(f'error when setting "{domain}" "{dico["name"]}": "{key}" with value "{value}": {err}')) print(_(f'error when setting "{element}" "{dico["name"]}": "{key}" with value "{value}": {err}'))
exit(1) exit(1)
except Exception as err: except Exception as err:
print(_(f'unexpected error when setting "{domain}" "{dico["name"]}": "{key}" with value "{value}": {err}')) print(_(f'unexpected error when setting "{element}" "{dico["name"]}": "{key}" with value "{value}": {err}'))
exit(1) exit(1)
self.send_configuration(tiramisu, self.send_configuration(tiramisu,
session_id, session_id,
@ -215,7 +219,14 @@ if __name__ == "__main__":
print(_(f'usage: {argv[0]} filename.yaml')) print(_(f'usage: {argv[0]} filename.yaml'))
exit(1) exit(1)
imp = Import(argv[1]) imp = Import(argv[1])
try:
imp.parse_zones() imp.parse_zones()
imp.parse_clusters() imp.parse_clusters()
imp.parse_servermodels() imp.parse_servermodels()
imp.parse_organizations() imp.parse_organizations()
except JsonError as err:
print(err.message['reason'])
exit(1)
except Exception as err:
print(err)
exit(1)

View File

@ -3,9 +3,11 @@ from requests import get, post
from json import dumps from json import dumps
from typing import Dict from typing import Dict
from .config import config
from tiramisu_api import Config from tiramisu_api import Config
from .config import config
from .i18n import _
if config.allow_insecure_https: if config.allow_insecure_https:
import warnings import warnings
@ -82,12 +84,11 @@ class Common:
self.send('v1.setting.session.validate', self.send('v1.setting.session.validate',
session_id=session_id, session_id=session_id,
) )
except Exception as err: except JsonError as err:
self.send('v1.setting.session.stop', self.send('v1.setting.session.stop',
session_id=session_id, session_id=session_id,
) )
print(_(f'error when validate setting to "{name}" "{dico["name"]}": {err}')) raise err from err
exit(1)
def send_data(uri: str, def send_data(uri: str,