Example #1
0
def puppet(manifest):
    """return the generated seedbank bootstrap init file"""
    file_name = os.path.join(cfg['paths']['templates'],
                             cfg['templates']['puppet_manifest'])
    result = utils.file_read(file_name)
    result = utils.apply_template(result, {'manifest': manifest}, file_name)
    return result
Example #2
0
 def _gather_script(self):
     """get node information via a lookup script"""
     command = utils.apply_template(self.provider, self.values)
     command = command.split(' ')
     result = utils.run(command)
     if not result.retcode:
         return self._return(yaml.load(result.output))
Example #3
0
 def _gather_script(self):
     """get node information via a lookup script"""
     command = utils.apply_template(self.provider, self.values)
     command = command.split(' ')
     result = utils.run(command)
     if not result.retcode:
         return self._return(yaml.load(result.output))
Example #4
0
 def hook_enable(self):
     """apply PXE variables on the configured enable hook(s) and run the
     hook(s)"""
     for hook in cfg['hooks_pxe']['enable']:
         hook = utils.apply_template(hook, self.pxe_variables)
         logging.info('found enable hook "%s"', hook)
         utils.run(hook, error=True)
Example #5
0
 def hook_enable(self):
     """apply PXE variables on the configured enable hook(s) and run the
     hook(s)"""
     for hook in cfg['hooks_pxe']['enable']:
         hook = utils.apply_template(hook, self.pxe_variables)
         logging.info('found enable hook "%s"', hook)
         utils.run(hook, error=True)
Example #6
0
def puppet(manifest):
    """return the generated seedbank bootstrap init file"""
    file_name = os.path.join(cfg['paths']['templates'],
        cfg['templates']['puppet_manifest'])
    result = utils.file_read(file_name)
    result = utils.apply_template(result, {'manifest': manifest}, file_name)
    return result
Example #7
0
 def _gather_http(self):
     """get internal nodes information via http ot https, delete the first line"""
     url = utils.apply_template(self.provider, self.values)
     result = utils.read_url(url)
     if result:
         del result[0]
     result = ''.join(result)
     return self._return(yaml.load(result))
Example #8
0
 def _gather_http(self):
     """get internal nodes information via http ot https, delete the first line"""
     url = utils.apply_template(self.provider, self.values)
     result = utils.read_url(url)
     if result:
         del result[0]
     result = ''.join(result)
     return self._return(yaml.load(result))
Example #9
0
def rclocal(address):
    """return the rc.local file"""
    pxe_vars = settings.pxe_variables(cfg, address)
    file_name = os.path.join(cfg['paths']['templates'],
        cfg['templates']['rc_local'])
    result = utils.file_read(file_name)
    result = utils.apply_template(result, pxe_vars, file_name)
    return result
Example #10
0
def rclocal(address):
    """return the rc.local file"""
    pxe_vars = settings.pxe_variables(cfg, address)
    file_name = os.path.join(cfg['paths']['templates'],
                             cfg['templates']['rc_local'])
    result = utils.file_read(file_name)
    result = utils.apply_template(result, pxe_vars, file_name)
    return result
Example #11
0
 def _merge_seeds(self, seeds, values):
     """merge the main seed file with the recipe(s) and additional seeds 
     return it as a string"""
     result = ''
     for seed in seeds:
         file_name = os.path.join(self.cfg['paths']['seeds'], seed + '.seed')
         logging.info('applying template values to "%s"', file_name)
         data = utils.file_read(file_name)
         result += utils.apply_template(data, values, file_name)
     return result
Example #12
0
 def _merge_seeds(self, seeds, values):
     """merge the main seed file with the recipe(s) and additional seeds
     return it as a string"""
     result = ''
     for seed in seeds:
         file_name = os.path.join(self.cfg['paths']['seeds'],
                                  seed + '.seed')
         logging.info('applying template values to "%s"', file_name)
         data = utils.file_read(file_name)
         result += utils.apply_template(data, values, file_name)
     return result
