zbuilder 0.0.70__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. {zbuilder-0.0.70 → zbuilder-0.2.0}/PKG-INFO +46 -21
  2. zbuilder-0.2.0/README.md +67 -0
  3. {zbuilder-0.0.70 → zbuilder-0.2.0}/pyproject.toml +33 -15
  4. {zbuilder-0.0.70 → zbuilder-0.2.0}/pyproject.toml.orig +50 -15
  5. zbuilder-0.2.0/src/zbuilder/base.py +115 -0
  6. {zbuilder-0.0.70 → zbuilder-0.2.0}/src/zbuilder/cli.py +4 -3
  7. {zbuilder-0.0.70 → zbuilder-0.2.0}/src/zbuilder/dns/__init__.py +6 -23
  8. {zbuilder-0.0.70 → zbuilder-0.2.0}/src/zbuilder/dns/ansible.py +2 -3
  9. {zbuilder-0.0.70 → zbuilder-0.2.0}/src/zbuilder/dns/aws.py +4 -1
  10. {zbuilder-0.0.70 → zbuilder-0.2.0}/src/zbuilder/dns/bind.py +4 -2
  11. {zbuilder-0.0.70 → zbuilder-0.2.0}/src/zbuilder/dns/gcp.py +16 -4
  12. {zbuilder-0.0.70 → zbuilder-0.2.0}/src/zbuilder/dns/powerdns.py +4 -2
  13. {zbuilder-0.0.70 → zbuilder-0.2.0}/src/zbuilder/helpers.py +10 -11
  14. {zbuilder-0.0.70 → zbuilder-0.2.0}/src/zbuilder/ipam/__init__.py +6 -28
  15. {zbuilder-0.0.70 → zbuilder-0.2.0}/src/zbuilder/ipam/phpipam.py +4 -2
  16. zbuilder-0.2.0/src/zbuilder/plugins.py +38 -0
  17. zbuilder-0.2.0/src/zbuilder/vm/__init__.py +8 -0
  18. {zbuilder-0.0.70 → zbuilder-0.2.0}/src/zbuilder/vm/aws.py +3 -14
  19. {zbuilder-0.0.70 → zbuilder-0.2.0}/src/zbuilder/vm/gcp.py +29 -9
  20. zbuilder-0.2.0/src/zbuilder/vm/kvm.py +753 -0
  21. {zbuilder-0.0.70 → zbuilder-0.2.0}/src/zbuilder/vm/proxmox.py +34 -6
  22. zbuilder-0.0.70/README.md +0 -40
  23. zbuilder-0.0.70/src/zbuilder/dns/azure.py +0 -52
  24. zbuilder-0.0.70/src/zbuilder/dns/do.py +0 -43
  25. zbuilder-0.0.70/src/zbuilder/dns/vagrant.py +0 -9
  26. zbuilder-0.0.70/src/zbuilder/vm/__init__.py +0 -71
  27. zbuilder-0.0.70/src/zbuilder/vm/azure.py +0 -263
  28. zbuilder-0.0.70/src/zbuilder/vm/do.py +0 -183
  29. zbuilder-0.0.70/src/zbuilder/vm/ganeti.py +0 -177
  30. zbuilder-0.0.70/src/zbuilder/vm/vagrant.py +0 -197
  31. zbuilder-0.0.70/src/zbuilder/wrappers.py +0 -13
  32. {zbuilder-0.0.70 → zbuilder-0.2.0}/LICENSE +0 -0
  33. {zbuilder-0.0.70 → zbuilder-0.2.0}/src/zbuilder/__init__.py +0 -0
  34. {zbuilder-0.0.70 → zbuilder-0.2.0}/src/zbuilder/cfg.py +0 -0
  35. {zbuilder-0.0.70 → zbuilder-0.2.0}/src/zbuilder/options.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zbuilder
3
- Version: 0.0.70
3
+ Version: 0.2.0
4
4
  Summary: Create VMs
5
5
  Author: Nikos Chasiotis
6
6
  Author-email: Nikos Chasiotis <hasiotis@gmail.com>
