- Preparing Your System for Virtualization
- Installing KVM
- libvirt: A Virtualization API
- Other VM Workflows
- Command-Line Access to libvirt with virsh / Running the Code
Command-Line Access to libvirt with virsh
If you open a command console and run the command virsh, you gain access to the full power of the command-line side of libvirt. This opens a console, as illustrated in Listing 6.
Listing 6Command-Line Access
stephen@stephen-Latitude-E5400:~$ virsh Welcome to virsh, the virtualization interactive terminal. Type: 'help' for help with commands 'quit' to quit virsh #
Type help to get assistance at the command line. Some simple tasks include:
- Starting a domain: start MyKVMVirtualMachine
- Stopping a domain: shutdown MyKVMVirtualMachine
- Print the canonical hypervisor URI: uri
Item 3 produces the URI: qemu:///system.
However, note that not all commands are supported, as illustrated in Listing 7.
Listing 7Command-Line Failure
virsh # reboot MyKVMVirtualMachine error: Failed to reboot domain MyKVMVirtualMachine error: this function is not supported by the connection driver: virDomainReboot
I guess there are reasons for not allowing rebooting of VMs from within the command-line toole.g., security. But it is also possible that this option has not yet been implemented.
Running the Code
I built the Java code as a simple Maven project in Eclipse. To run the code, download the Eclipse project zip file, unzip it, and then import the project into Eclipse. You should then be able to run the code provided you download and install a copy of libvirt.
Conclusion
The cloud is becoming a crowded place as more and more organizations embrace the idea of remote computing hosting facilities. Many organizations are now routinely using their often under-utilized and massive data centers to host new services for end users.
The foundation for such cloud services is, in many cases, virtualization technologies. There exists a rich array of such virtualization technologies, and the one I've used in this article is QEMU/KVM on Ubuntu.
Telecoms networks can really only survive with the support of comprehensive management facilities. And, cloud services are not entirely unlike telecoms networks. So, it's probably fair to say that any virtualization technology is only as good as its associated management tools. The libvirt technology is a great addition to the whole cloud/virtualization space because it allows for what is nearly a technology-agnostic software-rich approach to management and monitoring.
libvirt allows you to write code that reaches inside the virtualization technology and interacts with the underlying resources. This is a big challenge for any API, and makes libvirt well worth a look.
References
“Integrating Linux Into Your Windows Environment,” by Stephen Morris
Download the code.