xen summit 2008 tokyo - operating xen domains through ll(perl/python) with libvirt
TRANSCRIPT
![Page 1: Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with libvirt](https://reader035.vdocuments.site/reader035/viewer/2022062703/5550d411b4c905f2318b4fe3/html5/thumbnails/1.jpg)
Xen Summit 2008 Tokyo
2008/11/21
paperboy&co.
Gosuke Miyashita
![Page 2: Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with libvirt](https://reader035.vdocuments.site/reader035/viewer/2022062703/5550d411b4c905f2318b4fe3/html5/thumbnails/2.jpg)
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)
![Page 3: Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with libvirt](https://reader035.vdocuments.site/reader035/viewer/2022062703/5550d411b4c905f2318b4fe3/html5/thumbnails/3.jpg)
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
![Page 4: Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with libvirt](https://reader035.vdocuments.site/reader035/viewer/2022062703/5550d411b4c905f2318b4fe3/html5/thumbnails/4.jpg)
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
![Page 5: Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with libvirt](https://reader035.vdocuments.site/reader035/viewer/2022062703/5550d411b4c905f2318b4fe3/html5/thumbnails/5.jpg)
![Page 6: Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with libvirt](https://reader035.vdocuments.site/reader035/viewer/2022062703/5550d411b4c905f2318b4fe3/html5/thumbnails/6.jpg)
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
![Page 7: Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with libvirt](https://reader035.vdocuments.site/reader035/viewer/2022062703/5550d411b4c905f2318b4fe3/html5/thumbnails/7.jpg)
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
![Page 8: Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with libvirt](https://reader035.vdocuments.site/reader035/viewer/2022062703/5550d411b4c905f2318b4fe3/html5/thumbnails/8.jpg)
libvirt Xen driver(local)
xend xenstored xen hypervisor
libvirt
Perl Python OCaml RubyJava C#C
![Page 9: Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with libvirt](https://reader035.vdocuments.site/reader035/viewer/2022062703/5550d411b4c905f2318b4fe3/html5/thumbnails/9.jpg)
libvirt Xen driver(remote)
xend xenstored xen hypervisor
libvirtd
Perl Python OCaml RubyJava C#C
libvirt
Over a network
![Page 10: Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with libvirt](https://reader035.vdocuments.site/reader035/viewer/2022062703/5550d411b4c905f2318b4fe3/html5/thumbnails/10.jpg)
![Page 11: Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with libvirt](https://reader035.vdocuments.site/reader035/viewer/2022062703/5550d411b4c905f2318b4fe3/html5/thumbnails/11.jpg)
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};}
![Page 12: Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with libvirt](https://reader035.vdocuments.site/reader035/viewer/2022062703/5550d411b4c905f2318b4fe3/html5/thumbnails/12.jpg)
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] )
![Page 13: Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with libvirt](https://reader035.vdocuments.site/reader035/viewer/2022062703/5550d411b4c905f2318b4fe3/html5/thumbnails/13.jpg)
![Page 14: Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with libvirt](https://reader035.vdocuments.site/reader035/viewer/2022062703/5550d411b4c905f2318b4fe3/html5/thumbnails/14.jpg)
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
![Page 15: Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with libvirt](https://reader035.vdocuments.site/reader035/viewer/2022062703/5550d411b4c905f2318b4fe3/html5/thumbnails/15.jpg)
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 ); ....}
![Page 16: Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with libvirt](https://reader035.vdocuments.site/reader035/viewer/2022062703/5550d411b4c905f2318b4fe3/html5/thumbnails/16.jpg)
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
![Page 17: Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with libvirt](https://reader035.vdocuments.site/reader035/viewer/2022062703/5550d411b4c905f2318b4fe3/html5/thumbnails/17.jpg)
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)
![Page 18: Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with libvirt](https://reader035.vdocuments.site/reader035/viewer/2022062703/5550d411b4c905f2318b4fe3/html5/thumbnails/18.jpg)