backend.vm_manage.manager

class backend.vm_manage.manager.VmManager(opts, logger=None)[source]

VM manager, it is used for two purposes: - Daemon which control VMs lifecycle, requires params spawner,terminator - Client to acquire and release VM in builder process

Parameters
  • opts (Munch) – Global backend configuration

  • logger (logging.Logger) – Logger instance to use inside of manager, if None manager would create new logger using helpers.get_redis_logger

set_logger(logger)[source]
Parameters

logger (logging.Logger) – Logger to be used by manager

property vm_groups
Returns

VM build groups

Return type

list of int

add_vm_to_pool(vm_ip, vm_name, group)[source]

Adds newly spawned VM into the pool of available builders

Parameters
  • vm_ip (str) – IP

  • vm_name (str) – VM name

  • group (int) – builder group

Return type

VmDescriptor

lookup_vms_by_ip(vm_ip)[source]
Parameters

vm_ip

Returns

List of found VMD with the give ip

Return type

list of VmDescriptor

mark_vm_check_failed(vm_name)[source]
mark_server_start()[source]
can_user_acquire_more_vm(username, group)[source]
Return bool

True when user are allowed to acquire more VM

get_ready_vms(group)[source]
acquire_vm(groups, ownername, sandbox, pid, task_id='None', build_id='None', chroot='None')[source]

Try to acquire VM from pool.

Parameters
  • groups (list) – builder group ids where the build can be launched as defined in config

  • ownername – the owner name (user or group) this build is going to be accounted to, at this moment there’s max limit for concurrent jobs accounted to a single owner

  • sandbox – sandbox ID required by the build; we prefer to reuse existing VMs previously used for the same sandbox

  • pid – worker process id

Return type

VmDescriptor

Raises

NoVmAvailable when manager couldn’t find suitable VM for the given groups and owner

release_vm(vm_name)[source]

Return VM into the pool. :return: True if successful :rtype: bool

start_vm_termination(vm_name, allowed_pre_state='None')[source]

Initiate VM termination process using redis publish.

Parameters

allowed_pre_state (str constant from VmState) – When defined force check that old state is among allowed ones.

remove_vm_from_pool(vm_name)[source]

Backend forgets about VM after this method

Raises

VmError – if VM has wrong state

_load_multi_safe(vm_name_list)[source]
get_all_vm_in_group(group)[source]
Return type

list of VmDescriptor

get_all_vm()[source]
Return type

list of VmDescriptor

get_vm_by_name(vm_name)[source]
Return type

VmDescriptor

get_vm_by_task_id(task_id)[source]
Return type

VmDescriptor

get_vm_by_group_and_state_list(group, state_list)[source]

Select VM-s for the given group and allowed states

Parameters
  • group – filter VM-s by the build group. If group is None select VM-s from the all groups

  • state_list – VM state should be in the state_list.

Returns

Filtered VM-s

Return type

list of VmDescriptor

info()[source]

Present information about all managed VMs in a human readable form.

Return type

str

write_vm_pool_info(group, key, value)[source]
read_vm_pool_info(group, key)[source]