Package ganeti :: Package hypervisor :: Package hv_kvm :: Module monitor :: Class QmpConnection
[hide private]
[frames] | no frames]

Class QmpConnection

source code


Connection to the QEMU Monitor using the QEMU Monitor Protocol (QMP).

Instance Methods [hide private]
 
__init__(self, monitor_filename)
Instantiates the MonitorSocket object.
source code
 
__enter__(self) source code
 
__exit__(self, exc_type, exc_value, tb) source code
 
connect(self)
Connects to the QMP monitor.
source code
 
_ParseMessage(self, buf)
Extract and parse a QMP message from the given buffer.
source code
QmpMessage
_Recv(self)
Receives a message from QMP and decodes the received JSON object.
source code
 
_Send(self, message)
Encodes and sends a message to KVM using QMP.
source code
 
_GetSupportedCommands(self)
Update the list of supported commands.
source code
dict
Execute(self, command, arguments=None)
Executes a QMP command and returns the response of the server.
source code
 
_GetResponse(self, command)
Parse the QMP response
source code
 
_filter_hvinfo(self, hvinfo)
Filter non valid keys of the device's hvinfo (if any).
source code
 
HotAddNic(self, nic, devid, tapfds=None, vhostfds=None, features=None)
Hot-add a NIC
source code
 
HotDelNic(self, devid)
Hot-del a NIC
source code
 
HotAddDisk(self, disk, devid, uri, drive_add_fn=None)
Hot-add a disk
source code
 
HotDelDisk(self, devid)
Hot-del a Disk
source code
 
_GetPCIDevices(self)
Get the devices of the first PCI bus of a running instance.
source code
 
_HasPCIDevice(self, devid)
Check if a specific device ID exists on the PCI bus.
source code
list of dicts
_GetBlockDevices(self)
Get the block devices of a running instance.
source code
 
_HasBlockDevice(self, devid)
Check if a specific device ID exists among block devices.
source code
 
HasDevice(self, devid)
Check if a specific device exists or not on a running instance.
source code
 
GetFreePCISlot(self)
Get the first available PCI slot of a running instance.
source code
 
CheckDiskHotAddSupport(self)
Check if disk hotplug is possible
source code
 
CheckNicHotAddSupport(self)
Check if NIC hotplug is possible
source code
 
_GetFd(self, fd, fdname)
Wrapper around the getfd qmp command
source code
 
_AddFd(self, fd)
Wrapper around add-fd qmp command
source code
 
_RemoveFdset(self, fdset)
Wrapper around remove-fd qmp command
source code

Inherited from MonitorSocket: close, is_connected

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  _FIRST_MESSAGE_KEY = "QMP"
  _EVENT_KEY = "event"
  _ERROR_KEY = "error"
  _RETURN_KEY = "return"
  ACTUAL_KEY = "actual"
  _ACTUAL_KEY = "actual"
  _ERROR_CLASS_KEY = "class"
  _ERROR_DESC_KEY = "desc"
  _EXECUTE_KEY = "execute"
  _ARGUMENTS_KEY = "arguments"
  _VERSION_KEY = "version"
  _PACKAGE_KEY = "package"
  _QEMU_KEY = "qemu"
  _CAPABILITIES_COMMAND = "qmp_capabilities"
  _QUERY_COMMANDS = "query-commands"
  _MESSAGE_END_TOKEN = "\r\n"
  _DEVICE_ATTRIBUTES = ["driver", "id", "bus", "addr", "channel"...

Inherited from MonitorSocket (private): _SOCKET_TIMEOUT

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, monitor_filename)
(Constructor)

source code 

Instantiates the MonitorSocket object.

Parameters:
  • monitor_filename - the filename of the UNIX raw socket on which the monitor (QMP or simple one) is listening
Overrides: object.__init__
(inherited documentation)

connect(self)

source code 

Connects to the QMP monitor.

Connects to the UNIX socket and makes sure that we can actually send and receive data to the kvm instance via QMP.

Raises:
Overrides: MonitorSocket.connect

