SlideShare a Scribd company logo
1 of 39
[object Object],[object Object],[object Object],[object Object]
Agenda ,[object Object],[object Object],[object Object]
The Abstract ,[object Object],[object Object],[object Object]
The Technology ,[object Object],[object Object]
The Technology – openSUSE 11.0 ,[object Object],[object Object],[object Object],[object Object]
The Technology – Xen 3.2.1 ,[object Object],[object Object],[object Object]
The Technology – libvirt 0.4.0 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The Technology – Python 2.5.2 ,[object Object],[object Object]
The Hacks ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Hack #1 – The xm Command ,[object Object],NAME xm - Xen management user interface SYNOPSIS xm <subcommand> [args] DESCRIPTION The xm program is the main interface for managing Xen guest domains. The program can be used to create, pause, and shutdown domains. It can also be used to list current domains, enable or pin VCPUs, and attach or detach virtual block devices. The basic structure of every xm command is almost always: xm <subcommand> <domain-id> [OPTIONS] ...
Hack #1 – The xm Command (cont'd) ,[object Object],[object Object],[object Object],[object Object]
Hack #2 – The virsh Command ,[object Object],[object Object],NAME virsh - management user interface SYNOPSIS virsh <subcommand> [args] DESCRIPTION The virsh program is the main interface for managing virsh guest domains. The program can be used to create, pause, and shutdown domains. It can also be used to list current domains. Libvirt is a C toolkit to interact with the virtualization capabilities of recent ver‐ sions of Linux (and other OSes). It is free software available under the GNU Lesser General Public License. Virtualization of the Linux Operating System means the ability to run multiple instances of Operat‐ ing Systems concurrently on a single hardware system where the basic resources are driven by a Linux instance. The library aim at providing long term stable C API initially for the Xen paravirtualization but should be able to integrate other virtualization mechanisms, it cur‐ rently also support QEmu and KVM. ...
Hack #2 – The virsh Command (cont'd) ,[object Object],chonju:~ # virsh Welcome to virsh, the virtualization interactive terminal. Type:  'help' for help with commands 'quit' to quit virsh # dominfo 1 Id:  1 Name:  opensuse11 UUID:  60c451d0-9009-2bd6-1cfb-f71e9ec6926d OS Type:  linux State:  blocked CPU(s):  1 CPU time:  3.3s Max memory:  393216 kB Used memory:  393216 kB virsh # shutdown 1 Domain 1 is being shutdown virsh #
Hack #3 – virt-manager  ,[object Object],[object Object],[object Object]
Hack #3 – virt-manager (cont'd) ,[object Object],[object Object]
Hack #3 – virt-manager (cont'd) ,[object Object],[object Object],[object Object],[object Object],[object Object]
Hack #4 – libvirt + Python ,[object Object],[object Object],[object Object],[object Object]
Hack #4 – libvirt + Python (cont'd) ,[object Object],#!/usr/bin/python import libvirt import sys conn = libvirt.openReadOnly(None) if conn == None: print 'Failed to open connection to the hypervisor' sys.exit(1) try: dom0 = conn.lookupByName(&quot;Domain-0&quot;) except: print 'Failed to find the main domain' sys.exit(1) print &quot;Domain 0: id %d running %s&quot; % (dom0.ID(), dom0.OSType()) print dom0.info()
Hack #5 – Query the Hypervisor's Capabilities ,[object Object],[object Object],[object Object],[object Object]
Hack #5 – Query the Hypervisor's Capabilities (cont'd) #!/usr/bin/python import libvirt conn = libvirt.open(None) print conn.getCapabilities() info = conn.getInfo() print &quot;CPU model: %s&quot; % info[0] print &quot;memory: %d kB&quot; % info[1] print &quot;# of CPUs: %d&quot; % info[2] print &quot;CPU freq: %d MHz&quot; % info[3] print &quot;# of NUMA cell: %d&quot; % info[4] print &quot;# of CPU sockets: %d&quot; % info[5] print &quot;# of cores per socket: %d&quot; % info[6] print &quot;# of threads per core: %d&quot; % info[7]
Hack #6 – Start/Stop a VM ,[object Object],[object Object],#!/usr/bin/python import sys, libvirt vmname = sys.argv[1] conn = libvirt.open(None) dom = conn.lookupByName(vmname) dom.create() dom = conn.lookupByName(vmname) print &quot;%d started&quot; % dom.ID()
Hack #6 – Start/Stop a VM (cont'd) ,[object Object],#!/usr/bin/python import sys, libvirt vmid = int(sys.argv[1]) conn = libvirt.open(None) dom = conn.lookupByID(vmid) dom.shutdown()
Hack #7 – Migrate a VM ,[object Object],[object Object]
Hack #7 – Migrate a VM (cont'd) #!/usr/bin/python import sys, getpass, libvirt vmname = sys.argv[1] uri = sys.argv[2] mydata = &quot;&quot;  def getCredentials(credentials, data): for credential in credentials: print credential[1] + &quot;:&quot;, if credential[0] == libvirt.VIR_CRED_AUTHNAME: data = sys.stdin.readline() data = data[0:len(data)-1] credential[4] = data elif credential[0] == libvirt.VIR_CRED_PASSPHRASE: credential[4] = getpass(&quot;&quot;) else: return -1 return 0 flags = [libvirt.VIR_CRED_AUTHNAME,libvirt.VIR_CRED_PASSPHRASE] auth = [flags,getCredentials,mydata] localconn = libvirt.open(None) dom = localconn.lookupByName(vmname) remoteconn = libvirt.openAuth(None,auth,0) dom.migrate(remoteconn,libvirt.VIR_MIGRATE_LIVE,None,uri,0)
Hack #7 – Migrate a VM (cont'd) ,[object Object],[object Object],[object Object],[object Object]
Hack #7 – Migrate a VM (cont'd) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Hack #8 – Edit a VM Configuration ,[object Object],[object Object]
Hack #8 – Edit a VM Configuration (cont'd) ,[object Object],name=&quot;opensuse11&quot; uuid=&quot;60c451d0-9009-2bd6-1cfb-f71e9ec6926d&quot; memory=384 vcpus=1 on_poweroff=&quot;destroy&quot; on_reboot=&quot;restart&quot; on_crash=&quot;destroy&quot; localtime=0 keymap=&quot;en-us&quot; builder=&quot;linux&quot; bootloader=&quot;/usr/lib/xen/boot/domUloader.py&quot; bootargs=&quot;--entry=xvda2:/boot/vmlinuz-xen,/boot/initrd-xen&quot; extra=&quot; &quot; disk=[ 'file:/var/lib/xen/images/opensuse11/disk0,xvda,w', ] vif=[ 'mac=00:16:3e:49:b8:b2', ] vfb=['type=vnc,vncunused=1']
Hack #8 – Edit a VM Configuration (cont'd) ,[object Object],#!/usr/bin/python import sys, os original = sys.argv[1] new = sys.argv[2] f = file(original, &quot;rb&quot;) lines = f.readlines() dict = {} for line in lines: pieces = line.partition(&quot;=&quot;) dict[pieces[0]] = eval(pieces[2]) for key in dict.keys(): if key == &quot;name&quot;: dict[key] = new elif key == &quot;disk&quot;: disks = dict[key] dict[key] = [] for disk in disks: dict[key].append(disk.replace(os.path.basename(original),new)) elif key == &quot;vif&quot;: dict[key] = None elif key == &quot;uuid&quot;: dict[key] = None if dict[key] != None: print &quot;%s=%s&quot; % ( key, repr(dict[key]) )
Hack #8 – Edit a VM Configuration (cont'd) ,[object Object],#!/usr/bin/python import sys, libvirt vmname = sys.argv[1] maxMemory = int(sys.argv[2]) conn = libvirt.open(None) dom = conn.lookupByName(vmname)  print dom.maxMemory()  dom.create() dom.setMaxMemory(maxMemory) dom = conn.lookupByName(vmname) print dom.maxMemory()
Hack #9 – Edit a VM Image ,[object Object],[object Object],[object Object],[object Object],[object Object]
Hack #10 – Clone a VM ,[object Object],[object Object],[object Object]
Hack #10 – Clone a VM (cont'd) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Hack #11 – Create an Appliance ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Hack #11 – Create an Appliance (cont'd) ,[object Object],[object Object],[object Object],[object Object],[object Object]
Hack #11 – Create an Appliance (cont'd) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Hack #11 – Create an Appliance (cont'd) ,[object Object],[object Object],[object Object]
Hack #11 – Create an Appliance (cont'd) ,[object Object],[object Object],[object Object]
[object Object]

