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

[PR #3519/8825ef47 backport][stable-4] LXD inventory: Support virtual machines #3900

Conversation

patchback[bot]
Copy link

@patchback patchback bot commented Dec 13, 2021

This is a backport of PR #3519 as merged into main (8825ef4).

SUMMARY

Adds full compatibility for LXD 4.x. It allows to list containers and VMs

The plugin is already only compatible with LXD 4 (due to a call to /1.0/networks/{interface}/state), this PR adds requirement and VM support

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

lxd inventory plugin

ADDITIONAL INFORMATION

I renamed "container" to "instance" (sed) and fixed some specific needs: L611, L632, L636, L649

My LXD instances:

$ lxc list -c nt volatile.last_state.power="RUNNING"
+----------------+-----------------+
|      NAME      |      TYPE       |
+----------------+-----------------+
| gitlab-runner  | VIRTUAL-MACHINE |
+----------------+-----------------+
| grafana        | CONTAINER       |
+----------------+-----------------+
| home-assistant | VIRTUAL-MACHINE |
+----------------+-----------------+
| influxdb       | CONTAINER       |
+----------------+-----------------+
| mqtt           | CONTAINER       |
+----------------+-----------------+
| mysql          | CONTAINER       |
+----------------+-----------------+
| pi-hole        | CONTAINER       |
+----------------+-----------------+
| sozu           | CONTAINER       |
+----------------+-----------------+
| test           | CONTAINER       |
+----------------+-----------------+
| test-centos8   | CONTAINER       |
+----------------+-----------------+
| test-debian11  | CONTAINER       |
+----------------+-----------------+

Before (containers only):

$ ansible-inventory -i inventory/lxd.yml --playbook-dir ./ --graph
@all:
  |--@ungrouped:
  |  |--grafana
  |  |--influxdb
  |  |--mqtt
  |  |--mysql
  |  |--pi-hole
  |  |--sozu
  |  |--test
  |  |--test-centos8
  |  |--test-debian11

After (containers and VM):

$ ansible-inventory -i inventory/lxd.yml --playbook-dir ./ --graph
@all:
  |--@ungrouped:
  |  |--gitlab-runner
  |  |--grafana
  |  |--home-assistant
  |  |--influxdb
  |  |--mqtt
  |  |--mysql
  |  |--pi-hole
  |  |--sozu
  |  |--test
  |  |--test-centos8
  |  |--test-debian11

* LXD 4.x compatibility (Containers and VMs)

* add changelog fragment

* update fixture

* update plugin options

* backwards compatible alias

Co-authored-by: Felix Fontein <[email protected]>

* Update changelogs/fragments/3519-inventory-support-lxd-4.yml

Co-authored-by: Felix Fontein <[email protected]>

* add lxd 4.0 requirement

* filter for type of virtualization added. due to duplication in the namespace, "type" is not used as the keyword but "nature".

* add type filter

Since the first version of this inventory plugin only supports containers,
a filter function was added to filter between containers and
virtual machines or both.
By default only containers are displayed, as in the first version of the plugin.
This behavior will change in the future.

* rename C(nature) to C(type)

The term "nature" does not fit into the lxd namespace.
Therefore i renamed nature to type.

* update changelog fragment

* Update plugins/inventory/lxd.py

Co-authored-by: Felix Fontein <[email protected]>

* Apply suggestions from code review

Co-authored-by: Felix Fontein <[email protected]>

* rename typefilter to type_filter

* fix tests with type_filter

* Update plugins/inventory/lxd.py

* Update plugins/inventory/lxd.py

Co-authored-by: Felix Fontein <[email protected]>
Co-authored-by: Frank Dornheim <“[email protected]@users.noreply.github.com”>
(cherry picked from commit 8825ef4)
@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added backport feature This issue/PR relates to a feature request inventory inventory plugin new_contributor Help guide this first time contributor plugins plugin (any type) tests tests unit tests/unit labels Dec 13, 2021
@felixfontein felixfontein merged commit 5d6fcae into stable-4 Dec 14, 2021
@felixfontein felixfontein deleted the patchback/backports/stable-4/8825ef4711ab44598f9e480b3d5ea75c608701c8/pr-3519 branch December 14, 2021 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue/PR relates to a feature request inventory inventory plugin new_contributor Help guide this first time contributor plugins plugin (any type) tests tests unit tests/unit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants