Exemple #1
0
 def _render_directory_templates(self):
     """ Loop and use render_template helper method on all templates in destination directory  """
     for template in glob.glob(self._destination_directory_name +
                               "/*.jinja"):
         template_file_name = template.split('/')[-1]
         path = '/'.join(template.split('/')[0:-1])
         target_file_name = re.sub(r'\.jinja$', '', template_file_name)
         target = self._destination_directory_name + "/" + target_file_name
         render_template(template_file_name,
                         path,
                         target,
                         self._data,
                         overwrite=self._overwrite)
Exemple #2
0
 def __prepare_ansible_cfg_vars(self):
     template_name = "ansible.cfg-default.jinja"
     template_path = "{}/config/local".format(self._repository_directory)
     target = "{}/config/local/ansible.cfg-default".format(
         self._repository_directory)
     context = {}
     return render_template(template_name, template_path, target, context)
Exemple #3
0
    def _render_directory_templates(self, data):
        """ Overide Component method _render_directory_templates.
        Loop and use render_template helper method on all templates
        in destination directory, but use the _data['name'] as the base
        for the target file instead of the tempate name itself """

        # Here is where it differs from the Component._render_directory_templates()
        target_file_name = os.path.normpath("{}{}.tf".format(
            self._destination, data['resource_name']))

        render_template(self.template_file_name,
                        self._files_directory,
                        target_file_name,
                        data,
                        delete_template=False,
                        overwrite=self._overwrite)
Exemple #4
0
 def _render_directory_templates(self):
     """ Loop and use render_template helper method on all templates in destination directory  """
     logging.debug("Rendering Templates: ")
     for folder, dirnames, files in os.walk(
             self._destination_directory_name):
         for template in glob.glob(folder + "/*.jinja"):
             logging.debug("Rendering {}".format(template))
             template_file_name = template.split('/')[-1]
             path = '/'.join(template.split('/')[0:-1])
             target_file_name = re.sub(r'\.jinja$', '', template_file_name)
             target = folder + "/" + target_file_name
             render_template(template_file_name,
                             path,
                             target,
                             self._data,
                             overwrite=self._overwrite)
Exemple #5
0
 def __prepare_account_vars_sh(self):
     template_name = "vars.sh.jinja"
     template_path = "{}/default/account/".format(
         self._repository_directory)
     target = "{}/default/account/vars.sh".format(
         self._repository_directory)
     context = {'KOPS_STATE_STORE_BUCKET': self._infrastructure_bucket}
     return render_template(template_name, template_path, target, context)
Exemple #6
0
 def __prepare_tf_vpc_module_root(self):
     template_name = "main.tf.jinja"
     template_path = "{}/default/vpc".format(self._repository_directory)
     target = "{}/default/vpc/main.tf".format(self._repository_directory)
     context = {
         'vpc_name': self._vpc_name,
         'infrastructure_bucket': self._infrastructure_bucket,
         'aws_region': self._aws_default_region
     }
     return render_template(template_name, template_path, target, context)
Exemple #7
0
 def __prepare_config_private_secrets(self):
     template_name = "secrets.yml.jinja"
     template_path = "{}/config/private".format(self._repository_directory)
     target = "{}/config/private/secrets.yml".format(
         self._repository_directory)
     context = {
         'aws_secret_key': self._aws_secret_key,
         'aws_access_key': self._aws_access_key
     }
     return render_template(template_name, template_path, target, context)
Exemple #8
0
 def __prepare_vpn_cfg_vars(self):
     self.__get_vpn_ami_id()
     template_name = "env.yml.jinja"
     template_path = "{}/default/resources/admin-environment".format(
         self._repository_directory)
     target = "{}/default/resources/admin-environment/env.yml".format(
         self._repository_directory)
     context = {
         'admin_vpn_key': self._ssh_keys['admin_vpn'],
         'vpn_ami_id': self._vpn_ami_id
     }
     return render_template(template_name, template_path, target, context)
Exemple #9
0
 def __prepare_account_vars_yml(self):
     template_name = "vars.yml.jinja"
     template_path = "{}/default/account/".format(
         self._repository_directory)
     target = "{}/default/account/vars.yml".format(
         self._repository_directory)
     context = {
         'org_name': self._name,
         'vpc_name': self._vpc_name,
         'dns_zone': self._dns_zone,
     }
     return render_template(template_name, template_path, target, context)
Exemple #10
0
 def _render_directory_templates(self):
     """ Loop and use render_template helper method on all templates in destination directory  """
     template_location = self._destination_directory_name
     if os.path.isfile(template_location):
         template_location = os.path.dirname(template_location)
         logging.debug(
             "{} is a file. Using the directory {} instead.".format(
                 self._destination_directory_name, template_location))
     logging.debug("Rendering Templates in {}".format(template_location))
     for folder, dirnames, files in os.walk(template_location):
         for template in glob.glob(folder + "/*.jinja"):
             logging.debug("Rendering {}".format(template))
             template_file_name = template.split('/')[-1]
             path = '/'.join(template.split('/')[0:-1])
             target_file_name = re.sub(r'\.jinja$', '', template_file_name)
             target = folder + "/" + target_file_name
             render_template(template_file_name,
                             path,
                             target,
                             self._data,
                             overwrite=self._overwrite)
Exemple #11
0
 def __prepare_ssh_config_vars(self):
     template_name = "ssh_config-default.jinja"
     template_path = "{}/config/local".format(self._repository_directory)
     target = "{}/config/local/ssh_config-default".format(
         self._repository_directory)
     context = {
         'production_kube_key': self._ssh_keys['production_kube'],
         'working_kube_key': self._ssh_keys['working_kube'],
         'production_private_key': self._ssh_keys['production_private'],
         'working_private_key': self._ssh_keys['working_private'],
         'admin_vpn_key': self._ssh_keys['admin_vpn'],
     }
     return render_template(template_name, template_path, target, context)
Exemple #12
0
 def __prepare_config_local_vars(self):
     template_name = "vars.yml.jinja"
     template_path = "{}/config/local".format(self._repository_directory)
     target = "{}/config/local/vars.yml".format(self._repository_directory)
     context = {
         'org_name': self._name,
         'vpc_name': self._vpc_name,
         'aws_default_region': self._aws_default_region,
         'aws_availability_zones': self._aws_availability_zones,
         'aws_availability_zone_count': self._aws_availability_zone_count,
         'infrastructure_bucket': self._infrastructure_bucket
     }
     return render_template(template_name, template_path, target, context)
Exemple #13
0
    def add(self, destination):
        """ Copies files and templates from <component>/files and templates the *.jinja files """
        self._destination = destination
        try:
            shutil.copytree(self._files_directory,
                            self._destination_directory_name)

            init_file = self._destination_directory_name + "/__init__.py"
            if os.path.isfile(init_file):
                os.remove(init_file)

            for template in glob.glob(self._destination_directory_name +
                                      "/*.jinja"):
                template_file_name = template.split('/')[-1]
                path = '/'.join(template.split('/')[0:-1])
                target_file_name = re.sub(r'\.jinja$', '', template_file_name)
                target = self._destination_directory_name + "/" + target_file_name
                render_template(template_file_name, path, target, self._data)
        except Exception as e:
            logging.error("Error occured configuring component")
            logging.error(e)
            logging.debug(traceback.format_exc(e))