Example #1
0
File: vm.py Project: hfm/maglica
def remove(args):
    options = {
        "mandatory": ["name"],
        "optional" : ["on"],
    }
    check_args(args, options)
    name = args["name"]

    virt = Virt(hosts())
    dom = virt.get_inactive_domain(name)

    if not dom:
        (dom, host) = virt.get_active_domain(name)
        if dom:
            raise Exception("Active domain cannot be removed.Please stop it.")
        else:
            raise Exception("Domain not found.")

    host = dom["host"]
    if args.has_key("on"):
        host = args["on"]

    maglica.dispatcher.dispatch({
        "type"   : "vm",
        "host"   : host,
        "action" : "remove",
        "args"   : args,
    })
Example #2
0
def remove(args):
    options = {
        "mandatory": ["name"],
        "optional": ["on"],
    }
    check_args(args, options)
    name = args["name"]

    virt = Virt(hosts())
    dom = virt.get_inactive_domain(name)

    if not dom:
        (dom, host) = virt.get_active_domain(name)
        if dom:
            raise Exception("Active domain cannot be removed.Please stop it.")
        else:
            raise Exception("Domain not found.")

    host = dom["host"]
    if args.has_key("on"):
        host = args["on"]

    maglica.dispatcher.dispatch({
        "type": "vm",
        "host": host,
        "action": "remove",
        "args": args,
    })
Example #3
0
File: vm.py Project: hfm/maglica
def attach_disk(args):
    options = {
        "mandatory": ["name", "size"],
        "optional" : [],
    }
    check_args(args, options)

    size = args["size"]
    if re.match(r'.+G$', size):
        args["size"] = int(args["size"][:-1])
        args["size"] = args["size"] * 1024 * 1024
    elif re.match(r'.+M$', size):
        args["size"] = int(args["size"][:-1])
        args["size"] = args["size"] * 1024
    elif re.match(r'.+K$', size):
        args["size"] = int(args["size"][:-1])

    if args["size"] > 100 * 1024 * 1024:
        raise Exception("Size is too large.")

    name = args["name"]
    virt = Virt(hosts())
    (dom, host) = virt.get_active_domain(name)
    maglica.dispatcher.dispatch({
        "type"   : "vm",
        "host"   : host,
        "action" : "attach_disk",
        "args"   : args,
    })
Example #4
0
def attach_disk(args):
    options = {
        "mandatory": ["name", "size"],
        "optional": [],
    }
    check_args(args, options)

    size = args["size"]
    if re.match(r'.+G$', size):
        args["size"] = int(args["size"][:-1])
        args["size"] = args["size"] * 1024 * 1024
    elif re.match(r'.+M$', size):
        args["size"] = int(args["size"][:-1])
        args["size"] = args["size"] * 1024
    elif re.match(r'.+K$', size):
        args["size"] = int(args["size"][:-1])

    if args["size"] > 100 * 1024 * 1024:
        raise Exception("Size is too large.")

    name = args["name"]
    virt = Virt(hosts())
    (dom, host) = virt.get_active_domain(name)
    maglica.dispatcher.dispatch({
        "type": "vm",
        "host": host,
        "action": "attach_disk",
        "args": args,
    })
Example #5
0
File: virt.py Project: hfm/maglica
def test_get_active_domain():
    virt = Virt()
    (dom, host) = virt.get_active_domain("test")
    eq_(host, "test")
    eq_(dom.name(), "test")
    ok_(dom.isActive())