This commit is contained in:
jem 2020-03-03 18:30:17 +01:00
parent b22f0096f2
commit 23af9aa638
7 changed files with 31 additions and 26 deletions

View file

@ -27,7 +27,7 @@ use_plugin("python.distutils")
default_task = "publish"
name = "ddadevops"
version = "0.4.0.dev2"
version = "0.4.0.dev8"
summary = "tools to support builds combining gopass, terraform, dda-pallet, aws & hetzner-cloud"
description = __doc__
authors = [Author("meissa GmbH", "buero@meissa-gmbh.de")]

View file

@ -11,7 +11,7 @@ def add_aws_mixin_config(config, account_name):
class AwsMixin(DevopsTerraformBuild):
def __init__(project, config):
def __init__(self, project, config):
super().__init__(project, config)
aws_mixin_config = config['AwsMixin']
self.account_name = aws_mixin_config['account_name']
@ -21,11 +21,12 @@ class AwsMixin(DevopsTerraformBuild):
def project_vars(self):
ret = super().project_vars()
return ret.update({'account_name': self.account_name})
ret.update({'account_name': self.account_name})
return ret
def init_client(self):
tf = Terraform(working_dir=self.build_path())
tf.init(backend_config=self.backend_config)
tf.init(backend_config=self.backend_config())
try:
tf.workspace('select', slef.stage)
except:
@ -34,5 +35,5 @@ class AwsMixin(DevopsTerraformBuild):
def plan(self):
tf = self.init_client()
tf.plan(capture_output=False, var=self.project_vars,
var_file=self.backend_config)
tf.plan(capture_output=False, var=self.project_vars(),
var_file=self.backend_config())

View file

@ -32,6 +32,10 @@ class DdaPalletMixin(DevopsBuild):
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(

View file

@ -1,4 +1,5 @@
from subprocess import run
from .python_util import filter_none
def create_devops_build_config(stage, project_root_path, build_commons_path, module):
@ -8,7 +9,6 @@ def create_devops_build_config(stage, project_root_path, build_commons_path, mod
'module': module,
'build_dir_name': 'target'}
class DevopsBuild:
def __init__(self, project, config):
@ -24,16 +24,11 @@ class DevopsBuild:
return self.project.get_property('name')
def build_path(self):
return self.project_root_path + self.build_dir_name + '/' + self.module + '/'
mylist = [self.project_root_path,
self.build_dir_name,
self.module]
return '/'.join(filter_none(mylist))
def initialize_build_dir(self):
run('rm -rf ' + self.build_path(), shell=True)
run('mkdir -p ' + self.build_path(), shell=True)
def tf_import_name(project):
return project.get_property('tf_import_name')
def tf_import_resource(project):
return project.get_property('tf_import_resource')

View file

@ -2,6 +2,7 @@ from os import path
from json import load
from subprocess import run
from python_terraform import *
from .python_util import filter_none
from .devops_build import DevopsBuild, create_devops_build_config
@ -29,7 +30,9 @@ class DevopsTerraformBuild(DevopsBuild):
self.output_json_name = config['output_json_name']
def terraform_build_commons_path(self):
return self.build_commons_path() + '/' + self.terraform_build_commons_dir_name
mylist = [self.build_commons_path,
self.terraform_build_commons_dir_name]
return '/'.join(filter_none(mylist))
def project_vars(self):
ret = {'stage': self.stage}
@ -41,12 +44,11 @@ class DevopsTerraformBuild(DevopsBuild):
def initialize_build_dir(self):
super().initialize_build_dir()
run('cp -f ' + self.terraform_build_commons_path +
'* ' + self.build_path, shell=True)
run('cp *.tf ' + self.build_path, shell=True)
run('cp *.properties ' + self.build_path, shell=True)
run('cp *.tfars ' + self.build_path, shell=True)
run('cp *.edn ' + self.build_path, shell=True)
run('cp -f ' + self.terraform_build_commons_path() +
'* ' + self.build_path(), shell=True)
run('cp *.tf ' + self.build_path(), shell=True)
run('cp *.properties ' + self.build_path(), shell=True)
run('cp *.tfars ' + self.build_path(), shell=True)
def init_client(self):
tf = Terraform(working_dir=self.build_path())
@ -68,7 +70,7 @@ class DevopsTerraformBuild(DevopsBuild):
def plan(self):
tf = self.init_client()
tf.plan(capture_output=False, var=self.project_vars)
tf.plan(capture_output=False, var=self.project_vars())
def apply(self, p_auto_approve=False):
tf = self.init_client()

View file

@ -17,7 +17,7 @@ class HetznerMixin(DevopsTerraformBuild):
hetzner_mixin_config['HETZNER_API_KEY_PATH_ENVIRONMENT'])
def project_vars(self):
ret = super().project_vars
ret = super().project_vars()
if self.hetzner_api_key:
ret['hetzner_api_key'] = self.hetzner_api_key
return ret

View file

@ -6,4 +6,7 @@ def execute(cmd):
output = check_output(cmd, encoding='UTF-8')
else:
output = check_output(cmd)
return output
return output
def filter_none(list):
return [x for x in list if x is not None]