The nova.openstack.common.processutils Module

System-level utilities and helper functions.

exception InvalidArgumentError(message=None)

Bases: exceptions.Exception

exception NoRootWrapSpecified(message=None)

Bases: exceptions.Exception

exception ProcessExecutionError(stdout=None, stderr=None, exit_code=None, cmd=None, description=None)

Bases: exceptions.Exception

exception UnknownArgumentError(message=None)

Bases: exceptions.Exception

execute(*cmd, **kwargs)

Helper method to shell out and execute a command through subprocess.

Allows optional retry.

Parameters:
  • cmd (string) – Passed to subprocess.Popen.
  • process_input (string) – Send to opened process.
  • env_variables (dict) – Environment variables and their values that will be set for the process.
  • check_exit_code (boolean, int, or [int]) – Single bool, int, or list of allowed exit codes. Defaults to [0]. Raise ProcessExecutionError unless program exits with one of these code.
  • delay_on_retry (boolean) – True | False. Defaults to True. If set to True, wait a short amount of time before retrying.
  • attempts (int) – How many times to retry cmd.
  • run_as_root (boolean) – True | False. Defaults to False. If set to True, the command is prefixed by the command specified in the root_helper kwarg.
  • root_helper (string) – command to prefix to commands called with run_as_root=True
  • shell (boolean) – whether or not there should be a shell used to execute this command. Defaults to false.
  • loglevel (int. (Should be logging.DEBUG or logging.INFO)) – log level for execute commands.
  • on_execute (function(subprocess.Popen)) – This function will be called upon process creation with the object as a argument. The Purpose of this is to allow the caller of processutils.execute to track process creation asynchronously.
  • on_completion (function(subprocess.Popen)) – This function will be called upon process completion with the object as a argument. The Purpose of this is to allow the caller of processutils.execute to track process completion asynchronously.
Returns:

(stdout, stderr) from process execution

Raises :

UnknownArgumentError on receiving unknown arguments

Raises :

ProcessExecutionError

get_worker_count()

Utility to get the default worker count.

@return: The number of CPUs if that can be determined, else a default
worker count of 1 is returned.
ssh_execute(ssh, cmd, process_input=None, addl_env=None, check_exit_code=True)
trycmd(*args, **kwargs)

A wrapper around execute() to more easily handle warnings and errors.

Returns an (out, err) tuple of strings containing the output of the command’s stdout and stderr. If ‘err’ is not empty then the command can be considered to have failed.

:discard_warnings True | False. Defaults to False. If set to True,
then for succeeding commands, stderr is cleared

Previous topic

The nova.openstack.common.policy Module

Next topic

The nova.openstack.common.report.generators.conf Module

This Page