0

私は Libvirt の Python バインディングを使用しています。libvirt を使用して Xen でドメインの VCPU とメモリを追加または削除するにはどうすればよいですか?

私が使用しているコマンドラインで:

VCPU:

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

メモリー:

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

これらのコマンドを Python で libvirt バインディングを使用して実行するにはどうすればよいですか? サブプロセスを使用せずに。

4

1 に答える 1

0
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)

Python で vcpus を固定する完全な例

于 2016-05-13T10:09:01.297 に答える