More Related Content

What's hot

Vmware Command Line
Vmware   Command LineVmware   Command Line
Vmware Command Line
lifeit
 
S4 xen hypervisor_20080622
S4 xen hypervisor_20080622S4 xen hypervisor_20080622
S4 xen hypervisor_20080622
Todd Deshane
 

What's hot (20)

Introduction to Docker, December 2014 "Tour de France" Bordeaux Special Edition
Introduction to Docker, December 2014 "Tour de France" Bordeaux Special EditionIntroduction to Docker, December 2014 "Tour de France" Bordeaux Special Edition
Introduction to Docker, December 2014 "Tour de France" Bordeaux Special Edition
 
Alta disponibilidad en GNU/Linux
Alta disponibilidad en GNU/LinuxAlta disponibilidad en GNU/Linux
Alta disponibilidad en GNU/Linux
 
Why everyone is excited about Docker (and you should too...) - Carlo Bonamic...
Why everyone is excited about Docker (and you should too...) -  Carlo Bonamic...Why everyone is excited about Docker (and you should too...) -  Carlo Bonamic...
Why everyone is excited about Docker (and you should too...) - Carlo Bonamic...
 
Vmware Command Line
Vmware   Command LineVmware   Command Line
Vmware Command Line
 
Noah - Robust and Flexible Operating System Compatibility Architecture - Cont...
Noah - Robust and Flexible Operating System Compatibility Architecture - Cont...Noah - Robust and Flexible Operating System Compatibility Architecture - Cont...
Noah - Robust and Flexible Operating System Compatibility Architecture - Cont...
 
