lago package¶
-
class
lago.
Prefix
(prefix)[source]¶ Bases:
object
A prefix is a directory that will contain all the data needed to setup the environment.
-
_prefix
¶ str
Path to the directory of this prefix
-
_paths
¶ lago.path.Paths
Path handler class
-
_virt_env
¶ lago.virt.VirtEnv
Lazily loaded virtual env handler
-
_metadata
¶ dict
Lazily loaded metadata
-
_add_nic_to_mapping
(net, dom, nic)[source]¶ Populates the given net spec mapping entry with the nicks of the given domain
Parameters: Returns: None
-
_allocate_ips_to_nics
(conf)[source]¶ For all the nics of all the domains in the conf that have dynamic ip, allocate one and addit to the network mapping
Parameters: conf (dict) – Configuration spec to extract the domains from Returns: None
-
_allocate_subnets
(conf)[source]¶ Allocate all the subnets needed by the given configuration spec
Parameters: conf (dict) – Configuration spec where to get the nets definitions from Returns: allocated subnets Return type: list
-
_check_predefined_subnets
(conf)[source]¶ Checks if all of the nets defined in the config are inside the allowed range, throws exception if not
Parameters: conf (dict) – Configuration spec where to get the nets definitions from Returns: None Raises: RuntimeError
– If there are any subnets out of the allowed range
-
_config_net_topology
(conf)[source]¶ Initialize and populate all the network related elements, like reserving ips and populating network specs of the given confiiguration spec
Parameters: conf (dict) – Configuration spec to initalize Returns: None
-
_create_disk
(name, spec, template_repo=None, template_store=None)[source]¶ Creates a disc with the given name from the given repo or store.
Parameters: Returns: Tuple – Path with the disk and metadata
Return type: str, dict
Raises: RuntimeError
– If the type of the disk is not supported or failed to create the disk
-
_create_paths
()[source]¶ Get the path handler for this instance
Returns: Path handler Return type: lago.paths.Paths
-
_create_ssh_keys
()[source]¶ Generate a pair of ssh keys for this prefix
Returns: None Raises: RuntimeError
– if it fails to create the keys
-
_create_virt_env
()[source]¶ Create a new virt env from this prefix
Returns: virt env created from this prefix Return type: lago.virt.VirtEnv
-
_get_metadata
()[source]¶ Retrieve the metadata info for this prefix
Returns: metadata info Return type: dict
-
_init_net_specs
(conf)[source]¶ Given a configuration specification, initializes all the net definitions in it so they can be used comfortably
Parameters: conf (dict) – Configuration specification Returns: None
-
_register_preallocated_ips
(conf)[source]¶ Parse all the domains in the given conf and preallocate all their ips into the networks mappings, raising exception on duplicated ips or ips out of the allowed ranges
See also
Parameters: conf (dict) – Configuration spec to parse Returns: None Raises: RuntimeError
– if there are any duplicated ips or any ip out of the allowed range
-
_use_prototype
(spec, conf)[source]¶ Populates the given spec with the values of it’s declared prototype
Parameters: Returns: updated spec
Return type:
-
cleanup
()[source]¶ Stops any running entities in the prefix and uninitializes it, usually you want to do this if you are going to remove the prefix afterwards
Returns: None
-
create_snapshots
(name)[source]¶ Creates one snapshot on all the domains with the given name
Parameters: name (str) – Name of the snapshots to create Returns: None
-
initialize
()[source]¶ Initialize this prefix, this includes creating the destination path, and creating the uuid for the prefix, for any other actions see
Prefix.virt_conf()
Will safely roll back if any of those steps fail
Returns: None Raises: RuntimeError
– If it fails to create the prefix dir
-
paths
¶ Access the path handler for this prefix
Returns: Path handler Return type: lago.paths.Paths
-
revert_snapshots
(name)[source]¶ Revert all the snapshots with the given name from all the domains
Parameters: name (str) – Name of the snapshots to revert Returns: None
-
virt_conf
(conf, template_repo=None, template_store=None)[source]¶ Initializes all the virt infrastructure of the prefix, creating the domains disks, doing any network leases and creating all the virt related files and dirs inside this prefix.
Parameters: - conf (dict) – Configuration spec
- template_repo (TemplateRepository) – template repository intance
- template_store (TemplateStore) – template store instance
Returns: None
-
virt_env
¶ Getter for this instance’s virt env, creates it if needed
Returns: virt env instance used by this prefix Return type: lago.virt.VirtEnv
-
-
lago.
_create_ip
(subnet, index)[source]¶ Given a subnet or an ip and an index returns the ip with that lower index from the subnet (255.255.255.0 mask only subnets)
Parameters: - subnet (str) – Strign containing the three first elements of the decimal representation of a subnet (X.Y.Z) or a full ip (X.Y.Z.A)
- index (int or str) – Last element of a decimal ip representation, for example, 123 for the ip 1.2.3.123
Returns: The dotted decimal representation of the ip
Return type:
-
lago.
_ip_in_subnet
(subnet, ip)[source]¶ Checks if an ip is included in a subnet.
Note
only 255.255.255.0 masks allowed
Parameters: - subnet (str) – Strign containing the three first elements of the decimal representation of a subnet (X.Y.Z) or a full ip (X.Y.Z.A)
- ip (str or int) – Decimal ip representation
Returns: True
if ip is in subnet,False
otherwiseReturn type:
Submodules¶
lago.brctl module¶
lago.config module¶
lago.constants module¶
lago.dirlock module¶
lago.subnet_lease module¶
Module that handles the leases for the subnets of the virtual network interfaces.
Note
Currently only /24 ranges are handled, and all of them under the 192.168.MIN_SUBNET to 192.168.MAX_SUBNET ranges
The leases are stored under LEASE_DIR
as json files with the form:
[
"/path/to/prefix/uuid/file",
"uuid_hash",
]
Where the uuid_hash is the 32 char uuid of the prefix (the contents of the uuid file at the time of doing the lease)
-
lago.subnet_lease.
LEASE_DIR
= '/var/lib/lago/subnets/'¶ Path to the directory where the net leases are stored
-
lago.subnet_lease.
LOCK_FILE
= '/var/lib/lago/subnets/leases.lock'¶ Path to the net leases lock
-
lago.subnet_lease.
MAX_SUBNET
= 209¶ Upper range for the allowed subnets
-
lago.subnet_lease.
MIN_SUBNET
= 200¶ Lower range for the allowed subnets
-
lago.subnet_lease.
_acquire
(*args, **kwargs)[source]¶ Lease a free network for the given uuid path
Parameters: uuid_path (str) – Path to the uuid file of a lago.Prefix
Returns: the third element of the dotted ip of the leased network or None
if no lease was availableReturn type: int or None Todo
Raise exception or something instead of returning None so the caller can handle the failure case
-
lago.subnet_lease.
_lease_owned
(path, current_uuid_path)[source]¶ Checks if the given lease is owned by the prefix whose uuid is in the given path
Note
The prefix must be also in the same path it was when it took the lease
Parameters: Returns: True
if the given lease in owned by the prefix,False
otherwiseReturn type:
-
lago.subnet_lease.
_lease_valid
(path)[source]¶ Checs if the given lease still has a prefix that owns it
Parameters: path (str) – Path to the lease Returns: True
if the uuid path in the lease still exists and is the same as the one in the leaseReturn type: bool
-
lago.subnet_lease.
_locked
(func)[source]¶ Decorator that will make sure that you have the exclusive lock for the leases
-
lago.subnet_lease.
_release
(*args, **kwargs)[source]¶ Free the lease of the given subnet index
Parameters: index (int) – Third element of a dotted ip representation of the subnet, for example, for 1.2.3.4 it would be 3 Returns: None
-
lago.subnet_lease.
_take_lease
(path, uuid_path)[source]¶ Persist to the given leases path the prefix uuid that’s in the uuid path passed
Parameters: Returns: None
-
lago.subnet_lease.
_validate_lease_dir_present
(func)[source]¶ Decorator that will ensure that the lease dir exists, creating it if necessary
-
lago.subnet_lease.
acquire
(uuid_path)[source]¶ Lease a free network for the given uuid path
Parameters: uuid_path (str) – Path to the uuid file of a lago.Prefix
Returns: the dotted ip of the gateway for the leased net Return type: str Todo
_aquire might return None, this will throw a TypeError
lago.sysprep module¶
lago.templates module¶
lago.utils module¶
-
class
lago.utils.
CommandStatus
[source]¶ Bases:
lago.utils.CommandStatus
-
class
lago.utils.
RollbackContext
(*args)[source]¶ Bases:
object
A context manager for recording and playing rollback. The first exception will be remembered and re-raised after rollback
Sample usage: > with RollbackContext() as rollback: > step1() > rollback.prependDefer(lambda: undo step1) > def undoStep2(arg): pass > step2() > rollback.prependDefer(undoStep2, arg)
More examples see tests/utilsTests.py @ vdsm code
-
lago.utils.
_CommandStatus
¶ alias of
CommandStatus
-
lago.utils.
drain_ssh_channel
(chan, stdin=None, stdout=<open file '<stdout>', mode 'w'>, stderr=<open file '<stderr>', mode 'w'>)[source]¶
-
lago.utils.
interactive_ssh_channel
(chan, command=None, stdin=<open file '<stdin>', mode 'r'>)[source]¶
lago.virt module¶
-
class
lago.virt.
BridgeNetwork
(env, spec)[source]¶ Bases:
lago.virt.Network
-
class
lago.virt.
NATNetwork
(env, spec)[source]¶ Bases:
lago.virt.Network
-
class
lago.virt.
VM
(env, spec)[source]¶ Bases:
object
VM properties: * name * cpus * memory * disks * metadata * network/mac addr
-
metadata
¶
-
-
class
lago.virt.
VirtEnv
(prefix, vm_specs, net_specs)[source]¶ Bases:
object
Env properties: * prefix * vms * net
- libvirt_con
-
libvirt_con
¶
-
class
lago.virt.
_SysVInitService
(vm, name)[source]¶ Bases:
lago.virt._Service
-
BIN_PATH
= '/sbin/service'¶
-
-
class
lago.virt.
_SystemdContainerService
(vm, name)[source]¶ Bases:
lago.virt._Service
-
BIN_PATH
= '/usr/bin/docker'¶
-
HOST_BIN_PATH
= '/usr/bin/systemctl'¶
-
-
class
lago.virt.
_SystemdService
(vm, name)[source]¶ Bases:
lago.virt._Service
-
BIN_PATH
= '/usr/bin/systemctl'¶
-