Esempio n. 1
0
import requests as r
from lxml import etree
from lxml.builder import E
from past.builtins import basestring

from env2config.interface import RewriteOriented
from env2config.conversions import dotted_lower
from env2config.util import create_logger

HADOOP_URL = "http://hadoop.apache.org/docs/r{version}/{config_path}"

logger = create_logger()


class HadoopDefinition(RewriteOriented):
    service_name = 'hadoop'

    def get_tags(self):
        return {
            'distribution': self.tags.get('distribution', 'apache')
        }

    def default_configs(self):
        distribution = self.get_tags()['distribution']
        assert distribution == 'apache', 'Only apache hadoop distribution is supported for now.'

        def loader(config_path):
            url = HADOOP_URL.format(version=self.version, config_path=config_path)
            response = r.get(url)
Esempio n. 2
0
import os
import sys
import json
from glob import glob
from fnmatch import fnmatch

import env2config.services
import env2config.util as util
from env2config.interface import ServiceDefinition


logger = util.create_logger()


ENV_INJECT_KEY = 'ENV_INJECT'


def _tag_path(root, tags):
    tag_string = ','.join(
        '{0}={1}'.format(key, str(value))
        for key, value in sorted(tags.items(), key=lambda p: p[0])
    )
    return os.path.join(root, tag_string)


def _service_path(root, service_name):
    return os.path.join(root, service_name)


def _version_path(root, version):
    return os.path.join(root, version)
Esempio n. 3
0
from __future__ import unicode_literals
import sys
import os
from abc import ABCMeta, abstractmethod

from future.utils import with_metaclass

import env2config.util as util

logger = util.create_logger()


def write_config(dest, filename, content):
    content = content.encode('utf-8')

    if dest == '-':
        util.write_bytes(sys.stdout, content)
    elif os.path.isdir(dest):
        path = os.path.join(dest, filename)
        with open(path, 'wb') as f:
            f.write(content)
    else:
        with open(dest, 'wb') as f:
            f.write(content)


class AbstractProcessor(with_metaclass(ABCMeta, object)):
    def __init__(self, service, config_dir, configs_to_inject, injectables):
        self.service = service
        self.config_dir = config_dir
        self.configs_to_inject = configs_to_inject
Esempio n. 4
0
USAGE = '''
USAGE:
    env2config build <service_name> <version> [<default_config_folder>=./default_configs]
    env2config inject [<default_config_folder>=./default_configs]
'''.strip()


def ensure(result):
    if result is True:
        sys.exit(0)
    else:
        sys.exit(2)


logger = create_logger()

parser = argparse.ArgumentParser(
    description='Inject variables into configuration files.')
cmd_parsers = parser.add_subparsers()

build_cmd = cmd_parsers.add_parser(
    'build', help='Download default configuration files.')
inject_cmd = cmd_parsers.add_parser(
    'inject', help='Inject variables to override configuration files.')

build_cmd.add_argument('service_name')
build_cmd.add_argument('version')
build_cmd.add_argument('default_config_folder',
                       nargs='?',
                       default='./default_configs')