Esempio n. 1
0
    def setUp(self):
        self.local_dir = self.mkdtemp()
        self.hostdir = cdist.str_hash(self.target_host[0])
        self.host_base_path = os.path.join(self.local_dir, self.hostdir)

        self.local = local.Local(
            target_host=self.target_host,
            target_host_tags=self.target_host_tags,
            base_root_path=self.host_base_path,
            host_dir_name=self.hostdir,
            exec_path=cdist.test.cdist_exec_path,
            add_conf_dirs=[conf_dir])
        self.local.create_files_dirs()

        self.remote_dir = self.mkdtemp()
        remote_exec = self.remote_exec
        remote_copy = self.remote_copy
        self.remote = remote.Remote(
            target_host=self.target_host,
            remote_exec=remote_exec,
            remote_copy=remote_copy,
            base_path=self.remote_dir,
            stdout_base_path=self.local.stdout_base_path,
            stderr_base_path=self.local.stderr_base_path)
        self.remote.create_files_dirs()

        self.code = code.Code(self.target_host, self.local, self.remote)

        self.cdist_type = core.CdistType(self.local.type_path,
                                         '__dump_environment')
        self.cdist_object = core.CdistObject(
                self.cdist_type, self.local.object_path, 'whatever',
                self.local.object_marker_name)
        self.cdist_object.create()
Esempio n. 2
0
    def setUp(self):
        self.temp_dir = self.mkdtemp()
        self.local_path = os.path.join(self.temp_dir, "local")
        hostdir = cdist.str_hash(self.target_host[0])
        base_root_path = os.path.join(self.local_path, hostdir)
        self.remote_base_path = os.path.join(self.temp_dir, "remote")
        os.makedirs(self.remote_base_path)

        self.local = local.Local(
            target_host=self.target_host,
            target_host_tags=self.target_host_tags,
            base_root_path=base_root_path,
            host_dir_name=hostdir,
            exec_path=test.cdist_exec_path,
            add_conf_dirs=[conf_dir],
        )

        self.local.create_files_dirs()

        self.remote = remote.Remote(target_host=self.target_host,
                                    remote_exec=self.remote_exec,
                                    remote_copy=self.remote_copy,
                                    base_path=self.remote_base_path)
        self.remote.create_files_dirs()

        self.explorer = explorer.Explorer(self.target_host, self.local,
                                          self.remote)
Esempio n. 3
0
    def setUp(self):
        self.local_dir = self.mkdtemp()
        self.hostdir = cdist.str_hash(self.target_host[0])
        self.host_base_path = os.path.join(self.local_dir, self.hostdir)

        self.local = local.Local(target_host=self.target_host,
                                 target_host_tags=self.target_host_tags,
                                 base_root_path=self.host_base_path,
                                 host_dir_name=self.hostdir,
                                 exec_path=cdist.test.cdist_exec_path,
                                 add_conf_dirs=[conf_dir])
        self.local.create_files_dirs()

        self.remote_dir = self.mkdtemp()
        remote_exec = self.remote_exec
        remote_copy = self.remote_copy
        self.remote = remote.Remote(target_host=self.target_host,
                                    remote_exec=remote_exec,
                                    remote_copy=remote_copy,
                                    base_path=self.remote_dir)
        self.remote.create_files_dirs()

        self.code = code.Code(self.target_host, self.local, self.remote)

        self.cdist_type = core.CdistType(self.local.type_path,
                                         '__dump_environment')
        self.cdist_object = core.CdistObject(self.cdist_type,
                                             self.local.object_path,
                                             'whatever',
                                             self.local.object_marker_name)
        self.cdist_object.create()
