Package ganeti :: Package client :: Module gnt_instance
[hide private]
[frames] | no frames]

Module gnt_instance

source code

Instance related commands

Functions [hide private]
list
_ExpandMultiNames(mode, names, client=None)
Expand the given names using the passed mode.
source code
boolean
_ConfirmOperation(inames, text, extra="")
Ask the user to confirm an operation on a list of instances.
source code
 
_EnsureInstancesExist(client, names)
Check for and ensure the given instance names exist.
source code
 
GenericManyOps(operation, fn)
Generic multi-instance operations.
source code
int
ListInstances(opts, args)
List instances and their properties.
source code
 
AddInstance(opts, args)
Add an instance to the cluster.
source code
int
BatchCreate(opts, args)
Create instances using a definition file.
source code
int
ReinstallInstance(opts, args)
Reinstall an instance.
source code
int
RemoveInstance(opts, args)
Remove an instance.
source code
int
RenameInstance(opts, args)
Rename an instance.
source code
int
ActivateDisks(opts, args)
Activate an instance's disks.
source code
int
DeactivateDisks(opts, args)
Deactivate an instance's disks.
source code
int
RecreateDisks(opts, args)
Recreate an instance's disks.
source code
int
GrowDisk(opts, args)
Grow an instance's disks.
source code
 
_StartupInstance(name, opts)
Startup instances.
source code
 
_RebootInstance(name, opts)
Reboot instance(s).
source code
 
_ShutdownInstance(name, opts)
Shutdown an instance.
source code
int
ReplaceDisks(opts, args)
Replace the disks of an instance
source code
int
FailoverInstance(opts, args)
Failover an instance.
source code
int
MigrateInstance(opts, args)
Migrate an instance.
source code
int
MoveInstance(opts, args)
Move an instance.
source code
int
ConnectToInstanceConsole(opts, args)
Connect to the console of an instance.
source code
 
_FormatLogicalID(dev_type, logical_id, roman)
Formats the logical_id of a disk.
source code
 
_FormatBlockDevInfo(idx, top_level, dev, static, roman)
Show block device information.
source code
 
_FormatList(buf, data, indent_level)
Formats a list of data at a given indent level.
source code
 
_FormatParameterDict(buf, per_inst, actual)
Formats a parameter dictionary.
source code
int
ShowInstanceConfig(opts, args)
Compute instance run-time status.
source code
int
SetInstanceParams(opts, args)
Modifies an instance.
source code
 
