Wednesday, 8 June 2016

Libvirt objects state

10:48 Posted by SRE Hacks No comments
Libvirt

libvirt is an open source API, daemon and management tool for managing platform virtualization. It can be used to manage KVM, Xen, VMware ESX, QEMU and other virtualization technologies. These APIs are widely used in the orchestration layer of hypervisors in the development of a cloud-based solution.

To avoid ambiguity about the terms used, here are the definitions for some of the specific concepts used in libvirt documentation:
  • a node is a single physical machine
  • an hypervisor is a layer of software allowing to virtualize a node in a set of virtual machines with possibly different configurations than the node itself
  • a domain is an instance of an operating system (or subsystem in the case of container virtualization) running on a virtualized machine provided by the hypervisor
Libvirt distinguishes between two different types of domains: transient and persistent.
  • Transient domains only exist until the domain is shutdown or when the host server is restarted.
  • Persistent domains last indefinitely.


Libvirt States

There are five states of Instance (virtual machine) in libvirt. They are as following

  • Undefined
  • Defined
  • Runing
  • Paused
  • Saved

  • Undefined - This is a baseline state. Libvirt does not know anything about domains in this state because the domain hasn't been defined or created yet.
  • Defined or Stopped - The domain has been defined, but it's not running. This state is also called stopped. Only persistent domains can be in this state. When a transient domain is stopped or shut down, it ceases to exist.
  • Running - The domain has been created and started either as transient or persistent domain. Either domain in this state is being actively executed on the node's hypervisor.
  • Paused - The domain execution on hypervisor has been suspended. Its state has been temporarily stored until it is resumed. The domain does not have any knowledge whether it was paused or not. If you are familiar with processes in operating systems, this is the similar.
  • Saved - Similar to the paused state, but the domain state is stored to persistent storage. Again, the domain in this state can be restored and it does not notice that any time has passed.

Thursday, 2 June 2016

Libvirt and event based vm states

Now a days virtualization is one of the most common and fastest growing field in computer science. Basically now world move from physical and costly hardware to software based. Like if we need new machine we go to market and buy the new one, but virtualization made it easy, now we only spawn new machine with just few clicks.

So their is need for some tool to manage virtualization, Libvirt is an opensource daemon used for managing virtualization. It can manage many virtualization technologies like KVM, XEN, VMWARE ESX, QEMU.

Livirt has many use cases. I worked on a use case to detect change in vm states on event bases.
Open stack on back end use libvirt for virtualization. What if we want to detect any change in virtual machine states??? First method is you continuously check your vm by using ssh and polling, but it's bad approach. Libvirt allows you to detect vm current state. Libvirt developers writes a python plugin that detect any change in vm state and show it to you, without polling and any other over head on server. You can get agent from here. It is opensource, so you can modify it as you can.

Libvirt has 5 states for any vm


  • Undefined
  • Defined
  • Runing
  • Paused
  • Saved

The agent get state from libvirt whenever any of these event occurred and show details. Agent register itself in libvirt and get state on every event change. The agent show many details some of them are
  • Name of instance (openstack name, created by openstack)
  • UUID of instance
  • Event name
    • Defined,
    • Undefined
    • Started
    • Suspended
    • Resumed
    • Stopped
    • Shutdown

  • Event Detail (Detail of event to clarify action)
    • Added
    • Updated
    • Removed
    • Booted
    • Migrated
    • Restored
    • Snapshot
    • Wakeup
    • Paused
    • Migrated
    • IOError
    • Watchdog
    • Restored
    • Snapshot
    • Unpaused
    • Migrated
    • Snapshot
    • Shutdown
    • Destroyed
    • Crashed
    • Migrated
    • Saved
    • Failed
    • Snapshot
    • Finished