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

Script gnt_instance

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.
int
ListInstances(opts, args)
List instances and their properties.
int
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
GrowDisk(opts, args)
Grow an instance's disks.
int
StartupInstance(opts, args)
Startup instances.
int
RebootInstance(opts, args)
Reboot instance(s).
int
ShutdownInstance(opts, args)
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
ConnectToInstanceConsole(opts, args)
Connect to the console of an instance.
 
_FormatLogicalID(dev_type, logical_id)
Formats the logical_id of a disk.
 
_FormatBlockDevInfo(idx, top_level, dev, static)
Show block device information.
 
_FormatList(buf, data, indent_level)
Formats a list of data at a given indent level.
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_INSTANCES = "instances"
  _VALUE_TRUE = "true"
  _LIST_DEF_FIELDS = ["name", "hypervisor", "os", "pnode", "stat...
  node_opt = make_option("-n", "--node", dest= "node", help= "Ta...
  os_opt = cli_option("-o", "--os-type", dest= "os", help= "What...
  m_force_multi = make_option("--force-multiple", dest= "force_m...
  m_pri_node_opt = make_option("--primary", dest= "multi_mode", ...
  m_sec_node_opt = make_option("--secondary", dest= "multi_mode"...
  m_node_opt = make_option("--node", dest= "multi_mode", help= "...
  m_clust_opt = make_option("--all", dest= "multi_mode", help= "...
  m_inst_opt = make_option("--instance", dest= "multi_mode", hel...
  add_opts = [DEBUG_OPT, make_option("-n", "--node", dest= "node...
  commands = {'add':(AddInstance, ARGS_ONE, add_opts, "[...] -t ...
  aliases = {'activate_block_devs': 'activate-disks', 'replace_d...

Imports: sys, os, itertools, simplejson, make_option, StringIO, cli, opcodes, constants, utils, errors


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:

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.

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

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

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(opts, args)

 

Startup instances.

Depending on the options given, this will start one or more instances.

Parameters:
  • opts - the command line options selected by the user
  • args (list) - the instance or node names based on which we create the final selection (in conjunction with the opts argument)
Returns: int
the desired exit code

RebootInstance(opts, args)

 

Reboot instance(s).

Depending on the parameters given, this will reboot one or more instances.

Parameters:
  • opts - the command line options selected by the user
  • args (list) - the instance or node names based on which we create the final selection (in conjunction with the opts argument)
Returns: int
the desired exit code

ShutdownInstance(opts, args)

 

Shutdown an instance.

Parameters:
  • opts - the command line options selected by the user
  • args (list) - the instance or node names based on which we create the final selection (in conjunction with the opts argument)
Returns: int
the desired exit code

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

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)

 

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
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

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]

_LIST_DEF_FIELDS

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

node_opt

Value:
make_option("-n", "--node", dest= "node", help= "Target node", metavar\
= "<node>")

os_opt

Value:
cli_option("-o", "--os-type", dest= "os", help= "What OS to run", meta\
var= "<os>")

m_force_multi

Value:
make_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:
make_option("--primary", dest= "multi_mode", help= "Filter by nodes (p\
rimary only)", const= _SHUTDOWN_NODES_PRI, action= "store_const")

m_sec_node_opt

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

m_node_opt

Value:
make_option("--node", dest= "multi_mode", help= "Filter by nodes (prim\
ary and secondary)", const= _SHUTDOWN_NODES_BOTH, action= "store_const\
")

m_clust_opt

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

m_inst_opt

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

add_opts

Value:
[DEBUG_OPT, make_option("-n", "--node", dest= "node", help= "Target no\
de and optional secondary node", metavar= "<pnode>[:<snode>]"), os_opt\
, keyval_option("-B", "--backend", dest= "beparams", type= "keyval", d\
efault= {}, help= "Backend parameters"), make_option("-t", "--disk-tem\
plate", dest= "disk_template", help= "Custom disk setup (diskless, fil\
e, plain or drbd)", default= None, metavar= "TEMPL"), cli_option("-s",\
 "--os-size", dest= "sd_size", help= "Disk size for a" " single-disk c\
onfiguration, when not using the --disk option," " in MiB unless a suf\
...

commands

Value:
{'add':(AddInstance, ARGS_ONE, add_opts, "[...] -t disk-type -n node[:\
secondary-node] -o os-type <name>", "Creates and adds a new instance t\
o the cluster"), 'batch-create':(BatchCreate, ARGS_ONE, [DEBUG_OPT], "\
<instances_file.json>", "Create a bunch of instances based on specs in\
 the file."), 'console':(ConnectToInstanceConsole, ARGS_ONE, [DEBUG_OP\
T, make_option("--show-cmd", dest= "show_command", action= "store_true\
", default= False, help= ("Show command instead of executing it"))], "\
[--show-cmd] <instance>", "Opens a console on the specified instance")\
...

aliases

Value:
{'activate_block_devs': 'activate-disks', 'replace_disks': 'replace-di\
sks', 'start': 'startup', 'stop': 'shutdown',}