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
 
_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
int
ListInstanceFields(opts, args)
List instance fields.
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
 
_DoConsole(console, show_command, cluster_name, feedback_fn=ToStdout, _runcmd_fn=utils.RunCmd)
Acts based on the result of opcodes.OpInstanceConsole.
source code
 
_FormatDiskDetails(dev_type, dev, roman)
Formats the logical_id of a disk.
source code
 
_FormatBlockDevInfo(idx, top_level, dev, roman)
Show block device information.
source code
 
_FormatInstanceNicInfo(idx, nic)
Helper function for _FormatInstanceInfo()
source code
 
_FormatInstanceNodesInfo(instance)
Helper function for _FormatInstanceInfo()
source code
 
_GetVncConsoleInfo(instance)
Helper function for _FormatInstanceInfo()
source code
 
_FormatInstanceInfo(instance, roman_integers)
Format instance information for cli.PrintGenericInfo()
source code
int
ShowInstanceConfig(opts, args)
Compute instance run-time status.
source code
list of tuples
_ConvertNicDiskModifications(mods)
Converts NIC/disk modifications from CLI to opcode.
source code
 
_ParseDiskSizes(mods)
Parses disk sizes in parameters.
source code
int
SetInstanceParams(opts, args)
Modifies an instance.
source code
 
ChangeGroup(opts, args)
Moves an instance to another group.
source code
 
