Package ganeti :: Module query
[hide private]
[frames] | no frames]

Module query

source code

Module for query operations

How it works:


Attention: Retrieval functions must be idempotent. They can be called multiple times, in any order and any number of times. This is important to keep in mind for implementing filters in the future.

Classes [hide private]
  Query
  NodeQueryData
Data container for node data queries.
  InstanceQueryData
Data container for instance data queries.
  LockQueryData
Data container for lock data queries.
  GroupQueryData
Data container for node group data queries.
Functions [hide private]
 
_GetUnknownField(ctx, item)
Gets the contents of an unknown field.
source code
 
_GetQueryFields(fielddefs, selected)
Calculates the internal list of selected fields.
source code
list of objects.QueryFieldDefinition
GetAllFields(fielddefs)
Extract objects.QueryFieldDefinition from field definitions.
source code
 
_ProcessResult(value)
Converts result values into externally-visible ones.
source code
 
_VerifyResultRow(fields, row)
Verifies the contents of a query result row.
source code
dict
_PrepareFieldList(fields, aliases)
Prepares field list for use by Query.
source code
 
GetQueryResponse(query, ctx)
Prepares the response for a query.
source code
 
QueryFields(fielddefs, selected)
Returns list of available fields.
source code
 
_MakeField(name, title, kind)
Wrapper for creating objects.QueryFieldDefinition instances.
source code
 
_GetNodeRole(node, master_name)
Determine node role.
source code
 
_GetItemAttr(attr)
Returns a field function to return an attribute of the item.
source code
 
_GetItemTimestamp(getter)
Returns function for getting timestamp of item.
source code
 
_GetItemTimestampFields(datatype)
Returns common timestamp fields.
source code
 
_GetGroup(cb)
Build function for calling another function with an node group.
source code
 
_GetNodeGroup(ctx, node, ng)
Returns the name of a node's group.
source code
 
_GetNodePower(ctx, node)
Returns the node powered state
source code
 
_GetNdParams(ctx, node, ng)
Returns the ndparams for this node.
source code
 
_GetLiveNodeField(field, kind, ctx, node)
Gets the value of a "live" field from NodeQueryData.
source code
 
_BuildNodeFields()
Builds list of fields for node queries.
source code
 
_GetInstOperState(ctx, inst)
Get instance's operational status.
source code
 
_GetInstLiveData(name)
Build function for retrieving live data.
source code
 
_GetInstStatus(ctx, inst)
Get instance status.
source code
 
_GetInstDiskSize(index)
Build function for retrieving disk size.
source code
 
_GetInstNic(index, cb)
Build function for calling another function with an instance NIC.
source code
 
_GetInstNicIp(ctx, _, nic)
Get a NIC's IP address.
source code
 
_GetInstNicBridge(ctx, index, _)
Get a NIC's bridge.
source code
 
_GetInstAllNicBridges(ctx, inst)
Get all network bridges for an instance.
source code
 
_GetInstNicParam(name)
Build function for retrieving a NIC parameter.
source code
 
_GetInstanceNetworkFields()
Get instance fields involving network interfaces.
source code
 
_GetInstDiskUsage(ctx, inst)
Get disk usage for an instance.
source code
 
_GetInstanceConsole(ctx, inst)
Get console information for instance.
source code
 
_GetInstanceDiskFields()
Get instance fields involving disks.
source code
 
_GetInstanceParameterFields()
Get instance fields involving parameters.
source code
 
_BuildInstanceFields()
Builds list of fields for instance queries.
source code
 
_GetLockOwners(_, data)
Returns a sorted list of a lock's current owners.
source code
 
_GetLockPending(_, data)
Returns a sorted list of a lock's pending acquires.
source code
 
_BuildLockFields()
Builds list of fields for lock queries.
source code
 