@@ -23,45 +23,46 @@ Requires-Dist: arrow>=1.1,<2
23
23
  Requires-Dist: pyjwt>=2.5.0,<3
24
24
  Requires-Dist: dpath>=2.0,<3
25
25
  Requires-Dist: dnspython>=2,<3
26
- Requires-Dist: google-auth-oauthlib>=0.4,<1.5
27
- Requires-Dist: oauthlib>=3.2.1,<4
28
- Requires-Dist: azure-mgmt-resource>=18.0,<27
29
- Requires-Dist: azure-mgmt-network>=19.0,<33
30
- Requires-Dist: azure-mgmt-compute>=21.0,<39
31
- Requires-Dist: azure-mgmt-dns>=8.0,<10
32
- Requires-Dist: msrestazure>=0.6.4,<0.7
33
- Requires-Dist: python-digitalocean>=1.16,<2
34
- Requires-Dist: proxmoxer>=1.1,<3
35
26
  Requires-Dist: ansible>=14.3.1,<15
36
- Requires-Dist: google-api-python-client>=2.198.0,<3
37
- Requires-Dist: google-cloud-dns>=0.37.0,<0.38
38
27
  Requires-Dist: setuptools>=84.0.0,<85
39
28
  Requires-Dist: massedit>=0.71.0
40
29
  Requires-Dist: ruamel-yaml>=0.19.1
41
30
  Requires-Dist: boto3>=1.43.73
42
31
  Requires-Dist: tabulate>=0.10.0
32
+ Requires-Dist: libvirt-python>=11,<12
33
+ Requires-Dist: pycdlib>=1.14,<2
34
+ Requires-Dist: google-auth-oauthlib>=0.4,<1.5 ; extra == 'gcp'
35
+ Requires-Dist: oauthlib>=3.2.1,<4 ; extra == 'gcp'
36
+ Requires-Dist: google-api-python-client>=2.198.0,<3 ; extra == 'gcp'
37
+ Requires-Dist: google-cloud-dns>=0.37.0,<0.38 ; extra == 'gcp'
38
+ Requires-Dist: proxmoxer>=1.1,<3 ; extra == 'proxmox'
43
39
  Requires-Python: >=3.12, <4
44
40
  Project-URL: Repository, https://github.com/hasiotis/zbuilder
41
+ Provides-Extra: gcp
42
+ Provides-Extra: proxmox
45
43
  Description-Content-Type: text/markdown
46
44
 
47
45
  # Zbuilder: Building VMs and applying ansible playbooks
48
46
 
