forked from meffie/molecule-proxmox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
621 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
*.pyc | ||
*.pyo | ||
*.pyd | ||
*.egg-info/ | ||
__pycache__/ | ||
.*/ | ||
dist/ | ||
build/ | ||
|
||
# test artifacts | ||
.env.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
# Based on ansible-lint config | ||
extends: default | ||
|
||
rules: | ||
braces: | ||
max-spaces-inside: 1 | ||
level: error | ||
brackets: | ||
max-spaces-inside: 1 | ||
level: error | ||
colons: | ||
max-spaces-after: -1 | ||
level: error | ||
commas: | ||
max-spaces-after: -1 | ||
level: error | ||
comments: disable | ||
comments-indentation: disable | ||
document-start: disable | ||
empty-lines: | ||
max: 3 | ||
level: error | ||
hyphens: | ||
level: error | ||
indentation: disable | ||
key-duplicates: enable | ||
line-length: disable | ||
new-line-at-end-of-file: disable | ||
new-lines: | ||
type: unix | ||
trailing-spaces: disable | ||
truthy: disable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
graft src/molecule_proxmox | ||
global-exclude *.pyc *.pyo *.pyd __pycache__ *.so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
|
||
.PHONY: help init lint import test sdist wheel rpm deb upload clean distclean | ||
|
||
PYTHON3=python3 | ||
BIN=.venv/bin | ||
PIP=$(BIN)/pip | ||
PYTHON=$(BIN)/python | ||
PYFLAKES=$(BIN)/pyflakes | ||
YAMLLINT=$(BIN)/yamllint | ||
PYTEST=$(BIN)/pytest | ||
TWINE=$(BIN)/twine | ||
|
||
help: | ||
@echo "usage: make <target>" | ||
@echo "" | ||
@echo "targets:" | ||
@echo " init create python virtual env" | ||
@echo " lint run linter" | ||
@echo " import import external ansible roles" | ||
@echo " test run tests" | ||
@echo " sdist create source distribution" | ||
@echo " wheel create wheel distribution" | ||
@echo " rpm create rpm package" | ||
@echo " deb create deb package" | ||
@echo " upload upload to pypi.org" | ||
@echo " clean remove generated files" | ||
@echo " distclean remove generated files and virtual env" | ||
|
||
.venv: | ||
$(PYTHON3) -m venv .venv | ||
$(PIP) install -U pip | ||
$(PIP) install wheel | ||
$(PIP) install pyflakes pylint yamllint pytest collective.checkdocs twine | ||
$(PIP) install molecule[ansible] | ||
$(PIP) install -e . | ||
|
||
init: .venv | ||
|
||
lint: init | ||
$(PYFLAKES) src/*/*.py | ||
$(PYFLAKES) tests/*.py | ||
$(YAMLLINT) src/*/playbooks/*.yml | ||
$(YAMLLINT) tests/molecule/*/*.yml | ||
$(PYTHON) setup.py -q checkdocs | ||
|
||
check test: init lint | ||
. .venv/bin/activate && pytest -v $(T) tests | ||
|
||
sdist: init | ||
$(PYTHON) setup.py sdist | ||
|
||
wheel: init | ||
$(PYTHON) setup.py bdist_wheel | ||
|
||
rpm: init | ||
$(PYTHON) setup.py bdist_rpm | ||
|
||
deb: init | ||
$(PYTHON) setup.py --command-packages=stdeb.command bdist_deb | ||
|
||
upload: init sdist wheel | ||
$(TWINE) upload dist/* | ||
|
||
clean: | ||
rm -rf .pytest_cache | ||
rm -rf src/*/__pycache__ | ||
rm -rf tests/__pycache__ | ||
rm -rf tests/molecule/*/library/__pycache__/ | ||
rm -rf build dist | ||
|
||
distclean: clean | ||
rm -rf .eggs *.egg-info src/*.egg-info | ||
rm -rf .venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import setuptools | ||
import re | ||
|
||
name = 'molecule-proxmox' | ||
description='Proxmox Molecule Plugin :: run molecule tests using proxmox' | ||
|
||
def find_version(): | ||
text = open('src/%s/__init__.py' % name.replace('-', '_')).read() | ||
return re.search(r"__version__\s*=\s*'(.*)'", text).group(1) | ||
|
||
setuptools.setup( | ||
name=name, | ||
version=find_version(), | ||
author='Michael Meffie', | ||
author_email='[email protected]', | ||
description=description, | ||
long_description=open('README.rst').read(), | ||
long_description_content_type='text/x-rst', | ||
url='https://github.com/meffie/molecule-proxmox', | ||
packages=setuptools.find_packages(where='src'), | ||
package_dir={'': 'src'}, | ||
include_package_data=True, | ||
entry_points={ | ||
'molecule.driver': [ | ||
'proxmox = molecule_proxmox.driver:Proxmox', | ||
], | ||
}, | ||
install_requires=[ | ||
# molecule plugins are not allowed to mention Ansible as a direct dependency | ||
'molecule>=3.2.0', | ||
'pyyaml>=5.1,<6', | ||
'proxmoxer', | ||
], | ||
classifiers=[ | ||
'Programming Language :: Python :: 3', | ||
'License :: OSI Approved :: MIT License', | ||
'Operating System :: OS Independent', | ||
], | ||
python_requires='>=3.6', | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ = '0.1.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"molecule_directory": "molecule", | ||
"role_name": "OVERRIDDEN", | ||
"scenario_name": "OVERRIDDEN" | ||
} |
11 changes: 11 additions & 0 deletions
11
.../{{cookiecutter.molecule_directory}}/{{cookiecutter.scenario_name}}/INSTALL.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
*********************** | ||
Molecule Proxmox Plugin | ||
*********************** | ||
|
||
Requires | ||
======== | ||
|
||
|
||
Example | ||
======= | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
# Copyright (c) 2022 Sine Nomine Associates | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to | ||
# deal in the Software without restriction, including without limitation the | ||
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
# sell copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
# DEALINGS IN THE SOFTWARE. | ||
|
||
import os | ||
|
||
from molecule import logger | ||
from molecule import util | ||
from molecule.api import Driver | ||
|
||
|
||
LOG = logger.get_logger(__name__) | ||
|
||
|
||
class Proxmox(Driver): | ||
""" | ||
The class responsible for managing instances with Proxmox. | ||
.. code-block:: yaml | ||
driver: | ||
name: proxmox | ||
platforms: | ||
- name: instance | ||
template: generic-centos-8 | ||
memory: 1024 | ||
cpus: 1 | ||
.. code-block:: bash | ||
$ pip install molecule-proxmox | ||
""" # noqa | ||
|
||
def __init__(self, config=None): | ||
super(Proxmox, self).__init__(config) | ||
self._name = "proxmox" | ||
|
||
@property | ||
def name(self): | ||
return self._name | ||
|
||
@name.setter | ||
def name(self, value): | ||
self._name = value | ||
|
||
@property | ||
def login_cmd_template(self): | ||
connection_options = " ".join(self.ssh_connection_options) | ||
return ( | ||
"ssh {{address}} " | ||
"-l {{user}} " | ||
"-p {{port}} " | ||
"-i {{identity_file}} " | ||
"{}" | ||
).format(connection_options) | ||
|
||
@property | ||
def default_safe_files(self): | ||
return [] | ||
|
||
@property | ||
def default_ssh_connection_options(self): | ||
return self._get_ssh_connection_options() | ||
|
||
def login_options(self, instance_name): | ||
d = {"instance": instance_name} | ||
return util.merge_dicts(d, self._get_instance_config(instance_name)) | ||
|
||
def ansible_connection_options(self, instance_name): | ||
try: | ||
d = self._get_instance_config(instance_name) | ||
return { | ||
"ansible_user": d["user"], | ||
"ansible_host": d["address"], | ||
"ansible_port": d["port"], | ||
"ansible_private_key_file": d["identity_file"], | ||
"connection": "ssh", | ||
"ansible_ssh_common_args": " ".join(self.ssh_connection_options), | ||
} | ||
except StopIteration: | ||
return {} | ||
except IOError: | ||
# Instance has yet to be provisioned, therefore the | ||
# instance_config is not on disk. | ||
return {} | ||
|
||
def _get_instance_config(self, instance_name): | ||
instance_config_dict = util.safe_load_file(self._config.driver.instance_config) | ||
return next( | ||
item for item in instance_config_dict if item["instance"] == instance_name | ||
) | ||
|
||
def sanity_checks(self): | ||
pass | ||
|
||
def template_dir(self): | ||
"""Return path to its own cookiecutterm templates. It is used by init | ||
command in order to figure out where to load the templates from. | ||
""" | ||
return os.path.join(os.path.dirname(__file__), "cookiecutter") | ||
|
||
def modules_dir(self): | ||
return os.path.join(os.path.dirname(__file__), "modules") |
Empty file.
Oops, something went wrong.