Example #1
0
File: main.py Project: ngsru/heaver
def shutdown(args, config):
    must_be_root()
    names = ops.ls()

    for name in names:
        if ops.is_running(name):
            try:
                ops.stop(name)
                try:
                    box_config = ops.get_box_config(name)
                except Exception as e:
                    report.die("Cannot load '%s' config, is it broken? %s" % (name, e))
                if os.path.exists(ops.get_box_home(name, "heaver_root_generated")):
                    imager = image.get_image_operator(config["image"])
                    if box_config["datamounts"]:
                        for mountpoint, source in box_config["datamounts"]:
                            imager.disassemble_instance(source)
                    imager.disassemble_instance(box_config["root"])
            except ops.InvocationError as e:
                report.die("LXC is broken, cannot stop container %s: %s" % (name, e))
            except ops.ContainerNotFound as e:
                # WTF? Should not happen (containers in ops.ls() already exists)
                report.die("Container %s just disappeared, panic!" % name)

            send_status_soft(args, config)
            print report.format(dict(status="OK", action="shutdown", id=name,
                message="Container %s stopped at shutdown" % name))
Example #2
0
File: main.py Project: ngsru/heaver
def stop(args, config):
    must_be_root()
    names = must_get_names(args)
    for name in names:
        try:
            ops.stop(name)
            try:
                box_config = ops.get_box_config(name)
            except Exception as e:
                report.die("Cannot load '%s' config, is it broken? %s" % (name, e))
            if os.path.exists(ops.get_box_home(name, "heaver_root_generated")):
                imager = image.get_image_operator(config["image"])
                if box_config["datamounts"]:
                    for mountpoint, source in box_config["datamounts"]:
                        imager.disassemble_instance(source)
                imager.disassemble_instance(box_config["root"])
        except ops.InvocationError as e:
            report.die("LXC is broken, cannot stop container %s: %s" % (name, e))
        except ops.ContainerNotFound as e:
            report.die("Container %s just disappeared, panic!" % name)
        try:
            running_flag = ops.get_box_home(name, "heaver_box_running")
            if os.path.exists(running_flag):
                os.unlink(running_flag)
        except Exception as e:
            pass # FIXME: should not happen, warn user/log?
	send_status_soft(args, config)
        print report.format(dict(status="OK", action="stop", id=name,
            message="Container %s stopped" % name))