XenSummit NA 2012: Xen on ARM Cortex A15
XenSummit NA 2012: Xen on ARM Cortex A15XenSummit NA 2012: Xen on ARM Cortex A15
XenSummit NA 2012: Xen on ARM Cortex A15
 
Continuous delivery with docker
Continuous delivery with dockerContinuous delivery with docker
Continuous delivery with docker
 
BH Arsenal '14 TurboTalk: The Veil-framework
BH Arsenal '14 TurboTalk: The Veil-frameworkBH Arsenal '14 TurboTalk: The Veil-framework
BH Arsenal '14 TurboTalk: The Veil-framework
 
Tribal Nova Docker feedback
Tribal Nova Docker feedbackTribal Nova Docker feedback
Tribal Nova Docker feedback
 
Docker from scratch
Docker from scratchDocker from scratch
Docker from scratch
 
S4 xen hypervisor_20080622
S4 xen hypervisor_20080622S4 xen hypervisor_20080622
S4 xen hypervisor_20080622
 
Using QEMU for cross development
Using QEMU for cross developmentUsing QEMU for cross development
Using QEMU for cross development
 
Light my-fuse
Light my-fuseLight my-fuse
Light my-fuse
 
Android crash debugging
Android crash debuggingAndroid crash debugging
Android crash debugging
 
Docker security
Docker securityDocker security
Docker security
 
MINCS - containers in the shell script (Eng. ver.)
MINCS - containers in the shell script (Eng. ver.)MINCS - containers in the shell script (Eng. ver.)
MINCS - containers in the shell script (Eng. ver.)
 
SystemV vs systemd
SystemV vs systemdSystemV vs systemd
SystemV vs systemd
 
Lessons from running potentially malicious code inside Docker containers
Lessons from running potentially malicious code inside Docker containersLessons from running potentially malicious code inside Docker containers
Lessons from running potentially malicious code inside Docker containers
 
Init of Android
Init of AndroidInit of Android
Init of Android
 
Defcon - Veil-Pillage
Defcon - Veil-PillageDefcon - Veil-Pillage
Defcon - Veil-Pillage
 

Similar to Open Source Virtualization Hacks

Utilizing the Xen Hypervisor in business practice - Bryan Fusilier
Utilizing the Xen Hypervisor in business practice - Bryan FusilierUtilizing the Xen Hypervisor in business practice - Bryan Fusilier
Utilizing the Xen Hypervisor in business practice - Bryan Fusilier
Matthew Turland
 
Rmll Virtualization As Is Tool 20090707 V1.0
Rmll Virtualization As Is Tool 20090707 V1.0Rmll Virtualization As Is Tool 20090707 V1.0
Rmll Virtualization As Is Tool 20090707 V1.0
guest72e8c1
 
Linux sever building
Linux sever buildingLinux sever building
Linux sever building
Edmond Yu
 
Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with li...
Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with li...Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with li...
Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with li...
Gosuke Miyashita
 

Similar to Open Source Virtualization Hacks (20)

Practical Introduction To Linux
Practical Introduction To LinuxPractical Introduction To Linux
Practical Introduction To Linux
 
