Skip to content

Commit

Permalink
Merge pull request #775 from galitf/fix_msg_vm_type
Browse files Browse the repository at this point in the history
  • Loading branch information
ovirt-infra authored Dec 5, 2018
2 parents 61520a6 + 2d16dac commit 24fe9b0
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions lago/virt.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import uuid

import yaml
from future.builtins import super

from lago import log_utils, plugins, utils
from lago.config import config
Expand All @@ -36,6 +37,15 @@
log_task = functools.partial(log_utils.log_task, logger=LOGGER)


class LagoUnknownVMTypeError(utils.LagoUserException):
def __init__(self, vm_type_name, vm_types):
super().__init__(
'Unknown VM type: {0}, available types: {1}, \
maybe you need to install lago plugin'
.format(vm_type_name, vm_types)
)


def _gen_ssh_command_id():
return uuid.uuid1().hex[:8]

Expand Down Expand Up @@ -69,7 +79,6 @@ class VirtEnv(object):
* prefix
* vms
* net
'''

def __init__(self, prefix, vm_specs, net_specs):
Expand Down Expand Up @@ -104,23 +113,19 @@ def _create_vm(self, vm_spec):
try:
vm_type = self.vm_types[vm_type_name]
except KeyError:
raise RuntimeError(
'Unknown VM type: {0}, available types: {1}'.format(
vm_type_name, ','.join(self.vm_types.keys())
)
raise LagoUnknownVMTypeError(
vm_type_name, ','.join(self.vm_types.keys())
)
vm_spec['vm-type'] = vm_type_name
return vm_type(self, vm_spec)

def prefixed_name(self, unprefixed_name, max_length=0):
"""
Returns a uuid pefixed identifier
Args:
unprefixed_name(str): Name to add a prefix to
max_length(int): maximum length of the resultant prefixed name,
will adapt the given name and the length of the uuid ot fit it
Returns:
str: prefixed identifier for the given unprefixed name
"""
Expand Down Expand Up @@ -228,7 +233,6 @@ def generate_init(self, dst, out_format, vms_to_include, filters=None):
"""
Generate an init file which represents this env and can
be used with the images created by self.export_vms
Args:
dst (str): path and name of the new init file
out_format (plugins.output.OutFormatPlugin):
Expand Down Expand Up @@ -293,7 +297,6 @@ def get_env_spec(self, filters=None):
Get the spec of the current env.
The spec will hold the info about all the domains and
networks associated with this env.
Args:
filters (list): list of paths to keys that should be removed from
the init file
Expand Down Expand Up @@ -347,16 +350,13 @@ def start(self, vm_names=None):
def _get_stop_shutdown_common_args(self, vm_names):
"""
Get the common arguments for stop and shutdown commands
Args:
vm_names (list of str): The names of the requested vms
Returns
list of plugins.vm.VMProviderPlugin:
vms objects that should be stopped
list of virt.Network: net objects that should be stopped
str: log message
Raises:
utils.LagoUserException: If a vm name doesn't exist
"""
Expand All @@ -375,14 +375,11 @@ def _get_stop_shutdown_common_args(self, vm_names):
def _get_unused_nets(self, vms_to_stop):
"""
Return a list of nets that used only by the vms in vms_to_stop
Args:
vms_to_stop (list of str): The names of the requested vms
Returns
list of virt.Network: net objects that used only by
vms in vms_to_stop
Raises:
utils.LagoUserException: If a vm name doesn't exist
"""
Expand Down Expand Up @@ -450,13 +447,10 @@ def get_vms(self, vm_names=None):
"""
Returns the vm objects associated with vm_names
if vm_names is None, return all the vms in the prefix
Args:
vm_names (list of str): The names of the requested vms
Returns
dict: Which contains the requested vm objects indexed by name
Raises:
utils.LagoUserException: If a vm name doesn't exist
"""
Expand Down Expand Up @@ -539,11 +533,9 @@ def revert_snapshots(self, name):
def get_snapshots(self, domains=None):
"""
Get the list of snapshots for each domain
Args:
domanins(list of str): list of the domains to get the snapshots
for, all will be returned if none or empty list passed
Returns:
dict of str -> list(str): with the domain names and the list of
snapshots for each
Expand Down

0 comments on commit 24fe9b0

Please sign in to comment.