Esempio n. 4
0
    def setUp(self):
        self.temp_dir = self.mkdtemp()
        self.local_path = os.path.join(self.temp_dir, "local")
        hostdir = cdist.str_hash(self.target_host[0])
        base_root_path = os.path.join(self.local_path, hostdir)
        self.remote_base_path = os.path.join(self.temp_dir, "remote")
        os.makedirs(self.remote_base_path)

        self.local = local.Local(
            target_host=self.target_host,
            target_host_tags=self.target_host_tags,
            base_root_path=base_root_path,
            host_dir_name=hostdir,
            exec_path=test.cdist_exec_path,
            add_conf_dirs=[conf_dir],
            )

        self.local.create_files_dirs()

        self.remote = remote.Remote(
            target_host=self.target_host,
            remote_exec=self.remote_exec,
            remote_copy=self.remote_copy,
            base_path=self.remote_base_path,
            stdout_base_path=self.local.stdout_base_path,
            stderr_base_path=self.local.stderr_base_path)
        self.remote.create_files_dirs()

        self.explorer = explorer.Explorer(
            self.target_host,
            self.local,
            self.remote)
Esempio n. 5
0
    def commandline(cls, args):
        """Configure remote system"""

        # FIXME: Refactor relict - remove later
        log = logging.getLogger("cdist")

        cls._check_and_prepare_args(args)

        process = {}
        failed_hosts = []
        time_start = time.time()

        base_root_path = cls._base_root_path(args)

        hostcnt = 0
        for host in itertools.chain(cls.hosts(args.host),
                                    cls.hosts(args.hostfile)):
            hostdir = cdist.str_hash(host)
            host_base_path = os.path.join(base_root_path, hostdir)

            log.debug("Base root path for target host \"{}\" is \"{}\"".format(
                host, host_base_path))

            hostcnt += 1
            if args.parallel:
                log.debug("Creating child process for %s", host)
                process[host] = multiprocessing.Process(
                    target=cls.onehost,
                    args=(host, host_base_path, hostdir, args, True))
                process[host].start()
            else:
                try:
                    cls.onehost(host,
                                host_base_path,
                                hostdir,
                                args,
                                parallel=False)
                except cdist.Error as e:
                    failed_hosts.append(host)

        # Catch errors in parallel mode when joining
        if args.parallel:
            for host in process.keys():
                log.debug("Joining process %s", host)
                process[host].join()

                if not process[host].exitcode == 0:
                    failed_hosts.append(host)

        time_end = time.time()
        log.info("Total processing time for %s host(s): %s", hostcnt,
                 (time_end - time_start))

        if len(failed_hosts) > 0:
            raise cdist.Error("Failed to configure the following hosts: " +
                              " ".join(failed_hosts))
Esempio n. 6
0
    def setUp(self):
        # logging.root.setLevel(logging.TRACE)
        save_output_streams = False
        self.temp_dir = self.mkdtemp()

        self.local_dir = os.path.join(self.temp_dir, "local")
        self.hostdir = cdist.str_hash(self.target_host[0])
        self.host_base_path = os.path.join(self.local_dir, self.hostdir)
        os.makedirs(self.host_base_path)
        self.local = local.Local(
            target_host=self.target_host,
            target_host_tags=None,
            base_root_path=self.host_base_path,
            host_dir_name=self.hostdir,
            exec_path=cdist.test.cdist_exec_path,
            add_conf_dirs=[conf_dir],
            save_output_streams=save_output_streams)
        self.local.create_files_dirs()

        self.remote_dir = self.mkdtemp()
        remote_exec = self.remote_exec
        remote_copy = self.remote_copy
        self.remote = remote.Remote(
            target_host=self.target_host,
            remote_exec=remote_exec,
            remote_copy=remote_copy,
            base_path=self.remote_dir,
            stdout_base_path=self.local.stdout_base_path,
            stderr_base_path=self.local.stderr_base_path,
            save_output_streams=save_output_streams)
        self.remote.create_files_dirs()

        self.code = code.Code(self.target_host, self.local, self.remote)

        self.manifest = manifest.Manifest(self.target_host, self.local)

        self.cdist_type = core.CdistType(self.local.type_path,
                                         '__write_to_stdout_and_stderr')
        self.cdist_object = core.CdistObject(self.cdist_type,
                                             self.local.object_path,
                                             self.local.object_marker_name,
                                             '')
        self.cdist_object.create()
        self.output_dirs = {
            'object': {
                'stdout': os.path.join(self.cdist_object.absolute_path,
                                       'stdout'),
                'stderr': os.path.join(self.cdist_object.absolute_path,
                                       'stderr'),
            },
            'init': {
                'stdout': os.path.join(self.local.base_path, 'stdout'),
                'stderr': os.path.join(self.local.base_path, 'stderr'),
            },
        }