Krenel Based Virtual Machine In Centos7
Krenel Based Virtual Machine In Centos7Krenel Based Virtual Machine In Centos7
Krenel Based Virtual Machine In Centos7
 
Handout2o
Handout2oHandout2o
Handout2o
 
Command line for the beginner - Using the command line in developing for the...
Command line for the beginner -  Using the command line in developing for the...Command line for the beginner -  Using the command line in developing for the...
Command line for the beginner - Using the command line in developing for the...
 
Linux containers and docker
Linux containers and dockerLinux containers and docker
Linux containers and docker
 
Utilizing the Xen Hypervisor in business practice - Bryan Fusilier
Utilizing the Xen Hypervisor in business practice - Bryan FusilierUtilizing the Xen Hypervisor in business practice - Bryan Fusilier
Utilizing the Xen Hypervisor in business practice - Bryan Fusilier
 
RMLL / LSM 2009
RMLL / LSM 2009RMLL / LSM 2009
RMLL / LSM 2009
 
Rmll Virtualization As Is Tool 20090707 V1.0
Rmll Virtualization As Is Tool 20090707 V1.0Rmll Virtualization As Is Tool 20090707 V1.0
Rmll Virtualization As Is Tool 20090707 V1.0
 
2.Accessing the Pi
2.Accessing the Pi2.Accessing the Pi
2.Accessing the Pi
 
The Veil-Framework
The Veil-FrameworkThe Veil-Framework
The Veil-Framework
 
Linux for beginners
Linux for beginnersLinux for beginners
Linux for beginners
 
Dockers zero to hero
Dockers zero to heroDockers zero to hero
Dockers zero to hero
 
Kubernetes laravel and kubernetes
Kubernetes   laravel and kubernetesKubernetes   laravel and kubernetes
Kubernetes laravel and kubernetes
 
Libvirt and bhyve under FreeBSD
Libvirt and bhyve under FreeBSDLibvirt and bhyve under FreeBSD
Libvirt and bhyve under FreeBSD
 
Qubes os presentation_to_clug_20150727
Qubes os presentation_to_clug_20150727Qubes os presentation_to_clug_20150727
Qubes os presentation_to_clug_20150727
 
Linux sever building
Linux sever buildingLinux sever building
Linux sever building
 
Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with li...
Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with li...Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with li...
Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with li...
 
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
 
Linux Containers and Docker SHARE.ORG Seattle 2015
Linux Containers and Docker SHARE.ORG Seattle 2015Linux Containers and Docker SHARE.ORG Seattle 2015
Linux Containers and Docker SHARE.ORG Seattle 2015
 
TIAD - DYI: A simple orchestrator built step by step
TIAD - DYI: A simple orchestrator built step by stepTIAD - DYI: A simple orchestrator built step by step
TIAD - DYI: A simple orchestrator built step by step
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Open Source Virtualization Hacks

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20. Hack #5 – Query the Hypervisor's Capabilities (cont'd) #!/usr/bin/python import libvirt conn = libvirt.open(None) print conn.getCapabilities() info = conn.getInfo() print &quot;CPU model: %s&quot; % info[0] print &quot;memory: %d kB&quot; % info[1] print &quot;# of CPUs: %d&quot; % info[2] print &quot;CPU freq: %d MHz&quot; % info[3] print &quot;# of NUMA cell: %d&quot; % info[4] print &quot;# of CPU sockets: %d&quot; % info[5] print &quot;# of cores per socket: %d&quot; % info[6] print &quot;# of threads per core: %d&quot; % info[7]
  • 21.
  • 22.
  • 23.
  • 24. Hack #7 – Migrate a VM (cont'd) #!/usr/bin/python import sys, getpass, libvirt vmname = sys.argv[1] uri = sys.argv[2] mydata = &quot;&quot; def getCredentials(credentials, data): for credential in credentials: print credential[1] + &quot;:&quot;, if credential[0] == libvirt.VIR_CRED_AUTHNAME: data = sys.stdin.readline() data = data[0:len(data)-1] credential[4] = data elif credential[0] == libvirt.VIR_CRED_PASSPHRASE: credential[4] = getpass(&quot;&quot;) else: return -1 return 0 flags = [libvirt.VIR_CRED_AUTHNAME,libvirt.VIR_CRED_PASSPHRASE] auth = [flags,getCredentials,mydata] localconn = libvirt.open(None) dom = localconn.lookupByName(vmname) remoteconn = libvirt.openAuth(None,auth,0) dom.migrate(remoteconn,libvirt.VIR_MIGRATE_LIVE,None,uri,0)
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.