-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4893 from wazuh/enhancement/4495-DTT1
Merge 4495 into 4855
- Loading branch information
Showing
29 changed files
with
415 additions
and
261 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
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
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 |
---|---|---|
@@ -1,3 +1,2 @@ | ||
from .ansible import Ansible, Inventory | ||
from .playbook import Playbook | ||
from .schemaValidator import SchemaValidator | ||
from .schemaValidator import SchemaValidator |
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
This file was deleted.
Oops, something went wrong.
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
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,49 @@ | ||
from modules.generic import Ansible | ||
from .componentType import Package, AIO, Generic, Dependencies | ||
|
||
class Action: | ||
""" | ||
Class to define the action. | ||
""" | ||
def __init__(self, action, component_info, ansible_data): | ||
action_type = component_info.type | ||
|
||
if action_type == "package": | ||
self.component = Package(component_info, action) | ||
elif action_type == "aio": | ||
self.component = AIO(component_info, action) | ||
elif action_type == "generic": | ||
self.component = Generic(component_info, action) | ||
elif action_type == "dependencies": | ||
self.component = Dependencies(component_info, action) | ||
else: | ||
raise ValueError(f"Unsupported action_type: {action_type}") | ||
|
||
self.ansible = Ansible(ansible_data) | ||
|
||
def execute(self): | ||
""" | ||
Execute the action. | ||
""" | ||
status = {} | ||
|
||
print(self.component.variables_dict) | ||
|
||
tasks = self.ansible.render_playbooks(self.component.variables_dict) | ||
|
||
playbook = { | ||
'hosts': self.ansible.ansible_data.ansible_host, | ||
'become': True, | ||
'gather_facts': True, | ||
'tasks': tasks | ||
} | ||
|
||
status = self.ansible.run_playbook(playbook) | ||
|
||
return status | ||
|
||
def set_playbooks_variables(self, vars): | ||
""" | ||
Method to set the playbooks extra variables. | ||
""" | ||
pass |
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,100 @@ | ||
|
||
|
||
class ComponentType: | ||
""" | ||
Class to define the type of component to be provisioned | ||
""" | ||
def __init__(self, component_info): | ||
self.component = component_info.component | ||
self.type = component_info.type | ||
self.version = component_info.version | ||
self.manager_ip = component_info.manager_ip or None | ||
|
||
def get_templates_path(self, action): | ||
""" | ||
Get the path to the templates. | ||
""" | ||
pass | ||
|
||
def get_templates_order(self, action): | ||
""" | ||
Get the order of the templates to be executed. | ||
""" | ||
pass | ||
|
||
def generate_dict(self): | ||
""" | ||
Generate the dictionary with the variables to be used to render the templates. | ||
""" | ||
variables = { | ||
'component': self.component, | ||
'version': self.version, | ||
'version': self.type, | ||
'manager_ip': self.manager_ip, | ||
'templates_path': self.templates_path, | ||
'templates_order': self.templates_order or None | ||
} | ||
|
||
return variables | ||
|
||
class Package(ComponentType): | ||
""" | ||
Class to define the type of package to be provisioned | ||
""" | ||
TEMPLATE_BASE_PATH = 'provision/wazuh' | ||
|
||
def __init__(self, component_info, action): | ||
super().__init__(component_info) | ||
self.templates_path = f'{self.TEMPLATE_BASE_PATH}/{self.type}/{action}' | ||
self.templates_order = self.get_templates_order(action) | ||
self.variables_dict = self.generate_dict() | ||
|
||
def get_templates_order(self, action): | ||
if action == "install": | ||
return ["set_repo.j2", "install.j2", "register.j2", "service.j2"] | ||
return [] | ||
|
||
class AIO(ComponentType): | ||
""" | ||
Class to define the type of AIO to be provisioned | ||
""" | ||
TEMPLATE_BASE_PATH = 'provision/wazuh' | ||
|
||
def __init__(self, component_info, action): | ||
super().__init__(component_info) | ||
self.templates_path = f'{self.TEMPLATE_BASE_PATH}/{self.type}/{action}' | ||
self.templates_order = self.get_templates_order(action) | ||
self.variables_dict = self.generate_dict() | ||
|
||
def get_templates_order(self, action): | ||
return ["download.j2", f"{action}.j2"] | ||
|
||
class Generic(ComponentType): | ||
""" | ||
Class to define the type of generic component to be provisioned | ||
""" | ||
TEMPLATE_BASE_PATH = 'provision/generic' | ||
|
||
def __init__(self, component_info, action): | ||
super().__init__(component_info) | ||
self.templates_path = f'{self.TEMPLATE_BASE_PATH}/{action}' | ||
self.templates_order = self.get_templates_order(action) | ||
self.variables_dict = self.generate_dict() | ||
|
||
def get_templates_order(self, action): | ||
return [] | ||
|
||
class Dependencies(ComponentType): | ||
""" | ||
Class to define the type of dependencies to be provisioned | ||
""" | ||
TEMPLATE_BASE_PATH = 'provision/deps' | ||
|
||
def __init__(self, component_info, action): | ||
super().__init__(component_info) | ||
self.templates_path = f'{self.TEMPLATE_BASE_PATH}' | ||
self.templates_order = self.get_templates_order(action) | ||
self.variables_dict = self.generate_dict() | ||
|
||
def get_templates_order(self, action): | ||
return [] |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.