Esempio n. 7
0
    def setUp(self):
        # logging.root.setLevel(logging.TRACE)
        save_output_streams = False
        self.temp_dir = self.mkdtemp()

        self.local_dir = os.path.join(self.temp_dir, "local")
        self.hostdir = cdist.str_hash(self.target_host[0])
        self.host_base_path = os.path.join(self.local_dir, self.hostdir)
        os.makedirs(self.host_base_path)
        self.local = local.Local(target_host=self.target_host,
                                 target_host_tags=None,
                                 base_root_path=self.host_base_path,
                                 host_dir_name=self.hostdir,
                                 exec_path=cdist.test.cdist_exec_path,
                                 add_conf_dirs=[conf_dir],
                                 save_output_streams=save_output_streams)
        self.local.create_files_dirs()

        self.remote_dir = self.mkdtemp()
        remote_exec = self.remote_exec
        remote_copy = self.remote_copy
        self.remote = remote.Remote(
            target_host=self.target_host,
            remote_exec=remote_exec,
            remote_copy=remote_copy,
            base_path=self.remote_dir,
            stdout_base_path=self.local.stdout_base_path,
            stderr_base_path=self.local.stderr_base_path,
            save_output_streams=save_output_streams)
        self.remote.create_files_dirs()

        self.code = code.Code(self.target_host, self.local, self.remote)

        self.manifest = manifest.Manifest(self.target_host, self.local)

        self.cdist_type = core.CdistType(self.local.type_path,
                                         '__write_to_stdout_and_stderr')
        self.cdist_object = core.CdistObject(self.cdist_type,
                                             self.local.object_path,
                                             self.local.object_marker_name, '')
        self.cdist_object.create()
        self.output_dirs = {
            'object': {
                'stdout': os.path.join(self.cdist_object.absolute_path,
                                       'stdout'),
                'stderr': os.path.join(self.cdist_object.absolute_path,
                                       'stderr'),
            },
            'init': {
                'stdout': os.path.join(self.local.base_path, 'stdout'),
                'stderr': os.path.join(self.local.base_path, 'stderr'),
            },
        }
Esempio n. 8
0
    def setUp(self):
        self.temp_dir = self.mkdtemp()
        base_path = os.path.join(self.temp_dir, "out")
        hostdir = cdist.str_hash(self.target_host[0])
        host_base_path = os.path.join(base_path, hostdir)

        self.local = local.Local(target_host=self.target_host,
                                 base_root_path=host_base_path,
                                 host_dir_name=hostdir,
                                 exec_path=test.cdist_exec_path,
                                 add_conf_dirs=[conf_dir])
        self.local.create_files_dirs()
        self.manifest = core.Manifest(self.target_host, self.local)
Esempio n. 9
0
    def setUp(self):
        self.temp_dir = self.mkdtemp()
        base_path = os.path.join(self.temp_dir, "out")
        hostdir = cdist.str_hash(self.target_host[0])
        host_base_path = os.path.join(base_path, hostdir)

        self.local = local.Local(
            target_host=self.target_host,
            base_root_path=host_base_path,
            host_dir_name=hostdir,
            exec_path=test.cdist_exec_path,
            add_conf_dirs=[conf_dir])
        self.local.create_files_dirs()
        self.manifest = core.Manifest(self.target_host, self.local)
