Ejemplo n.º 1
0
    def __fstab_remove__(self):
        """
        Removes the users mount by index or matching string.

        :return: The destination of the specified mount
        """
        removed = False
        index = 0

        with open("{}/jails/{}/fstab".format(self.iocroot,
                                             self.uuid), "r") as \
                fstab:
            with open_atomic(
                    "{}/jails/{}/fstab".format(self.iocroot, self.uuid),
                    "w") as _fstab:
                for line in fstab.readlines():
                    if line.rsplit("#")[0].rstrip() == self.mount or index \
                            == self.index and not removed:
                        removed = True
                        dest = line.split()[1]
                        continue
                    else:
                        _fstab.write(line)

                    index += 1
        if removed:
            self.lgr.info(
                "Successfully removed mount from {} ({})'s fstab".format(
                    self.uuid, self.tag))
            return dest  # Needed for umounting, otherwise we lack context.
        else:
            self.lgr.info("No matching fstab entry.")
            exit()
Ejemplo n.º 2
0
    def __fstab_remove__(self):
        removed = False
        index = 0

        with open("{}/jails/{}/fstab".format(self.iocroot,
                                             self.uuid), "r") as \
                fstab:
            with open_atomic(
                    "{}/jails/{}/fstab".format(self.iocroot, self.uuid),
                    "w") as _fstab:
                for line in fstab.readlines():
                    if line.rsplit("#")[0].rstrip() == self.mount or index \
                            == self.index and not removed:
                        removed = True
                        continue
                    else:
                        _fstab.write(line)

                    index += 1
        if removed:
            self.lgr.info(
                "Successfully removed mount from {} ({})'s fstab".format(
                    self.uuid, self.tag))
        else:
            self.lgr.info("No fstab entry matching: {}".format(self.mount))
Ejemplo n.º 3
0
 def start_generate_resolv(self):
     resolver = self.get("resolver")
     #                                     compat
     if resolver != "/etc/resolv.conf" and resolver != "none":
         with open_atomic("{}/root/etc/resolv.conf".format(self.path),
                          "w") as resolv_conf:
             for line in resolver.split(";"):
                 resolv_conf.write(line + "\n")
     elif resolver == "none":
         copy("/etc/resolv.conf",
              "{}/root/etc/resolv.conf".format(self.path))
     else:
         copy(resolver, "{}/root/etc/resolv.conf".format(self.path))
Ejemplo n.º 4
0
    def __fstab_add__(self):
        with open("{}/jails/{}/fstab".format(self.iocroot,
                                             self.uuid), "r") as \
                fstab:
            with open_atomic(
                    "{}/jails/{}/fstab".format(self.iocroot, self.uuid),
                    "w") as _fstab:
                # open_atomic will empty the file, we need these still.
                for line in fstab.readlines():
                    _fstab.write(line)

                _fstab.write("{} # Added by iocage on {}\n".format(
                    self.mount,
                    datetime.utcnow().strftime("%F %T")))

        self.lgr.info("Successfully added mount to {} ({})'s fstab".format(
            self.uuid, self.tag))
Ejemplo n.º 5
0
 def json_write(self, data, _file="/config.json"):
     """Write a JSON file at the location given with supplied data."""
     with open_atomic(self.location + _file, 'w') as out:
         json.dump(data, out, sort_keys=True, indent=4, ensure_ascii=False)