diff --git a/provisioning_example.sh b/provisioning_example.sh index 6f653e4..cc81d2b 100755 --- a/provisioning_example.sh +++ b/provisioning_example.sh @@ -1,6 +1,17 @@ #!/usr/bin/env bash set -xe +function get_id() { + S=$($1) + V=$(echo $S|jq -r .session_id) + if [ $? = 0 ]; then + echo $V + else + echo $S + exit 1 + fi +} + #======================================================================================================= # Infrastructure #======================================================================================================= @@ -22,12 +33,12 @@ cucchiaiata-cli v1.user.role.create --user_login gnunux \ # +~~~~~~~~~~+ cucchiaiata-cli v1.infra.zone.create --zone_name internet # zone configuration -S=$(cucchiaiata-cli v1.setting.session.zone.start --zone_name internet | jq -r .session_id) -cucchiaiata-cli v1.setting.session.configure --session_id "$S" --configuration.network.network "192.168.1.0/24" \ - --configuration.network.host_start "192.168.1.10" \ - --configuration.network.host_stop "192.168.1.100" \ - --configuration.network.dns 192.168.1.2 \ - --configuration.network.gateway 192.168.1.254 +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" \ + --configuration.dns 192.168.1.2 \ + --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 @@ -46,7 +57,7 @@ cucchiaiata-cli v1.infra.cluster.node.create --node_name node1.cadoles.com \ --zones_name internet # configuration -S=$(cucchiaiata-cli v1.setting.session.cluster.start --cluster_name cluster.cadoles.com | jq -r .session_id) +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" cucchiaiata-cli v1.setting.session.validate --session_id $S cucchiaiata-cli v1.setting.session.stop --session_id "$S" --save @@ -88,12 +99,12 @@ cucchiaiata-cli v1.setting.servermodel.create --servermodel_name unbound_etab1 - # configuration # Servermodel ACA -S=$(cucchiaiata-cli v1.setting.session.servermodel.start --servermodel_name aca| jq -r .session_id) +S=$(get_id "cucchiaiata-cli v1.setting.session.servermodel.start --servermodel_name aca") cucchiaiata-cli v1.setting.session.configure --session_id "$S" --configuration.serveur_ssh.ssh_allow_networks admin.cadoles.com cucchiaiata-cli v1.setting.session.stop --session_id "$S" --save # Servermodel unbound -S=$(cucchiaiata-cli v1.setting.session.servermodel.start --servermodel_name unbound| jq -r .session_id) +S=$(get_id "cucchiaiata-cli v1.setting.session.servermodel.start --servermodel_name unbound") cucchiaiata-cli v1.setting.session.configure --session_id "$S" --configuration.serveur_dns.unbound_local_zones cadoles.com \ --configuration.reseau.unbound_route_address 192.168.1.254 \ --configuration.serveur_dns.unbound_allowed_client_cidr 192.168.1.0/24 @@ -105,7 +116,7 @@ cucchiaiata-cli v1.setting.session.configure --session_id "$S" --unbound.unbound cucchiaiata-cli v1.setting.session.stop --session_id "$S" --save # Servermodel unbound_etab1 -S=$(cucchiaiata-cli v1.setting.session.servermodel.start --servermodel_name unbound_etab1 | jq -r .session_id) +S=$(get_id "cucchiaiata-cli v1.setting.session.servermodel.start --servermodel_name unbound_etab1") cucchiaiata-cli v1.setting.session.configure --session_id "$S" --configuration.reseau.unbound_domain_name dns.cadoles.com cucchiaiata-cli v1.setting.session.stop --session_id "$S" --save @@ -125,12 +136,12 @@ cucchiaiata-cli v1.infra.server.create --server_name dns.cadoles.com \ --servermodel_name unbound_etab1 # configuration sleep 1 -S=$(cucchiaiata-cli v1.setting.session.server.start --server dns.cadoles.com | jq -r .session_id) +S=$(get_id "cucchiaiata-cli v1.setting.session.server.start --server dns.cadoles.com") cucchiaiata-cli v1.setting.session.configure --session_id "$S" --configuration.reseau.unbound_ip_address_cidr 192.168.1.2/24 cucchiaiata-cli v1.setting.session.filter --session_id "$S" --namespace opennebula -cucchiaiata-cli v1.setting.session.configure --session_id "$S" --opennebula.configuration.cpu 0.2 \ - --opennebula.configuration.vcpu 2 \ - --opennebula.configuration.memory 2 +cucchiaiata-cli v1.setting.session.configure --session_id "$S" --opennebula.cpu 0.2 \ + --opennebula.vcpu 2 \ + --opennebula.memory 2 cucchiaiata-cli v1.setting.session.validate --session_id $S cucchiaiata-cli v1.setting.session.stop --session_id "$S" --save diff --git a/src/cucchiaiata/configuration.py b/src/cucchiaiata/configuration.py index 6e4b18b..ee998be 100644 --- a/src/cucchiaiata/configuration.py +++ b/src/cucchiaiata/configuration.py @@ -29,9 +29,9 @@ class Configuration(Common): version = smessage[0] type = smessage[-2] url = '{}/{}/setting/{}'.format(self.cucchiaiata_config.remote_url, - version, - self.session_id, - ) + version, + self.session_id, + ) tconfig = self.remote_json_to_config(url, ConfigAPI, ) @@ -65,8 +65,11 @@ class Configuration(Common): def get(self): parameters = self.get_parameters() tiramisu_config = self.configure_server() + option = next(tiramisu_config.option.list('all')) + namespace = option.option.path().split('.', 1)[0] parser = TiramisuCmdlineParser(tiramisu_config, self.prog, + root=namespace, unrestraint=True, fullpath=True) parser.parse_args(parameters,