Esempio n. 10
0
    def setUp(self):

        # Change env for context
        self.orig_environ = os.environ
        os.environ = os.environ.copy()
        self.temp_dir = self.mkdtemp()

        self.local_dir = os.path.join(self.temp_dir, "local")
        self.hostdir = cdist.str_hash(self.target_host[0])
        self.host_base_path = os.path.join(self.local_dir, self.hostdir)
        os.makedirs(self.host_base_path)
        self.local = cdist.exec.local.Local(
            target_host=self.target_host,
            target_host_tags=self.target_host_tags,
            base_root_path=self.host_base_path,
            host_dir_name=self.hostdir)

        # Setup test objects
        self.object_base_path = op.join(self.temp_dir, 'object')

        self.objects = []
        for cdist_object_name in expected_object_names:
            cdist_type, cdist_object_id = cdist_object_name.split("/", 1)
            cdist_object = core.CdistObject(core.CdistType(type_base_path,
                                                           cdist_type),
                                            self.object_base_path,
                                            self.local.object_marker_name,
                                            cdist_object_id)
            cdist_object.create()
            self.objects.append(cdist_object)

        self.object_index = dict((o.name, o) for o in self.objects)
        self.object_names = [o.name for o in self.objects]

        self.remote_dir = os.path.join(self.temp_dir, "remote")
        os.mkdir(self.remote_dir)
        self.remote = cdist.exec.remote.Remote(
            target_host=self.target_host,
            remote_copy=self.remote_copy,
            remote_exec=self.remote_exec,
            base_path=self.remote_dir,
            stdout_base_path=self.local.stdout_base_path,
            stderr_base_path=self.local.stderr_base_path)

        self.local.object_path = self.object_base_path
        self.local.type_path = type_base_path

        self.config = cdist.config.Config(self.local, self.remote)
Esempio n. 11
0
    def setUp(self):

        # Change env for context
        self.orig_environ = os.environ
        os.environ = os.environ.copy()
        self.temp_dir = self.mkdtemp()

        self.local_dir = os.path.join(self.temp_dir, "local")
        self.hostdir = cdist.str_hash(self.target_host[0])
        self.host_base_path = os.path.join(self.local_dir, self.hostdir)
        os.makedirs(self.host_base_path)
        self.local = cdist.exec.local.Local(
            target_host=self.target_host,
            target_host_tags=self.target_host_tags,
            base_root_path=self.host_base_path,
            host_dir_name=self.hostdir)

        # Setup test objects
        self.object_base_path = op.join(self.temp_dir, 'object')

        self.objects = []
        for cdist_object_name in expected_object_names:
            cdist_type, cdist_object_id = cdist_object_name.split("/", 1)
            cdist_object = core.CdistObject(
                core.CdistType(type_base_path,
                               cdist_type), self.object_base_path,
                self.local.object_marker_name, cdist_object_id)
            cdist_object.create()
            self.objects.append(cdist_object)

        self.object_index = dict((o.name, o) for o in self.objects)
        self.object_names = [o.name for o in self.objects]

        self.remote_dir = os.path.join(self.temp_dir, "remote")
        os.mkdir(self.remote_dir)
        self.remote = cdist.exec.remote.Remote(
            target_host=self.target_host,
            remote_copy=self.remote_copy,
            remote_exec=self.remote_exec,
            base_path=self.remote_dir,
            stdout_base_path=self.local.stdout_base_path,
            stderr_base_path=self.local.stderr_base_path)

        self.local.object_path = self.object_base_path
        self.local.type_path = type_base_path

        self.config = cdist.config.Config(self.local, self.remote)
Esempio n. 12
0
    def setUp(self):
        self.orig_environ = os.environ
        os.environ = os.environ.copy()

        self.temp_dir = self.mkdtemp()
        base_path = os.path.join(self.temp_dir, "out")
        hostdir = cdist.str_hash(self.target_host[0])
        host_base_path = os.path.join(base_path, hostdir)

        self.local = local.Local(target_host=self.target_host,
                                 target_host_tags=self.target_host_tags,
                                 base_root_path=host_base_path,
                                 host_dir_name=hostdir,
                                 exec_path=test.cdist_exec_path,
                                 add_conf_dirs=[conf_dir])

        self.local.create_files_dirs()
