Compare commits
6 Commits
14f4bbf234
...
pkg/dev/ri
Author | SHA1 | Date | |
---|---|---|---|
326af0cd5c | |||
9cf64d8238 | |||
fbf4fc9643 | |||
1b5ef5021e | |||
24ea05b64a | |||
7fc109842d |
@ -2,22 +2,26 @@ zones:
|
||||
- name: internet
|
||||
settings:
|
||||
configuration:
|
||||
network: 192.168.1.0/24
|
||||
host_start: 192.168.1.10
|
||||
host_stop: 192.168.1.100
|
||||
host:
|
||||
network: 192.168.1.0/24
|
||||
start: 192.168.1.10
|
||||
stop: 192.168.1.100
|
||||
dns: [192.168.1.2]
|
||||
vlan_id: 192
|
||||
gateway: 192.168.1.254
|
||||
|
||||
clusters:
|
||||
- name: cluster.cadoles.com
|
||||
- name: hapy.ac-test.fr
|
||||
zone: internet
|
||||
zones: [internet]
|
||||
settings:
|
||||
configuration:
|
||||
network:
|
||||
virtual_ip: 192.168.1.1
|
||||
virtual_ip: 192.168.1.1
|
||||
opennebula:
|
||||
one_user: eoleone
|
||||
one_password: eole
|
||||
nodes:
|
||||
- name: node1.cadoles.com
|
||||
zones: [internet]
|
||||
|
||||
servermodels:
|
||||
- name: unbound
|
||||
@ -67,7 +71,7 @@ organizations:
|
||||
zones: [internet]
|
||||
servers:
|
||||
- name: dns.cadoles.com
|
||||
cluster: cluster.cadoles.com
|
||||
cluster: hapy.ac-test.fr
|
||||
zones: [internet]
|
||||
servermodel: unbound_etab1
|
||||
settings:
|
||||
|
@ -34,31 +34,35 @@ cucchiaiata-cli v1.user.role.create --user_login gnunux \
|
||||
cucchiaiata-cli v1.infra.zone.create --zone_name internet
|
||||
# zone configuration
|
||||
S=$(get_id "cucchiaiata-cli v1.setting.session.zone.start --zone_name internet")
|
||||
cucchiaiata-cli v1.setting.session.configure --session_id "$S" --configuration.network "192.168.1.0/24" \
|
||||
--configuration.host_start "192.168.1.10" \
|
||||
--configuration.host_stop "192.168.1.100" \
|
||||
cucchiaiata-cli v1.setting.session.configure --session_id "$S" --configuration.host.network "192.168.1.0/24" \
|
||||
--configuration.host.start "192.168.1.10" \
|
||||
--configuration.host.stop "192.168.1.100" \
|
||||
--configuration.dns 192.168.1.2 \
|
||||
--configuration.vlan_id 192 \
|
||||
--configuration.gateway 192.168.1.254
|
||||
cucchiaiata-cli v1.setting.session.validate --session_id $S
|
||||
cucchiaiata-cli v1.setting.session.stop --session_id "$S" --save
|
||||
|
||||
|
||||
# Create the cluster cluster.cadoles.com
|
||||
# Create the cluster hapy.ac-test.fr
|
||||
# +---------------------------+
|
||||
# | cluster.cadoles.com | +~~~~~~~~~~+
|
||||
# | hapy.ac-test.fr | +~~~~~~~~~~+
|
||||
# | +--------------------+ |-------! ZONE !
|
||||
# | | node1.cadoles.com |---|-------! internet !
|
||||
# | +--------------------+ | +~~~~~~~~~~+
|
||||
# +---------------------------+
|
||||
cucchiaiata-cli v1.infra.cluster.create --cluster_name cluster.cadoles.com \
|
||||
--zone_name internet
|
||||
cucchiaiata-cli v1.infra.cluster.create --cluster_name hapy.ac-test.fr \
|
||||
--zone_name internet \
|
||||
--zones_name internet
|
||||
cucchiaiata-cli v1.infra.cluster.node.create --node_name node1.cadoles.com \
|
||||
--cluster_name cluster.cadoles.com \
|
||||
--zones_name internet
|
||||
--cluster_name hapy.ac-test.fr
|
||||
|
||||
# configuration
|
||||
S=$(get_id "cucchiaiata-cli v1.setting.session.cluster.start --cluster_name cluster.cadoles.com")
|
||||
cucchiaiata-cli v1.setting.session.configure --session_id "$S" --configuration.network.virtual_ip "192.168.1.1"
|
||||
S=$(get_id "cucchiaiata-cli v1.setting.session.cluster.start --cluster_name hapy.ac-test.fr")
|
||||
cucchiaiata-cli v1.setting.session.configure --session_id "$S" --configuration.virtual_ip "192.168.1.1"
|
||||
# FIXME endpoint == https://<cluster_name>/RPC2
|
||||
cucchiaiata-cli v1.setting.session.configure --session_id "$S" --configuration.opennebula.one_user "eoleone"
|
||||
cucchiaiata-cli v1.setting.session.configure --session_id "$S" --configuration.opennebula.one_password "eole"
|
||||
cucchiaiata-cli v1.setting.session.validate --session_id $S
|
||||
cucchiaiata-cli v1.setting.session.stop --session_id "$S" --save
|
||||
|
||||
@ -128,7 +132,7 @@ cucchiaiata-cli v1.setting.session.stop --session_id "$S" --save
|
||||
# '-> dns.cadoles.com (server)
|
||||
cucchiaiata-cli v1.infra.server.create --server_name dns.cadoles.com \
|
||||
--site_name etab1 \
|
||||
--cluster_name cluster.cadoles.com \
|
||||
--cluster_name hapy.ac-test.fr \
|
||||
--zones_name internet \
|
||||
--servermodel_name unbound_etab1
|
||||
# configuration
|
||||
@ -147,11 +151,8 @@ cucchiaiata-cli v1.setting.session.stop --session_id "$S" --save
|
||||
#=======================================================================================================
|
||||
|
||||
# Generate configuration
|
||||
cucchiaiata-cli v1.setting.config.configuration.server.deploy --server_name dns.cadoles.com
|
||||
cucchiaiata-cli v1.setting.template.generate --server_name dns.cadoles.com
|
||||
|
||||
# Generate cluster's configurtion
|
||||
#cucchiaiata-cli v1.provider.configure -c cluster.cadoles.com
|
||||
#cucchiaiata-cli v1.provider.deploy --server dns.cadoles.com
|
||||
cucchiaiata-cli v1.infra.cluster.deploy --cluster_name hapy.ac-test.fr
|
||||
cucchiaiata-cli v1.infra.zone.deploy --zone_name internet
|
||||
cucchiaiata-cli v1.infra.server.deploy --server_name dns.cadoles.com
|
||||
|
||||
echo "fin"
|
||||
|
@ -4,7 +4,7 @@
|
||||
from sys import exit, argv
|
||||
from json import dumps
|
||||
from traceback import print_exc
|
||||
from cucchiaiata import Parser, config, Configuration
|
||||
from cucchiaiata import Parser, config, Configuration, JsonError
|
||||
from cucchiaiata.i18n import _
|
||||
|
||||
|
||||
@ -15,9 +15,15 @@ def main():
|
||||
else:
|
||||
parser = Parser()
|
||||
print(dumps(parser.get(),
|
||||
indent=config.indent))
|
||||
indent=config.indent),
|
||||
)
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
except JsonError as err:
|
||||
print(dumps(err.message,
|
||||
indent=config.indent),
|
||||
)
|
||||
exit(1)
|
||||
except Exception as err:
|
||||
if config.debug:
|
||||
print_exc()
|
||||
|
@ -5,8 +5,9 @@ from sys import exit, argv
|
||||
from yaml import load, SafeLoader, YAMLError
|
||||
from time import sleep
|
||||
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.i18n import _
|
||||
|
||||
@ -33,6 +34,9 @@ class Import(Common):
|
||||
'zone',
|
||||
zone,
|
||||
)
|
||||
self.send('v1.infra.zone.deploy',
|
||||
zone_name=zone['name'],
|
||||
)
|
||||
|
||||
def parse_clusters(self) -> None:
|
||||
for cluster in self.config.get('clusters', []):
|
||||
@ -40,14 +44,17 @@ class Import(Common):
|
||||
'cluster',
|
||||
cluster,
|
||||
zone_name=cluster['zone'],
|
||||
zones_name=cluster['zones'],
|
||||
)
|
||||
for node in cluster.get('nodes', []):
|
||||
self.configuration('infra',
|
||||
'cluster.node',
|
||||
node,
|
||||
cluster_name=cluster['name'],
|
||||
zones_name=node['zones'],
|
||||
)
|
||||
self.send('v1.infra.cluster.deploy',
|
||||
cluster_name=cluster['name'],
|
||||
)
|
||||
|
||||
def parse_servermodels(self) -> None:
|
||||
for servermodel in self.config.get('servermodels', []):
|
||||
@ -75,10 +82,7 @@ class Import(Common):
|
||||
zones_name=server['zones'],
|
||||
servermodel_name=server['servermodel'],
|
||||
)
|
||||
self.send('v1.setting.config.configuration.server.deploy',
|
||||
server_name=server['name'],
|
||||
)
|
||||
self.send('v1.setting.template.generate',
|
||||
self.send('v1.infra.server.deploy',
|
||||
server_name=server['name'],
|
||||
)
|
||||
|
||||
@ -96,9 +100,12 @@ class Import(Common):
|
||||
if 'settings' in dico:
|
||||
#FIXME
|
||||
sleep(1)
|
||||
self.apply_settings(element,
|
||||
dico,
|
||||
)
|
||||
try:
|
||||
self.apply_settings(element,
|
||||
dico,
|
||||
)
|
||||
except JsonError as err:
|
||||
raise Exception(f'unable to configure {element} "{dico["name"]}": {err.message["reason"]}')
|
||||
|
||||
def apply_settings(self,
|
||||
element: str,
|
||||
@ -135,10 +142,10 @@ class Import(Common):
|
||||
value = [value]
|
||||
tiramisu.option(key).value.set(value)
|
||||
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)
|
||||
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)
|
||||
self.send_configuration(tiramisu,
|
||||
session_id,
|
||||
@ -212,7 +219,14 @@ if __name__ == "__main__":
|
||||
print(_(f'usage: {argv[0]} filename.yaml'))
|
||||
exit(1)
|
||||
imp = Import(argv[1])
|
||||
imp.parse_zones()
|
||||
imp.parse_clusters()
|
||||
imp.parse_servermodels()
|
||||
imp.parse_organizations()
|
||||
try:
|
||||
imp.parse_zones()
|
||||
imp.parse_clusters()
|
||||
imp.parse_servermodels()
|
||||
imp.parse_organizations()
|
||||
except JsonError as err:
|
||||
print(err.message['reason'])
|
||||
exit(1)
|
||||
except Exception as err:
|
||||
print(err)
|
||||
exit(1)
|
||||
|
@ -1,6 +1,7 @@
|
||||
from .parser import Parser
|
||||
from .configuration import Configuration
|
||||
from .config import config
|
||||
from .common import JsonError
|
||||
|
||||
__all__ = ('Parser', 'config')
|
||||
__all__ = ('Parser', 'config', 'Configuration', 'JsonError')
|
||||
__version__ = "0.0.1"
|
||||
|
@ -3,9 +3,11 @@ from requests import get, post
|
||||
from json import dumps
|
||||
from typing import Dict
|
||||
|
||||
from .config import config
|
||||
from tiramisu_api import Config
|
||||
|
||||
from .config import config
|
||||
from .i18n import _
|
||||
|
||||
|
||||
if config.allow_insecure_https:
|
||||
import warnings
|
||||
@ -13,6 +15,10 @@ if config.allow_insecure_https:
|
||||
warnings.simplefilter('ignore', InsecureRequestWarning)
|
||||
|
||||
|
||||
class JsonError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class Common:
|
||||
def __init__(self):
|
||||
self.cucchiaiata_config = config
|
||||
@ -78,12 +84,11 @@ class Common:
|
||||
self.send('v1.setting.session.validate',
|
||||
session_id=session_id,
|
||||
)
|
||||
except Exception as err:
|
||||
except JsonError as err:
|
||||
self.send('v1.setting.session.stop',
|
||||
session_id=session_id,
|
||||
)
|
||||
print(_(f'error when validate setting to "{name}" "{dico["name"]}": {err}'))
|
||||
exit(1)
|
||||
raise err from err
|
||||
|
||||
|
||||
def send_data(uri: str,
|
||||
@ -97,11 +102,12 @@ def send_data(uri: str,
|
||||
ret = post(final_url,
|
||||
data=dumps(payload),
|
||||
verify=config.allow_insecure_https)
|
||||
if ret.status_code != 200:
|
||||
try:
|
||||
response = ret.json()
|
||||
except:
|
||||
raise Exception(ret.text)
|
||||
response = ret.json()
|
||||
if 'error' in response:
|
||||
if 'reason' in response['error']['kwargs']:
|
||||
raise Exception("{}".format(response['error']['kwargs']['reason']))
|
||||
raise Exception('erreur inconnue')
|
||||
if response['type'] == 'error':
|
||||
err = JsonError()
|
||||
err.message = response['response']
|
||||
raise err
|
||||
return response['response']
|
||||
|
Reference in New Issue
Block a user