_BuildGroupFields()
Builds list of fields for node group queries.
source code
Variables [hide private]
  FIELD_NAME_RE = re.compile(r"^[a-z0-9/._]+$")
  TITLE_RE = re.compile(r"^[^\s]+$")
  _VERIFY_FN = {QFT_UNKNOWN: ht.TNone, QFT_TEXT: ht.TString, QFT...
Verification function for each field type
  _FS_UNKNOWN = object()
  _FS_NODATA = object()
  _FS_UNAVAIL = object()
  _FS_OFFLINE = object()
  _VTToQFT = {constants.VTYPE_STRING: QFT_OTHER, constants.VTYPE...
VType to QFT mapping
  _NODE_SIMPLE_FIELDS = {"drained":("Drained", QFT_BOOL), "maste...
Fields that are direct attributes of an objects.Node object
  _NODE_LIVE_FIELDS = {"bootid":("BootID", QFT_TEXT, "bootid"), ...
Fields requiring talking to the node
  _INST_SIMPLE_FIELDS = {"disk_template":("Disk_template", QFT_T...
  _GROUP_SIMPLE_FIELDS = {"alloc_policy":("AllocPolicy", QFT_TEX...
  NODE_FIELDS = _BuildNodeFields()
Fields available for node queries
  INSTANCE_FIELDS = _BuildInstanceFields()
Fields available for instance queries
  LOCK_FIELDS = _BuildLockFields()
Fields available for lock queries
  GROUP_FIELDS = _BuildGroupFields()
Fields available for node group queries
  ALL_FIELD_LISTS = [NODE_FIELDS, INSTANCE_FIELDS, LOCK_FIELDS, ...
All available field lists

Imports: logging, operator, re, constants, errors, utils, compat, objects, ht, QFT_UNKNOWN, QFT_TEXT, QFT_BOOL, QFT_NUMBER, QFT_UNIT, QFT_TIMESTAMP, QFT_OTHER, RS_NORMAL, RS_UNKNOWN, RS_NODATA, RS_UNAVAIL, RS_OFFLINE


Function Details [hide private]

_GetQueryFields(fielddefs, selected)

source code 

Calculates the internal list of selected fields.

Unknown fields are returned as constants.QFT_UNKNOWN.

Parameters:
  • fielddefs (dict) - Field definitions
  • selected (list of strings) - List of selected fields

_VerifyResultRow(fields, row)

source code 

Verifies the contents of a query result row.

Parameters:
  • fields (list) - Field definitions for result
  • row (list of tuples) - Row data

_PrepareFieldList(fields, aliases)

source code 

Prepares field list for use by Query.

Converts the list to a dictionary and does some verification.

Parameters:
  • fields (list of tuples; (objects.QueryFieldDefinition, data kind, retrieval function)) - List of fields, see Query.__init__ for a better description
  • aliases (list of tuples; (alias, target)) - list of tuples containing aliases; for each alias/target pair, a duplicate will be created in the field list
Returns: dict
Field dictionary for Query

GetQueryResponse(query, ctx)

source code 

Prepares the response for a query.

Parameters:

QueryFields(fielddefs, selected)

source code 

Returns list of available fields.

Parameters:
  • fielddefs (dict) - Field definitions
  • selected (list of strings) - List of selected fields
Returns:
List of objects.QueryFieldDefinition

_MakeField(name, title, kind)

source code 

Wrapper for creating objects.QueryFieldDefinition instances.

Parameters:
  • name - Field name as a regular expression
  • title - Human-readable title
  • kind - Field type

_GetNodeRole(node, master_name)

source code 

Determine node role.

Parameters:
  • node (objects.Node) - Node object
  • master_name (string) - Master node name

_GetItemAttr(attr)

source code 

Returns a field function to return an attribute of the item.

Parameters:
  • attr - Attribute name

_GetItemTimestamp(getter)

source code 

Returns function for getting timestamp of item.

Parameters:
  • getter (callable) - Function to retrieve timestamp attribute

_GetItemTimestampFields(datatype)

source code 

Returns common timestamp fields.

Parameters:

_GetGroup(cb)

source code 

Build function for calling another function with an node group.

Parameters:
  • cb - The callback to be called with the nodegroup

_GetNodeGroup(ctx, node, ng)

source code 

Returns the name of a node's group.

Parameters:

_GetNodePower(ctx, node)

source code 

Returns the node powered state

Parameters:

_GetNdParams(ctx, node, ng)

source code 

Returns the ndparams for this node.

Parameters:

_GetLiveNodeField(field, kind, ctx, node)

source code 

Gets the value of a "live" field from NodeQueryData.

Parameters:

_GetInstOperState(ctx, inst)

source code 

Get instance's operational status.

Parameters:

_GetInstLiveData(name)

source code 

Build function for retrieving live data.

Parameters:
  • name (string) - Live data field name

_GetInstStatus(ctx, inst)

source code 

Get instance status.

Parameters:

_GetInstDiskSize(index)

source code 

Build function for retrieving disk size.

Parameters:
  • index (int) - Disk index

_GetInstNic(index, cb)

source code 

Build function for calling another function with an instance NIC.

Parameters:
  • index (int) - NIC index
  • cb (callable) - Callback

_GetInstNicIp(ctx, _, nic)

source code 

Get a NIC's IP address.

Parameters:

_GetInstNicBridge(ctx, index, _)

source code 

Get a NIC's bridge.

Parameters:

_GetInstAllNicBridges(ctx, inst)

source code 

Get all network bridges for an instance.

Parameters:

_GetInstNicParam(name)

source code 

Build function for retrieving a NIC parameter.

Parameters:
  • name (string) - Parameter name

_GetInstanceNetworkFields()

source code 

Get instance fields involving network interfaces.

Returns:
List of field definitions used as input for _PrepareFieldList

_GetInstDiskUsage(ctx, inst)

source code 

Get disk usage for an instance.

Parameters:

_GetInstanceConsole(ctx, inst)

source code 

Get console information for instance.

Parameters:

_GetInstanceDiskFields()

source code 

Get instance fields involving disks.

Returns:
List of field definitions used as input for _PrepareFieldList

_GetInstanceParameterFields()

source code 

Get instance fields involving parameters.

Returns:
List of field definitions used as input for _PrepareFieldList

Variables Details [hide private]

_VERIFY_FN

Verification function for each field type

Value:
{QFT_UNKNOWN: ht.TNone, QFT_TEXT: ht.TString, QFT_BOOL: ht.TBool, QFT_\
NUMBER: ht.TInt, QFT_UNIT: ht.TInt, QFT_TIMESTAMP: ht.TNumber, QFT_OTH\
ER: lambda _: True,}

_VTToQFT

VType to QFT mapping

Value:
{constants.VTYPE_STRING: QFT_OTHER, constants.VTYPE_MAYBE_STRING: QFT_\
OTHER, constants.VTYPE_BOOL: QFT_BOOL, constants.VTYPE_SIZE: QFT_UNIT,\
 constants.VTYPE_INT: QFT_NUMBER,}

_NODE_SIMPLE_FIELDS

Fields that are direct attributes of an objects.Node object

Value:
{"drained":("Drained", QFT_BOOL), "master_candidate":("MasterC", QFT_B\
OOL), "master_capable":("MasterCapable", QFT_BOOL), "name":("Node", QF\
T_TEXT), "offline":("Offline", QFT_BOOL), "serial_no":("SerialNo", QFT\
_NUMBER), "uuid":("UUID", QFT_TEXT), "vm_capable":("VMCapable", QFT_BO\
OL),}

_NODE_LIVE_FIELDS

Fields requiring talking to the node

Value:
{"bootid":("BootID", QFT_TEXT, "bootid"), "cnodes":("CNodes", QFT_NUMB\
ER, "cpu_nodes"), "csockets":("CSockets", QFT_NUMBER, "cpu_sockets"), \
"ctotal":("CTotal", QFT_NUMBER, "cpu_total"), "dfree":("DFree", QFT_UN\
IT, "vg_free"), "dtotal":("DTotal", QFT_UNIT, "vg_size"), "mfree":("MF\
ree", QFT_UNIT, "memory_free"), "mnode":("MNode", QFT_UNIT, "memory_do\
m0"), "mtotal":("MTotal", QFT_UNIT, "memory_total"),}

_INST_SIMPLE_FIELDS

Value:
{"disk_template":("Disk_template", QFT_TEXT), "hypervisor":("Hyperviso\
r", QFT_TEXT), "name":("Instance", QFT_TEXT), "network_port":("Network\
_port", QFT_OTHER), "os":("OS", QFT_TEXT), "serial_no":("SerialNo", QF\
T_NUMBER), "uuid":("UUID", QFT_TEXT),}

_GROUP_SIMPLE_FIELDS

Value:
{"alloc_policy":("AllocPolicy", QFT_TEXT), "name":("Group", QFT_TEXT),\
 "serial_no":("SerialNo", QFT_NUMBER), "uuid":("UUID", QFT_TEXT), "ndp\
arams":("NDParams", QFT_OTHER),}

ALL_FIELD_LISTS

All available field lists

Value:
[NODE_FIELDS, INSTANCE_FIELDS, LOCK_FIELDS, GROUP_FIELDS]