Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing backport for 3000.3 #257

Merged

Conversation

cbosdo
Copy link
Contributor

@cbosdo cbosdo commented Aug 31, 2020

Port PR #236 to 3000.3

* Revert "virt._get_domain: don't raise an exception if there is no VM"

This reverts commit 9d43377.

* Revert "openSUSE-3000 virt-defined-states (openSUSE#222)"

This reverts commit 900fdc4.

* Revert "Add virt.all_capabilities"

This reverts commit 96e8307.

* Blacken salt -- virt only

* virt._get_domain: don't raise an exception if there is no VM

Raising an exception if there is no VM in _get_domain makes sense if
looking for some VMs, but not when listing all VMs.

* fixed bug on update existing boot parameters

* add support to boot vm with UEFI

* virt: don't depend on ElementTree.tostring to compare XML fragments

ElementTree.tostring() implementation starts to keep the attribute order
defined by the user in python 3.8. This can lead to equal elements to be
considered different. Use xmlutil.to_dict(element, True) to compare the
elements.

This also uncovered a wrong behavior of pool_update when only changing
the password.

* openSUSE-3000 virt-defined-states (openSUSE#222)

* Create virt.pool_defined state out of virt.pool_running

Users may want to use states to ensure a virtual storage pool is defined
and not enforce it to be running. Extract the code that performs the
pool definition / update from virt.pool_running state into a
virt.pool_defined.

Obviously the virt.pool_running state calls the virt.pool_defined one.
In such a case no additionnal test is needed for virt.pool_defined since
this is already tested with virt.pool_running.

* Add virt.update test parameter

In order to allow running dry-runs of virt.update module add a test
parameter. This will later be used by the virt states.

* Extract virt.defined state from virt.running

In order to ensure a virtual guest is defined independently of its
status, extract the corresponding code from the virt.running state.

This commit also handles the __opts__['test'] for the running state.
Since the update call only performs changes if needed, deprecate the
update parameter.

* Extract virt.network_defined from virt.network_running

Just like domains and storage pools, users may want to ensure a network
is defined without influencing it's status. Extract the code from
network_running state defining the network into a network_defined state.

While at it, support __opt__['test'] == True in these states. Updating
the network definition in the pool_defined state will come in a future
PR.

* Fix virt.update to handle None mem and cpu

virt.running state now may call virt.update with None mem and cpu
parameters. This was not handled in _gen_xml(). Also add some more tests
cases matching this for virt.update.

* Add support to virt for libvirt loader

* Add bhyve compatibility to virt

* Fix test_get_hypervisor: mock bhyve

* Add virt.all_capabilities

In order to get all possible capabilities from a host, the user has to
call virt.capabilities, and then loop over the guests and domains
before calling virt.domain_capabilities for each of them.

This commit embeds all this logic to get them all in a single
virt.all_capabilities call.

* Virt init disks support (PR#56666)

* Fix pylint warning in test_virt.py after blackening

* Add pool parameter to virt.define_vol_xml_str

* Remove useless default values for disks and vm_name in _disk_profile

* virt._gen_vol_xml: move all esx-specifics outside

In the near future gen_vol_xml will be able to handle many volume types,
not only for ESX volumes. For this, clean up the function from all the
ESX-specifics code and move them to the caller code.

The volume key and target path values have also been removed since those
are read-only elements that should not be provided for volume creation
as per https://libvirt.org/formatstorage.html#StorageVol

* virt: add more properties to generate volume XML

In order to generate almost all the volumes that libvirt can handle, add
the type, backingStore, permissions and allocation parameters to the
virt._gen_vol_xml() function.

Also make the format parameter optional since libvirt has default values
depending on the storage backend.

* virt.define_vol_xml_str variant using an existing libvirt connection

In order to avoid connection multiple times when reusing this function
in the virt module, create _define_vol_xml_str not caring about the
connection opening and closing.

* Add virt.volume_define function

In the same vein than pool_define and network_define, expose a
volume_define function to let users create a volume without needing to
know all of libvirt's XML details.

* Add virt.volume_upload function

When using volumes the user can just copy the template disk image into
the target path. In such a case, the image needs to be uploaded into the
volume.

* virt.capabilities refactoring

Extract the libvirt-handling code from virt.capabilities into a
virt._capabilities function accepting an opened libvirt connection.
This allows reusing the code in other functions with easy connection
handling.

* Extract virt.pool_capabilities logic for use with a libvirt connection

Te virt.pool_capabilities function computes a lot of interesting values
on the virtual storage pool types. Extract the logic of it into
virt._pool_capabilities for reuse.

* Share libvirt connection in virt.init

Since the next commits will introduce more uses of the libvirt
connection in virt.init(), start sharing it now.

* Add disk volumes support in virt.init

In order to support creating VMs with disk on more storage pools like
iSCSI, disks, LVM, RBD, etc, virt.init needs to handle disks not only as
files, but also as libvirt volumes.

* fix libvirtError use

libvirtError is not defined, libvirt.libvirtError should be used
instead.

* virt: let libvirt generate MAC addresses

There is no need to generate MAC addresses in the virt module if the
user hasn't provided any. This only makes it harder to make the
difference between a real mac address change from the user and a new
generated one.

Now the mac address is not written in the domain XML definition if not
provided by the user. This avoids unnecessary changes when applying
virt.running.

* virt.update handle disk volumes

* virt.volume_infos: output backing store as well

Since it could be useful to know whether a volume has a backing store,
output the path and format of the backing store if any is defined.

* virt.volume_infos: output disk format

Since the format of a volume may be of interest and could help to tell
if two volumes are similar, output this information in the
virt.volume_infos function.

* Add virt.volume_defined state

In order to help creating storage volumes in virtual storage pools from
states, add a virt.volume_defined state.

* Add volume support to virt._get_disks

If a virtual machine has disks of volume types, they will now be
reported by the virt._get_disk() function and all the user-exposed
functions using it like virt.get_disks(), virt.vm_info() and
virt.full_info().

* Add volume disks support to virt.purge()

virt.purge will now remove not only the file disks, but also the disk volumes.

* Handle RBD volumes as network disks in VM definition

libvirt doesn't support attaching RBD storage pool volumes to a VM.
For instance, a disk with such a source is invalid:

    <source pool='rbd-pool' volume='rbd-volume'/>

And needs to be replaced with:

    <source protocol="rbd" name="rbd-pool-name/rbd-volume">
      <host name="hostname" port="7000"/>
      <auth username='myuser'>
        <secret type='ceph' usage='mypassid'/>
      </auth>
    </source>

This means that we need to fetch the connection data from the pool
definition and convert the volume disk definition into a network one
when creating the VM.

This also means that when purging the VM we need to search for the
pool by looking in every pool's XML to delete the volume.

* virt: fix VM creating with disk volume

Since volumes in a virtual storage pool of type 'disk' are partitions,
then need to be named after the disk name with sequential numbers rather
than using the VM and disk names.

Also, the format passed by the user is the one used when creating the volume.
However in the VM definition for logical and disk volumes, the format should
be set to raw.

* virt: handle cdrom remote images

Libvirt allows to use network images for cdroms. Use them if the image
is a remote URL for a cdrom device.

* virt.update properly handle removable devices

Live attaching / detaching removable devices results in failures.
To change the source of those, we need to call updateDeviceFlags instead.

* improve boot parameter documentation (PR#57086)

* Remove buggy start parameter from virt.pool_running docstring

As mentioned by issue #57275, the start parameter in virt.pool_running
documentation is not implemented at all. Remove it from the doc.

* virt: fix removable_changes definition place

* virt: show the proper pool name in get_disks

From the user point of view the internal RBD pool name doesn't make
sense when listing the disks of a VM. We need then to resolve it to the
libvirt pool name if possible.

Move the corresponding code from purge to get_disks.

* virt: fix updating VM with backing store disks

libvirt adds the index attribute in the XML definition when there is a
backing store file for a disk. We need to elude it before comparing the
sources to avoid trying to recreate disks in such cases.

* virt: default cdrom model to ide

cdrom devices can't use virtio. Set the default bus to ide for cdroms.

* virt.get_disk: output the full URL for cdroms with remote image

virt._gen_xml converts the cdroms with remote URL into a network device,
but to be coherent with the user input the virt.get_disk() function
needs to reassemble the URL in thoses cases.

* virt.pool_delete: remove also secret

Some pool type require a secret for the authentication on the remote
source. Remove the secrets that were added by pool_defined but leave the
others in place.

* virt.init: cdrom format default to raw

cdrom sources can't be of format qcow2. Force raw as the default if
needed when creating VM with source_file set for the cdrom.

* virt.init: fix disk target names

Fixes issue #57477.

* virt.update: handle changing cdrom images for devices with remote source

When a DVD device on a VM has a remote source, virt.update needs to be
able to handle detaching it and attaching a file image live.

* virt.init: fix the name of volumes reused in disk-types pools

Only compute the partition name if no source_file was provided by the
user for a pool of disk type.

Co-authored-by: Blacken Salt <jenkins@saltstack.com>
Co-authored-by: Firefly <leevn2011@hotmail.com>
Co-authored-by: Jeroen Schutrup <jeroenschutrup@hotmail.nl>
Co-authored-by: ch3ll <megan.wilhite@gmail.com>
@meaksh meaksh merged commit de6c0e0 into openSUSE:openSUSE-3000.3 Sep 1, 2020
@cbosdo cbosdo deleted the openSUSE-3000.3-missing-virt branch September 1, 2020 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants