예제 #1
0
파일: iocage.py 프로젝트: gronke/iocage
 def stop(self, jail=None):
     """Stops the jail."""
     if self.rc or self._all:
         if not jail:
             self.__jail_order__("stop")
     else:
         tag, uuid, path = self.__check_jail_existence__()
         conf = ioc_json.IOCJson(path).json_load()
         ioc_stop.IOCStop(uuid, tag, path, conf, silent=self.silent)
예제 #2
0
파일: upgrade.py 프로젝트: wxcafe/iocage
def cli(jail, release):
    """Runs upgrade with the command given inside the specified jail."""
    # TODO: Move to API
    release = release.rsplit("-", 1)[0].rsplit("-", 1)[0]
    host_release = os.uname()[2].rsplit("-", 1)[0].rsplit("-", 1)[0]

    if release is not None:
        if host_release < release:
            ioc_common.logit({
                "level":
                "EXCEPTION",
                "message":
                f"\nHost: {host_release} is not greater than"
                f" target: {release}\nThis is unsupported."
            })

    jails = ioc_list.IOCList("uuid").list_datasets()
    _jail = {
        uuid: path
        for (uuid, path) in jails.items() if uuid.startswith(jail)
    }

    if len(_jail) == 1:
        uuid, path = next(iter(_jail.items()))
        root_path = f"{path}/root"
    elif len(_jail) > 1:
        ioc_common.logit({
            "level": "ERROR",
            "message": f"Multiple jails found for {jail}:"
        })

        for u, p in sorted(_jail.items()):
            ioc_common.logit({"level": "ERROR", "message": f"  {u} ({p})"})
        exit(1)
    else:
        ioc_common.logit(
            {
                "level": "EXCEPTION",
                "message": f"{jail} not found!"
            },
            exit_on_error=True)

    status, jid = ioc_list.IOCList.list_get_jid(uuid)
    conf = ioc_json.IOCJson(path).json_load()
    jail_release = conf["release"]

    if release in jail_release:
        ioc_common.logit(
            {
                "level": "EXCEPTION",
                "message": f"Jail: {uuid} is already at version {release}!"
            },
            exit_on_error=True)

    started = False

    if conf["release"] == "EMPTY":
        ioc_common.logit(
            {
                "level": "EXCEPTION",
                "message": "Upgrading is not supported for empty jails."
            },
            exit_on_error=True)

    if conf["type"] == "jail":
        if not status:
            ioc_start.IOCStart(uuid, path, conf, silent=True)
            started = True

        new_release = ioc_upgrade.IOCUpgrade(conf, release,
                                             root_path).upgrade_jail()
    elif conf["type"] == "basejail":
        ioc_common.logit(
            {
                "level":
                "EXCEPTION",
                "message":
                "Please run \"iocage migrate\" before trying"
                f" to upgrade {uuid}"
            },
            exit_on_error=True)
    elif conf["type"] == "template":
        ioc_common.logit(
            {
                "level":
                "EXCEPTION",
                "message":
                "Please convert back to a jail before trying"
                f" to upgrade {uuid}"
            },
            exit_on_error=True)
    else:
        ioc_common.logit(
            {
                "level": "EXCEPTION",
                "message": f"{conf['type']} is not a supported jail type."
            },
            exit_on_error=True)

    if started:
        ioc_stop.IOCStop(uuid, path, conf, silent=True)

        ioc_common.logit({
            "level":
            "INFO",
            "message":
            f"\n{uuid} successfully upgraded from"
            f" {jail_release} to {new_release}!"
        })
예제 #3
0
 def __jail_stop__(self, jail, silent=False):
     """Stops the jail."""
     tag, uuid, path = self.__check_jail_existence__(jail)
     conf = ioc_json.IOCJson(path).json_load()
     ioc_stop.IOCStop(uuid, tag, path, conf, silent)
