Example #1
0
def parse_cfg():
    """validate the configuration"""
    settings = None
    override_files = ['./settings.yaml', '~/.seedbank/settings.yaml']
    settings_file_name = '/etc/seedbank/settings.yaml'
    files = override_files + [settings_file_name]

    for file_name in files:
        if os.path.isfile(file_name):
            settings_file = file_name
            break

    settings = utils.yaml_read(settings_file)
    if not settings:
        err = 'can not find a settings.yaml file (%s)' % ', '.join(files)
        raise utils.FatalException(err)

    path = settings['settings']['configuration_path']
    if not os.path.isdir(path):
        raise utils.FatalException('directory "%s" does not exist' % path)

    if settings_file in override_files:
        logging.info('found settings file "%s", will use this settings file '
            'instead of the default (%s)', settings_file, settings_file_name)

    files = os.listdir(path)
    files = [file_name for file_name in files if file_name.endswith('.yaml')]
    files = [os.path.join(path, file_name) for file_name in files]
    cfg = utils.yaml_read(files)
    cfg.update(settings)

    netboots = []
    for release in cfg['distributions']['netboots']:
        for architecture in cfg['distributions']['architectures']:
            netboots.append(release + '-' + architecture)
    cfg['distributions']['netboots'] = netboots

    isos = []
    for iso in cfg['distributions']['isos']:
        iso_split = iso.split('-')
        distribution, release = iso_split

        for flavour in cfg['distributions'][distribution + '_iso_flavours']:
            for architecture in cfg['distributions']['architectures']:
                isos.append('%s-%s-%s-%s' % (distribution, release, architecture, flavour))
    cfg['distributions']['isos'] = isos

    return cfg
Example #2
0
def parse_cfg():
    """validate the configuration"""
    settings = None
    override_files = ['./settings.yaml', '~/.seedbank/settings.yaml']
    settings_file_name = '/etc/seedbank/settings.yaml'
    files = override_files + [settings_file_name]

    for file_name in files:
        if os.path.isfile(file_name):
            settings_file = file_name
            break

    settings = utils.yaml_read(settings_file)
    if not settings:
        err = 'can not find a settings.yaml file (%s)' % ', '.join(files)
        raise utils.FatalException(err)

    path = settings['settings']['configuration_path']
    if not os.path.isdir(path):
        raise utils.FatalException('directory "%s" does not exist' % path)

    if settings_file in override_files:
        logging.info(
            'found settings file "%s", will use this settings file '
            'instead of the default (%s)', settings_file, settings_file_name)

    files = os.listdir(path)
    files = [file_name for file_name in files if file_name.endswith('.yaml')]
    files = [os.path.join(path, file_name) for file_name in files]
    cfg = utils.yaml_read(files)
    cfg.update(settings)

    distributions = ['debian', 'ubuntu']
    isos = []
    netboots = []
    for distribution in distributions:
        if 'isos' in cfg[distribution]:
            isos = list_isos(cfg, distribution, isos)
        if 'netboots' in cfg[distribution]:
            netboots = list_netboots(cfg, distribution, netboots)
    cfg['netboots'] = netboots
    cfg['isos'] = isos
    return cfg
Example #3
0
def parse_cfg():
    """validate the configuration"""
    settings = None
    override_files = ['./settings.yaml', '~/.seedbank/settings.yaml']
    settings_file_name = '/etc/seedbank/settings.yaml'
    files = override_files + [settings_file_name]

    for file_name in files:
        if os.path.isfile(file_name):
            settings_file = file_name
            break

    settings = utils.yaml_read(settings_file)
    if not settings:
        err = 'can not find a settings.yaml file (%s)' % ', '.join(files)
        raise utils.FatalException(err)

    path = settings['settings']['configuration_path']
    if not os.path.isdir(path):
        raise utils.FatalException('directory "%s" does not exist' % path)

    if settings_file in override_files:
        logging.info('found settings file "%s", will use this settings file '
            'instead of the default (%s)', settings_file, settings_file_name)

    files = os.listdir(path)
    files = [file_name for file_name in files if file_name.endswith('.yaml')]
    files = [os.path.join(path, file_name) for file_name in files]
    cfg = utils.yaml_read(files)
    cfg.update(settings)

    distributions = ['debian', 'ubuntu']
    isos = []
    netboots = []
    for distribution in distributions:
        if 'isos' in cfg[distribution]:
            isos = list_isos(cfg, distribution, isos)
        if 'netboots' in cfg[distribution]:
            netboots = list_netboots(cfg, distribution, netboots)
    cfg['netboots'] = netboots
    cfg['isos'] = isos
    return cfg
Example #4
0
def merge_cfg(config):
    """merge the default configuration with the configuration overrides"""
    cfg = parse_cfg()
    if config:
        yaml_file = os.path.join(cfg['paths']['configs'], config)
        yaml_file += '.yaml'
        overrides = utils.yaml_read(yaml_file)
        for key in cfg:
            if key in overrides:
                cfg[key].update(overrides[key])
    return cfg
Example #5
0
def merge_cfg(config):
    """merge the default configuration with the configuration overrides"""
    cfg = parse_cfg()
    if config:
        yaml_file = os.path.join(cfg['paths']['configs'], config)
        yaml_file += '.yaml'
        overrides = utils.yaml_read(yaml_file)
        for key in cfg:
            if key in overrides:
                cfg[key].update(overrides[key])
    return cfg
