From 6858c9931a44311cc5f47f5583f0228375f2f136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= Date: Fri, 20 Apr 2018 16:10:44 +0200 Subject: [PATCH] virt module: move virt.images to virt:images To continue the virt module options harmonization, deprecate virt.images in favor of virt:images and add documentation on this option. --- doc/topics/tutorials/cloud_controller.rst | 2 +- salt/client/ssh/wrapper/config.py | 4 +-- salt/modules/config.py | 4 +-- salt/modules/virt.py | 36 ++++++++++++++++++++--- 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/doc/topics/tutorials/cloud_controller.rst b/doc/topics/tutorials/cloud_controller.rst index ce8504e6da..39a8249092 100644 --- a/doc/topics/tutorials/cloud_controller.rst +++ b/doc/topics/tutorials/cloud_controller.rst @@ -245,7 +245,7 @@ The Salt Virt runner will now automatically select a hypervisor to deploy the new virtual machine on. Using ``salt://`` assumes that the CentOS virtual machine image is located in the root of the :ref:`file-server` on the master. When images are cloned (i.e. copied locatlly after retrieval from the file server) -the destination directory on the hypervisor minion is determined by the ``virt.images`` +the destination directory on the hypervisor minion is determined by the ``virt:images`` config option; by default this is ``/srv/salt/salt-images/``. When a VM is initialized using ``virt.init`` the image is copied to the hypervisor diff --git a/salt/client/ssh/wrapper/config.py b/salt/client/ssh/wrapper/config.py index f9fee979cd..23d685b909 100644 --- a/salt/client/ssh/wrapper/config.py +++ b/salt/client/ssh/wrapper/config.py @@ -49,8 +49,8 @@ DEFAULTS = {'mongo.db': 'salt', 'ldap.bindpw': '', 'hosts.file': '/etc/hosts', 'aliases.file': '/etc/aliases', - 'virt.images': os.path.join(syspaths.SRV_ROOT_DIR, 'salt-images'), - 'virt': {'tunnel': False}, + 'virt': {'tunnel': False, + 'images': os.path.join(syspaths.SRV_ROOT_DIR, 'salt-images')}, } diff --git a/salt/modules/config.py b/salt/modules/config.py index 962f6325ba..972f9c0b6b 100644 --- a/salt/modules/config.py +++ b/salt/modules/config.py @@ -76,8 +76,8 @@ DEFAULTS = {'mongo.db': 'salt', 'ldap.bindpw': '', 'hosts.file': _HOSTS_FILE, 'aliases.file': '/etc/aliases', - 'virt.images': os.path.join(syspaths.SRV_ROOT_DIR, 'salt-images'), - 'virt': {'tunnel': False}, + 'virt': {'tunnel': False, + 'images': os.path.join(syspaths.SRV_ROOT_DIR, 'salt-images')}, } diff --git a/salt/modules/virt.py b/salt/modules/virt.py index 515cba1168..77fa2bc001 100644 --- a/salt/modules/virt.py +++ b/salt/modules/virt.py @@ -615,6 +615,26 @@ def _qemu_image_info(path): return ret +def _get_images_dir(): + ''' + Extract the images dir from the configuration. First attempts to + find legacy virt.images, then tries virt:images. + ''' + img_dir = __salt__['config.option']('virt.images') + if img_dir: + salt.utils.warn_until( + 'Sodium', + '\'virt.images\' has been deprecated in favor of ' + '\'virt:images\'. \'virt.images\' will stop ' + 'being used in {version}.') + else: + img_dir = __salt__['config.get']('virt:images') + + log.debug('Image directory from config option `virt:images`' + ' is %s', img_dir) + return img_dir + + def _qemu_image_create(vm_name, disk_file_name, disk_image=None, @@ -634,9 +654,8 @@ def _qemu_image_create(vm_name, .format(disk_file_name) ) - img_dir = __salt__['config.option']('virt.images') - log.debug('Image directory from config option `virt.images`' - ' is %s', img_dir) + img_dir = _get_images_dir() + img_dest = os.path.join( img_dir, vm_name, @@ -786,7 +805,7 @@ def _disk_profile(profile, hypervisor, **kwargs): elif hypervisor in ['qemu', 'kvm']: overlay = {'format': 'qcow2', 'model': 'virtio', - 'pool': __salt__['config.option']('virt.images')} + 'pool': _get_images_dir()} else: overlay = {} @@ -957,6 +976,15 @@ def init(name, salt 'hypervisor' virt.init vm_name 4 512 salt://path/to/image.raw salt 'hypervisor' virt.init vm_name 4 512 /var/lib/libvirt/images/img.raw salt 'hypervisor' virt.init vm_name 4 512 nic=profile disk=profile + + The disk images will be created in an image folder within the directory + defined by the ``virt:images`` option. Its default value is + ``/srv/salt/salt-images/`` but this can changed with such a configuration: + + .. code-block:: yaml + + virt: + images: /data/my/vm/images/ ''' hypervisor = __salt__['config.get']('libvirt:hypervisor', hypervisor) log.debug('Using hyperisor %s', hypervisor)