def clean(self, config_file): self._setup_parser(config_file) if is_container_existing(self._result()): if is_container_running(self._result()): stop_container(self._result()) delete_container(self._result()) print_success("Deleted lxc container {}.".format(self._result()))
def _run(self): # configure in any case since the container might be only partially configured Configure().run(self._result(), self.config.get_base_config_file()) print("Going to stop lxc container {}.".format(self._result())) stop_container(self._result(), timeout=self.config.get_lxc_stop_timeout()) print_success("Stopped lxc container {}.".format(self._result())) return self._result()
def run(self, config_file, introspection_method=None): with command_context({'edi_create_distributable_image': True}): self._setup_parser(config_file) if introspection_method: print(introspection_method()) return self._result() # configure in any case since the container might be only partially configured Configure().run(self._result(), config_file) print("Going to stop lxc container {}.".format(self._result())) stop_container(self._result()) print_success("Stopped lxc 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()