Beispiel #1
0
    def run(self, container_name, config_file):
        self._setup_parser(config_file)
        self.container_name = container_name

        if not is_valid_hostname(container_name):
            raise FatalError(
                ("The provided container name '{}' "
                 "is not a valid host name.").format(container_name))

        if self._is_container_existing():
            logging.info(
                ("Container {0} is already existing. "
                 "Destroy it to regenerate it or reconfigure it.").format(
                     self._result()))
            if not self._is_container_running():
                logging.info(("Starting existing container {0}.").format(
                    self._result()))
                self._start_container()
                print_success("Started container {}.".format(self._result()))
        else:
            image = Import().run(config_file)
            profiles = Profile().run(config_file)
            print("Going to launch container.")
            self._launch_container(image, profiles)
            print_success("Launched container {}.".format(self._result()))

        return self._result()
Beispiel #2
0
    def run(self, container_name, config_file, introspection_method=None):
        self._setup_parser(config_file)
        self.container_name = container_name

        if introspection_method:
            print(introspection_method())
            return self._result()

        if not is_valid_hostname(container_name):
            raise FatalError(
                ("The provided container name '{}' "
                 "is not a valid host name.").format(container_name))

        profiles = Profile().run(config_file)

        if is_container_existing(self._result()):
            logging.info(
                ("Container {0} is already existing. "
                 "Destroy it to regenerate it or reconfigure it.").format(
                     self._result()))

            current_profiles = get_container_profiles(self._result())
            if not Launch.verify_profiles(profiles, current_profiles):
                # we might end up here if the container got imported
                # from a distributable image
                logging.info(
                    ("The profiles of container {0} need to be updated."
                     ).format(self._result()))
                if is_container_running(self._result()):
                    logging.info(
                        ("Stopping container {0} to update profiles.").format(
                            self._result()))
                    stop_container(self._result())
                apply_profiles(self._result(), profiles)

            if not is_container_running(self._result()):
                logging.info(("Starting existing container {0}.").format(
                    self._result()))
                start_container(self._result())
                print_success("Started container {}.".format(self._result()))
        else:
            image = Import().run(config_file)
            print("Going to launch container.")
            launch_container(image, self._result(), profiles)
            print_success("Launched container {}.".format(self._result()))

        return self._result()
Beispiel #3
0
    def _run(self):
        if not is_valid_hostname(self.container_name):
            raise FatalError(
                ("The provided container name '{}' "
                 "is not a valid host name.").format(self.container_name))

        if is_container_existing(self._result()):
            logging.info(
                ("Container {0} is already existing. "
                 "Destroy it to regenerate it or reconfigure it.").format(
                     self._result()))

            profiles = Profile().run(self.config.get_base_config_file(),
                                     include_post_config_profiles=False)
            current_profiles = get_container_profiles(self._result())
            if not Launch.verify_profiles(profiles, current_profiles):
                # we might end up here if the container got imported
                # from a distributable image
                logging.info(
                    ("The profiles of container {0} need to be updated."
                     ).format(self._result()))
                if is_container_running(self._result()):
                    logging.info(
                        ("Stopping container {0} to update profiles.").format(
                            self._result()))
                    stop_container(self._result(),
                                   timeout=self.config.get_lxc_stop_timeout())
                apply_profiles(self._result(), profiles)

            if not is_container_running(self._result()):
                logging.info(("Starting existing container {0}.").format(
                    self._result()))
                self._setup_bridge()
                start_container(self._result())
                print_success("Started container {}.".format(self._result()))
        else:
            image = Import().run(self.config.get_base_config_file())
            profiles = Profile().run(self.config.get_base_config_file(),
                                     include_post_config_profiles=False)
            self._setup_bridge()
            print("Going to launch container.")
            launch_container(image, self._result(), profiles)
            print_success("Launched container {}.".format(self._result()))

        return self._result()