Esempio n. 13
0
    def setUp(self):
        self.orig_environ = os.environ
        os.environ = os.environ.copy()
        self.temp_dir = self.mkdtemp()

        out_path = self.temp_dir
        hostdir = cdist.str_hash(self.target_host[0])
        base_root_path = os.path.join(out_path, hostdir)
        self.local = local.Local(target_host=self.target_host,
                                 target_host_tags=self.target_host_tags,
                                 base_root_path=base_root_path,
                                 host_dir_name=hostdir,
                                 exec_path=cdist.test.cdist_exec_path,
                                 add_conf_dirs=[conf_dir])
        self.local.create_files_dirs()

        self.manifest = manifest.Manifest(self.target_host, self.local)
        self.log = logging.getLogger(self.target_host[0])
Esempio n. 14
0
    def setUp(self):
        self.temp_dir = self.mkdtemp()
        handle, self.script = self.mkstemp(dir=self.temp_dir)
        os.close(handle)
        base_path = self.temp_dir
        hostdir = cdist.str_hash(self.target_host[0])
        host_base_path = os.path.join(base_path, hostdir)

        self.local = local.Local(target_host=self.target_host,
                                 base_root_path=host_base_path,
                                 host_dir_name=hostdir,
                                 exec_path=test.cdist_exec_path,
                                 add_conf_dirs=[conf_dir])
        self.local.create_files_dirs()

        self.manifest = core.Manifest(self.target_host, self.local)
        self.env = self.manifest.env_initial_manifest(self.script)
        self.env['__cdist_object_marker'] = self.local.object_marker_name
Esempio n. 15
0
    def setUp(self):
        self.orig_environ = os.environ
        os.environ = os.environ.copy()
        self.temp_dir = self.mkdtemp()

        out_path = self.temp_dir
        hostdir = cdist.str_hash(self.target_host[0])
        base_root_path = os.path.join(out_path, hostdir)
        self.local = local.Local(
            target_host=self.target_host,
            base_root_path=base_root_path,
            host_dir_name=hostdir,
            exec_path=cdist.test.cdist_exec_path,
            add_conf_dirs=[conf_dir])
        self.local.create_files_dirs()

        self.manifest = manifest.Manifest(self.target_host, self.local)
        self.log = logging.getLogger(self.target_host[0])
Esempio n. 16
0
    def setUp(self):
        self.orig_environ = os.environ
        os.environ = os.environ.copy()

        self.temp_dir = self.mkdtemp()
        base_path = os.path.join(self.temp_dir, "out")
        hostdir = cdist.str_hash(self.target_host[0])
        host_base_path = os.path.join(base_path, hostdir)

        self.local = local.Local(
            target_host=self.target_host,
            target_host_tags=self.target_host_tags,
            base_root_path=host_base_path,
            host_dir_name=hostdir,
            exec_path=test.cdist_exec_path,
            add_conf_dirs=[conf_dir])

        self.local.create_files_dirs()
Esempio n. 17
0
    def setUp(self):
        self.temp_dir = self.mkdtemp()
        handle, self.script = self.mkstemp(dir=self.temp_dir)
        os.close(handle)
        base_path = self.temp_dir
        hostdir = cdist.str_hash(self.target_host[0])
        host_base_path = os.path.join(base_path, hostdir)

        self.local = local.Local(
            target_host=self.target_host,
            base_root_path=host_base_path,
            host_dir_name=hostdir,
            exec_path=test.cdist_exec_path,
            add_conf_dirs=[conf_dir])
        self.local.create_files_dirs()

        self.manifest = core.Manifest(self.target_host, self.local)
        self.env = self.manifest.env_initial_manifest(self.script)
        self.env['__cdist_object_marker'] = self.local.object_marker_name
