Example #1
0
File: vm.py Project: hfm/maglica
def clone(args): 
    virt = Virt(hosts())

    options = {
        "mandatory": ["image", "hostname"],
        "optional" : ["on", "start", "format"],
    }
    check_args(args, options)

    images = maglica.image.list()
    target_hosts = []

    for image in images:
        if args["image"] == image["name"]:
            target_hosts.append(image["host"])

    if len(target_hosts) < 1:
        raise Exception('Image "%s" is active or not exist.' % args["image"])

    if args.has_key("on"):
        host = args["on"]
    else:
        min = 65535
        for target_host in target_hosts:
            size = len(virt.get_active_domains_of(target_host["name"])) * 10 / target_host["weight"]
            if size < min:
                min = size
                host = target_host["name"]

    maglica.dispatcher.dispatch({
        "type"   : "vm",
        "action" : "clone",
        "host"   : host,
        "args"   : args,
    })
Example #2
0
def clone(args):
    virt = Virt(hosts())

    options = {
        "mandatory": ["image", "hostname"],
        "optional": ["on", "start", "format"],
    }
    check_args(args, options)

    images = maglica.image.list()
    target_hosts = []

    for image in images:
        if args["image"] == image["name"]:
            target_hosts.append(image["host"])

    if len(target_hosts) < 1:
        raise Exception('Image "%s" is active or not exist.' % args["image"])

    if args.has_key("on"):
        host = args["on"]
    else:
        min = 65535
        for target_host in target_hosts:
            size = len(virt.get_active_domains_of(
                target_host["name"])) * 10 / target_host["weight"]
            if size < min:
                min = size
                host = target_host["name"]

    maglica.dispatcher.dispatch({
        "type": "vm",
        "action": "clone",
        "host": host,
        "args": args,
    })