Merge "Drop Travis CI support"
diff --git a/LICENSE b/LICENSE
index 6f2b42f..327cc68 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2014-2015 tcp cloud a.s.
+Copyright (c) 2014-2019 Mirantis Inc. et al
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -10,4 +10,4 @@
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
-limitations under the License.
\ No newline at end of file
+limitations under the License.
diff --git a/README.rst b/README.rst
index 2e836bf..2e62556 100644
--- a/README.rst
+++ b/README.rst
@@ -308,7 +308,7 @@
master:
gitfs_remotes:
salt_formula:
- url: https://github.com/salt-formulas/salt-formula-salt.git
+ url: https://gerrit.mcp.mirantis.com/salt-formulas/salt.git
enabled: true
params:
base: master
@@ -411,6 +411,10 @@
.. code-block:: yaml
_param:
+ vcp_links: &vcp_links
+ - type: phy
+ id: ens2
+ name: ens2
private-ipv4: &private-ipv4
- id: private-ipv4
type: ipv4
@@ -515,6 +519,7 @@
# manual interfaces configuration
cloud_init:
network_data:
+ links: *vcp_links
networks:
- <<: *private-ipv4
ip_address: 192.168.0.161
@@ -896,6 +901,86 @@
.. literalinclude:: tests/pillar/control_virt_custom.sls
:language: yaml
+Salt shared library
+-------------------
+
+This formula includes 'sharedlib' execution module which is a kind
+of 'library' of function and / or classes to be used in Jinja templates
+or directly as execution module.
+
+'sharedlib' implements a loader that is able to scan nested directories
+and import Python classes / functions from nested modules. Salt doesn't
+allow this as it only imports top-level modules:
+
+https://github.com/saltstack/salt/issues/37273
+
+'sharedlib' implements 4 main functions:
+
+* 'sharedlib.list' - search and print functions / classes found in nested directories
+* 'sharedlib.info' - print docstring of a function (if it exists)
+* 'sharedlib.get' - get function / class object, but not execute it immediately
+* 'sharedlib.call' - get function / class and execute / initialize it with
+ arguments given.
+
+Each of the commands above also have it's own docstring so it's possible to
+use them on a system:
+
+.. code-block:: text
+
+ # salt-call sys.doc sharedlib.list
+ local:
+ ----------
+ sharedlib.list:
+
+ List available functions.
+
+ .. code-block::
+
+ salt-call sharedlib.list
+
+Usage examples:
+
+.. code-block:: text
+
+ # salt-call sharedlib.list
+ local:
+ ----------
+ sharedlib.list:
+ ----------
+ classes:
+ - misc.Test
+ - misc2.Test
+ functions:
+ - misc.cast_dict_keys_to_int
+
+.. code-block:: text
+
+ # salt-call sharedlib.info misc.cast_dict_keys_to_int
+ local:
+ ----------
+ sharedlib.info:
+ ----------
+ misc.cast_dict_keys_to_int:
+
+ Return a dictionary with keys casted to int.
+ This usually is required when you want sort the dict later.
+
+ Jinja example:
+
+ .. code-block: jinja
+
+ {%- set ruleset = salt['sharedlib.call']('misc.cast_dict_keys_to_int', c.get('ruleset', {})) %}
+
+ .. code-block:: jinja
+
+ {%- set func = salt['sharedlib.get']('misc.cast_dict_keys_to_int') %}
+ {%- for c_name, c in t.chains.items() %}
+ {%- set ruleset = func(c.get('ruleset', {})) %}
+ {%- for rule_id, r in ruleset | dictsort %}
+ ...
+ {%- endfor %}
+
+
Usage
=====
@@ -932,29 +1017,3 @@
* http://salt-cloud.readthedocs.org/en/latest/topics/rackspace.html
* http://salt-cloud.readthedocs.org/en/latest/topics/map.html
* http://docs.saltstack.com/en/latest/topics/tutorials/multimaster.html
-
-Documentation and Bugs
-======================
-
-* http://salt-formulas.readthedocs.io/
- Learn how to install and update salt-formulas
-
-* https://github.com/salt-formulas/salt-formula-salt/issues
- In the unfortunate event that bugs are discovered, report the issue to the
- appropriate issue tracker. Use the Github issue tracker for a specific salt
- formula
-
-* https://launchpad.net/salt-formulas
- For feature requests, bug reports, or blueprints affecting the entire
- ecosystem, use the Launchpad salt-formulas project
-
-* https://launchpad.net/~salt-formulas-users
- Join the salt-formulas-users team and subscribe to mailing list if required
-
-* https://github.com/salt-formulas/salt-formula-salt
- Develop the salt-formulas projects in the master branch and then submit pull
- requests against a specific formula
-
-* #salt-formulas @ irc.freenode.net
- Use this IRC channel in case of any questions or feedback which is always
- welcome
diff --git a/_modules/sharedlib/__init__.py b/_modules/sharedlib/__init__.py
new file mode 100644
index 0000000..609d13c
--- /dev/null
+++ b/_modules/sharedlib/__init__.py
@@ -0,0 +1,110 @@
+from inspect import getmembers, isclass, isfunction
+from functools import wraps
+
+import importlib
+import pkgutil
+import sys
+
+
+class Loader(object):
+ def __init__(self, name):
+ self.name = name
+ self.loader = pkgutil.get_loader(self.name)
+ self.path = self.loader.filename
+ sys.path.append(self.path)
+
+ def get(self, name, *args, **kwargs):
+ parts = name.split('.')
+ module_name = '.'.join(parts[:-1])
+ module = importlib.import_module(module_name)
+ module.__salt__ = __salt__
+ return getattr(module, parts[-1])
+
+ def info(self, name, *args, **kwargs):
+ return {name: getattr(self.get(name), '__doc__')}
+
+ def call(self, name, *args, **kwargs):
+ return self.get(name)(*args, **kwargs)
+
+ def list(self, *args, **kwargs):
+ classes = set()
+ functions = set()
+ for _,name,ispkg in pkgutil.walk_packages([self.path,]):
+ if ispkg:
+ continue
+ try:
+ module = importlib.import_module(name)
+ for member_name,_ in getmembers(module, isfunction):
+ functions.add('.'.join((name, member_name)))
+ for member_name,_ in getmembers(module, isclass):
+ classes.add('.'.join((name, member_name)))
+ except:
+ pass
+ return {'functions': sorted(functions), 'classes': sorted(classes)}
+
+
+LOADER = Loader('sharedlib')
+
+
+def loader_attr(name):
+ def wrapper(f):
+ @wraps(f)
+ def func_wrapper(*args, **kwargs):
+ return getattr(LOADER, name)(*args, **kwargs)
+ return func_wrapper
+ return wrapper
+
+
+def wrap_output(f):
+ @wraps(f)
+ def wrapper(*args, **kwargs):
+ return {kwargs.get('__pub_fun'): f(*args, **kwargs)}
+ return wrapper
+
+
+@wrap_output
+@loader_attr('list')
+def list(*args, **kwargs):
+ '''
+ List available functions.
+
+ .. code-block:: text
+
+ salt-call sharedlib.list
+ '''
+
+@wrap_output
+@loader_attr('info')
+def info(name, *args, **kwargs):
+ '''
+ Returns info about function.
+
+ .. code-block:: text
+
+ salt-call sharedlib.info function.name
+ '''
+
+@loader_attr('get')
+def get(name):
+ '''
+ Returns function / class object (but not calls it) for later use.
+ This is mostly useful in jinja templates.
+
+ .. code-block:: jinja
+
+ {%- set func = salt['sharedlib.get']('function.name') %}
+ {%- func(*args, **kwargs) %}
+ '''
+
+@loader_attr('call')
+def call(name, *args, **kwargs):
+ '''
+ Calls a function from library.
+
+ For more information about a function being called use 'sharedlib.info'.
+
+ .. code-block:: jinja
+
+ {%- set x = salt['sharedlib.call']('function.name', *args, **kwargs) %}
+ '''
+
diff --git a/_modules/sharedlib/misc.py b/_modules/sharedlib/misc.py
new file mode 100644
index 0000000..5a6f5c4
--- /dev/null
+++ b/_modules/sharedlib/misc.py
@@ -0,0 +1,22 @@
+def cast_dict_keys_to_int(x, *args, **kwargs):
+ '''
+ Return a dictionary with keys casted to int.
+ This usually is required when you want sort the dict later.
+
+ Jinja examples:
+
+ .. code-block: jinja
+
+ {%- set ruleset = salt['sharedlib.call']('misc.cast_dict_keys_to_int', c.get('ruleset', {})) %}
+
+ .. code-block:: jinja
+
+ {%- set func = salt['sharedlib.get']('misc.cast_dict_keys_to_int') %}
+ {%- for c_name, c in t.chains.items() %}
+ {%- set ruleset = func(c.get('ruleset', {})) %}
+ {%- for rule_id, r in ruleset | dictsort %}
+ ...
+ {%- endfor %}
+ '''
+ return dict([(int(key),value) for key,value in x.items()])
+
diff --git a/debian/control b/debian/control
index 9f78368..9412c00 100644
--- a/debian/control
+++ b/debian/control
@@ -1,13 +1,13 @@
Source: salt-formula-salt
-Maintainer: Ales Komarek <ales.komarek@tcpcloud.eu>
+Maintainer: Mirantis Dev <dev@mirantis.com>
Section: admin
Priority: optional
Build-Depends: salt-master, python, python-yaml, debhelper (>= 9),
salt-formula-git, salt-formula-reclass
Standards-Version: 3.9.6
-Homepage: http://www.tcpcloud.eu
-Vcs-Browser: https://github.com/tcpcloud/salt-formula-salt
-Vcs-Git: https://github.com/tcpcloud/salt-formula-salt.git
+Homepage: https://www.mirantis.com
+Vcs-Browser: https://gerrit.mcp.mirantis.com/#/admin/projects/salt-formulas/salt
+Vcs-Git: https://gerrit.mcp.mirantis.com/salt-formulas/salt.git
Package: salt-formula-salt
Architecture: all
diff --git a/debian/copyright b/debian/copyright
index 79abd6c..547ff5f 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -1,12 +1,12 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: salt-formula-salt
-Upstream-Contact: Ales Komarek <ales.komarek@tcpcloud.eu>
-Source: https://github.com/tcpcloud/salt-formula-salt
+Upstream-Contact: Mirantis Dev <dev@mirantis.com>
+Source: https://gerrit.mcp.mirantis.com/#/admin/projects/salt-formulas/salt
Files: *
-Copyright: 2014-2015 tcp cloud a.s.
+Copyright: 2014-2019 Mirantis Inc. et al
License: Apache-2.0
- Copyright (C) 2014-2015 tcp cloud a.s.
+ Copyright (C) 2014-2019 Mirantis Inc. et al
.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
diff --git a/metadata.yml b/metadata.yml
index 07d8f6f..952021f 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -1,8 +1,8 @@
name: "salt"
version: "0.4"
-source: "https://github.com/salt-formulas/salt-formula-salt"
+source: "https://gerrit.mcp.mirantis.com/salt-formulas/salt"
dependencies:
- name: git
- source: "https://github.com/salt-formulas/salt-formula-git"
+ source: "https://gerrit.mcp.mirantis.com/salt-formulas/git"
- name: reclass
- source: "https://github.com/salt-formulas/salt-formula-reclass"
\ No newline at end of file
+ source: "https://gerrit.mcp.mirantis.com/salt-formulas/reclass"
diff --git a/tests/pillar/master_formulas.sls b/tests/pillar/master_formulas.sls
index 0209bb4..ed1c3fe 100644
--- a/tests/pillar/master_formulas.sls
+++ b/tests/pillar/master_formulas.sls
@@ -43,11 +43,11 @@
formula:
aptly:
source: git
- address: 'https://github.com/salt-formulas/salt-formula-aptly.git'
+ address: 'https://gerrit.mcp.mirantis.com/salt-formulas/aptly.git'
revision: master
bind:
source: git
- address: 'https://github.com/salt-formulas/salt-formula-bind.git'
+ address: 'https://gerrit.mcp.mirantis.com/salt-formulas/bind.git'
revision: master
renderer:
jinja:
diff --git a/tests/pillar/master_single_extolddays.sls b/tests/pillar/master_single_extolddays.sls
index 87c3df7..d9a99d2 100644
--- a/tests/pillar/master_single_extolddays.sls
+++ b/tests/pillar/master_single_extolddays.sls
@@ -22,7 +22,7 @@
# formula:
# python:
# source: git
- # address: 'https://github.com/salt-formulas/salt-formula-python.git'
+ # address: 'https://gerrit.mcp.mirantis.com/salt-formulas/python.git'
# revision: master
pillar:
engine: reclass
diff --git a/tests/pillar/master_single_extpillars.sls b/tests/pillar/master_single_extpillars.sls
index d2d2422..b3332f0 100644
--- a/tests/pillar/master_single_extpillars.sls
+++ b/tests/pillar/master_single_extpillars.sls
@@ -23,7 +23,7 @@
# formula:
# python:
# source: git
- # address: 'https://github.com/salt-formulas/salt-formula-python.git'
+ # address: 'https://gerrit.mcp.mirantis.com/salt-formulas/python.git'
# revision: master
pillar:
engine: composite
diff --git a/tests/pillar/master_single_extreclass.sls b/tests/pillar/master_single_extreclass.sls
index 7162dce..197f60c 100644
--- a/tests/pillar/master_single_extreclass.sls
+++ b/tests/pillar/master_single_extreclass.sls
@@ -22,7 +22,7 @@
# formula:
# python:
# source: git
- # address: 'https://github.com/salt-formulas/salt-formula-python.git'
+ # address: 'https://gerrit.mcp.mirantis.com/salt-formulas/python.git'
# revision: master
pillar:
engine: reclass