From 8fe52fa1e3fa3d0a8f3aeb802d0f688c2e675a7e Mon Sep 17 00:00:00 2001 From: jem Date: Fri, 1 May 2020 17:38:17 +0200 Subject: [PATCH] adddda-simple-mixin --- .travis.yml | 1 - src/main/python/ddadevops/__init__.py | 3 +- src/main/python/ddadevops/dda_simple_mixin.py | 72 +++++++++++++++++++ src/main/python/ddadevops/devops_build.py | 1 + 4 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 src/main/python/ddadevops/dda_simple_mixin.py diff --git a/.travis.yml b/.travis.yml index ac0a118..8043b3f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: python python: - - "2.7" - "3.7" before_script: sudo apt-get install pychecker install: pip install pybuilder diff --git a/src/main/python/ddadevops/__init__.py b/src/main/python/ddadevops/__init__.py index 1c7b4ba..f92ff8f 100644 --- a/src/main/python/ddadevops/__init__.py +++ b/src/main/python/ddadevops/__init__.py @@ -11,6 +11,7 @@ from .devops_docker_build import DevopsDockerBuild, create_devops_docker_build_c from .hetzner_mixin import HetznerMixin, add_hetzner_mixin_config from .aws_backend_properties_mixin import AwsBackendPropertiesMixin, add_aws_backend_properties_mixin_config from .aws_mfa_mixin import AwsMfaMixin, add_aws_mfa_mixin_config -from .dda_pallet_mixin import DdaPalletMixin, add_dda_pallet_mixin_config +from .dda_tenant_mixin import DdaTenantMixin, add_dda_tenant_mixin_config +from .dda_simple_mixin import DdaSimpleMixin, add_dda_simple_mixin_config __version__ = "${version}" \ No newline at end of file diff --git a/src/main/python/ddadevops/dda_simple_mixin.py b/src/main/python/ddadevops/dda_simple_mixin.py new file mode 100644 index 0000000..6e55345 --- /dev/null +++ b/src/main/python/ddadevops/dda_simple_mixin.py @@ -0,0 +1,72 @@ +from string import Template +from subprocess import run +from .python_util import * +from .devops_build import DevopsBuild + + +def add_dda_simple_mixin_config(config, domain_file_name, + jar_file=None, + target_edn_name='target.edn'): + config.update({'DdaSimpleMixin': + {'domain_file_name': domain_file_name, + 'target_edn_name': target_edn_name, + 'jar_file': jar_file, + 'target_template': + """ +{:existing [{:node-name "$node_name" + :node-ip "$ipv4"}] + :provisioning-user {:login "root"}} +""", }}) + return config + + +class DdaSimpleMixin(DevopsBuild): + + def __init__(self, project, config): + super().__init__(project, config) + dda_pallet_mixin_config = config['DdaSimpleMixin'] + self.domain_file_name = dda_pallet_mixin_config['domain_file_name'] + self.target_edn_name = dda_pallet_mixin_config['target_edn_name'] + self.jar_file = dda_pallet_mixin_config['jar_file'] + if not self.jar_file: + self.jar_file = 'target/uberjar/' + self.module + '-standalone.jar' + self.target_template = Template( + dda_pallet_mixin_config['target_template']) + + def initialize_build_dir(self): + super().initialize_build_dir() + run('cp *.edn ' + self.build_path(), shell=True) + + def dda_write_target(self, node_name, ipv4): + with open(self.build_path() + '/' + self.target_edn_name, "w") as output_file: + output_file.write( + self.target_template.substitute({'ipv4': ipv4, 'node_name': node_name})) + + def dda_write_domain(self, substitues): + with open(self.build_path() + '/' + self.domain_file_name, "r") as input_file: + domain_input = input_file.read() + domain_template = Template(domain_input) + with open(self.build_path() + '/out_' + self.domain_file_name, "w") as output_file: + output_file.write(domain_template.substitute(substitues)) + + def dda_uberjar(self, configure_switch=None): + if configure_switch: + cmd = ['java', '-jar', self.project_root_path + '/' + self.jar_file, + '--targets', self.build_path() + '/' + self.target_edn_name, + '--configure', + self.build_path() + '/out_' + self.domain_file_name] + else: + cmd = ['java', '-jar', self.project_root_path + '/' + self.jar_file, + '--targets', self.build_path() + '/' + self.target_edn_name, + self.build_path() + '/out_' + self.domain_file_name] + prn_cmd = list(cmd) + print(" ".join(prn_cmd)) + output = execute(cmd) + print(output) + return output + + def dda_install(self): + return self.dda_uberjar() + + def dda_configure(self): + return self.dda_uberjar(True) diff --git a/src/main/python/ddadevops/devops_build.py b/src/main/python/ddadevops/devops_build.py index b1bfad3..1843714 100644 --- a/src/main/python/ddadevops/devops_build.py +++ b/src/main/python/ddadevops/devops_build.py @@ -15,6 +15,7 @@ def get_devops_build(project): class DevopsBuild: def __init__(self, project, config): + #deprecate stage self.stage = config['stage'] self.project_root_path = config['project_root_path'] self.module = config['module']