diff options
Diffstat (limited to 'roles/kubernetes/kubeadm/base/filter_plugins')
-rw-r--r-- | roles/kubernetes/kubeadm/base/filter_plugins/net_kubeguard.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/roles/kubernetes/kubeadm/base/filter_plugins/net_kubeguard.py b/roles/kubernetes/kubeadm/base/filter_plugins/net_kubeguard.py new file mode 100644 index 00000000..2220e545 --- /dev/null +++ b/roles/kubernetes/kubeadm/base/filter_plugins/net_kubeguard.py @@ -0,0 +1,33 @@ +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +from ansible import errors + + +def kubeguard_direct_net_zone(data, myname, peer): + try: + zones = [] + for zone in data: + if myname in data[zone]['node_interface'] and peer in data[zone]['node_interface']: + zones.append(zone) + + if not zones: + return "" + if len(zones) > 1: + raise errors.AnsibleFilterError("host '%s' and '%s' have multiple direct net zones in common: %s" % + (myname, peer, zones.join(','))) + return zones[0] + + except Exception as e: + raise errors.AnsibleFilterError("kubeguard_direct_net_zones(): %s" % str(e)) + + +class FilterModule(object): + + ''' Kubeguard Network Filters ''' + filter_map = { + 'kubeguard_direct_net_zone': kubeguard_direct_net_zone, + } + + def filters(self): + return self.filter_map |