Module dealing with command line parsing
Class |
|
Choice argument. |
Class |
|
Command argument. |
Class |
|
ExtStorage argument. |
Class |
|
File path argument. |
Class |
|
Filter UUID argument. |
Class |
|
Node group argument. |
Class |
|
Host argument. |
Class |
|
Instances argument. |
Class |
|
Job ID argument. |
Class |
|
Network argument. |
Class |
|
Node argument. |
Class |
|
OS argument. |
Class |
|
Suggesting argument. |
Class |
|
Unknown argument to program (e.g. determined at runtime). |
Class |
|
No class docstring; 0/1 instance variable, 3/3 methods documented |
Class |
|
Class which manages the submission and execution of multiple jobs. |
Class |
|
Base class for GenericPollJob callbacks. |
Class |
|
Base class for GenericPollJob reporting callbacks. |
Class |
|
No class docstring; 0/2 instance variable, 3/3 methods documented |
Class |
|
Describes a column for FormatTable . |
Function |
|
Add tags on a given object. |
Function |
|
Ask the user a question. |
Function |
|
Calculates all the names an OS can be called, according to its variants. |
Function |
|
Ask the user to confirm an operation on a list of list_type. |
Function |
|
Creation of instance policy based on command line options. |
Function |
|
Undocumented |
Function |
|
Return a formatted error message for a given error. |
Function |
|
Formats a job message according to its type. |
Function |
|
Formats a parameter dictionary. |
Function |
|
Formats an instance policy. |
Function |
|
Formats data in objects.QueryResponse . |
Function |
|
Formats result status other than constants.RS_NORMAL . |
Function |
|
Formats data as a table. |
Function |
|
Formats a given timestamp. |
Function |
|
Prints a table with headers and different fields. |
Function |
|
Add an instance to the cluster via either creation or import. |
Function |
|
Generic implementation for listing all items of a resource. |
Function |
|
Generic implementation for listing fields for a resource. |
Function |
|
Generic main function for all the gnt-* commands. |
Function |
|
Generic job-polling function. |
Function |
|
Retrieves SSH ports of given nodes. |
Function |
|
Retrieves the UUIDs of given nodes. |
Function |
|
Returns the names of online nodes. |
Function |
|
List the tags on a given object. |
Function |
|
Parses the values of "--field"-like options. |
Function |
|
Parses the value of the --net option(s). |
Function |
|
Parse a time specification. |
Function |
|
Function to poll for the result of a job. |
Function |
|
Print information formatted according to the hierarchy. |
Function |
|
Print the command option used to generate the given instance policy. |
Function |
|
Remove tags from a given object. |
Function |
|
Calls a function while all cluster daemons are stopped. |
Function |
|
Calls a function while all cluster daemons are stopped. |
Function |
|
Function to submit an opcode without waiting for the results. |
Function |
|
Processor for generic options. |
Function |
|
Splits the value of a --node option. |
Function |
|
Legacy function to submit an opcode. |
Function |
|
Forcefully insert a job in the queue, even if it is drained. |
Function |
|
Wrapper around SubmitOpCode or SendJob. |
Function |
|
Write a message to stderr only, bypassing the logging system |
Function |
|
Write a message to stdout only, bypassing the logging system |
Function |
|
Write a message to stdout and additionally log it at INFO level |
Constant | ARGS |
Undocumented |
Constant | ARGS |
Undocumented |
Constant | ARGS |
Undocumented |
Constant | ARGS |
Undocumented |
Constant | ARGS |
Undocumented |
Constant | ARGS |
Undocumented |
Constant | ARGS |
Undocumented |
Constant | ARGS |
Undocumented |
Constant | ARGS |
Undocumented |
Constant | ARGS |
Undocumented |
Constant | ARGS |
Undocumented |
Constant | ARGS |
Undocumented |
Constant | QR |
Undocumented |
Constant | QR |
Undocumented |
Constant | QR |
Undocumented |
Constant | TISPECS |
Undocumented |
Constant | TISPECS |
Undocumented |
Class | _ |
Undocumented |
Class | _ |
No class docstring; 0/1 instance variable, 4/4 methods documented |
Class | _ |
Callable class for formatting fields of a query. |
Class | _ |
Helper class for RunWhileDaemonsStopped to simplify state management |
Exception | _ |
Exception class for _ParseArgs . |
Exception | _ |
Exception class for _ParseArgs . |
Function | _ |
Verifies the arguments using the argument definition. |
Function | _ |
Extend the args if a source file has been given. |
Function | _ |
Extract the tag type object. |
Function | _ |
Helper function for GenericListFields to get query field description. |
Function | _ |
Formats a boolean value as a string. |
Function | _ |
Undocumented |
Function | _ |
Generates a nice description of all commands. |
Function | _ |
Returns info about alignment if present in an encoded ordered dictionary. |
Function | _ |
Returns the format string for a field. |
Function | _ |
Returns formatting function for a field. |
Function | _ |
Undocumented |
Function | _ |
Returns list of unknown fields included in fdefs. |
Function | _ |
Undocumented |
Function | _ |
Undocumented |
Function | _ |
Builds the first part of the reason trail |
Function | _ |
Parses and returns an array of potential values with units. |
Function | _ |
Checks whether the input is not a container data type. |
Function | _ |
Parser for the command line arguments. |
Function | _ |
Undocumented |
Function | _ |
Undocumented |
Function | _ |
Undocumented |
Function | _ |
Formatting core of PrintGenericInfo . |
Function | _ |
Write a message to a stream, bypassing the logging system |
Function | _ |
Prints a warning to stderr if a query included unknown fields. |
Constant | _CHOOSE |
Undocumented |
Constant | _DEFAULT |
Undocumented |
Constant | _QFT |
Undocumented |
Add tags on a given object.
This is a generic implementation that knows how to deal with all three cases of tag objects (cluster, node, instance). The opts argument is expected to contain a tag_type field denoting what object type we work on.
Ask the user a question.
Parameters | |
text | the question to ask |
choices | list with elements tuples (input_char, return_value, description); if not given, it will default to: [('y', True, 'Perform the operation'), ('n', False, 'Do no do the operation')]; note that the '?' char is reserved for help |
Returns | |
one of the return values from the choices list; if input is not possible (i.e. not running with a tty, we return the last entry from the list |
Calculates all the names an OS can be called, according to its variants.
Parameters | |
os | base name of the os |
os | list of supported variants |
Returns | |
list | list of valid names |
Ask the user to confirm an operation on a list of list_type.
This function is used to request confirmation for doing an operation on a given list of list_type.
Parameters | |
names:list | the list of names that we display when we ask for confirmation |
list | Human readable name for elements in the list (e.g. nodes) |
text:str | the operation that the user should confirm |
extra | Undocumented |
Returns | |
boolean | True or False depending on user's confirmation. |
Creation of instance policy based on command line options.
Parameters | |
ispecs | Undocumented |
ispecs | Undocumented |
ispecs | Undocumented |
ispecs | Undocumented |
ispecs | Undocumented |
minmax | Undocumented |
std | Undocumented |
ipolicy | Undocumented |
ipolicy | Undocumented |
ipolicy | Undocumented |
group | Undocumented |
allowed | Undocumented |
fill | whether for cluster policies we should ensure that all values are filled |
Return a formatted error message for a given error.
This function takes an exception instance and returns a tuple consisting of two values: first, the recommended exit code, and second, a string describing the error message (not newline-terminated).
Formats a parameter dictionary.
Parameters | |
param | the own parameters |
actual:dict | the current parameter set (including defaults) |
roman | Undocumented |
Returns | |
dict | dictionary where the value of each parameter is either a fully formatted string or a dictionary containing formatted strings |
Formats an instance policy.
Parameters | |
custom | own policy |
eff | effective policy (including defaults); ignored for cluster |
iscluster:bool | the policy is at cluster level |
roman:bool | whether to print the values in roman numerals |
Returns | |
list of pairs | formatted data, suitable for PrintGenericInfo |
Formats data in objects.QueryResponse
.
Parameters | |
result:objects.QueryResponse | result of query operation |
unit:string | Unit used for formatting fields of type constants.QFT_UNIT , see utils.text.FormatUnit |
format | Dictionary for overriding field formatting functions, indexed by field name, contents like _DEFAULT_FORMAT_QUERY |
separator:string or None | String used to separate fields |
header:bool | Whether to output header row |
verbose:boolean | whether to use verbose field descriptions or not |
Formats result status other than constants.RS_NORMAL
.
Parameters | |
status | The result status |
verbose:boolean | Whether to return the verbose text |
Returns | |
Text of result status |
Formats data as a table.
Parameters | |
rows:list of lists | Row data, one list per row |
columns:list of TableColumn | Column descriptions |
header:bool | Whether to show header row |
separator:string or None | String used to separate columns |
Formats a given timestamp.
Parameters | |
ts:timestamp | a timeval-type timestamp, a tuple of seconds and microseconds |
Returns | |
string | a string with the formatted timestamp |
Prints a table with headers and different fields.
Parameters | |
headers:dict | dictionary mapping field names to headers for the table |
fields:list | the field names corresponding to each row in the data field |
separator | the separator to be used; if this is None, the default 'smart' algorithm is used which computes optimal field width, otherwise just the separator is used between each field |
data:list | a list of lists, each sublist being one row to be output |
numfields:list | a list with the fields that hold numeric values and thus should be right-aligned |
unitfields:list | a list with the fields that hold numeric values that should be formatted with the units field |
units:string or None | the units we should use for formatting, or None for automatic choice (human-readable for non-separator usage, otherwise megabytes); this is a one-letter string |
Add an instance to the cluster via either creation or import.
Parameters | |
mode | constants.INSTANCE_CREATE or constants.INSTANCE_IMPORT |
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 |
Generic implementation for listing all items of a resource.
Parameters | |
resource | One of constants.QR_VIA_LUXI |
fields:list of strings | List of fields to query for |
names:list of strings | Names of items to query for |
unit:string or None | Unit used for formatting fields of type constants.QFT_UNIT or None for automatic choice (human-readable for non-separator usage, otherwise megabytes); this is a one-letter string |
separator:string or None | String used to separate fields |
header:bool | Whether to show header row |
cl | Undocumented |
format | Dictionary for overriding field formatting functions, indexed by field name, contents like _DEFAULT_FORMAT_QUERY |
verbose:boolean | whether to use verbose field descriptions or not |
force | Whether to always treat names as filter |
namefield:string | Name of field to use for simple filters (see qlang.MakeFilter for details) |
qfilter:list or None | Query filter (in addition to names) |
isnumeric | Whether the namefield's type is numeric, and therefore any simple filters built by namefield should use integer values to reflect that |
Generic implementation for listing fields for a resource.
Parameters | |
resource | One of constants.QR_VIA_LUXI |
fields:list of strings | List of fields to query for |
separator:string or None | String used to separate fields |
header:bool | Whether to show header row |
cl | Undocumented |
Generic main function for all the gnt-* commands.
Parameters | |
commands | a dictionary with a special structure, see the design doc for command line handling. |
override | if not None, we expect a dictionary with keys that will override command line options; this can be used to pass options from the scripts to generic functions |
aliases | dictionary with command aliases {'alias': 'target, ...} |
env | list of environment names which are allowed to submit default args for commands |
Generic job-polling function.
Parameters | |
job | Job ID |
cbs:Instance of JobPollCbBase | Data callbacks |
reportJobPollReportCbBase | Reporting callbacks |
cancel | Function to check if we should cancel the running job |
update | number of seconds between each WFJC reports |
Returns | |
the opresult of the job | |
Raises | |
errors.JobLost | If job can't be found |
errors.JobCanceled | If job is canceled |
errors.OpExecError | If job didn't succeed |
Retrieves SSH ports of given nodes.
Parameters | |
nodes:a list of strings | the names of nodes |
cl:ganeti.luxi.Client | a client to use for the query |
Returns | |
a list of tuples | the list of SSH ports corresponding to the nodes |
Retrieves the UUIDs of given nodes.
Parameters | |
nodes:a list of string | the names of nodes |
cl:ganeti.luxi.Client | a client to use for the query |
Returns | |
a list of tuples | the list of UUIDs corresponding to the nodes |
Returns the names of online nodes.
This function will also log a warning on stderr with the names of the online nodes.
Parameters | |
nodes | if not empty, use only this subset of nodes (minus the offline ones) |
cl | if not None, luxi client to use |
nowarn:boolean | by default, this function will output a note with the offline nodes that are skipped; if this parameter is True the note is not displayed |
secondary | if True, return the secondary IPs instead of the names, useful for doing network traffic over the replication interface (if any) |
filter | if True, do not return the master node in the list (useful in coordination with secondary_ips where we cannot check our node name against the list) |
nodegroup:string | If set, only return nodes in this node group |
List the tags on a given object.
This is a generic implementation that knows how to deal with all three cases of tag objects (cluster, node, instance). The opts argument is expected to contain a tag_type field denoting what object type we work on.
Parses the values of "--field"-like options.
Parameters | |
selected:string or None | User-selected options |
default:list | Default fields |
Parse a time specification.
The following suffixed will be recognized:
- s: seconds
- m: minutes
- h: hours
- d: day
- w: weeks
Without any suffix, the value will be taken to be in seconds.
Function to poll for the result of a job.
Parameters | |
job | the job to poll for results |
cl:luxi.Client | the luxi client to use for communicating with the master; if None, a new client will be created |
feedback | Undocumented |
reporter | Undocumented |
cancel | Function to check if we should cancel the running job |
update | number of seconds between each WFJC report |
Print information formatted according to the hierarchy.
The output is a valid YAML string.
Parameters | |
data | the data to print. It's a hierarchical structure whose elements can be:
|
Print the command option used to generate the given instance policy.
Currently only the parts dealing with specs are supported.
Parameters | |
buf:StringIO | stream to write into |
ipolicy:dict | instance policy |
isgroup:bool | whether the policy is at group level |
Remove tags from a given object.
This is a generic implementation that knows how to deal with all three cases of tag objects (cluster, node, instance). The opts argument is expected to contain a tag_type field denoting what object type we work on.
Calls a function while all cluster daemons are stopped.
Parameters | |
feedback | Feedback function |
fn:callable | Function to be called when daemons are stopped |
*args | Undocumented |
Calls a function while all cluster daemons are stopped.
Parameters | |
feedback | Feedback function |
exclude | list of daemons that stopped, but immediately restarted on the master to be available when calling 'fn'. If None, all daemons will be stopped and none will be started before calling 'fn'. |
fn:callable | Function to be called when daemons are stopped |
*args | Undocumented |
**kwargs | Undocumented |
Function to submit an opcode without waiting for the results.
Parameters | |
ops:list | list of opcodes |
cl:luxi.Client | the luxi client to use for communicating with the master; if None, a new client will be created |
Processor for generic options.
This function updates the given opcodes based on generic command line options (like debug, dry-run, etc.).
Parameters | |
opcode | list of opcodes |
options | command line options or None |
Returns | |
None (in-place modification) |
Legacy function to submit an opcode.
This is just a simple wrapper over the construction of the processor instance. It should be extended to better handle feedback and interaction functions.
Wrapper around SubmitOpCode or SendJob.
This function will decide, based on the 'opts' parameter, whether to submit and wait for the result of the opcode (and return it), or whether to just send the job and print its identifier. It is used in order to simplify the implementation of the '--submit' option.
It will also process the opcodes if we're sending the via SendJob (otherwise SubmitOpCode does it).
Write a message to stderr only, bypassing the logging system
This is just a wrapper over _ToStream.
Parameters | |
txt:str | the message |
*args | Undocumented |
Write a message to stdout only, bypassing the logging system
This is just a wrapper over _ToStream.
Parameters | |
txt:str | the message |
*args | Undocumented |
Undocumented
Value |
|
Undocumented
Value |
|
Verifies the arguments using the argument definition.
Algorithm:
- Abort with error if values specified by user but none expected.
For each argument in definition
- Keep running count of minimum number of values (min_count)
- Keep running count of maximum number of values (max_count)
- If it has an unlimited number of values
- Abort with error if it's not the last argument in the definition
- If last argument has limited number of values
- Abort with error if number of values doesn't match or is too large
- Abort with error if user didn't pass enough values (min_count)
Extend the args if a source file has been given.
This function will extend the tags with the contents of the file passed in the 'tags_source' attribute of the opts parameter. A file named '-' will be replaced by stdin.
Helper function for GenericListFields
to get query field description.
Parameters | |
fdef:objects.QueryFieldDefinition | Undocumented |
Returns | |
list | Undocumented |
Generates a nice description of all commands.
Parameters | |
binary | Script name |
commands | Dictionary containing command definitions |
Returns info about alignment if present in an encoded ordered dictionary.
Parameters | |
data:list of tuple | The encoded ordered dictionary, as defined in _SerializeGenericInfo . |
Returns | |
dict of any to int | The dictionary mapping alignment groups to the maximum length of the dictionary key found in the group. |
Returns formatting function for a field.
Parameters | |
fdef:objects.QueryFieldDefinition | Undocumented |
override:dict | Dictionary for overriding field formatting functions, indexed by field name, contents like _DEFAULT_FORMAT_QUERY |
unit:string | Unit used for formatting fields of type constants.QFT_UNIT |
Returns | |
tuple; (callable, bool) | Returns the function to format a value (takes one parameter) and a boolean for aligning the value on the right-hand side |
Returns list of unknown fields included in fdefs.
Parameters | |
fdefs:list of objects.QueryFieldDefinition | Undocumented |
Undocumented
Undocumented
Builds the first part of the reason trail
Builds the initial part of the reason trail, adding the user provided reason (if it exists) and the name of the command starting the operation.
Parameters | |
op | the opcode the reason trail will be added to |
opts | the command line options selected by the user |
Parser for the command line arguments.
This function parses the arguments and returns the function which must be executed together with its (modified) arguments.
Parameters | |
binary | Script name |
argv | Command line arguments |
commands | Dictionary containing command definitions |
aliases | dictionary with command aliases {"alias": "target", ...} |
env | list of env variables allowed for default args |
Raises | |
_ShowUsage | If usage description should be shown |
_ShowVersion | If version should be shown |
Formatting core of PrintGenericInfo
.
Parameters | |
buf | (string) stream to accumulate the result into |
data | data to format |
level:int | depth in the data hierarchy, used for indenting |
afterkey:bool | True when we are in the middle of a line after a key (used to properly add newlines or indentation) |
Write a message to a stream, bypassing the logging system
Parameters | |
stream:file object | the file to which we should write |
txt:str | the message |
*args | Undocumented |
Prints a warning to stderr if a query included unknown fields.
Parameters | |
fdefs:list of objects.QueryFieldDefinition | Undocumented |
Undocumented
Value |
|
Undocumented
Value |
|