go.ligato.io/vpp-agent/v3@v3.5.0/ansible/action_plugins/vpp_etcd.py (about) 1 # Copyright (c) 2019 PANTHEON.tech 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at: 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 import os 16 import sys 17 18 basedir = os.path.split(sys.modules['ansible.plugins.action.vpp_etcd'].__file__)[0] 19 sys.path = ['/'.join(basedir.split('/')[:-1]), '/'.join(basedir.split('/')[:-2])] + sys.path 20 21 from ansible.plugins.action import ActionBase 22 23 24 class ActionModule(ActionBase): 25 26 def run(self, tmp=None, task_vars=None): 27 28 if task_vars is None: 29 task_vars = dict() 30 plugin = None 31 result = super(ActionModule, self).run(tmp, task_vars) 32 33 args = self._task.args.copy() 34 plugin_name = args.get('value_type') 35 36 plugindir = basedir + '/plugins' 37 poutdir = basedir + '/pout' 38 syspath = sys.path 39 sys.path = [basedir, plugindir, poutdir] + syspath 40 41 fnames = os.listdir(plugindir) 42 values = args.get('value') 43 agent_name = args.get('agent_name', task_vars.get('agent')) 44 45 if agent_name is None: 46 return {'failed': True, 'msg': 'agent_name must be defined'} 47 for fname in fnames: 48 if not fname.startswith(".#") and fname.endswith(".py") and \ 49 not fname.startswith('__'): 50 pluginmod = __import__(fname[:-3]) 51 try: 52 plugin = pluginmod.plugin_init(plugin_name, values, agent_name, task_vars.get('bridge_connection'), 53 task_vars.get('etcd_port')) 54 if plugin: 55 break 56 except AttributeError as s: 57 print(pluginmod.__dict__) 58 raise AttributeError(pluginmod.__file__ + ': ' + str(s)) 59 sys.path = syspath 60 61 new_args = dict() 62 new_args['state'] = args.get('state') 63 64 values = plugin.validate() 65 66 new_args['host'] = task_vars.get('bridge_connection') # bridged connection for awx otherwise "172.0.0.1" 67 new_args['port'] = int(task_vars.get('etcd_port')) 68 new_args['key'] = plugin.create_key() 69 70 new_args['value'] = values 71 if args.get('secure_transport', task_vars.get('secureTransport')): 72 new_args['ca_cert'] = "/tmp/certificates/ca.pem" 73 new_args['client_cert'] = "/tmp/certificates/client.pem" 74 new_args['client_key'] = "/tmp/certificates/client-key.pem" 75 76 result.update(self._execute_module(module_name='etcd3', module_args=new_args, task_vars=task_vars)) 77 return result