Exemplo n.º 1
0
Arquivo: vm.py Projeto: 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,
    })
Exemplo n.º 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,
    })
Exemplo n.º 3
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,
    })
Exemplo n.º 4
0
Arquivo: vm.py Projeto: 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,
    })
Exemplo n.º 5
0
Arquivo: vm.py Projeto: 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,
    })
Exemplo n.º 6
0
Arquivo: vm.py Projeto: hfm/maglica
def console(args):
    options = {
        "mandatory": ["name"],
        "optional" : [],
    }
    check_args(args, options)

    virt = Virt(hosts())
    virt.console(args["name"])
Exemplo n.º 7
0
Arquivo: vm.py Projeto: hfm/maglica
def set_vcpus(args):
    options = {
        "mandatory": ["name", "vcpus"],
        "optional" : [],
    }
    check_args(args, options)

    virt = Virt(hosts())
    virt.set_vcpus(args["name"], args["vcpus"])
Exemplo n.º 8
0
Arquivo: vm.py Projeto: hfm/maglica
def set_boot_device(args):
    options = {
        "mandatory": ["name", "dev"],
        "optional" : [],
    }
    check_args(args, options)
     
    virt = Virt(hosts())
    virt.set_boot_device(args["name"], args["dev"])
Exemplo n.º 9
0
Arquivo: vm.py Projeto: hfm/maglica
def destroy(args):
    options = {
        "mandatory": ["name"],
        "optional" : [],
    }
    check_args(args, options)

    virt = Virt(hosts())
    virt.destroy(args["name"])
Exemplo n.º 10
0
def destroy(args):
    options = {
        "mandatory": ["name"],
        "optional": [],
    }
    check_args(args, options)

    virt = Virt(hosts())
    virt.destroy(args["name"])
Exemplo n.º 11
0
def console(args):
    options = {
        "mandatory": ["name"],
        "optional": [],
    }
    check_args(args, options)

    virt = Virt(hosts())
    virt.console(args["name"])
Exemplo n.º 12
0
Arquivo: vm.py Projeto: hfm/maglica
def info(args):
    options = {
        "mandatory": ["name"],
        "optional" : [],
    }
    check_args(args, options)

    virt = Virt(hosts())
    return virt.info(args["name"]);
Exemplo n.º 13
0
def set_vcpus(args):
    options = {
        "mandatory": ["name", "vcpus"],
        "optional": [],
    }
    check_args(args, options)

    virt = Virt(hosts())
    virt.set_vcpus(args["name"], args["vcpus"])
Exemplo n.º 14
0
def set_boot_device(args):
    options = {
        "mandatory": ["name", "dev"],
        "optional": [],
    }
    check_args(args, options)

    virt = Virt(hosts())
    virt.set_boot_device(args["name"], args["dev"])
Exemplo n.º 15
0
def info(args):
    options = {
        "mandatory": ["name"],
        "optional": [],
    }
    check_args(args, options)

    virt = Virt(hosts())
    return virt.info(args["name"])
Exemplo n.º 16
0
def attach_iso(args):
    options = {
        "mandatory": ["name", "iso"],
        "optional": [],
    }
    check_args(args, options)

    name = args["name"]
    iso = args["iso"]

    virt = Virt(hosts())
    virt.attach_iso(name, iso)
Exemplo n.º 17
0
Arquivo: vm.py Projeto: hfm/maglica
def attach_iso(args):
    options = {
        "mandatory": ["name", "iso"],
        "optional" : [],
    }
    check_args(args, options)

    name = args["name"]
    iso  = args["iso"]

    virt = Virt(hosts())
    virt.attach_iso(name, iso)
Exemplo n.º 18
0
def copy(args):
    options = {
        "mandatory": ["name", "dest"],
        "optional": [],
    }
    check_args(args, options)
    maglica.dispatcher.dispatch({
        "type": "image",
        "action": "copy",
        "args": {
            "name": args["name"],
            "dest": args["dest"],
        }
    })
Exemplo n.º 19
0
Arquivo: image.py Projeto: hfm/maglica
def copy(args):
    options = {
        "mandatory": ["name", "dest"],
        "optional": [],
    }
    check_args(args, options)
    maglica.dispatcher.dispatch({
        "type": "image",
        "action": "copy",
        "args": {
            "name": args["name"],
            "dest": args["dest"],
        }
    })
Exemplo n.º 20
0
def set_memory(args):
    options = {
        "mandatory": ["name", "size"],
        "optional": [],
    }
    check_args(args, options)

    name = args["name"]
    size = args["size"]

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

    if size > 10 * 1024 * 1024:
        raise Exception("Size is too large.")

    virt = Virt(hosts())
    virt.set_memory(name, size)
Exemplo n.º 21
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,
    })
Exemplo n.º 22
0
Arquivo: vm.py Projeto: hfm/maglica
def set_memory(args):
    options = {
        "mandatory": ["name", "size"],
        "optional" : [],
    }
    check_args(args, options)

    name = args["name"]
    size = args["size"]

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

    if size > 10 * 1024 * 1024:
        raise Exception("Size is too large.")

    virt = Virt(hosts())
    virt.set_memory(name, size)