def uninstall(self, iobject, name=None, **kwargs): atomic = kwargs.get('atomic') ignore = kwargs.get('ignore') assert (isinstance(atomic, Atomic)) args = atomic.args con_obj = None if not name else self.has_container(name) # We have a container by that name, need to stop and delete it if con_obj: if con_obj.running: self.stop_container(con_obj) self.delete_container(con_obj.id) if args.force: self.delete_containers_by_image(iobject, force=True) else: containers_by_image = self.get_containers_by_image(iobject) if len(containers_by_image) > 0: containers_active = ", ".join( [i.name for i in containers_by_image]) raise ValueError( "Containers `%s` are using this image, delete them first or use --force" % containers_active) uninstall_command = iobject.get_label('UNINSTALL') command_line_args = args.args cmd = [] if uninstall_command: try: cmd = cmd + uninstall_command except TypeError: cmd = cmd + uninstall_command.split() if command_line_args: cmd += command_line_args cmd = atomic.gen_cmd(cmd) cmd = atomic.sub_env_strings(cmd) atomic.display(cmd) if args.display: return 0 if cmd: result = util.check_call(cmd, env=atomic.cmd_env()) if result == 0: util.InstallData.delete_by_id(iobject.id, name, ignore=ignore) return result system_package_nvra = None if not ignore: install_data = util.InstallData.get_install_data_by_id(iobject.id) system_package_nvra = install_data.get("system_package_nvra", None) if system_package_nvra: RPMHostInstall.uninstall_rpm(system_package_nvra) # Delete the entry in the install data last_image = util.InstallData.delete_by_id(iobject.id, name, ignore=ignore) if last_image: return self.delete_image(iobject.image, force=args.force)
def uninstall(self, iobject, name=None, **kwargs): atomic = kwargs.get('atomic') ignore = kwargs.get('ignore') assert(isinstance(atomic, Atomic)) args = atomic.args con_obj = None if not name else self.has_container(name) # We have a container by that name, need to stop and delete it if con_obj: if con_obj.running: self.stop_container(con_obj) self.delete_container(con_obj.id) if args.force: self.delete_containers_by_image(iobject, force=True) else: containers_by_image = self.get_containers_by_image(iobject) if len(containers_by_image) > 0: containers_active = ", ".join([i.name for i in containers_by_image]) raise ValueError("Containers `%s` are using this image, delete them first or use --force" % containers_active) uninstall_command = iobject.get_label('UNINSTALL') command_line_args = args.args cmd = [] if uninstall_command: try: cmd = cmd + uninstall_command except TypeError: cmd = cmd + uninstall_command.split() if command_line_args: cmd += command_line_args cmd = atomic.gen_cmd(cmd) cmd = atomic.sub_env_strings(cmd) atomic.display(cmd) if args.display: return 0 if cmd: result = util.check_call(cmd, env=atomic.cmd_env()) if result == 0: util.InstallData.delete_by_id(iobject.id, ignore=ignore) return result system_package_nvra = None if not ignore: install_data = util.InstallData.get_install_data_by_id(iobject.id) system_package_nvra = install_data.get("system_package_nvra", None) if system_package_nvra: RPMHostInstall.uninstall_rpm(system_package_nvra) # Delete the entry in the install data util.InstallData.delete_by_id(iobject.id, ignore=ignore) return self.delete_image(iobject.image, force=args.force)
def build_rpm_for_docker_backend(image, name, temp_dir, labels): """ build rpm package for specified docker image :param image, instance of Atomic.objects.image.Image :param name, str, name of the associated container :param temp_dir: str, directory where all the data will be processed :param labels: dict, these labels come from container image :return: instance of StandaloneContainerInstallation """ from Atomic.mount import DockerMount, MountContextManager mount_path = os.path.join(temp_dir, "mountpoint") destination = os.path.join(temp_dir, "system_rpm") os.makedirs(destination) os.makedirs(mount_path) dm = DockerMount(mount_path) cm = MountContextManager(dm, image.id) with cm: # if we are on devicemapper, the path to container is <mount_point>/hostfs/ dm_candidate_path = os.path.join(cm.mnt_path, "rootfs") if os.path.exists(dm_candidate_path): exports_dir = os.path.join(dm_candidate_path, "exports") else: exports_dir = os.path.join(cm.mnt_path, "exports") r = RPMHostInstall.generate_rpm( name, image.id, labels, exports_dir, destination) return ContainerInstallation(r[0], r[1], r[2])
def build_rpm_for_docker_backend(image, name, temp_dir, labels): """ build rpm package for specified docker image :param image, instance of Atomic.objects.image.Image :param name, str, name of the associated container :param temp_dir: str, directory where all the data will be processed :param labels: dict, these labels come from container image :return: instance of StandaloneContainerInstallation """ from Atomic.mount import DockerMount, MountContextManager mount_path = os.path.join(temp_dir, "mountpoint") destination = os.path.join(temp_dir, "system_rpm") os.makedirs(destination) os.makedirs(mount_path) dm = DockerMount(mount_path) cm = MountContextManager(dm, image.id) with cm: # if we are on devicemapper, the path to container is <mount_point>/hostfs/ dm_candidate_path = os.path.join(cm.mnt_path, "rootfs") if os.path.exists(dm_candidate_path): exports_dir = os.path.join(dm_candidate_path, "exports") else: exports_dir = os.path.join(cm.mnt_path, "exports") r = RPMHostInstall.generate_rpm( name, image.id, labels, exports_dir, destination) return ContainerInstallation(r[0], r[1], r[2])
def uninstall(self, iobject, name=None, **kwargs): atomic = kwargs.get('atomic') ignore = kwargs.get('ignore') assert(isinstance(atomic, Atomic)) args = atomic.args con_obj = None if not name else self.has_container(name) # We have a container by that name, need to stop and delete it if con_obj: if con_obj.running: self.stop_container(con_obj) self.delete_container(con_obj.id) if args.force: self.delete_containers_by_image(iobject, force=True) uninstall_command = iobject.get_label('UNINSTALL') command_line_args = args.args cmd = [] if uninstall_command: try: cmd = cmd + uninstall_command except TypeError: cmd = cmd + uninstall_command.split() if command_line_args: cmd += command_line_args cmd = atomic.gen_cmd(cmd) cmd = atomic.sub_env_strings(cmd) atomic.display(cmd) if args.display: return 0 if cmd: return util.check_call(cmd, env=atomic.cmd_env()) install_data = util.InstallData.get_install_data_by_id(iobject.id) system_package_nvra = install_data.get("system_package_nvra", None) if system_package_nvra: RPMHostInstall.uninstall_rpm(system_package_nvra) # Delete the entry in the install data util.InstallData.delete_by_id(iobject.id, ignore=ignore) return self.delete_image(iobject.image, force=args.force)
def rpm_install(self, image, name): """ Install system rpm for selected docker image on this system. :param image: instance of Atomic.objects.image.Image :param name, str, name of the associated container :return: instance of ContainerInstallation or None if no rpm was installed """ labels = image.labels or {} # we actually don't care about value of the label if 'atomic.has_install_files' in labels: # we are going to install the system package - the image provides some files to host temp_dir = tempfile.mkdtemp() try: installation = build_rpm_for_docker_backend(image, name, temp_dir, labels) RPMHostInstall.install_rpm(installation.destination_path) finally: shutil.rmtree(temp_dir) return installation
def rpm_install(self, image, name): """ Install system rpm for selected docker image on this system. :param image: instance of Atomic.objects.image.Image :param name, str, name of the associated container :return: instance of ContainerInstallation or None if no rpm was installed """ labels = image.labels or {} # we actually don't care about value of the label if 'atomic.has_install_files' in labels: # we are going to install the system package - the image provides some files to host temp_dir = tempfile.mkdtemp() try: installation = build_rpm_for_docker_backend(image, name, temp_dir, labels) RPMHostInstall.install_rpm(installation.destination_path) finally: shutil.rmtree(temp_dir) return installation