def final_restore(self, img, connection): try: with open(os.path.join(self._runc_bundle, runc_conf_name), "r") as config: self._container_state = json.loads(config.read()) root_path = self._container_state["root"]["path"] except IOError: raise Exception("Unable to get container config") except KeyError: raise Exception("Invalid config") if not os.path.isabs(root_path): self._ct_rootfs = os.path.join(self._runc_bundle, root_path) else: self._ct_rootfs = root_path if any([ mount["type"] == "cgroup" for mount in self._container_state["mounts"] ]): self_cgroups = self._parse_self_cgroup() cgroup_paths = self._container_state["cgroup_paths"] for mount in self._container_state["mounts"]: if mount["type"] == "bind": if mount["destination"].startswith(self._ct_rootfs): dst = mount["destination"][len(self._ct_rootfs):] else: dst = mount["destination"] self._binds.update({dst: mount["source"]}) if mount["type"] == "cgroup": with open("/proc/self/mountinfo", "r") as mountinfo: lines = mountinfo.readlines() for subsystem, c_mp in cgroup_paths.items(): # Remove container ID from path mountpoint = os.path.split(c_mp)[0] dst = os.path.join(mount["destination"], os.path.split(mountpoint)[0]) if dst.startswith(self._ct_rootfs): dst = dst[len(self._ct_rootfs):] line = next(line for line in lines if mountpoint in line) src = os.path.join( mountpoint, os.path.relpath(self_cgroups[subsystem], line.split()[3])) self._binds.update({dst: src}) with open(os.path.join(img.image_dir(), "descriptors.json"), "r") as descr: inherits = [(dsc, i) for i, dsc in enumerate(json.loads(descr.read())) if "pipe:" in dsc] for dsc, i in inherits: self._inherit_fd.update({dsc: i}) with open(os.path.join(img.image_dir(), "state.json"), "r") as old_state_file: self._restore_state = json.loads(old_state_file.read()) criu_cr.criu_restore(self, img, connection)
def final_restore(self, img, connection): try: with open(os.path.join(self._runc_bundle, runc_conf_name), "r") as config: self._container_state = json.loads(config.read()) root_path = self._container_state["root"]["path"] except IOError: raise Exception("Unable to get container config") except KeyError: raise Exception("Invalid config") if not os.path.isabs(root_path): self._ct_rootfs = os.path.join(self._runc_bundle, root_path) else: self._ct_rootfs = root_path if any([mount["type"] == "cgroup" for mount in self._container_state["mounts"]]): self_cgroups = self._parse_self_cgroup() cgroup_paths = self._container_state["cgroup_paths"] for mount in self._container_state["mounts"]: if mount["type"] == "bind": if mount["destination"].startswith(self._ct_rootfs): dst = mount["destination"][len(self._ct_rootfs):] else: dst = mount["destination"] self._binds.update({dst: mount["source"]}) if mount["type"] == "cgroup": with open("/proc/self/mountinfo", "r") as mountinfo: lines = mountinfo.readlines() for subsystem, c_mp in cgroup_paths.items(): # Remove container ID from path mountpoint = os.path.split(c_mp)[0] dst = os.path.join(mount["destination"], os.path.split(mountpoint)[0]) if dst.startswith(self._ct_rootfs): dst = dst[len(self._ct_rootfs):] line = next(line for line in lines if mountpoint in line) src = os.path.join(mountpoint, os.path.relpath( self_cgroups[subsystem], line.split()[3])) self._binds.update({dst: src}) with open(os.path.join(img.image_dir(), "descriptors.json"), "r") as descr: inherits = [(dsc, i) for i, dsc in enumerate(json.loads(descr.read())) if "pipe:" in dsc] for dsc, i in inherits: self._inherit_fd.update({dsc: i}) with open(os.path.join(img.image_dir(), "state.json"), "r") as old_state_file: self._restore_state = json.loads(old_state_file.read()) criu_cr.criu_restore(self, img, connection)
def final_restore(self, img, connection): criu_cr.criu_restore(self, img, connection)