Main() source code
Variables [hide private]
  _EXPAND_CLUSTER = "cluster"
  _EXPAND_NODES_BOTH = "nodes"
  _EXPAND_NODES_PRI = "nodes-pri"
  _EXPAND_NODES_SEC = "nodes-sec"
  _EXPAND_NODES_BOTH_BY_TAGS = "nodes-by-tags"
  _EXPAND_NODES_PRI_BY_TAGS = "nodes-pri-by-tags"
  _EXPAND_NODES_SEC_BY_TAGS = "nodes-sec-by-tags"
  _EXPAND_INSTANCES = "instances"
  _EXPAND_INSTANCES_BY_TAGS = "instances-by-tags"
  _EXPAND_NODES_TAGS_MODES = compat.UniqueFrozenset([_EXPAND_NOD...
  _LIST_DEF_FIELDS = ["name", "hypervisor", "os", "pnode", "stat...
default list of options for ListInstances
  _MISSING = object()
  _ENV_OVERRIDE = compat.UniqueFrozenset(["list"])
  _INST_DATA_VAL = ht.TListOf(ht.TDict)
  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", "show": "in...
dictionary with aliases for commands

Imports: copy, itertools, simplejson, logging, ARGS_ONE_INSTANCE, POWER_DELAY_OPT, NEW_RAPI_CERT_OPT, OOB_TIMEOUT_OPT, TO_GROUP_OPT, MAC_PREFIX_OPT, IPOLICY_STD_SPECS_OPT, CONFIRM_OPT, NOSHUTDOWN_OPT, SHUTDOWN_TIMEOUT_OPT, ParseFields, PRIMARY_IP_VERSION_OPT, ARGS_NONE, ARGS_ONE_GROUP, ARGS_MANY_NODES, UsesRPC, ALLOC_POLICY_OPT, NEW_NODE_CERT_OPT, NOVOTING_OPT, INSTANCE_POLICY_OPTS, ArgUnknown, ERROR_CODES_OPT, SPECS_CPU_COUNT_OPT, SPECS_DISK_SIZE_OPT, SECONDARY_IP_OPT, ARGS_ONE_NETWORK, GATEWAY_OPT, REMOVE_INSTANCE_OPT, RQL_OPT, IPOLICY_DISK_TEMPLATES, FormatTimestamp, GenerateTable, ABSOLUTE_OPT, DEFAULT_IALLOCATOR_PARAMS_OPT, IGNORE_SIZE_OPT, COMMON_CREATE_OPTS, READD_OPT, NO_REMEMBER_OPT, SUBMIT_OPTS, ConfirmOperation, SubmitOrSend, RAPI_CERT_OPT, ROMAN_OPT, HV_STATE_OPT, HOTPLUG_IF_POSSIBLE_OPT, ARGS_MANY_NETWORKS, FILESTORE_DIR_OPT, RUNTIME_MEM_OPT, SEP_OPT, RESERVED_LVS_OPT, USE_EXTERNAL_MIP_SCRIPT, GLOBAL_SHARED_FILEDIR_OPT, FormatPolicyInfo, NOMODIFY_SSH_SETUP_OPT, GenericInstanceCreate, SubmitOpCodeToDrainedQueue, ArgChoice, ENABLED_USER_SHUTDOWN_OPT, TRANSPORT_COMPRESSION_OPT, NODE_FORCE_JOIN_OPT, DRY_RUN_OPT, CAPAB_VM_OPT, NODE_POWERED_OPT, NODE_PLACEMENT_OPT, JobExecutor, FixHvParams, ToStderr, SELECT_OS_OPT, SINGLE_NODE_OPT, ArgExtStorage, ArgOs, SPICE_CACERT_OPT, PrintIPolicyCommand, IGNORE_ERRORS_OPT, AUTO_REPLACE_OPT, HVLIST_OPT, cli_option, AskUser, ENABLED_DISK_TEMPLATES_OPT, DISK_STATE_OPT, USEUNITS_OPT, EARLY_RELEASE_OPT, VERBOSE_OPT, ArgHost, UIDPOOL_OPT, ALL_OPT, HOTPLUG_OPT, CalculateOSNames, OS_OPT, OFFLINE_OPT, ARGS_ONE_NODE, ArgCommand, FAILURE_ONLY_OPT, ALLOW_FAILOVER_OPT, NOSTART_OPT, SPECS_NIC_COUNT_OPT, OS_SIZE_OPT, DEBUG_OPT, ON_PRIMARY_OPT, JobSubmittedException, SUBMIT_OPT, MASTER_NETMASK_OPT, SPICE_CERT_OPT, NEW_CLUSTER_CERT_OPT, INTERVAL_OPT, ToStdout, FORCE_FILTER_OPT, OSPARAMS_OPT, AddTags, NONICS_OPT, NODE_PARAMS_OPT, ArgNetwork, RunWhileClusterStopped, BLK_OS_OPT, GLOBAL_FILEDIR_OPT, SRC_NODE_OPT, CAPAB_MASTER_OPT, MODIFY_ETCHOSTS_OPT, GenericListFields, SPECS_MEM_SIZE_OPT, GetNodesSshPorts, TAG_SRC_OPT, NOSSH_KEYCHECK_OPT, NET_OPT, IGNORE_FAILURES_OPT, ADD_UIDS_OPT, MASTER_NETDEV_OPT, USE_REPL_NET_OPT, NODEGROUP_OPT, SRC_DIR_OPT, SYNC_OPT, IDENTIFY_DEFAULTS_OPT, REMOVE_UIDS_OPT, HYPERVISOR_OPT, IGNORE_IPOLICY_OPT, MC_OPT, ONLINE_INST_OPT, IGNORE_SECONDARIES_OPT, SplitNodeOption, REBOOT_TYPE_OPT, NONPLUS1_OPT, IGNORE_CONSIST_OPT, NOHDR_OPT, NEW_SPICE_CERT_OPT, TAG_ADD_OPT, SPECS_DISK_COUNT_OPT, NONLIVE_OPT, ARGS_ONE_OS, DISK_OPT, PRIMARY_ONLY_OPT, RemoveTags, AUTO_PROMOTE_OPT, ListTags, DEFAULT_IALLOCATOR_OPT, NEW_PRIMARY_OPT, FORCE_VARIANT_OPT, GetOnlineNodes, NETWORK_OPT, TIMEOUT_OPT, NODE_LIST_OPT, GenericList, ON_SECONDARY_OPT, FormatLogMessage, ArgInstance, CLEANUP_OPT, CreateIPolicyFromOpts, MIGRATION_MODE_OPT, NIC_PARAMS_OPT, NOIPCHECK_OPT, ArgJobId, SEQUENTIAL_OPT, DRBD_HELPER_OPT, DEBUG_SIMERR_OPT, STATIC_OPT, DISK_TEMPLATE_OPT, FORCE_FAILOVER_OPT, ARGS_MANY_GROUPS, REASON_OPT, NO_INSTALL_OPT, YES_DOIT_OPT, FORCE_OPT, PRINT_JOBID_OPT, SHOWCMD_OPT, SPLIT_ISPECS_OPTS, ArgGroup, OFFLINE_INST_OPT, NWSYNC_OPT, NOCONFLICTSCHECK_OPT, PRIORITY_OPT, SECONDARY_ONLY_OPT, NEW_CLUSTER_DOMAIN_SECRET_OPT, FormatParamsDictInfo, SubmitOpCode, DRAINED_OPT, ParseTimespec, REMOVE_RESERVED_IPS_OPT, GenericMain, ArgFile, WFSYNC_OPT, PrintGenericInfo, NORUNTIME_CHGS_OPT, ArgNode, IGNORE_REMOVE_FAILURES_OPT, CP_SIZE_OPT, ADD_RESERVED_IPS_OPT, CLUSTER_DOMAIN_SECRET_OPT, HID_OS_OPT, SHOW_MACHINE_OPT, GATEWAY6_OPT, ALLOCATABLE_OPT, ARGS_MANY_INSTANCES, PREALLOC_WIPE_DISKS_OPT, NONAMECHECK_OPT, FormatQueryResult, FormatError, COMPRESS_OPT, MAINTAIN_NODE_HEALTH_OPT, ArgSuggest, HVOPTS_OPT, IPOLICY_VCPU_RATIO, GetClient, NETWORK6_OPT, NOMODIFY_ETCHOSTS_OPT, ENABLED_HV_OPT, NEW_SECONDARY_OPT, IGNORE_OFFLINE_OPT, VG_NAME_OPT, DISK_PARAMS_OPT, FIELDS_OPT, GLOBAL_GLUSTER_FILEDIR_OPT, DST_NODE_OPT, IALLOCATOR_OPT, NEW_CONFD_HMAC_KEY_OPT, FILESTORE_DRIVER_OPT, INCLUDEDEFAULTS_OPT, STARTUP_PAUSED_OPT, DISKIDX_OPT, BACKEND_OPT, opcodes, constants, compat, utils, errors, netutils, ssh, objects, ht


Function Details [hide private]

_ExpandMultiNames(mode, names, client=None)

source code 

Expand the given names using the passed mode.

For _EXPAND_CLUSTER, all instances will be returned. For _EXPAND_NODES_PRI/SEC, all instances having those nodes as primary/secondary will be returned. For _EXPAND_NODES_BOTH, all instances having those nodes as either primary or secondary will be returned. For _EXPAND_INSTANCES, the given instances will be returned.

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

_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

ListInstanceFields(opts, args)

source code 

List instance fields.

Parameters:
  • opts - the command line options selected by the user
  • args (list) - fields to list, or empty for all
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 opcodes.OpInstanceCreate serialisations.

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 three elements, the target instance name, the target disk id, and the target growth
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

_DoConsole(console, show_command, cluster_name, feedback_fn=ToStdout, _runcmd_fn=utils.RunCmd)

source code 

Acts based on the result of opcodes.OpInstanceConsole.

Parameters:
  • console (objects.InstanceConsole) - Console object
  • show_command (bool) - Whether to just display commands
  • cluster_name (string) - Cluster name as retrieved from master daemon

_FormatBlockDevInfo(idx, top_level, dev, 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
  • 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)

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

_ConvertNicDiskModifications(mods)

source code 

Converts NIC/disk modifications from CLI to opcode.

When opcodes.OpInstanceSetParams was changed to support adding/removing disks at arbitrary indices, its parameter format changed. This function converts legacy requests (e.g. "--net add" or "--disk add:size=4G") to the newer format and adds support for new-style requests (e.g. "--new 4:add").

Parameters:
  • mods (list of tuples) - Modifications as given by command line parser
Returns: list of tuples
Modifications as understood by opcodes.OpInstanceSetParams

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]

_EXPAND_NODES_TAGS_MODES

Value:
compat.UniqueFrozenset([_EXPAND_NODES_BOTH_BY_TAGS, _EXPAND_NODES_PRI_\
BY_TAGS, _EXPAND_NODES_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= _EXPAND_NODES_PRI, action= "store_const")

m_sec_node_opt

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

m_node_opt

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

m_clust_opt

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

m_inst_opt

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

m_node_tags_opt

Value:
cli_option("--node-tags", dest= "multi_mode", help= "Filter by node ta\
g", const= _EXPAND_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= _EXPAND_NODES_PRI_BY_TAGS, action= "store_const\
")

m_sec_node_tags_opt

Value:
cli_option("--sec-node-tags", dest= "multi_mode", help= "Filter by sec\
ondary node tag", const= _EXPAND_NODES_SEC_BY_TAGS, action= "store_con\
st")

m_inst_tags_opt

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

add_opts

Value:
[NOSTART_OPT, OS_OPT, FORCE_VARIANT_OPT, NO_INSTALL_OPT, IGNORE_IPOLIC\
Y_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, IA\
LLOCATOR_OPT]+ SUBMIT_OPTS, "<instances.json>", "Create a bunch of ins\
tances based on specs in the file."), "console":(ConnectToInstanceCons\
ole, ARGS_ONE_INSTANCE, [SHOWCMD_OPT, PRIORITY_OPT], "[--show-cmd] <in\
stance>", "Opens a console on the specified instance"), "failover":(Fa\
...

aliases

dictionary with aliases for commands

Value:
{"start": "startup", "stop": "shutdown", "show": "info",}