当前位置: 首页>>代码示例>>Python>>正文


Python virt.Virt类代码示例

本文整理汇总了Python中maglica.virt.Virt的典型用法代码示例。如果您正苦于以下问题:Python Virt类的具体用法?Python Virt怎么用?Python Virt使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Virt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: remove

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,
    })
开发者ID:hfm,项目名称:maglica,代码行数:28,代码来源:vm.py

示例2: test_get_inactive_domain

def test_get_inactive_domain():
    virt = Virt()
    virt.hosts[0]["conn"].defineXML(xml)
    dom = virt.get_inactive_domain("test2")
    eq_(dom["name"], "test2")
    eq_(dom["host"], "test")
    eq_(dom["state"], "shut off")
开发者ID:hfm,项目名称:maglica,代码行数:7,代码来源:virt.py

示例3: clone

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,
    })
开发者ID:hfm,项目名称:maglica,代码行数:35,代码来源:vm.py

示例4: test_get_domains

def test_get_domains():
    virt = Virt()
    virt.hosts[0]["conn"].defineXML(xml)
    dom = virt.get_inactive_domain("test2")
    domains = virt.get_domains()
    eq_(domains[0]["name"], "test")
    eq_(domains[1]["name"], "test2")
开发者ID:hfm,项目名称:maglica,代码行数:7,代码来源:virt.py

示例5: attach_disk

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,
    })
开发者ID:hfm,项目名称:maglica,代码行数:29,代码来源:vm.py

示例6: info

def info(args):
    options = {
        "mandatory": ["name"],
        "optional" : [],
    }
    check_args(args, options)

    virt = Virt(hosts())
    return virt.info(args["name"]);
开发者ID:hfm,项目名称:maglica,代码行数:9,代码来源:vm.py

示例7: destroy

def destroy(args):
    options = {
        "mandatory": ["name"],
        "optional" : [],
    }
    check_args(args, options)

    virt = Virt(hosts())
    virt.destroy(args["name"])
开发者ID:hfm,项目名称:maglica,代码行数:9,代码来源:vm.py

示例8: console

def console(args):
    options = {
        "mandatory": ["name"],
        "optional" : [],
    }
    check_args(args, options)

    virt = Virt(hosts())
    virt.console(args["name"])
开发者ID:hfm,项目名称:maglica,代码行数:9,代码来源:vm.py

示例9: set_vcpus

def set_vcpus(args):
    options = {
        "mandatory": ["name", "vcpus"],
        "optional" : [],
    }
    check_args(args, options)

    virt = Virt(hosts())
    virt.set_vcpus(args["name"], args["vcpus"])
开发者ID:hfm,项目名称:maglica,代码行数:9,代码来源:vm.py

示例10: set_boot_device

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"])
开发者ID:hfm,项目名称:maglica,代码行数:9,代码来源:vm.py

示例11: attach_iso

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)
开发者ID:hfm,项目名称:maglica,代码行数:12,代码来源:vm.py

示例12: test_uri_qemu

def test_uri_qemu():
    virt = Virt()

    conf = maglica.config.load_from_dict({
        "libvirt": {
            "driver"    : "qemu",
            "transport" : "tcp",
            "path"      : "system",
        }
    })

    virt.conf = conf

    eq_(virt.uri("host0.example.jp"), "qemu+tcp://host0.example.jp/system")
开发者ID:hfm,项目名称:maglica,代码行数:14,代码来源:virt.py

示例13: set_memory

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)
开发者ID:hfm,项目名称:maglica,代码行数:24,代码来源:vm.py

示例14: test_set_vcpus

def test_set_vcpus():
    virt = Virt()
    ok_(virt.set_vcpus("test", "1"))
开发者ID:hfm,项目名称:maglica,代码行数:3,代码来源:virt.py

示例15: test_set_boot_device

def test_set_boot_device():
    virt = Virt()
    ok_(virt.attach_iso("test", "cdrom"))
开发者ID:hfm,项目名称:maglica,代码行数:3,代码来源:virt.py


注:本文中的maglica.virt.Virt类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。