Main() source code
Variables [hide private]
  _SHUTDOWN_CLUSTER = "cluster"
  _SHUTDOWN_NODES_BOTH = "nodes"
  _SHUTDOWN_NODES_PRI = "nodes-pri"
  _SHUTDOWN_NODES_SEC = "nodes-sec"
  _SHUTDOWN_NODES_BOTH_BY_TAGS = "nodes-by-tags"
  _SHUTDOWN_NODES_PRI_BY_TAGS = "nodes-pri-by-tags"
  _SHUTDOWN_NODES_SEC_BY_TAGS = "nodes-sec-by-tags"
  _SHUTDOWN_INSTANCES = "instances"
  _SHUTDOWN_INSTANCES_BY_TAGS = "instances-by-tags"
  _SHUTDOWN_NODES_TAGS_MODES = _SHUTDOWN_NODES_BOTH_BY_TAGS, _SH...
  _VALUE_TRUE = "true"
  _LIST_DEF_FIELDS = ["name", "hypervisor", "os", "pnode", "stat...
default list of options for ListInstances
  m_force_multi = cli_option("--force-multiple", dest= "force_mu...
  m_pri_node_opt = cli_option("--primary", dest= "multi_mode", h...
  m_sec_node_opt = cli_option("--secondary", dest= "multi_mode",...
  m_node_opt = cli_option("--node", dest= "multi_mode", help= "F...
  m_clust_opt = cli_option("--all", dest= "multi_mode", help= "S...
  m_inst_opt = cli_option("--instance", dest= "multi_mode", help...
  m_node_tags_opt = cli_option("--node-tags", dest= "multi_mode"...
  m_pri_node_tags_opt = cli_option("--pri-node-tags", dest= "mul...
  m_sec_node_tags_opt = cli_option("--sec-node-tags", dest= "mul...
  m_inst_tags_opt = cli_option("--tags", dest= "multi_mode", hel...
  add_opts = [NOSTART_OPT, OS_OPT, FORCE_VARIANT_OPT, NO_INSTALL...
  commands = {'add':(AddInstance, [ArgHost(min= 1, max= 1)], COM...
  aliases = {'start': 'startup', 'stop': 'shutdown',}
dictionary with aliases for commands

Imports: os, itertools, simplejson, StringIO, opcodes, constants, compat, utils, errors, netutils


Function Details [hide private]

_ExpandMultiNames(mode, names, client=None)

source code 

Expand the given names using the passed mode.

For _SHUTDOWN_CLUSTER, all instances will be returned. For _SHUTDOWN_NODES_PRI/SEC, all instances having those nodes as primary/secondary will be returned. For _SHUTDOWN_NODES_BOTH, all instances having those nodes as either primary or secondary will be returned. For _SHUTDOWN_INSTANCES, the given instances will be returned.

Parameters:
Returns: list
the list of names after the expansion
Raises:

_ConfirmOperation(inames, text, extra="")

source code 

Ask the user to confirm an operation on a list of instances.

This function is used to request confirmation for doing an operation on a given list of instances.

Parameters:
  • inames (list) - the list of names that we display when we ask for confirmation
  • text (str) - the operation that the user should confirm (e.g. shutdown or startup)
Returns: boolean
True or False depending on user's confirmation.

_EnsureInstancesExist(client, names)

source code 

Check for and ensure the given instance names exist.

This function will raise an OpPrereqError in case they don't exist. Otherwise it will exit cleanly.

Parameters:
  • client (ganeti.luxi.Client) - the client to use for the query
  • names (list) - the list of instance names to query
Raises:

GenericManyOps(operation, fn)

source code 

Generic multi-instance operations.

The will return a wrapper that processes the options and arguments given, and uses the passed function to build the opcode needed for the specific operation. Thus all the generic loop/confirmation code is abstracted into this function.

ListInstances(opts, args)

source code 

List instances and their properties.

Parameters:
  • opts - the command line options selected by the user
  • args (list) - should be an empty list
Returns: int
the desired exit code

AddInstance(opts, args)

source code 

Add an instance to the cluster.

This is just a wrapper over GenericInstanceCreate.

BatchCreate(opts, args)

source code 

Create instances using a definition file.

This function reads a json file with instances defined in the form:

 {"instance-name":{
   "disk_size": [20480],
   "template": "drbd",
   "backend": {
     "memory": 512,
     "vcpus": 1 },
   "os": "debootstrap",
   "primary_node": "firstnode",
   "secondary_node": "secondnode",
   "iallocator": "dumb"}
 }

Note that primary_node and secondary_node have precedence over iallocator.

Parameters:
  • opts - the command line options selected by the user
  • args (list) - should contain one element, the json filename
Returns: int
the desired exit code

ReinstallInstance(opts, args)

source code 

Reinstall an instance.

Parameters:
  • opts - the command line options selected by the user
  • args (list) - should contain only one element, the name of the instance to be reinstalled
Returns: int
the desired exit code

RemoveInstance(opts, args)

source code 

Remove an instance.

Parameters:
  • opts - the command line options selected by the user
  • args (list) - should contain only one element, the name of the instance to be removed
Returns: int
the desired exit code

RenameInstance(opts, args)

source code 

Rename an instance.

Parameters:
  • opts - the command line options selected by the user
  • args (list) - should contain two elements, the old and the new instance names
Returns: int
the desired exit code

ActivateDisks(opts, args)

source code 

Activate an instance's disks.

This serves two purposes:

  • it allows (as long as the instance is not running) mounting the disks and modifying them from the node
  • it repairs inactive secondary drbds
Parameters:
  • opts - the command line options selected by the user
  • args (list) - should contain only one element, the instance name
Returns: int
the desired exit code

DeactivateDisks(opts, args)

source code 

Deactivate an instance's disks.

This function takes the instance name, looks for its primary node and the tries to shutdown its block devices on that node.

Parameters:
  • opts - the command line options selected by the user
  • args (list) - should contain only one element, the instance name
Returns: int
the desired exit code

RecreateDisks(opts, args)

source code 

Recreate an instance's disks.

Parameters:
  • opts - the command line options selected by the user
  • args (list) - should contain only one element, the instance name
Returns: int
the desired exit code

GrowDisk(opts, args)

source code 

Grow an instance's disks.

Parameters:
  • opts - the command line options selected by the user
  • args (list) - should contain two elements, the instance name whose disks we grow and the disk name, e.g. sda
Returns: int
the desired exit code

_StartupInstance(name, opts)

source code 

Startup instances.

This returns the opcode to start an instance, and its decorator will wrap this into a loop starting all desired instances.

Parameters:
  • name - the name of the instance to act on
  • opts - the command line options selected by the user
Returns:
the opcode needed for the operation

_RebootInstance(name, opts)

source code 

Reboot instance(s).

This returns the opcode to reboot an instance, and its decorator will wrap this into a loop rebooting all desired instances.

Parameters:
  • name - the name of the instance to act on
  • opts - the command line options selected by the user
Returns:
the opcode needed for the operation

_ShutdownInstance(name, opts)

source code 

Shutdown an instance.

This returns the opcode to shutdown an instance, and its decorator will wrap this into a loop shutting down all desired instances.

Parameters:
  • name - the name of the instance to act on
  • opts - the command line options selected by the user
Returns:
the opcode needed for the operation

ReplaceDisks(opts, args)

source code 

Replace the disks of an instance

Parameters:
  • opts - the command line options selected by the user
  • args (list) - should contain only one element, the instance name
Returns: int
the desired exit code

FailoverInstance(opts, args)

source code 

Failover an instance.

The failover is done by shutting it down on its present node and starting it on the secondary.

Parameters:
  • opts - the command line options selected by the user
  • args (list) - should contain only one element, the instance name
Returns: int
the desired exit code

MigrateInstance(opts, args)

source code 

Migrate an instance.

The migrate is done without shutdown.

Parameters:
  • opts - the command line options selected by the user
  • args (list) - should contain only one element, the instance name
Returns: int
the desired exit code

MoveInstance(opts, args)

source code 

Move an instance.

Parameters:
  • opts - the command line options selected by the user
  • args (list) - should contain only one element, the instance name
Returns: int
the desired exit code

ConnectToInstanceConsole(opts, args)

source code 

Connect to the console of an instance.

Parameters:
  • opts - the command line options selected by the user
  • args (list) - should contain only one element, the instance name
Returns: int
the desired exit code

_FormatBlockDevInfo(idx, top_level, dev, static, roman)

source code 

Show block device information.

This is only used by ShowInstanceConfig, but it's too big to be left for an inline definition.

Parameters:
  • idx (int) - the index of the current disk
  • top_level (boolean) - if this a top-level disk?
  • dev (dict) - dictionary with disk information
  • static (boolean) - wheter the device information doesn't contain runtime information but only static data
  • roman (boolean) - whether to try to use roman integers
Returns:
a list of either strings, tuples or lists (which should be formatted at a higher indent level)

_FormatList(buf, data, indent_level)

source code 

Formats a list of data at a given indent level.

If the element of the list is:

  • a string, it is simply formatted as is
  • a tuple, it will be split into key, value and the all the values in a list will be aligned all at the same start column
  • a list, will be recursively formatted
Parameters:
  • buf (StringIO) - the buffer into which we write the output
  • data - the list to format
  • indent_level (int) - the indent level to format at

_FormatParameterDict(buf, per_inst, actual)

source code 

Formats a parameter dictionary.

Parameters:
  • buf (StringIO) - the buffer into which to write
  • per_inst (dict) - the instance's own parameters
  • actual (dict) - the current parameter set (including defaults)

ShowInstanceConfig(opts, args)

source code 

Compute instance run-time status.

Parameters:
  • opts - the command line options selected by the user
  • args (list) - either an empty list, and then we query all instances, or should contain a list of instance names
Returns: int
the desired exit code

SetInstanceParams(opts, args)

source code 

Modifies an instance.

All parameters take effect only at the next restart of the instance.

Parameters:
  • opts - the command line options selected by the user
  • args (list) - should contain only one element, the instance name
Returns: int
the desired exit code

Variables Details [hide private]

_SHUTDOWN_NODES_TAGS_MODES

Value:
_SHUTDOWN_NODES_BOTH_BY_TAGS, _SHUTDOWN_NODES_PRI_BY_TAGS, _SHUTDOWN_N\
ODES_SEC_BY_TAGS

_LIST_DEF_FIELDS

default list of options for ListInstances

Value:
["name", "hypervisor", "os", "pnode", "status", "oper_ram",]

m_force_multi

Value:
cli_option("--force-multiple", dest= "force_multi", help= "Do not ask \
for confirmation when more than" " one instance is affected", action= \
"store_true", default= False)

m_pri_node_opt

Value:
cli_option("--primary", dest= "multi_mode", help= "Filter by nodes (pr\
imary only)", const= _SHUTDOWN_NODES_PRI, action= "store_const")

m_sec_node_opt

Value:
cli_option("--secondary", dest= "multi_mode", help= "Filter by nodes (\
secondary only)", const= _SHUTDOWN_NODES_SEC, action= "store_const")

m_node_opt

Value:
cli_option("--node", dest= "multi_mode", help= "Filter by nodes (prima\
ry and secondary)", const= _SHUTDOWN_NODES_BOTH, action= "store_const"\
)

m_clust_opt

Value:
cli_option("--all", dest= "multi_mode", help= "Select all instances in\
 the cluster", const= _SHUTDOWN_CLUSTER, action= "store_const")

m_inst_opt

Value:
cli_option("--instance", dest= "multi_mode", help= "Filter by instance\
 name [default]", const= _SHUTDOWN_INSTANCES, action= "store_const")

m_node_tags_opt

Value:
cli_option("--node-tags", dest= "multi_mode", help= "Filter by node ta\
g", const= _SHUTDOWN_NODES_BOTH_BY_TAGS, action= "store_const")

m_pri_node_tags_opt

Value:
cli_option("--pri-node-tags", dest= "multi_mode", help= "Filter by pri\
mary node tag", const= _SHUTDOWN_NODES_PRI_BY_TAGS, action= "store_con\
st")

m_sec_node_tags_opt

Value:
cli_option("--sec-node-tags", dest= "multi_mode", help= "Filter by sec\
ondary node tag", const= _SHUTDOWN_NODES_SEC_BY_TAGS, action= "store_c\
onst")

m_inst_tags_opt

Value:
cli_option("--tags", dest= "multi_mode", help= "Filter by instance tag\
", const= _SHUTDOWN_INSTANCES_BY_TAGS, action= "store_const")

add_opts

Value:
[NOSTART_OPT, OS_OPT, FORCE_VARIANT_OPT, NO_INSTALL_OPT,]

commands

Value:
{'add':(AddInstance, [ArgHost(min= 1, max= 1)], COMMON_CREATE_OPTS+ ad\
d_opts, "[...] -t disk-type -n node[:secondary-node] -o os-type <name>\
", "Creates and adds a new instance to the cluster"), 'batch-create':(\
BatchCreate, [ArgFile(min= 1, max= 1)], [DRY_RUN_OPT, PRIORITY_OPT], "\
<instances.json>", "Create a bunch of instances based on specs in the \
file."), 'console':(ConnectToInstanceConsole, ARGS_ONE_INSTANCE, [SHOW\
CMD_OPT, PRIORITY_OPT], "[--show-cmd] <instance>", "Opens a console on\
 the specified instance"), 'failover':(FailoverInstance, ARGS_ONE_INST\
...