【问题标题】:Libvirt python add vCPU and memoryLibvirt python 添加 vCPU 和内存
【发布时间】:2016-03-03 10:34:36
【问题描述】:

我正在为 Libvirt 使用 python 绑定。如何使用 libvirt 在 Xen 中为域添加或删除 VCPU 和内存?

在我正在使用的命令行中:

虚拟处理器:

xm vcpu-set [domain-id] [count in #cores] 

内存:

Memory: xm mem-set [domain-id] [count in MB] 

如何使用 libvirt 绑定在 python 中运行这些命令?不使用子进程。

【问题讨论】:

    标签: python memory xen libvirt vcpu


    【解决方案1】:
    from xen.util.xmlrpcclient import ServerProxy
    server = ServerProxy(serverURI)
    def xm_vcpu_pin(args):
    
        def cpu_make_map(cpulist):
            cpus = []
            for c in cpulist.split(','):
                if c == '':
                    continue
                if c.find('-') != -1:
                    (x, y) = c.split('-')
                    for i in range(int(x), int(y) + 1):
                        cpus.append(int(i))
                else:
                    # remove this element from the list
                    if c[0] == '^':
                        cpus = [x for x in cpus if x != int(c[1:])]
                    else:
                        cpus.append(int(c))
            cpus.sort()
            return ",".join(map(str, cpus))
    
        dom = args[0]
        vcpu = args[1]
        cpumap = cpu_make_map(args[2])
    
        server.xend.domain.pincpu(dom, vcpu, cpumap)
    

    pinning vcpus with python 的完整示例

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-04
      • 2017-06-21
      • 1970-01-01
      • 2021-08-30
      • 1970-01-01
      相关资源
      最近更新 更多