LCEU13 : Xen Project Lessons Learned - Lars Kurth, Xen Project
Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with libvirt
-
Upload
gosuke-miyashita -
Category
Technology
-
view
3.513 -
download
0
Transcript of Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with libvirt
Xen Summit 2008 Tokyo
2008/11/21
paperboy&co.
Gosuke Miyashita
Agenda
About me Purpose of this talk What is libvirt libvirt Xen driver architecture libvirt sample codes with Perl/Python Related tools (Avahi and Func)
About me
Gosuke Miyashitahttp://mizzy.org/
Technical manager at paperboy&co.Web hosting, blog, ec hosting and so on for
indivisuals
Thinking introduce virtualization technologies to our services
Purpose of this talk I seek how to manage Xen domains on
many host machines I need a simple and customizable tool It may be fast to develop my own tool libvirt is the one for developing my own
Xen management tool Why python and perl?
These languages may be used widly in system administration
What is libvirt? The virtualization API A library intracts with virtualization
systemsXen, QEMU, KVM, LXC and OpenVZ
Language bindingsC, Python, Perl, OCaml, Ruby, Java and C#
Support multiple authentication methodsSSH, TLS and X.509, SASL and Kerberos
Avahi multicast DNS support
What can you do with libvirt? Get Dom0 info
CPU model/threads/cores, memory size and so on List domains Get domain info
id, uuid, name, xml description, os type and state Various domain operations
create, shutdown, reboot, suspend, resumeset/get max memory/memory size, get max vcpus
Network, Storage operations (excluded in this talk)
See http://libvirt.org/html/libvirt-libvirt.html
libvirt Xen driver(local)
xend xenstored xen hypervisor
libvirt
Perl Python OCaml RubyJava C#C
libvirt Xen driver(remote)
xend xenstored xen hypervisor
libvirtd
Perl Python OCaml RubyJava C#C
libvirt
Over a network
Perl code exampleuse Sys::Virt;
# connect to the remote hostmy $vmm = Sys::Virt->new( uri => "xen://remote_host/“ );
# get domainsmy @doms = $vmm->list_domains;
# print state of each domainsfor my $dom ( @doms ) { printf "%s: %s\n", $dom->get_name, $dom->get_info->{state};}
Python code exampleimport libvirt
# connect to the remote hostconn = libvirt.open(‘xen://remote_host/’)
# get domain idsids = conn.listDomainsID()
# print state of each domainsfor id in ids: vm = conn.lookupByID(id) print "%s: %s" % ( vm.name(), vm.info()[0] )
Avahi support
libvirt is integrated with Avahi Ahahi is a one of mDNS implementation You can discover hosts with libvirtd
running by mDNS client automatically
Perl example with libvirt and avahiuse Net::Bonjour;use Sys::Virt;
# discover hosts with libvirtd runningmy $res = Net::Bonjour->new('libvirt');$res->discover;
# access libvirtd on each hostfor my $host ( $res->entries ) { my $vmm = Sys::Virt->new( uri => ‘xen://’ . $host->address ); ....}
Func Fedora Unified Network Controller
https://fedorahosted.org/func/ Sysadmin application framework made
of Python A programming framework for “Exec
some operations for multiple hosts” Many modules
yum, user, service, command, smart, virt ... Virt module uses libvirt
Func virt module sample codeimport func.overlord.client as fc
# call state method of virt module on all hostsresults = fc.Client("*").virt.state()
# create domain if domain state is ‘shutdown’for ( host, vms ) in results.iteritems(): if vms[0] == 'REMOTE_ERROR': continue
for vm in vms: ( domain, state ) = vm.split(' ') if state == 'shutdown': fc.Client(host).virt.create(domain)