Beispiel #1
0
 def __init__(self,
              obj_type,
              config='/etc/conftool/config.yaml',
              schema='/etc/conftool/schema.yaml'):
     self._schema = loader.Schema.from_file(schema)
     self.entity = self._schema.entities[obj_type]
     kvobject.KVObject.setup(configuration.get(config))
def main(arguments=None):
    if arguments is None:
        arguments = sys.argv[1:]

    args = get_args(arguments)

    if args.debug:
        log_level = logging.DEBUG
    else:
        log_level = logging.INFO

    logging.basicConfig(
        level=log_level,
        format='%(asctime)s [%(levelname)s] %(name)s::%(funcName)s: %(message)s',
        datefmt='%F %T'
    )

    try:
        c = configuration.get(args.config)
        KVObject.setup(c)
    except Exception as e:
        _log.critical("Invalid configuration: %s", e)
        sys.exit(1)

    if not os.path.isdir(args.directory):
        _log.critical("Could not find directory %s", args.directory)
        sys.exit(2)

    sync = Syncer(args.schema, args.directory)
    sync.load()
def main(arguments=None):
    if arguments is None:
        arguments = sys.argv[1:]

    args = get_args(arguments)

    if args.debug:
        log_level = logging.DEBUG
    else:
        log_level = logging.INFO

    logging.basicConfig(
        level=log_level,
        format=
        '%(asctime)s [%(levelname)s] %(name)s::%(funcName)s: %(message)s',
        datefmt='%F %T')

    try:
        c = configuration.get(args.config)
        KVObject.setup(c)
    except Exception as e:
        _log.critical("Invalid configuration: %s", e)
        sys.exit(1)

    if not os.path.isdir(args.directory):
        _log.critical("Could not find directory %s", args.directory)
        sys.exit(2)

    sync = Syncer(args.schema, args.directory)
    sync.load()
Beispiel #4
0
    def __init__(self, config_file, servers):
        """
        Read the conftool configuration and load all the provided nodes

        :param config_file: The path to a config file for conftool
        :param servers: Which servers to work with
        """
        KVObject.setup(configuration.get(config_file))
        node_re = re.compile('({name})'.format(name='|'.join(servers)))
        self.nodes = [n for n in node.Node.query({'name': node_re})]
Beispiel #5
0
    def __init__(
        self,
        config: str = "/etc/conftool/config.yaml",
        schema: str = "/etc/conftool/schema.yaml",
        dry_run: bool = True,
    ) -> None:
        """Initialize the instance.

        Arguments:
            config (str, optional): the path to the configuration file to load.
            schema (str, optional): the path to the Conftool schema to load.
            dry_run (bool, optional): whether this is a DRY-RUN.

        """
        self._dry_run = dry_run
        self._schema = loader.Schema.from_file(schema)
        kvobject.KVObject.setup(configuration.get(config))
Beispiel #6
0
 def setup(self):
     c = configuration.get(self.args.config)
     KVObject.setup(c)
     setup_irc(c)
 def setup(self):
     c = configuration.get(self.args.config)
     KVObject.setup(c)
     setup_irc(c)
Beispiel #8
0
def main(arguments=None):
    if arguments is None:
        arguments = list(sys.argv)
        arguments.pop(0)

    args = get_args(arguments)
    if args.debug:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.WARN)

    try:
        c = configuration.get(args.config)
        KVObject.setup(c)
    except Exception as e:
        raise
        _log.critical("Invalid configuration: %s", e)
        sys.exit(1)

    files = tag_files(args.directory)
    # Load services data.
    servdata = {}
    if files['services']:
        for service_file in files['services']:
            with open(service_file, 'rb') as fh:
                try:
                    d = yaml.load(fh)
                except:
                    d = {}
            servdata.update(d)
    if not servdata:
        _log.critical("We found no services, so we can't import"
                      " nodes either. Bailing out")
        sys.exit(1)

    # Refresh services:
    rem = {}
    for cluster, data in servdata.items():
        if not type(data) == dict:
            continue
        load, rem[cluster] = get_service_actions(cluster, data)
        if args.lock:
            servlocker = service.Service.lock
        else:
            servlocker = dummy_lock
        load_services(cluster, load, data, servlocker)
    # sync nodes
    for filename in files['nodes']:
        dc = os.path.basename(filename).rstrip('.yaml')
        try:
            with open(filename, 'rb') as fh:
                dc_data = yaml.load(fh)
        except:
            _log.error("Malformed yaml data in %s", filename)
            _log.error("Skipping loading/removing nodes, please correct!")
        else:
            if args.lock:
                locker = service.Service.lock
            else:
                locker = dummy_lock
            load_nodes(dc, dc_data, locker)

    # Now delete services
    for cluster, servnames in rem.items():
        remove_services(cluster, servnames, servlocker)