본문 바로가기
개발 저장소/가상화

libvirt python 개발 가이드 1편

by 팡삼이 2016. 7. 12.

이 문서는 팡삼이 블로그( http://pangsam.tistory.com/) 에서 libvirt.org 공식문서를 바탕으로 해석하며 정리한 내용들입니다.

 


기본 개념



libvirt python

파이썬 libvirt 모듈은 가상머신을 관리에 용이한 모듈입니다.

하이퍼 바이저에 연결하여 가상머신의 상태, 네트워킹, 저장소, pci/usb 장치, 모니터링 등 관리할수 있습니다.


Guest domain

게스트 도메인은 가상머신 객체를 뜻합니다.

각각의 객체는 식별자 구분을 할수 있습니다.

 Unique identifiers 

ID :활성된 도메인은 유니크한 정수로 구성되어있으며 있습니다.

NAME : 짧은 string 값으로 되어있으며 (a-Z,0-9, _ , -)로 구성되어 있는것을 추천합니다.

UUID : 16 unsigned bytes로 구성되어있으며 RFC 4122정의 포맷형식으로 되어있습니다.  고유성을 보장하고, uuid를 생성하는 알고리즘을 제공합니다.




스토리지 볼륨

스토리지 볼륨 객체는 poll 내에서 스토리지를 할당된 블록을 관리하는 기능을 제공합니다.

(디스크 파티션이나, 논리적 볼륨, SCSI/iSCSI LUN또는 논리적네트워크 파일시스템 등)

 Unique identifiers : key ->pool에서 볼륨을 구분 

, path ->volume을 제공하는 파일 시스템의 경로로써 호스트의 모든 storage volumes에서 유일한 경로다.

, name



드라이버 모델 

-> libvirt를 실행하여 가상화 기술을 사용할 수 있는 안정되고 보장된 API 드라이버들을 말하며


hypervisor drivers
  • Xen: The open source Xen hypervisor providing paravirtualized and fully virtualized machines. A single system driver runs in the Dom0 host talking directly to a combination of the hypervisor, xenstored and xend. Example local URI scheme xen:///.
  • QEMU: Any open source QEMU based virtualization technology, including KVM. A single privileged system driver runs in the host managing QEMU processes. Each unprivileged user account also has a private instance of the driver. Example privileged URI scheme qemu:///system. Example unprivileged URI scheme qemu:///session
    QEMU는 오픈소스를 기반한 가상화기술이다. KVM을 포함하였다.

  • UML: The User Mode Linux kernel, a pure paravirtualization technology. A single privileged system driver runs in the host managing UML processes. Each unprivileged user account also has a private instance of the driver. Example privileged URI scheme uml:///system. Example unprivileged URI scheme uml:///session
  • OpenVZ: The OpenVZ container based virtualization technology, using a modified Linux host kernel. A single privileged system driver runs in the host talking to the OpenVZ tools. Example privileged URI schemeopenvz:///system
  • LXC: The native Linux container based virtualization technology, available with Linux kernels since 2.6.25. A single privileged system driver runs in the host talking to the kernel. Example privileged URI scheme lxc:///
  • Remote: Generic secure RPC service talking to a libvirtd daemon. Encryption and authentication using a choice of TLS, x509 certificates, SASL (GSSAPI/Kerberos) and SSH tunneling. URIs follow the scheme of the desired driver, but with a hostname filled in, and a data transport name appended to the URI scheme. Example URI to talk to Xen over a TLS channel xen+tls://somehostname/. Example URI to talk to QEMU over a SASL channelqemu+tcp:///somehost/system
  • Test: A mock driver, providing a virtual in-memory hypervisor covering all the libvirt APIs. Facilities testing of applications using libvirt, by allowing automated tests to run which exercise libvirt APIs without needing to deal with a real hypervisor Example default URI scheme test:///default. Example customized URI schemetest:///path/to/driver/config.xml

원격 관리

대부분 가상화 기술은 원격 관리기능을 제공하며 모든 libvirt전용 하이퍼바이저 드라이버들은 원격제어를 제공합니다.  
드라이버는 데이터를 다양한 데이터 통신을 위해 높은수준의 보안성을 재공하고있습니다. 
RPC 



데이터 통신

다양한 개발환경에 대응하기 위해  libvirt의 RPC 서비스 지원으로  여러 데이터 통신이 가능합니다.

이들은 산업표준 암호화 및 인증기능으로 구성되어 있습니다.

TLS

TCP

UNIX ->로컬 데이터만 전송하며 다른 사용자 계정의 libvirt 데몬에 연결할수 있습니다.  오직 로컬 VM만 접근가능하며 암호화되어있지 않습니다.

표준 socket 이름은/var/run/libvirt/libvirt-sock

SSH

EXT




libvirt 연결 

Open Function - > libvirt에 접근,읽기쓰기 기능을 제공하며 인증 콜백에 대한 범위를 제공하지 않습니다.


# Example-1.py
from __future__ import print_function
import sys
import libvirt

conn = libvirt.open('qemu:///system')
if conn == None:
    print('Failed to open connection to qemu:///system', file=sys.stderr)
    exit(1)
conn.close()
exit(0)

close

A connection must be released by calling the close method of the virConnection class when no longer required. Connections are reference counted objects, so there should be a cooresponding call to the close method for each openfunction call.

# Example-5.py
from __future__ import print_function
import sys
import libvirt

conn1 = libvirt.open('qemu:///system')
if conn1 == None:
    print('Failed to open connection to qemu:///system', file=sys.stderr)
    exit(1)
conn2 = libvirt.open('qemu:///system')
if conn2 == None:
    print('Failed to open connection to qemu:///system', file=sys.stderr)
    exit(1)
conn1.close()
conn2.close()
exit(0)






댓글