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() Launch().run(container_name, config_file) print("Going to configure container {} - be patient.".format(self._result())) playbook_runner = PlaybookRunner(self.config, self._result(), "lxd") playbook_runner.run_all() sfc = SharedFolderCoordinator(self.config) sfc.create_host_folders() sfc.verify_container_mountpoints(container_name) profiles = Profile().run(config_file, include_post_config_profiles=True) # TODO: stop container if profiles need to be updated apply_profiles(container_name, profiles) # TODO: restart container if needed print_success("Configured container {}.".format(self._result())) return self._result()
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()
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()
def _run(self): Launch().run(self.container_name, self.config.get_base_config_file()) print("Going to configure container {} - be patient.".format( self._result())) playbook_runner = PlaybookRunner(self.config, self._result(), self.ansible_connection) playbook_runner.run_all() sfc = SharedFolderCoordinator(self.config) sfc.create_host_folders() sfc.verify_container_mountpoints(self.container_name) profiles = Profile().run(self.config.get_base_config_file(), include_post_config_profiles=True) # TODO: stop container if profiles need to be updated apply_profiles(self.container_name, profiles) # TODO: restart container if needed print_success("Configured container {}.".format(self._result())) return self._result()