Python LibvirtConnect Example

说明

python libvirtconnect示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: Python

命名空间/包名称: ovmlvconnect

示例#1
文件: vmtop.py项目: lightcode/OVM

    def __init__(self):
        self._domains = {}

        self.libvirt_conn = LibvirtConnect.get_connection()

        self._sort_on = SORT_NAME

        self.host_stats = HostStats(self.libvirt_conn)

        self.screen = curses.initscr()
        self.init_terminal()

        # Init colors
        colors = (
            ('TABLE_HEADER', curses.COLOR_BLACK, curses.COLOR_GREEN),
            ('TABLE_HEADER_SELECTED', curses.COLOR_BLACK, curses.COLOR_CYAN),
            ('RED_ON_BLACK', curses.COLOR_RED, curses.COLOR_BLACK),
            ('GREEN_ON_BLACK', curses.COLOR_GREEN, curses.COLOR_BLACK),
            ('CYAN_ON_BLACK',  curses.COLOR_CYAN, curses.COLOR_BLACK),
            ('BLACK_ON_CYAN',  curses.COLOR_BLACK, curses.COLOR_CYAN),
            ('YELLOW_ON_BLACK', curses.COLOR_YELLOW, curses.COLOR_BLACK)
        )

        for i, color in enumerate(colors, 1):
            name, fg, bg = color
            curses.init_pair(i, fg, bg)
            setattr(self, name, curses.color_pair(i))

        try:
            self.main()
        finally:
            self.reset_terminal()

示例#2
文件: libvirt_console.py项目: lightcode/OVM

    def start(self):
        libvirt.virEventRegisterDefaultImpl()
        libvirt.registerErrorHandler(error_handler, None)

        atexit.register(self.reset_term)
        self.attrs = termios.tcgetattr(0)
        tty.setraw(0)

        self.connection = LibvirtConnect.get_connection()
        self.domain = self.connection.lookupByName(self.domain_name)
        self.state = self.domain.state(0)
        self.connection.domainEventRegister(self.lifecycle_callback, self)

        sys.stdout.write('Press Control+] to quit.\n\r')
        sys.stdout.flush()

        libvirt.virEventAddHandle(
            0, libvirt.VIR_EVENT_HANDLE_READABLE, self.stdin_callback, None)

        while self.check_console():
            libvirt.virEventRunDefaultImpl()

        sys.stdout.write('\n\rExited.\n\r')
        sys.stdout.flush()

示例#3
文件: inventory.py项目: lightcode/OVM

 def add_domain(cls, domain):
     connection = LibvirtConnect.get_connection()
     connection.defineXML(domain.get_xml().decode('utf8'))

示例#4
文件: inventory.py项目: lightcode/OVM

 def get_domain(cls, name):
     connection = LibvirtConnect.get_connection()
     domain = connection.lookupByName(name)
     return Domain(domain)

示例#5
文件: inventory.py项目: lightcode/OVM

 def get_domains(cls):
     connection = LibvirtConnect.get_connection()
     for domain in connection.listAllDomains():
         yield Domain(domain)

展开阅读全文