예제 #4
0
def cli(jail):
    """Runs update with the command given inside the specified jail."""
    # TODO: Move to API
    jails = ioc_list.IOCList("uuid").list_datasets()
    _jail = {
        uuid: path
        for (uuid, path) in jails.items() if uuid.startswith(jail)
    }

    if len(_jail) == 1:
        uuid, path = next(iter(_jail.items()))
    elif len(_jail) > 1:
        ioc_common.logit({
            "level": "ERROR",
            "message": f"Multiple jails found for {jail}:"
        })
        for u, p in sorted(_jail.items()):
            ioc_common.logit({"level": "ERROR", "message": f"  {u} ({p})"})
        exit(1)
    else:
        ioc_common.logit({"level": "ERROR", "message": f"{jail} not found!"})
        exit(1)

    freebsd_version = ioc_common.checkoutput(["freebsd-version"])
    status, jid = ioc_list.IOCList.list_get_jid(uuid)
    conf = ioc_json.IOCJson(path).json_load()
    started = False

    if conf["type"] == "jail":
        if not status:
            ioc_start.IOCStart(uuid, path, conf, silent=True)
            status, jid = ioc_list.IOCList.list_get_jid(uuid)
            started = True
    elif conf["type"] == "basejail":
        ioc_common.logit({
            "level":
            "ERROR",
            "message":
            "Please run \"iocage migrate\" before trying"
            f" to update {uuid}"
        })
        exit(1)
    elif conf["type"] == "template":
        ioc_common.logit({
            "level":
            "ERROR",
            "message":
            "Please convert back to a jail before trying"
            f" to update {uuid}"
        })
        exit(1)
    else:
        ioc_common.logit({
            "level":
            "ERROR",
            "message":
            f"{conf['type']} is not a supported jail type."
        })
        exit(1)

    if "HBSD" in freebsd_version:
        su.Popen(["hbsd-update", "-j", jid]).communicate()

        if started:
            ioc_stop.IOCStop(uuid, path, conf, silent=True)
    else:
        ioc_fetch.IOCFetch(conf["cloned_release"]).fetch_update(True, uuid)

        if started:
            ioc_stop.IOCStop(uuid, path, conf, silent=True)
예제 #5
0
파일: restart.py 프로젝트: gronke/iocage
def __hard_restart__(uuid, jail, path, conf):
    """Stops and then starts the jail."""
    ioc_stop.IOCStop(uuid, jail, path, conf)
    ioc_start.IOCStart(uuid, jail, path, conf)
예제 #6
0
def cli(jail, release):
    """Runs upgrade with the command given inside the specified jail."""
    jails, paths = ioc_list.IOCList("uuid").list_datasets()
    _jail = {
        tag: uuid
        for (tag, uuid) in jails.items()
        if uuid.startswith(jail) or tag == jail
    }

    if len(_jail) == 1:
        tag, uuid = next(iter(_jail.items()))
        path = paths[tag]
        root_path = "{}/root".format(path)
    elif len(_jail) > 1:
        ioc_common.logit({
            "level": "ERROR",
            "message": f"Multiple jails found for {jail}:"
        })
        for t, u in sorted(_jail.items()):
            ioc_common.logit({"level": "ERROR", "message": f"  {u} ({t})"})
        exit(1)
    else:
        ioc_common.logit({"level": "ERROR", "message": f"{jail} not found!"})
        exit(1)

    status, jid = ioc_list.IOCList.list_get_jid(uuid)
    conf = ioc_json.IOCJson(path).json_load()
    jail_release = conf["release"]
    started = False

    if conf["release"] == "EMPTY":
        ioc_common.logit({
            "level":
            "ERROR",
            "message":
            "Upgrading is not supported for empty jails."
        })
        exit(1)
    if conf["type"] == "jail":
        if not status:
            ioc_start.IOCStart(uuid, tag, path, conf, silent=True)
            started = True

            new_release = ioc_upgrade.IOCUpgrade(conf, release,
                                                 root_path).upgrade_jail()
    elif conf["type"] == "basejail":
        ioc_common.logit({
            "level":
            "ERROR",
            "message":
            "Please run \"iocage migrate\" before trying"
            f" to upgrade {uuid} ({tag})"
        })
        exit(1)
    elif conf["type"] == "template":
        ioc_common.logit({
            "level":
            "ERROR",
            "message":
            "Please convert back to a jail before trying"
            f" to upgrade {uuid} ({tag})"
        })
        exit(1)
    else:
        ioc_common.logit({
            "level":
            "ERROR",
            "message":
            f"{conf['type']} is not a supported jail type."
        })
        exit(1)

    if started:
        ioc_stop.IOCStop(uuid, tag, path, conf, silent=True)

        ioc_common.logit({
            "level":
            "INFO",
            "message":
            f"\n{uuid} ({tag}) successfully upgraded from"
            f" {jail_release} to {new_release}!"
        })