Example #13
0
    def generate(self):
        """generate the pxe boot file"""
        self.pxe_variables.update({
            'config': self.config,
            'seeds': self.seeds,
            'seed_host': cfg['settings']['seed_host'],
            'seed_port': cfg['settings']['bottle_port'],
            'address': self.address,
            'overlay': self.overlay,
            'puppet_manifests': self.puppet,
            'host_name': self.host_name,
            'dns_domain': self.dns_domain,
            'fqdn': self.fqdn,
            'query': urllib.urlencode([('address', self.address)]),
            'date_generated': utils.date_time(),
            'date_disabled': '',
            'kernel': '%s/%s/%s' % ('seedbank', self.release, 'linux'),
            'initrd': '%s/%s/%s' % ('seedbank', self.release, 'initrd.gz')
        })

        if self.config:
            yaml_file = os.path.join(cfg['paths']['configs'], self.config)
            yaml_file = yaml_file + '.yaml'
            overrides = utils.yaml_read(yaml_file)
            if 'pxe' in overrides:
                cfg['pxe'].update(overrides['pxe'])
        values = cfg['pxe']
        self.pxe_variables.update(values)

        distribution = self.release.split('-')[0]
        file_name = cfg[distribution]['template_pxe']
        file_name = os.path.join(cfg['paths']['templates'], file_name)
        if not os.path.isfile(file_name):
            err = 'file "%s" does not exist (hint: check the templates '\
                'section in your settings)' % file_name
            raise utils.FatalException(err)

        pxe_variables_custom = []
        for variable in self.variables:
            key, value = variable
            pxe_variables_custom.append('# %s = %s' % (key, value))
            self.pxe_variables[key] = value
        pxe_variables_custom = '\n'.join(pxe_variables_custom)

        data = utils.file_read(file_name)
        data = utils.apply_template(data, self.pxe_variables, file_name)
        if pxe_variables_custom:
            data = re.sub(
                '(#\n# \*\*\* end - seedBank pxe variables \*\*\*)',
                pxe_variables_custom + '\n\\1', data)
        return data
Example #14
0
def commands_template(cmds, values):
    """apply values to a command template"""
    cmds = [utils.apply_template(cmd, values, cmd) for cmd in cmds]
    return cmds
Example #15
0
def commands_template(cmds, values):
    """apply values to a command template"""
    cmds = [utils.apply_template(cmd, values, cmd) for cmd in cmds]
    return cmds
Example #16
0
    def generate(self):
        """generate the pxe boot file"""
        self.pxe_variables.update({
            'config':
            self.config,
            'seeds':
            self.seeds,
            'seed_host':
            cfg['settings']['seed_host'],
            'seed_port':
            cfg['settings']['bottle_port'],
            'address':
            self.address,
            'overlay':
            self.overlay,
            'puppet_manifests':
            self.puppet,
            'host_name':
            self.host_name,
            'dns_domain':
            self.dns_domain,
            'fqdn':
            self.fqdn,
            'query':
            urllib.urlencode([('address', self.address)]),
            'date_generated':
            utils.date_time(),
            'date_disabled':
            '',
            'kernel':
            '%s/%s/%s' % ('seedbank', self.release, 'linux'),
            'initrd':
            '%s/%s/%s' % ('seedbank', self.release, 'initrd.gz')
        })

        if self.config:
            yaml_file = os.path.join(cfg['paths']['configs'], self.config)
            yaml_file = yaml_file + '.yaml'
            overrides = utils.yaml_read(yaml_file)
            if 'pxe' in overrides:
                cfg['pxe'].update(overrides['pxe'])
        values = cfg['pxe']
        self.pxe_variables.update(values)

        distribution = self.release.split('-')[0]
        file_name = cfg[distribution]['template_pxe']
        file_name = os.path.join(cfg['paths']['templates'], file_name)
        if not os.path.isfile(file_name):
            err = 'file "%s" does not exist (hint: check the templates '\
                'section in your settings)' % file_name
            raise utils.FatalException(err)

        pxe_variables_custom = []
        for variable in self.variables:
            key, value = variable
            pxe_variables_custom.append('# %s = %s' % (key, value))
            self.pxe_variables[key] = value
        pxe_variables_custom = '\n'.join(pxe_variables_custom)

        data = utils.file_read(file_name)
        data = utils.apply_template(data, self.pxe_variables, file_name)
        if pxe_variables_custom:
            data = re.sub('(#\n# \*\*\* end - seedBank pxe variables \*\*\*)',
                          pxe_variables_custom + '\n\\1', data)
        return data
Example #17
0
import utils

# utils.html_output()

# utils.apply_template()

import sys
print("This is argv:", sys.argv)
command = sys.argv[1]
if command == "build":
    utils.html_output()
    utils.apply_template()
elif command == "new":
    page_name = input("What is the page name?")
    new_page = 'content/' + page_name + '.html'
    open(new_page, "w+").write("Import new content")
else:
    print("Please specify ’build’ or ’new’")