Example #6
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 #7
0
    def _shared(self, args, release):
        """process shared arguments between the pxe and iso commands"""
        if args.config:
            yaml_file = os.path.join(self.cfg["paths"]["configs"], args.config)
            yaml_file += ".yaml"
            overrides = utils.yaml_read(yaml_file)
            if "args" in overrides:
                args = settings.override(args, overrides)
            config = dict(self.cfg.items() + overrides.items())
        else:
            config = self.cfg

        if args.overlay:
            path = os.path.join(self.cfg["paths"]["overlays"], args.overlay)
            if os.path.isdir(path):
                args.path = path
            else:
                raise self.exception('file overlay directory "%s" does not ' "exist" % path)

        if not "." in args.fqdn:
            raise self.exception('"%s" is not a fully qualified domain name' % args.fqdn)

        if not args.seed:
            args.seed = release
        args.seeds = [args.seed] + args.additional
        for seed_file in args.seeds:
            file_name = os.path.join(self.cfg["paths"]["seeds"], seed_file)
            file_name += ".seed"
            if not os.path.isfile(file_name):
                raise self.exception('preseed file "%s" does not exist' % file_name)

        if args.puppet:
            for index, manifest in enumerate(args.puppet):
                file_name = os.path.join(config["paths"]["puppet_manifests"], manifest + ".pp")
                if not os.path.isfile(file_name):
                    err = 'Puppet manifest "%s" does not exist' % file_name
                    raise self.exception(err)
                else:
                    args.puppet[index] = manifest

        return args, config
Example #8
0
    def _shared(self, args, release_type):
        """process shared arguments between the pxe and iso commands"""

        if args.config:
            yaml_file = os.path.join(self.cfg["paths"]["configs"], args.config)
            yaml_file += ".yaml"
            overrides = utils.yaml_read(yaml_file)
            if "args" in overrides:
                args = settings.override(args, overrides)
            config = self._merge_config(self.cfg, overrides)
        else:
            config = self.cfg

        if not args.release:
            args.release = self.cfg["default_release"][release_type]
        else:
            args.release = args.release

        try:
            release = args.release.split("-")[1]
        except (ValueError, IndexError):
            raise self.exception(
                '"%s" is not a valid release, use the '
                '"seedbank list" command to list available releases' % args.release
            )

        if "overlay" in args and args.overlay:
            path = os.path.join(self.cfg["paths"]["overlays"], args.overlay)
            if os.path.isdir(path):
                args.path = path
            else:
                raise self.exception('file overlay directory "%s" does not ' "exist" % path)

        if not args.fqdn:
            raise self.exception(
                "you will need to specify a fully qualified "
                "domain name on the command line or in the args section of a "
                "config override file"
            )
        elif not "." in args.fqdn:
            raise self.exception('"%s" is not a fully qualified domain name' % args.fqdn)

        if not args.seed:
            args.seed = release
        args.seeds = [args.seed] + args.additional
        for seed_file in args.seeds:
            file_name = os.path.join(self.cfg["paths"]["seeds"], seed_file)
            file_name += ".seed"
            if not os.path.isfile(file_name):
                raise self.exception('preseed file "%s" does not exist' % file_name)

        if args.puppet:
            for index, manifest in enumerate(args.puppet):
                file_name = os.path.join(config["paths"]["puppet_manifests"], manifest + ".pp")
                if not os.path.isfile(file_name):
                    err = 'Puppet manifest "%s" does not exist' % file_name
                    raise self.exception(err)
                else:
                    args.puppet[index] = manifest

        return args, config
Example #9
0
    def _shared(self, args, release_type):
        """process shared arguments between the pxe and iso commands"""

        if args.config:
            yaml_file = os.path.join(self.cfg['paths']['configs'], args.config)
            yaml_file += '.yaml'
            overrides = utils.yaml_read(yaml_file)
            if 'args' in overrides:
                args = settings.override(args, overrides)
            config = self._merge_config(self.cfg, overrides)
        else:
            config = self.cfg

        if not args.release:
            args.release = self.cfg['default_release'][release_type]
        else:
            args.release = args.release

        try:
            release = args.release.split('-')[1]
        except (ValueError, IndexError):
            raise self.exception(
                '"%s" is not a valid release, use the '
                '"seedbank list" command to list available releases' %
                args.release)

        if 'overlay' in args and args.overlay:
            path = os.path.join(self.cfg['paths']['overlays'], args.overlay)
            if os.path.isdir(path):
                args.path = path
            else:
                raise self.exception('file overlay directory "%s" does not '
                                     'exist' % path)

        if not args.fqdn:
            raise self.exception(
                'you will need to specify a fully qualified '
                'domain name on the command line or in the args section of a '
                'config override file')
        elif not '.' in args.fqdn:
            raise self.exception('"%s" is not a fully qualified domain name' %
                                 args.fqdn)

        if not args.seed:
            args.seed = release
        args.seeds = [args.seed] + args.additional
        for seed_file in args.seeds:
            file_name = os.path.join(self.cfg['paths']['seeds'], seed_file)
            file_name += '.seed'
            if not os.path.isfile(file_name):
                raise self.exception('preseed file "%s" does not exist' %
                                     file_name)

        if args.puppet:
            for index, manifest in enumerate(args.puppet):
                file_name = os.path.join(config['paths']['puppet_manifests'],
                                         manifest + '.pp')
                if not os.path.isfile(file_name):
                    err = 'Puppet manifest "%s" does not exist' % file_name
                    raise self.exception(err)
                else:
                    args.puppet[index] = manifest

        return args, config
Example #10
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