From 1b1c1281a2bf3dd7df1e47020178d1bae5560c8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Sun, 4 Sep 2022 22:44:06 +0200 Subject: [PATCH] Use abc for the instruction class and its abstract methods --- inventory_plugins/reconstructed.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/inventory_plugins/reconstructed.py b/inventory_plugins/reconstructed.py index 12eafbb..a06ef35 100644 --- a/inventory_plugins/reconstructed.py +++ b/inventory_plugins/reconstructed.py @@ -1,3 +1,5 @@ +import abc + from ansible import constants as C from ansible.errors import AnsibleParserError, AnsibleRuntimeError, AnsibleError from ansible.module_utils.six import string_types @@ -105,7 +107,7 @@ INSTR_FIELDS = {k: set(v + INSTR_COMMON_FIELDS) for k, v in INSTR_OWN_FIELDS.ite """All supported fields for each instruction, including common and specific fields.""" -class RcInstruction: +class RcInstruction(abc.ABC): """An instruction that can be executed by the plugin.""" DEFAULT_LOOP_VAR = "item" @@ -208,6 +210,7 @@ class RcInstruction: ) return may_be_template, group + @abc.abstractmethod def parse_action(self, record): raise NotImplementedError @@ -275,9 +278,6 @@ class RcInstruction: ) return value - def execute_action(self, host_name, merged_vars, host_vars, script_vars): - raise NotImplementedError - def get_templated_group(self, variables, may_be_template, name, must_exist=False): if may_be_template: self._templar.available_variables = variables @@ -299,6 +299,10 @@ class RcInstruction: ) return real_name + @abc.abstractmethod + def execute_action(self, host_name, merged_vars, host_vars, script_vars): + raise NotImplementedError + class RciCreateGroup(RcInstruction): def __init__(self, inventory, templar, display):