Esempio n. 18
0
    def setUp(self):

        target_host = (
            'localhost',
            'localhost',
            'localhost',
        )
        self.temp_dir = self.mkdtemp()
        self.out_parent_path = self.temp_dir
        self.hostdir = cdist.str_hash(target_host[0])
        self.host_base_path = op.join(self.out_parent_path, self.hostdir)
        self.out_path = op.join(self.host_base_path, "data")

        self.local = local.Local(target_host=target_host,
                                 base_root_path=self.host_base_path,
                                 host_dir_name=self.hostdir,
                                 exec_path=test.cdist_exec_path)

        self.home_dir = os.path.join(os.environ['HOME'], ".cdist")
Esempio n. 19
0
    def setUp(self):

        target_host = (
            'localhost',
            'localhost',
            'localhost',
        )
        self.temp_dir = self.mkdtemp()
        self.out_parent_path = self.temp_dir
        self.hostdir = cdist.str_hash(target_host[0])
        self.host_base_path = op.join(self.out_parent_path, self.hostdir)
        self.out_path = op.join(self.host_base_path, "data")

        self.local = local.Local(
            target_host=target_host,
            base_root_path=self.host_base_path,
            host_dir_name=self.hostdir,
            exec_path=test.cdist_exec_path
        )

        self.home_dir = os.path.join(os.environ['HOME'], ".cdist")
Esempio n. 20
0
    def commandline(cls, args):
        """Configure remote system"""
        import multiprocessing

        # FIXME: Refactor relict - remove later
        log = logging.getLogger("cdist")

        if args.manifest == '-' and args.hostfile == '-':
            raise cdist.Error(("Cannot read both, manifest and host file, "
                               "from stdin"))

        # if no host source is specified then read hosts from stdin
        if not (args.hostfile or args.host):
            args.hostfile = '-'

        initial_manifest_tempfile = None
        if args.manifest == '-':
            # read initial manifest from stdin
            try:
                handle, initial_manifest_temp_path = tempfile.mkstemp(
                        prefix='cdist.stdin.')
                with os.fdopen(handle, 'w') as fd:
                    fd.write(sys.stdin.read())
            except (IOError, OSError) as e:
                raise cdist.Error(("Creating tempfile for stdin data "
                                   "failed: %s" % e))

            args.manifest = initial_manifest_temp_path
            import atexit
            atexit.register(lambda: os.remove(initial_manifest_temp_path))

        process = {}
        failed_hosts = []
        time_start = time.time()

        # default remote cmd patterns
        args.remote_exec_pattern = None
        args.remote_copy_pattern = None

        args_dict = vars(args)
        # if remote-exec and/or remote-copy args are None then user
        # didn't specify command line options nor env vars:
        # inspect multiplexing options for default cdist.REMOTE_COPY/EXEC
        if (args_dict['remote_copy'] is None or
                args_dict['remote_exec'] is None):
            mux_opts = inspect_ssh_mux_opts()
            if args_dict['remote_exec'] is None:
                args.remote_exec_pattern = cdist.REMOTE_EXEC + mux_opts
            if args_dict['remote_copy'] is None:
                args.remote_copy_pattern = cdist.REMOTE_COPY + mux_opts

        if args.out_path:
            base_root_path = args.out_path
        else:
            base_root_path = tempfile.mkdtemp()

        hostcnt = 0
        for host in itertools.chain(cls.hosts(args.host),
                                    cls.hosts(args.hostfile)):
            hostdir = cdist.str_hash(host)
            host_base_path = os.path.join(base_root_path, hostdir)

            log.debug("Base root path for target host \"{}\" is \"{}\"".format(
                host, host_base_path))

            hostcnt += 1
            if args.parallel:
                log.debug("Creating child process for %s", host)
                process[host] = multiprocessing.Process(
                        target=cls.onehost,
                        args=(host, host_base_path, hostdir, args, True))
                process[host].start()
            else:
                try:
                    cls.onehost(host, host_base_path, hostdir,
                                args, parallel=False)
                except cdist.Error as e:
                    failed_hosts.append(host)

        # Catch errors in parallel mode when joining
        if args.parallel:
            for host in process.keys():
                log.debug("Joining process %s", host)
                process[host].join()

                if not process[host].exitcode == 0:
                    failed_hosts.append(host)

        time_end = time.time()
        log.info("Total processing time for %s host(s): %s", hostcnt,
                 (time_end - time_start))

        if len(failed_hosts) > 0:
            raise cdist.Error("Failed to configure the following hosts: " +
                              " ".join(failed_hosts))
