Ejemplo n.º 1
0
 def resolve_target_addresses(host, family):
     try:
         return ipaddr.resolve_target_addresses(host, family)
     except:
         e = sys.exc_info()[1]
         raise cdist.Error(("Error resolving target addresses for host '{}'"
                            ": {}").format(host, e))
Ejemplo n.º 2
0
    def onehost(cls, host, host_tags, host_base_path, host_dir_name, args,
                parallel, configuration, remove_remote_files_dirs=False):
        """Configure ONE system.
           If operating in parallel then return tuple (host, True|False, )
           so that main process knows for which host function was successful.
        """

        log = logging.getLogger(host)

        try:
            remote_exec, remote_copy, cleanup_cmd = cls._resolve_remote_cmds(
                args)
            log.debug("remote_exec for host \"{}\": {}".format(
                host, remote_exec))
            log.debug("remote_copy for host \"{}\": {}".format(
                host, remote_copy))

            target_host = ipaddr.resolve_target_addresses(host)
            log.debug("target_host for host \"{}\": {}".format(
                host, target_host))

            local = cdist.exec.local.Local(
                target_host=target_host,
                target_host_tags=host_tags,
                base_root_path=host_base_path,
                host_dir_name=host_dir_name,
                initial_manifest=args.manifest,
                add_conf_dirs=args.conf_dir,
                cache_path_pattern=args.cache_path_pattern,
                quiet_mode=args.quiet,
                configuration=configuration,
                exec_path=sys.argv[0])

            remote = cdist.exec.remote.Remote(
                target_host=target_host,
                remote_exec=remote_exec,
                remote_copy=remote_copy,
                base_path=args.remote_out_path,
                quiet_mode=args.quiet,
                archiving_mode=args.use_archiving,
                configuration=configuration)

            cleanup_cmds = []
            if cleanup_cmd:
                cleanup_cmds.append(cleanup_cmd)
            c = cls(local, remote, dry_run=args.dry_run, jobs=args.jobs,
                    cleanup_cmds=cleanup_cmds,
                    remove_remote_files_dirs=remove_remote_files_dirs)
            c.run()
            cls._remove_paths()

        except cdist.Error as e:
            log.error(e)
            if parallel:
                return (host, False, )
            else:
                raise

        if parallel:
            return (host, True, )
Ejemplo n.º 3
0
 def resolve_target_addresses(host, family):
     try:
         return ipaddr.resolve_target_addresses(host, family)
     except:
         e = sys.exc_info()[1]
         raise cdist.Error(("Error resolving target addresses for host '{}'"
                            ": {}").format(host, e))
Ejemplo n.º 4
0
    def onehost(cls, host, host_base_path, host_dir_name, args, parallel):
        """Configure ONE system"""

        log = logging.getLogger(host)

        try:
            remote_exec, remote_copy = cls._resolve_remote_cmds(
                args, host_base_path)
            log.debug("remote_exec for host \"{}\": {}".format(
                host, remote_exec))
            log.debug("remote_copy for host \"{}\": {}".format(
                host, remote_copy))

            target_host = ipaddr.resolve_target_addresses(host)
            log.debug("target_host: {}".format(target_host))

            local = cdist.exec.local.Local(
                target_host=target_host,
                base_root_path=host_base_path,
                host_dir_name=host_dir_name,
                initial_manifest=args.manifest,
                add_conf_dirs=args.conf_dir)

            remote = cdist.exec.remote.Remote(
                target_host=target_host,
                remote_exec=remote_exec,
                remote_copy=remote_copy)

            c = cls(local, remote, dry_run=args.dry_run, jobs=args.jobs)
            c.run()

        except cdist.Error as e:
            log.error(e)
            if parallel:
                # We are running in our own process here, need to sys.exit!
                sys.exit(1)
            else:
                raise

        except KeyboardInterrupt:
            # Ignore in parallel mode, we are existing anyway
            if parallel:
                sys.exit(0)
            # Pass back to controlling code in sequential mode
            else:
                raise
Ejemplo n.º 5
0
    def onehost(cls,
                host,
                host_tags,
                host_base_path,
                host_dir_name,
                args,
                parallel,
                configuration,
                remove_remote_files_dirs=False):
        """Configure ONE system.
           If operating in parallel then return tuple (host, True|False, )
           so that main process knows for which host function was successful.
        """

        log = logging.getLogger(host)

        try:
            remote_exec, remote_copy, cleanup_cmd = cls._resolve_remote_cmds(
                args)
            log.debug("remote_exec for host \"{}\": {}".format(
                host, remote_exec))
            log.debug("remote_copy for host \"{}\": {}".format(
                host, remote_copy))

            family = cls._address_family(args)
            log.debug("address family: {}".format(family))
            target_host = ipaddr.resolve_target_addresses(host, family)
            log.debug("target_host for host \"{}\": {}".format(
                host, target_host))

            local = cdist.exec.local.Local(
                target_host=target_host,
                target_host_tags=host_tags,
                base_root_path=host_base_path,
                host_dir_name=host_dir_name,
                initial_manifest=args.manifest,
                add_conf_dirs=args.conf_dir,
                cache_path_pattern=args.cache_path_pattern,
                quiet_mode=args.quiet,
                configuration=configuration,
                exec_path=sys.argv[0],
                save_output_streams=args.save_output_streams)

            remote = cdist.exec.remote.Remote(
                target_host=target_host,
                remote_exec=remote_exec,
                remote_copy=remote_copy,
                base_path=args.remote_out_path,
                quiet_mode=args.quiet,
                archiving_mode=args.use_archiving,
                configuration=configuration,
                stdout_base_path=local.stdout_base_path,
                stderr_base_path=local.stderr_base_path,
                save_output_streams=args.save_output_streams)

            cleanup_cmds = []
            if cleanup_cmd:
                cleanup_cmds.append(cleanup_cmd)
            c = cls(local,
                    remote,
                    dry_run=args.dry_run,
                    jobs=args.jobs,
                    cleanup_cmds=cleanup_cmds,
                    remove_remote_files_dirs=remove_remote_files_dirs)
            c.run()
            cls._remove_paths()

        except cdist.Error as e:
            log.error(e)
            if parallel:
                return (
                    host,
                    False,
                )
            else:
                raise

        if parallel:
            return (
                host,
                True,
            )