Script gnt_instance
[hide private]
[frames] | no frames]

Script gnt_instance

Instance related commands

Functions [hide private]
list
_ExpandMultiNames(mode, names, client=None)
Expand the given names using the passed mode.
boolean
_ConfirmOperation(inames, text, extra="")
Ask the user to confirm an operation on a list of instances.
 
_EnsureInstancesExist(client, names)
Check for and ensure the given instance names exist.
 
GenericManyOps(operation, fn)
Generic multi-instance operations.
int
ListInstances(opts, args)
List instances and their properties.
 
AddInstance(opts, args)
Add an instance to the cluster.
int
BatchCreate(opts, args)
Create instances using a definition file.
int
ReinstallInstance(opts, args)
Reinstall an instance.
int
RemoveInstance(opts, args)
Remove an instance.
int
RenameInstance(opts, args)
Rename an instance.
int
ActivateDisks(opts, args)
Activate an instance's disks.
int
DeactivateDisks(opts, args)
Deactivate an instance's disks.
int
RecreateDisks(opts, args)
Recreate an instance's disks.
int
GrowDisk(opts, args)
Grow an instance's disks.
 
_StartupInstance(name, opts)
Startup instances.
 
_RebootInstance(name, opts)
Reboot instance(s).
 
_ShutdownInstance(name, opts)
Shutdown an instance.
int
ReplaceDisks(opts, args)
Replace the disks of an instance
int
FailoverInstance(opts, args)
Failover an instance.
int
MigrateInstance(opts, args)
Migrate an instance.
int
MoveInstance(opts, args)
Move an instance.
int
ConnectToInstanceConsole(opts, args)
Connect to the console of an instance.
 
_FormatLogicalID(dev_type, logical_id, roman)
Formats the logical_id of a disk.
 
_FormatBlockDevInfo(idx, top_level, dev, static, roman)
Show block device information.
 
_FormatList(buf, data, indent_level)
Formats a list of data at a given indent level.
 
_FormatParameterDict(buf, per_inst, actual)
Formats a parameter dictionary.
int
ShowInstanceConfig(opts, args)
Compute instance run-time status.
int
SetInstanceParams(opts, args)
Modifies an instance.
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 = [BACKEND_OPT, DISK_OPT, DISK_TEMPLATE_OPT, FILESTOR...
  commands = {'add':(AddInstance, [ArgHost(min= 1, max= 1)], add...
  aliases = {'start': 'startup', 'stop': 'shutdown',}
dictionary with aliases for commands

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


Function Details [hide private]

_ExpandMultiNames(mode, names, client=None)

 

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="")

 

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)

 

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)

 

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)

 

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)

 

Add an instance to the cluster.

This is just a wrapper over GenericInstanceCreate.

BatchCreate(opts, args)

 

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)

 

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)

 

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)

 

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)

 

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)

 

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)

 

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)

 

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)

 

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)

 

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)

 

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)

 

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)

 

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)

 

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)

 

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)

 

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)

 

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)

 

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)

 

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)

 

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)

 

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:
[BACKEND_OPT, DISK_OPT, DISK_TEMPLATE_OPT, FILESTORE_DIR_OPT, FILESTOR\
E_DRIVER_OPT, HYPERVISOR_OPT, IALLOCATOR_OPT, NET_OPT, NODE_PLACEMENT_\
OPT, NOIPCHECK_OPT, NONAMECHECK_OPT, NONICS_OPT, NOSTART_OPT, NWSYNC_O\
PT, OSPARAMS_OPT, OS_OPT, FORCE_VARIANT_OPT, NO_INSTALL_OPT, OS_SIZE_O\
PT, SUBMIT_OPT, DRY_RUN_OPT,]

commands

Value:
{'add':(AddInstance, [ArgHost(min= 1, max= 1)], add_opts, "[...] -t di\
sk-type -n node[:secondary-node] -o os-type <name>", "Creates and adds\
 a new instance to the cluster"), 'batch-create':(BatchCreate, [ArgFil\
e(min= 1, max= 1)], [DRY_RUN_OPT], "<instances.json>", "Create a bunch\
 of instances based on specs in the file."), 'console':(ConnectToInsta\
nceConsole, ARGS_ONE_INSTANCE, [SHOWCMD_OPT], "[--show-cmd] <instance>\
", "Opens a console on the specified instance"), 'failover':(FailoverI\
nstance, ARGS_ONE_INSTANCE, [FORCE_OPT, IGNORE_CONSIST_OPT, SUBMIT_OPT\
...