_ParseMessage(self, buf)

source code 

Extract and parse a QMP message from the given buffer.

Seeks for a QMP message in the given buf. If found, it parses it and returns it together with the rest of the characters in the buf. If no message is found, returns None and the whole buffer.

Raises:

_Recv(self)

source code 

Receives a message from QMP and decodes the received JSON object.

Returns: QmpMessage
the received message
Raises:

_Send(self, message)

source code 

Encodes and sends a message to KVM using QMP.

Parameters:
  • message (QmpMessage) - message to send to KVM
Raises:

Execute(self, command, arguments=None)

source code 

Executes a QMP command and returns the response of the server.

Parameters:
  • command (str) - the command to execute
  • arguments (dict) - dictionary of arguments to be passed to the command
Returns: dict
dictionary representing the received JSON object
Raises:

_GetResponse(self, command)

source code 

Parse the QMP response

If error key found in the response message raise HypervisorError. Ignore any async event and thus return the response message related to command.

HotAddNic(self, nic, devid, tapfds=None, vhostfds=None, features=None)

source code 

Hot-add a NIC

First pass the tapfds, then netdev_add and then device_add

Decorators:
  • @_ensure_connection

HotDelNic(self, devid)

source code 

Hot-del a NIC

Decorators:
  • @_ensure_connection

HotAddDisk(self, disk, devid, uri, drive_add_fn=None)

source code 

Hot-add a disk

Try opening the device to obtain a fd and pass it with SCM_RIGHTS. This will be omitted in case of userspace access mode (open will fail). Then use blockdev-add QMP command or drive_add_fn() callback if any. The add the guest device.

Decorators:
  • @_ensure_connection

HotDelDisk(self, devid)

source code 

Hot-del a Disk

Note that drive_del is not supported yet in qmp and thus should be invoked from HMP.

Decorators:
  • @_ensure_connection

_GetBlockDevices(self)

source code 

Get the block devices of a running instance.

The query-block QMP command returns a list of dictionaries including information for each virtual disk. For example:

[{"device": "disk-049f140d", "inserted": {"file": ..., "image": ...}}]

Returns: list of dicts
Info about the virtual disks of the instance.

HasDevice(self, devid)

source code 

Check if a specific device exists or not on a running instance.

It first checks the PCI devices and then the block devices.

Decorators:
  • @_ensure_connection

GetFreePCISlot(self)

source code 

Get the first available PCI slot of a running instance.

Decorators:
  • @_ensure_connection

CheckDiskHotAddSupport(self)

source code 

Check if disk hotplug is possible

Hotplug is *not* supported in case:

  • fdsend module is missing
  • add-fd and blockdev-add qmp commands are not supported
Decorators:
  • @_ensure_connection

CheckNicHotAddSupport(self)

source code 

Check if NIC hotplug is possible

Hotplug is *not* supported in case:

  • fdsend module is missing
  • getfd and netdev_add qmp commands are not supported
Decorators:
  • @_ensure_connection

_GetFd(self, fd, fdname)

source code 

Wrapper around the getfd qmp command

Use fdsend to send an fd to a running process via SCM_RIGHTS and then use the getfd qmp command to name it properly so that it can be used later by NIC hotplugging.

Parameters:
  • fd (int) - The file descriptor to pass
Raises:

_AddFd(self, fd)

source code 

Wrapper around add-fd qmp command

Use fdsend to send fd to a running process via SCM_RIGHTS and then add-fd qmp command to add it to an fdset so that it can be used later by disk hotplugging.

Parameters:
  • fd (int) - The file descriptor to pass
Returns:
The fdset ID that the fd has been added to
Raises:

_RemoveFdset(self, fdset)

source code 

Wrapper around remove-fd qmp command

Remove the file descriptor previously passed. After qemu has dup'd the fd (e.g. during disk hotplug), it can be safely removed.


Class Variable Details [hide private]

_DEVICE_ATTRIBUTES

Value:
["driver", "id", "bus", "addr", "channel", "scsi-id", "lun"]