Esempio n. 21
0
    def create_host_base_dirs(host, base_root_path):
        hostdir = cdist.str_hash(host)
        host_base_path = os.path.join(base_root_path, hostdir)

        return (host_base_path, hostdir)
Esempio n. 22
0
    def commandline(cls, args):
        """Configure remote system"""
        import multiprocessing

        # FIXME: Refactor relict - remove later
        log = logging.getLogger("cdist")

        if args.manifest == '-' and args.hostfile == '-':
            raise cdist.Error(("Cannot read both, manifest and host file, "
                               "from stdin"))

        # if no host source is specified then read hosts from stdin
        if not (args.hostfile or args.host):
            args.hostfile = '-'

        initial_manifest_tempfile = None
        if args.manifest == '-':
            # read initial manifest from stdin
            try:
                handle, initial_manifest_temp_path = tempfile.mkstemp(
                        prefix='cdist.stdin.')
                with os.fdopen(handle, 'w') as fd:
                    fd.write(sys.stdin.read())
            except (IOError, OSError) as e:
                raise cdist.Error(("Creating tempfile for stdin data "
                                   "failed: %s" % e))

            args.manifest = initial_manifest_temp_path
            import atexit
            atexit.register(lambda: os.remove(initial_manifest_temp_path))

        process = {}
        failed_hosts = []
        time_start = time.time()

        # default remote cmd patterns
        args.remote_exec_pattern = None
        args.remote_copy_pattern = None

        args_dict = vars(args)
        # if remote-exec and/or remote-copy args are None then user
        # didn't specify command line options nor env vars:
        # inspect multiplexing options for default cdist.REMOTE_COPY/EXEC
        if (args_dict['remote_copy'] is None or
                args_dict['remote_exec'] is None):
            mux_opts = inspect_ssh_mux_opts()
            if args_dict['remote_exec'] is None:
                args.remote_exec_pattern = cdist.REMOTE_EXEC + mux_opts
            if args_dict['remote_copy'] is None:
                args.remote_copy_pattern = cdist.REMOTE_COPY + mux_opts

        if args.out_path:
            base_root_path = args.out_path
        else:
            base_root_path = tempfile.mkdtemp()

        hostcnt = 0
        for host in itertools.chain(cls.hosts(args.host),
                                    cls.hosts(args.hostfile)):
            hostdir = cdist.str_hash(host)
            host_base_path = os.path.join(base_root_path, hostdir)

            log.debug("Base root path for target host \"{}\" is \"{}\"".format(
                host, host_base_path))

            hostcnt += 1
            if args.parallel:
                log.debug("Creating child process for %s", host)
                process[host] = multiprocessing.Process(
                        target=cls.onehost,
                        args=(host, host_base_path, hostdir, args, True))
                process[host].start()
            else:
                try:
                    cls.onehost(host, host_base_path, hostdir,
                                args, parallel=False)
                except cdist.Error as e:
                    failed_hosts.append(host)

        # Catch errors in parallel mode when joining
        if args.parallel:
            for host in process.keys():
                log.debug("Joining process %s", host)
                process[host].join()

                if not process[host].exitcode == 0:
                    failed_hosts.append(host)

        time_end = time.time()
        log.info("Total processing time for %s host(s): %s", hostcnt,
                 (time_end - time_start))

        if len(failed_hosts) > 0:
            raise cdist.Error("Failed to configure the following hosts: " +
                              " ".join(failed_hosts))
Esempio n. 23
0
    def create_host_base_dirs(host, base_root_path):
        hostdir = cdist.str_hash(host)
        host_base_path = os.path.join(base_root_path, hostdir)

        return (host_base_path, hostdir)