49
47
  [![PyPi version](https://badge.fury.io/py/zbuilder.svg)](https://pypi.org/project/zbuilder/)
50
48
  [![PyPi downloads](https://img.shields.io/pypi/dm/zbuilder.svg)](https://pypistats.org/packages/zbuilder)
51
- [![Build status](https://github.com/hasiotis/zbuilder/workflows/Merge%20to%20master/badge.svg)](https://github.com/hasiotis/zbuilder/actions?query=workflow%3A%22Merge+to+master%22)
52
- [![Documentation Status](https://readthedocs.org/projects/zbuilder/badge/?version=stable)](https://zbuilder.readthedocs.io/en/develop/?badge=develop)
49
+ [![Build status](https://github.com/hasiotis/zbuilder/workflows/master/badge.svg)](https://github.com/hasiotis/zbuilder/actions?query=workflow%3A%22master%22)
50
+ [![Documentation Status](https://readthedocs.org/projects/zbuilder/badge/?version=stable)](https://zbuilder.readthedocs.io/en/stable/?badge=stable)
53
51
  [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://github.com/hasiotis/zbuilder/blob/master/LICENSE)
54
52
 
55
- ZBuilder is a tool to help you build VMs ready to be transfered to ansible.
53
+ ZBuilder is a tool to help you build VMs ready to be transferred to ansible.
56
54
  By using ansible as a library, it has access to all ansible variables. This
57
55
  way it achieves high integration with ansible.
58
56
 
59
57
  ## Installation
60
58
 
59
+ zbuilder depends on the libvirt python bindings, which compile against the
60
+ libvirt headers, so install those first:
61
+ ```
62
+ apt install libvirt-dev pkg-config gcc # or: dnf install libvirt-devel
63
+ ```
61
64
 
62
- ## Installation
63
-
64
- Install with:
65
+ Then install with:
65
66
  ```
66
67
  pipx install --force zbuilder
67
68
  ```
@@ -72,15 +73,39 @@ or
72
73
  pip3 install --user --upgrade zbuilder
73
74
  ```
74
75
 
76
+ The `gcp` provider needs the google client libraries, which ship as an extra:
77
+ ```
78
+ pipx install --force 'zbuilder[gcp]'
79
+ ```
80
+
81
+ The `proxmox` provider needs `proxmoxer`, which ships as an extra:
82
+ ```
83
+ pipx install --force 'zbuilder[proxmox]'
84
+ ```
85
+
86
+ ## Providers
87
+
88
+ | Family | Providers |
89
+ |---|---|
90
+ | VM | `aws`, `gcp`, `kvm`, `proxmox` |
91
+ | DNS | `ansible`, `aws`, `bind`, `gcp`, `powerdns` |
92
+ | IPAM | `phpipam` |
93
+
94
+ See the [documentation](https://zbuilder.readthedocs.io/en/stable/) for the
95
+ settings each one accepts, or run `zbuilder providers`.
96
+
75
97
  ## Development
76
98
  During development you can:
77
99
  ```
78
100
  uv sync
79
101
  . .venv/bin/activate
102
+
103
+ uv run pytest # run the tests
104
+ prek run --all-files # lint and format
80
105
  ```
81
106
 
82
107
  ## Links
83
108
 
84
- * [Documentation](https://zbuilder.readthedocs.io/en/stable/?badge=stable)
85
- * [Releases](https://pypi.org/project/zbuilder/)
86
- * [Code](https://github.com/hasiotis/zbuilder)
109
+ [Documentation](https://zbuilder.readthedocs.io/en/stable/?badge=stable)
110
+ | [Releases](https://pypi.org/project/zbuilder/)
111
+ | [Code](https://github.com/hasiotis/zbuilder)
@@ -0,0 +1,67 @@
1
+ # Zbuilder: Building VMs and applying ansible playbooks
2
+
3
+ [![PyPi version](https://badge.fury.io/py/zbuilder.svg)](https://pypi.org/project/zbuilder/)
4
+ [![PyPi downloads](https://img.shields.io/pypi/dm/zbuilder.svg)](https://pypistats.org/packages/zbuilder)
5
+ [![Build status](https://github.com/hasiotis/zbuilder/workflows/master/badge.svg)](https://github.com/hasiotis/zbuilder/actions?query=workflow%3A%22master%22)
6
+ [![Documentation Status](https://readthedocs.org/projects/zbuilder/badge/?version=stable)](https://zbuilder.readthedocs.io/en/stable/?badge=stable)
7
+ [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://github.com/hasiotis/zbuilder/blob/master/LICENSE)
8
+
9
+ ZBuilder is a tool to help you build VMs ready to be transferred to ansible.
10
+ By using ansible as a library, it has access to all ansible variables. This
11
+ way it achieves high integration with ansible.
12
+
13
+ ## Installation
14
+
15
+ zbuilder depends on the libvirt python bindings, which compile against the
16
+ libvirt headers, so install those first:
17
+ ```
18
+ apt install libvirt-dev pkg-config gcc # or: dnf install libvirt-devel
19
+ ```
20
+
21
+ Then install with:
22
+ ```
23
+ pipx install --force zbuilder
24
+ ```
25
+
26
+ or
27
+
28
+ ```
29
+ pip3 install --user --upgrade zbuilder
30
+ ```
31
+
32
+ The `gcp` provider needs the google client libraries, which ship as an extra:
33
+ ```
34
+ pipx install --force 'zbuilder[gcp]'
35
+ ```
36
+
37
+ The `proxmox` provider needs `proxmoxer`, which ships as an extra:
38
+ ```
39
+ pipx install --force 'zbuilder[proxmox]'
40
+ ```
41
+
42
+ ## Providers
43
+
44
+ | Family | Providers |
45
+ |---|---|
46
+ | VM | `aws`, `gcp`, `kvm`, `proxmox` |
47
+ | DNS | `ansible`, `aws`, `bind`, `gcp`, `powerdns` |
48
+ | IPAM | `phpipam` |
49
+
50
+ See the [documentation](https://zbuilder.readthedocs.io/en/stable/) for the
51
+ settings each one accepts, or run `zbuilder providers`.
52
+
53
+ ## Development
54
+ During development you can:
55
+ ```
56
+ uv sync
57
+ . .venv/bin/activate
58
+
59
+ uv run pytest # run the tests
60
+ prek run --all-files # lint and format
61
+ ```
62
+
63
+ ## Links
64
+
65
+ [Documentation](https://zbuilder.readthedocs.io/en/stable/?badge=stable)
66
+ | [Releases](https://pypi.org/project/zbuilder/)
67
+ | [Code](https://github.com/hasiotis/zbuilder)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "zbuilder"
3
- version = "0.0.70"
3
+ version = "0.2.0"
4
4
  description = "Create VMs"
5
5
  license = "GPL-3.0-or-later"
6
6
  license-files = ["LICENSE"]
@@ -26,41 +26,54 @@ dependencies = [
26
26
  "PyJWT>=2.5.0,<3",
27
27
  "dpath>=2.0,<3",
28
28
  "dnspython>=2,<3",
29
- "google-auth-oauthlib>=0.4,<1.5",
30
- "oauthlib>=3.2.1,<4",
31
- "azure-mgmt-resource>=18.0,<27",
32
- "azure-mgmt-network>=19.0,<33",
33
- "azure-mgmt-compute>=21.0,<39",
34
- "azure-mgmt-dns>=8.0,<10",
35
- "msrestazure>=0.6.4,<0.7",
36
- "python-digitalocean>=1.16,<2",
37
- "proxmoxer>=1.1,<3",
38
29
  "ansible>=14.3.1,<15",
39
- "google-api-python-client>=2.198.0,<3",
40
- "google-cloud-dns>=0.37.0,<0.38",
41
30
  "setuptools>=84.0.0,<85",
42
31
  "massedit>=0.71.0",
43
32
  "ruamel-yaml>=0.19.1",
44
33
  "boto3>=1.43.73",
45
34
  "tabulate>=0.10.0",
35
+ "libvirt-python>=11,<12",
36
+ "pycdlib>=1.14,<2",
46
37
  ]
47
38
 
48
39
  [[project.authors]]
49
40
  name = "Nikos Chasiotis"
50
41
  email = "hasiotis@gmail.com"
51
42
 
43
+ [project.optional-dependencies]
44
+ gcp = [
45
+ "google-auth-oauthlib>=0.4,<1.5",
46
+ "oauthlib>=3.2.1,<4",
47
+ "google-api-python-client>=2.198.0,<3",
48
+ "google-cloud-dns>=0.37.0,<0.38",
49
+ ]
50
+ proxmox = ["proxmoxer>=1.1,<3"]
51
+
52
52
  [project.urls]
53
53
  Repository = "https://github.com/hasiotis/zbuilder"
54
54
 
55
55
  [project.scripts]
56
56
  zbuilder = "zbuilder.cli:cli"
57
57
 
58
+ [project.entry-points."zbuilder.vm"]
59
+ aws = "zbuilder.vm.aws:vmProvider"
60
+ gcp = "zbuilder.vm.gcp:vmProvider"
61
+ kvm = "zbuilder.vm.kvm:vmProvider"
62
+ proxmox = "zbuilder.vm.proxmox:vmProvider"
63
+
64
+ [project.entry-points."zbuilder.dns"]
65
+ ansible = "zbuilder.dns.ansible:dnsProvider"
66
+ aws = "zbuilder.dns.aws:dnsProvider"
67
+ bind = "zbuilder.dns.bind:dnsProvider"
68
+ gcp = "zbuilder.dns.gcp:dnsProvider"
69
+ powerdns = "zbuilder.dns.powerdns:dnsProvider"
70
+
71
+ [project.entry-points."zbuilder.ipam"]
72
+ phpipam = "zbuilder.ipam.phpipam:ipamProvider"
73
+
58
74
  [dependency-groups]
59
75
  dev = [
60
- "pylint>=2,<3",
61
- "pre-commit>=2.13.0,<3",
62
76
  "pytest>=9.1.1,<10",
63
- "pytest-cov>=7.1.0,<8",
64
77
  "pytest-md-report>=0.8.0",
65
78
  ]
66
79
  docs = ["sphinx>=7.2.6,<8"]
@@ -68,6 +81,11 @@ docs = ["sphinx>=7.2.6,<8"]
68
81
  [tool.uv]
69
82
  default-groups = ["dev"]
70
83
 
84
+ [[tool.uv.dependency-metadata]]
85
+ name = "libvirt-python"
86
+ version = "11.10.0"
87
+ requires-dist = []
88
+
71
89
  [tool.ruff]
72
90
  line-length = 120
73
91
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "zbuilder"
3
- version = "0.0.70"
3
+ version = "0.2.0"
4
4
  description = "Create VMs"
5
5
  authors = [{ name = "Nikos Chasiotis", email = "hasiotis@gmail.com" }]
6
6
  license = "GPL-3.0-or-later"
@@ -27,23 +27,33 @@ dependencies = [
27
27
  "PyJWT>=2.5.0,<3",
28
28
  "dpath>=2.0,<3",
29
29
  "dnspython>=2,<3",
30
- "google-auth-oauthlib>=0.4,<1.5",
31
- "oauthlib>=3.2.1,<4",
32
- "azure-mgmt-resource>=18.0,<27",
33
- "azure-mgmt-network>=19.0,<33",
34
- "azure-mgmt-compute>=21.0,<39",
35
- "azure-mgmt-dns>=8.0,<10",
36
- "msrestazure>=0.6.4,<0.7",
37
- "python-digitalocean>=1.16,<2",
38
- "proxmoxer>=1.1,<3",
39
30
  "ansible>=14.3.1,<15",
40
- "google-api-python-client>=2.198.0,<3",
41
- "google-cloud-dns>=0.37.0,<0.38",
42
31
  "setuptools>=84.0.0,<85",
43
32
  "massedit>=0.71.0",
44
33
  "ruamel-yaml>=0.19.1",
45
34
  "boto3>=1.43.73",
46
35
  "tabulate>=0.10.0",
36
+ # The kvm provider. libvirt-python compiles against libvirt-dev, which has
37
+ # to be present before `uv sync` - see the dependency-metadata block below.
38
+ "libvirt-python>=11,<12",
39
+ "pycdlib>=1.14,<2",
40
+ ]
41
+
42
+ [project.optional-dependencies]
43
+ # The gcp providers (vm and dns) pull in the whole google client stack, which
44
+ # is a large dependency tree nobody outside GCP needs. zbuilder/vm/gcp.py and
45
+ # zbuilder/dns/gcp.py import it lazily and say what to install when missing.
46
+ gcp = [
47
+ "google-auth-oauthlib>=0.4,<1.5",
48
+ "oauthlib>=3.2.1,<4",
49
+ "google-api-python-client>=2.198.0,<3",
50
+ "google-cloud-dns>=0.37.0,<0.38",
51
+ ]
52
+ # The proxmox provider talks to PVE through proxmoxer, which nobody outside a
53
+ # proxmox cluster needs. zbuilder/vm/proxmox.py imports it lazily and says what
54
+ # to install when it is missing.
55
+ proxmox = [
56
+ "proxmoxer>=1.1,<3",
47
57
  ]
48
58
 
49
59
  [project.urls]
@@ -52,12 +62,27 @@ Repository = "https://github.com/hasiotis/zbuilder"
52
62
  [project.scripts]
53
63
  zbuilder = "zbuilder.cli:cli"
54
64
 
65
+ # Provider plugins. Discovered at runtime by zbuilder.plugins, so an external
66
+ # distribution can register providers under the same groups.
67
+ [project.entry-points."zbuilder.vm"]
68
+ aws = "zbuilder.vm.aws:vmProvider"
69
+ gcp = "zbuilder.vm.gcp:vmProvider"
70
+ kvm = "zbuilder.vm.kvm:vmProvider"
71
+ proxmox = "zbuilder.vm.proxmox:vmProvider"
72
+
73
+ [project.entry-points."zbuilder.dns"]
74
+ ansible = "zbuilder.dns.ansible:dnsProvider"
75
+ aws = "zbuilder.dns.aws:dnsProvider"
76
+ bind = "zbuilder.dns.bind:dnsProvider"
77
+ gcp = "zbuilder.dns.gcp:dnsProvider"
78
+ powerdns = "zbuilder.dns.powerdns:dnsProvider"
79
+
80
+ [project.entry-points."zbuilder.ipam"]
81
+ phpipam = "zbuilder.ipam.phpipam:ipamProvider"
82
+
55
83
  [dependency-groups]
56
84
  dev = [
57
- "pylint>=2,<3",
58
- "pre-commit>=2.13.0,<3",
59
85
  "pytest>=9.1.1,<10",
60
- "pytest-cov>=7.1.0,<8",
61
86
  "pytest-md-report>=0.8.0",
62
87
  ]
63
88
  docs = [
@@ -67,6 +92,16 @@ docs = [
67
92
  [tool.uv]
68
93
  default-groups = ["dev"]
69
94
 
95
+ # libvirt-python ships as an sdist whose setup.py shells out to `pkg-config
96
+ # libvirt`, so uv cannot even read its metadata without libvirt-dev installed
97
+ # and `uv lock` fails on a machine that has no libvirt at all - CI included.
98
+ # Declaring the metadata here keeps resolution static; the package is still
99
+ # built the normal way at install time, which does need the libvirt headers.
100
+ [[tool.uv.dependency-metadata]]
101
+ name = "libvirt-python"
102
+ version = "11.10.0"
103
+ requires-dist = []
104
+
70
105
  [build-system]
71
106
  requires = ["uv_build>=0.12.5,<0.13.0"]
72
107
  build-backend = "uv_build"
@@ -0,0 +1,115 @@
1
+ """Base classes for provider plugins.
2
+
3
+ Every provider subclasses the base class of its family, and that base class is
4
+ the contract: `@abstractmethod` marks the actions a provider must implement,
5
+ the concrete methods are the defaults for the actions it may skip.
6
+ """
7
+
8
+ from abc import ABC, abstractmethod
9
+
10
+ import click
11
+
12
+
13
+ class UnsupportedAction(click.ClickException):
14
+ """Raised when a provider does not implement an optional action"""
15
+
16
+ def __init__(self, provider, action):
17
+ super().__init__("Provider [{}] does not implement action [{}]".format(provider, action))
18
+
19
+
20
+ class Provider(ABC):
21
+ """Common behaviour of every provider plugin"""
22
+
23
+ #: Entry point name the provider was loaded as, set by the loader facades
24
+ factory = None
25
+
26
+ def __init__(self, cfg=None):
27
+ self.cfg = cfg
28
+
29
+ def _unsupported(self, action):
30
+ """Report an action this provider does not support"""
31
+ raise UnsupportedAction(self.factory or type(self).__module__.rpartition(".")[2], action)
32
+
33
+ def config(self):
34
+ """Human readable summary of the credentials in use"""
35
+ self._unsupported("config")
36
+
37
+ def status(self):
38
+ """Either "PASS" or the reason the provider is not usable"""
39
+ self._unsupported("status")
40
+
41
+
42
+ class VMProvider(Provider):
43
+ """A cloud able to create and manage VMs"""
44
+
45
+ @abstractmethod
46
+ def build(self, hosts):
47
+ """Create the enabled hosts"""
48
+
49
+ @abstractmethod
50
+ def up(self, hosts):
51
+ """Boot the enabled hosts"""
52
+
53
+ @abstractmethod
54
+ def halt(self, hosts):
55
+ """Shut down the enabled hosts"""
56
+
57
+ @abstractmethod
58
+ def destroy(self, hosts):
59
+ """Delete the enabled hosts"""
60
+
61
+ def dnsupdate(self, hosts):
62
+ """Publish the DNS records of the enabled hosts"""
63
+ self._unsupported("dnsupdate")
64
+
65
+ def dnsremove(self, hosts):
66
+ """Withdraw the DNS records of the enabled hosts"""
67
+ self._unsupported("dnsremove")
68
+
69
+ def snapCreate(self, hosts):
70
+ """Snapshot the enabled hosts"""
71
+ self._unsupported("snapCreate")
72
+
73
+ def snapRestore(self, hosts):
74
+ """Restore the enabled hosts from their snapshot"""
75
+ self._unsupported("snapRestore")
76
+
77
+ def snapDelete(self, hosts):
78
+ """Delete the snapshot of the enabled hosts"""
79
+ self._unsupported("snapDelete")
80
+
81
+ def params(self, params):
82
+ """The VM options of a host, as shown by the summary"""
83
+ self._unsupported("params")
84
+
85
+ def enabled(self):
86
+ """Whether the provider can be used on this machine"""
87
+ return True
88
+
89
+
90
+ class DNSProvider(Provider):
91
+ """A DNS zone able to hold the records of the VMs"""
92
+
93
+ @abstractmethod
94
+ def update(self, host, zone, ip):
95
+ """Point the A record of `host` in `zone` to `ip`"""
96
+
97
+ @abstractmethod
98
+ def remove(self, host, zone):
99
+ """Drop the A record of `host` in `zone`"""
100
+
101
+
102
+ class IPAMProvider(Provider):
103
+ """An IPAM able to hand out addresses of the subnets of the VMs"""
104
+
105
+ @abstractmethod
106
+ def reserve(self, host, subnet):
107
+ """Reserve an address of `subnet` for `host` and return it"""
108
+
109
+ @abstractmethod
110
+ def locate(self, host, subnet):
111
+ """Return the address of `subnet` already reserved for `host`"""
112
+
113
+ @abstractmethod
114
+ def release(self, host, ip, subnet):
115
+ """Give the address of `host` back to `subnet`"""
@@ -8,6 +8,7 @@ import distutils.dir_util
8
8
 
9
9
  import zbuilder.vm
10
10
  import zbuilder.cfg
11
+ import zbuilder.plugins
11
12
 
12
13
  from zbuilder.helpers import (
13
14
  getHosts,
@@ -307,11 +308,11 @@ def update(state, yes):
307
308
  def plugins(state):
308
309
  """Autocomplete for bash"""
309
310
  click.echo("List of available vm plugins")
310
- for plugin in ["vagrant", "gcp", "aws", "do", "azure", "proxmox", "ganeti"]:
311
+ for plugin in zbuilder.plugins.names(zbuilder.plugins.VM):
311
312
  try:
312
313
  p = zbuilder.vm.vmProvider(plugin)
313
- p.enabled()
314
- click.echo(f" - {plugin:8}: enabled")
314
+ if p.enabled():
315
+ click.echo(f" - {plugin:8}: enabled")
315
316
  except Exception:
316
317
  pass
317
318
 
@@ -1,10 +1,9 @@
1
1
  import time
2
2
  import click
3
- import importlib
4
3
  import dns.resolver
5
4
 
6
5
  import zbuilder.cfg
7
- from zbuilder.wrappers import trywrap
6
+ import zbuilder.plugins
8
7
 
9
8
 
10
9
  def waitDNS(hostname, ip):
@@ -71,24 +70,8 @@ def dnsRemove(hosts):
71
70
  click.echo("No DNS provider found for zone [{}]".format(zone))
72
71
 
73
72
 
74
- class dnsProvider(object):
75
- def __init__(self, factory, cfg=None):
76
- self.factory = factory
77
- dnsProviderClass = getattr(importlib.import_module("zbuilder.dns.%s" % factory), "dnsProvider")
78
- self.provider = dnsProviderClass(cfg)
79
-
80
- @trywrap
81
- def update(self, host, zone, ip):
82
- self.provider.update(host, zone, ip)
83
-
84
- @trywrap
85
- def remove(self, host, zone):
86
- self.provider.remove(host, zone)
87
-
88
- @trywrap
89
- def config(self):
90
- return self.provider.config()
91
-
92
- @trywrap
93
- def status(self):
94
- return self.provider.status()
73
+ def dnsProvider(factory, cfg=None):
74
+ """Instantiate the DNS provider registered as `factory`"""
75
+ provider = zbuilder.plugins.load(zbuilder.plugins.DNS, factory)(cfg)
76
+ provider.factory = factory
77
+ return provider
@@ -1,11 +1,10 @@
1
1
  import click
2
2
  import massedit
3
3
 
4
+ from zbuilder.base import DNSProvider
4
5
 
5
- class dnsProvider(object):
6
- def __init__(self, state):
7
- self.state = state
8
6
 
7
+ class dnsProvider(DNSProvider):
9
8
  def update(self, host, zone, ip):
10
9
  click.echo(" - Updating record [{}.{}] with ip [{}]".format(host, zone, ip))
11
10
  filenames = ["hosts"]
@@ -1,9 +1,12 @@
1
1
  import click
2
2
  import boto3
3
3
 
4
+ from zbuilder.base import DNSProvider
4
5
 
5
- class dnsProvider(object):
6
+
7
+ class dnsProvider(DNSProvider):
6
8
  def __init__(self, cfg):
9
+ super().__init__(cfg)
7
10
  if cfg:
8
11
  if "aws_access_key_id" and "aws_access_key_id" in cfg:
9
12
  self.route53 = boto3.client(
@@ -3,11 +3,13 @@ import dns.query
3
3
  import dns.tsigkeyring
4
4
  import dns.update
5
5
 
6
+ from zbuilder.base import DNSProvider
6
7
 
7
- class dnsProvider(object):
8
+
9
+ class dnsProvider(DNSProvider):
8
10
  def __init__(self, cfg):
11
+ super().__init__(cfg)
9
12
  if cfg:
10
- self.cfg = cfg
11
13
  self.keyname = cfg["keyname"]
12
14
  self.keysecret = cfg["keysecret"]
13
15
  self.server = cfg["server"]
@@ -1,18 +1,30 @@
1
+ """GCP DNS provider.
2
+
3
+ Like the gcp vm provider, the google client stack is an optional extra
4
+ (`zbuilder[gcp]`) imported lazily, so this module imports without it.
5
+ """
6
+
1
7
  import time
2
8
  import click
3
9
 
4
10
 
5
- from zbuilder.vm.gcp import auth
6
- from google.cloud import dns
11
+ from zbuilder.base import DNSProvider
12
+ from zbuilder.vm.gcp import auth, require
13
+
14
+ try:
15
+ from google.cloud import dns
16
+ except ImportError: # installed without the gcp extra
17
+ dns = None
7
18
 
8
19
 
9
20
  DNS_TTL = 60 * 10 # 10 mins
10
21
 
11
22
 
12
- class dnsProvider(object):
23
+ class dnsProvider(DNSProvider):
13
24
  def __init__(self, cfg):
25
+ super().__init__(cfg)
14
26
  if cfg:
15
- self.cfg = cfg
27
+ require(dns, "google-cloud-dns")
16
28
  creds = auth(self.cfg)
17
29
 
18
30
  try:
@@ -1,11 +1,13 @@
1
1
  import click
2
2
  import requests
3
3
 
4
+ from zbuilder.base import DNSProvider
4
5
 
5
- class dnsProvider(object):
6
+
7
+ class dnsProvider(DNSProvider):
6
8
  def __init__(self, cfg):
9
+ super().__init__(cfg)
7
10
  if cfg:
8
- self.cfg = cfg
9
11
  self.apikey = self.cfg["apikey"]
10
12
  self.url = self.cfg["url"] + "api/v1"
11
13