Code¶
The code can be found on GitHub.
vmupdate.channel¶
Provide wrapper classes around virtual machine communication.
-
class
vmupdate.channel.
Channel
(hostname, port)[source]¶ Bases:
object
Provide virtual machine communication.
Variables: - hostname (str) – name or IP of the virtual machine
- port (int) – port of the virtual machine
-
connect
(username, password)[source]¶ Connect to the virtual machine.
Parameters: - username (str) – username for authentication
- password (str) – password for authentication
-
run
(args)[source]¶ Run command against the virtual machine and return a
ChannelCommand
.Parameters: args (str or list) – the command to be run Return type: ChannelCommand
vmupdate.cli¶
Provide the main entry point and command line parsing.
-
vmupdate.cli.
main
()[source]¶ Initialize environment and call
host.update_all_vms()
.This is the main entry point for vmupdate.
Returns: exitcode Return type: int
vmupdate.config¶
Provide a wrapper around configuration.
-
class
vmupdate.config.
Config
[source]¶ Bases:
vmupdate.config.ConfigSection
Provide a wrapper for the merged configuration files.
-
credentials
¶ Return the Credentials configuration section.
Return type: Credentials
-
load
(config_path=None, log_dir=None)[source]¶ Load the configuration files and configure logging.
Parameters: - config_path (str) – path to a user defined configuration file
- log_dir (str) – path to the directory where log files are to be stored
-
pkgmgrs
¶ Return the Package Managers configuration section.
Return type: PackageManagers
-
virtualizers
¶ Return the Virtualizers configuration section.
Return type: Virtualizers
-
-
class
vmupdate.config.
ConfigSection
(data=None)[source]¶ Bases:
object
Provide a base class for configuration sections.
This class wraps a
dict
.
-
class
vmupdate.config.
Credentials
(data)[source]¶ Bases:
vmupdate.config.ConfigSection
Provide a wrapper around the credentials configuration section.
-
password
¶ Return the Password configuration.
Return type: str
-
run_as_elevated
¶ Return the Run As Elevated configuration.
Return type: bool
-
use_keyring
¶ Return the Use Keyring configuration.
Return type: bool
-
username
¶ Return the Username configuration.
Return type: str
-
-
class
vmupdate.config.
General
(data)[source]¶ Bases:
vmupdate.config.ConfigSection
Provide a wrapper around the general configuration section.
-
wait_after_start
¶ Return the Wait After Start configuration.
Return type: int
-
wait_before_stop
¶ Return the Wait Before Stop configuration.
Return type: int
-
-
class
vmupdate.config.
Machine
(data)[source]¶ Bases:
vmupdate.config.ConfigSection
Provide a wrapper around the machine configuration section.
-
ignore
¶ Return the Ignore configuration.
Return type: bool
-
password
¶ Return the Password configuration.
Return type: str
-
run_as_elevated
¶ Return the Run As Elevated configuration.
Return type: bool
-
shell
¶ Return the Shell configuration.
Return type: str
-
use_keyring
¶ Return the Use Keyring configuration.
Return type: bool
-
username
¶ Return the Username configuration.
Return type: str
-
-
class
vmupdate.config.
Machines
(data)[source]¶ Bases:
vmupdate.config.ConfigSection
Provide a wrapper around the machines configuration section.
This class wraps a dict of
Machine
.
-
class
vmupdate.config.
Network
(data)[source]¶ Bases:
vmupdate.config.ConfigSection
Provide a wrapper around the network configuration section.
-
class
vmupdate.config.
PackageManagers
(data)[source]¶ Bases:
vmupdate.config.ConfigSection
Provide a wrapper around the package managers configuration section.
-
class
vmupdate.config.
Shells
(data)[source]¶ Bases:
vmupdate.config.ConfigSection
Provide a wrapper around the shells configuration section.
-
class
vmupdate.config.
Ssh
(data)[source]¶ Bases:
vmupdate.config.ConfigSection
Provide a wrapper around the SSH configuration section.
-
guest_port
¶ Return the guest port configuration.
Return type: int
-
host_max_port
¶ Return the host port maximum configuration, else 65,535.
Return type: int
-
host_min_port
¶ Return the host port minimum configuration.
Return type: int
-
-
class
vmupdate.config.
Virtualizers
(data)[source]¶ Bases:
vmupdate.config.ConfigSection
Provide a wrapper around the virtualizers configuration section.
vmupdate.constants¶
Provide constants for vmupdate.
-
vmupdate.constants.
OS_ARCH
= 'Arch'¶ VM OS Arch
-
vmupdate.constants.
OS_DEBIAN
= 'Debian'¶ VM OS Debian
-
vmupdate.constants.
OS_FEDORA
= 'Fedora'¶ VM OS Fedora
-
vmupdate.constants.
OS_GENTOO
= 'Gentoo'¶ VM OS Gentoo
-
vmupdate.constants.
OS_LINUX
= 'Linux'¶ VM OS Linux
-
vmupdate.constants.
OS_MAC_OS_X
= 'Mac OS X'¶ VM OS Mac OS X
-
vmupdate.constants.
OS_MANDRIVA
= 'Mandriva'¶ VM OS Mandriva
-
vmupdate.constants.
OS_OPENSUSE
= 'openSUSE'¶ VM OS openSUSE
-
vmupdate.constants.
OS_ORACLE
= 'Oracle'¶ VM OS Oracle
-
vmupdate.constants.
OS_REDHAT
= 'Red Hat'¶ VM OS Red Hat
-
vmupdate.constants.
OS_TURBOLINUX
= 'Turbolinux'¶ VM OS Turbolinux
-
vmupdate.constants.
OS_UBUNTU
= 'Ubuntu'¶ VM OS Ubuntu
-
vmupdate.constants.
OS_UNKNOWN
= 'Unknown'¶ VM OS Unknown
-
vmupdate.constants.
OS_WINDOWS
= 'Windows'¶ VM OS Windows
-
vmupdate.constants.
OS_XANDROS
= 'Xandros'¶ VM OS Xandros
-
vmupdate.constants.
VM_PAUSED
= 3¶ VM State Paused
-
vmupdate.constants.
VM_RUNNING
= 1¶ VM State Running
-
vmupdate.constants.
VM_STOPPED
= 0¶ VM State Stopped
-
vmupdate.constants.
VM_SUSPENDED
= 2¶ VM State Suspended
-
vmupdate.constants.
VM_UNKNOWN
= -1¶ VM State Unknown
vmupdate.credentials¶
Provide functions for accessing credential information from the config and keyring.
-
vmupdate.credentials.
get_credentials
(uid)[source]¶ Return the configured credentials for the virtual machine.
Parameters: uid (str) – name of the virtual machine Returns: tuple of (username, password) Return type: (str, str)
-
vmupdate.credentials.
get_password
(username, uid)[source]¶ Return the password for the
username
and virtual machine.Parameters: - username (str) – username associated with the password
- uid (str) – name of the virtual machine
Returns: password
Return type: str
vmupdate.errors¶
Provide application-specific error classes.
-
exception
vmupdate.errors.
AppError
[source]¶ Bases:
exceptions.Exception
Provide base class for application-specific errors.
-
exception
vmupdate.errors.
SshError
[source]¶ Bases:
vmupdate.errors.AppError
Provide class for SSH errors.
-
exception
vmupdate.errors.
UpdateError
[source]¶ Bases:
vmupdate.errors.AppError
Provide class for update errors.
vmupdate.host¶
Provide functions to find and update VM’s.
vmupdate.pkgmgr¶
Provide functions to query and command package managers.
-
vmupdate.pkgmgr.
get_pkgmgrs
(vm)[source]¶ Return all package managers on the virtual machine.
Parameters: vm ( VM
) – virtual machine to targetReturns: list of tuples of (name, list of paths) Return type: list((str, list(str)))
-
vmupdate.pkgmgr.
run_pkgmgr
(vm, pkgmgr, cmds)[source]¶ Run the package manager commands on the virtual machine in sequence.
Parameters: - vm (
VM
) – virtual machine to target - pkgmgr (str) – name of the package manager to run
- cmds (list(str)) – list of commands to run in sequence
Raises: UpdateError – if any command does not exit with
0
- vm (
vmupdate.shells¶
Provide a transparent abstraction for interacting with shells.
-
class
vmupdate.shells.
Posix
(channel)[source]¶ Bases:
vmupdate.shells.Shell
Represent a POSIX shell that communicates through a channel.
Variables: channel ( Channel
) – channel used for virtual machine communication-
command_exists
(command)[source]¶ Return whether the
command
exists in the shell.Parameters: command (str) – name of the command Return type: bool
-
-
class
vmupdate.shells.
Shell
[source]¶ Bases:
object
Abstract virtual machine shell that communicates through a channel.
This class must be inherited and cannot be used directly.
Variables: channel ( Channel
) – channel used for virtual machine communication-
command_exists
(command)[source]¶ Return whether the
command
exists in the shell.This is a shell-specific command and must be overridden.
Parameters: command (str) – name of the command Return type: bool
-
run
(args)[source]¶ Run command against the virtual machine.
Parameters: args (str or list) – the command to be run Return type: ChannelCommand
-
vmupdate.virtualizers¶
Provide a transparent abstraction for interacting with virtualizers.
-
class
vmupdate.virtualizers.
VirtualBox
(manager_path)[source]¶ Bases:
vmupdate.virtualizers.Virtualizer
Control the VirtualBox virtualizer.
-
enable_ssh
(uid, host_port, guest_port)[source]¶ Enable SSH port forwarding for the virtual machine.
Parameters: - uid (str) – identifier of the machine
- host_port (int) – the post on the host to forward to the guest
- guest_port (int) – SSH port of the guest
Returns: exitcode
Return type: int
-
get_ssh_info
(uid, ssh_port)[source]¶ Return the SSH connection information for the virtual machine.
Parameters: - uid (str) – identifier of the machine
- ssh_port (int) – expected SSH port of the guest
Returns: tuple of (hostname, port)
Return type: (str, int)
-
get_vm_os
(uid)[source]¶ Return the operating system of the virtual machine.
Possible values can be found in
constants
.Parameters: uid (str) – identifier of the machine Return type: str
-
get_vm_status
(uid)[source]¶ Return the status of the virtual machine.
Possible values can be found in
constants
.Parameters: uid (str) – identifier of the machine Return type: str
-
list_vms
()[source]¶ Return all virtual machines.
Returns: list of tuple (name, id) Return type: list(str, str)
-
-
class
vmupdate.virtualizers.
Virtualizer
[source]¶ Bases:
object
Abstract virtualizer control.
This class must be inherited and cannot be used directly.
-
enable_ssh
(uid, host_port, guest_port)[source]¶ Enable SSH port forwarding for the virtual machine.
This is a virtualizer-specific command and must be overridden.
Parameters: - uid (str) – identifier of the machine
- host_port (int) – the post on the host to forward to the guest
- guest_port (int) – SSH port of the guest
Returns: exitcode
Return type: int
-
get_ssh_info
(uid, ssh_port)[source]¶ Return the SSH connection information for the virtual machine.
This is a virtualizer-specific command and must be overridden.
Parameters: - uid (str) – identifier of the machine
- ssh_port (int) – expected SSH port of the guest
Returns: tuple of (hostname, port)
Return type: (str, int)
-
get_vm_os
(uid)[source]¶ Return the operating system of the virtual machine.
This is a virtualizer-specific command and must be overridden.
Possible values can be found in
constants
.Parameters: uid (str) – identifier of the machine Return type: str
-
get_vm_status
(uid)[source]¶ Return the status of the virtual machine.
This is a virtualizer-specific command and must be overridden.
Possible values can be found in
constants
.Parameters: uid (str) – identifier of the machine Return type: str
-
list_vms
()[source]¶ Return all virtual machines.
This is a virtualizer-specific command and must be overridden.
Returns: list of tuple (name, id) Return type: list(str, str)
-
-
vmupdate.virtualizers.
get_virtualizer
(name, path)[source]¶ Return an instance of a virtualizer.
The virtualizer should extend
Virtualizer
.Parameters: - name (str) – name of the virtualizer class to instantiate
- path (str) – path of the virtualizer to pass to the constructor
vmupdate.vm¶
Provide a wrapper class around VM interactions.
-
class
vmupdate.vm.
VM
(virtualizer, uid)[source]¶ Bases:
object
Provide virtual machine interface.
Variables: - virtualizer (
Virtualizer
) – virtualizer that the virtual machine runs under - uid (str) – identifier of the virtual machine
-
enable_ssh
(host_port)[source]¶ Enable SSH port forwarding for the virtual machine.
Parameters: host_port (int) – the post on the host to forward to the guest Returns: exitcode Return type: int
-
get_os
()[source]¶ Return the operating system of the virtual machine.
Possible values can be found in
constants
.Return type: str
-
get_ssh_info
()[source]¶ Return the SSH connection information for the virtual machine.
Returns: tuple of (hostname, port) Return type: (str, int)
-
get_status
()[source]¶ Return the status of the virtual machine.
Possible values can be found in
constants
.Return type: str
-
shell_name
¶ Return the name of the shell.
Return type: str
-
ssh_port
¶ Return the SSH port of the guest.
Return type: int
- virtualizer (