Maintainers
This module is part of the cetmix/cetmix-tower project on GitHub.
You are welcome to contribute.
Cetmix Tower offers a streamlined solution for managing remote servers via SSH or API calls directly from Odoo. It is designed for versatility across different operating systems and software environments, providing a practical option for those looking to manage servers without getting tied down by vendor or technology constraints.
Table of contents
Please ensure that you have read and understood the documentation before running Cetmix Tower in the production environment.
In order for a user to be able to use Cetmix Tower features you need to provide access to in the the user settings. To configure it go to Setting/Users & Companies/Users and open a user whom you would like to provide access to the Cetmix Tower.
In Other section find the Cetmix Tower field and select one of the following options:
NB: Please keep in mind that some of the entities can have their additional access management variations.
Go to the Cetmix Tower/Servers/Servers menu and click Create. Enter server name and a unique server reference. Leave the “reference” field blank to generate a reference automatically. You can also select a color which is used to mark a server in the kanban view.
Fill the values it the tabs below:
General Settings
There is a special Status field which indicates current Server status. It is meant to be updated automatically using external API with further customizations. Following pre-defined statuses are available:
Default status is ‘Undefined’.
Configuration
Configure configuration variables values to be used when rendering commands and files on this server.
Secrets
Configure secret values to used when rendering commands and files on this server. Check the Configuring Keys/Secrets section for more details.
Server Logs
Configure server logs in order to have convenient access to them. Logs can be fetched either from Files or using Commands. Check the Configuring a Server Log section for more details.
Following action buttons are located in the top of the form:
Go to the Cetmix Tower/Servers/Templates menu and click Create. Enter template name and a unique template reference. Leave the “reference” field blank to generate a reference automatically.
Fill the values it the tabs below:
General Settings
Variables
Configure default variable values for new servers. Check the Configuring Variables section for more details.
Server Logs
Please check the Configuring a Server Log section for more details.
To configure variables go to the Cetmix Tower/Settings and select the Variables menu. Click Create and put values in the fields:
Cetmix Tower supports jinja2 syntax for variables. You can use variables to render:
You can use any jinja2 supported expressions. For example if else statements:
docker run -d -p {{ odoo_port }}:8069 \ {% if odoo_longpolling_port and odoo_longpolling_port != '0' and odoo_workers and odoo_workers != '0' %} -p {{ odoo_longpolling_port }}:8072 \ {% endif %} -v {{ odoo_data }}:/var/lib/odoo \ {% if odoo_config_location %} -v {{ odoo_config_location }}:/etc/odoo \ {% endif %}
There are two rendering modes available:
Let use the following code as example:
current_branch={{ branch }} current_version={{ package_version }} need_update={{ update_available }}
where branch is main, package_version is 0.12 and update_available is False
Default mode which renders variable values “as is”. It is done in order to keep compatibility with any code interpreter which may be used to run a command. The code from example will be rendered the following way:
current_branch=main current_version=0.12 need_update=False
This mode is used in commands that run Python code (Action: Execute Python code). In this mode all variable values except Boolean and None are enclosed in double quotes. The code from example will be rendered the following way:
current_branch="main" current_version="0.12" need_update=False
Following types of variable values available in Cetmix Tower:
When rendering an expression local values are used first. If no local value is found then global value will be used. For example default value of the odoo_port variable is 8069. However you can easily specify any other value and thus run multiple Odoo instances on a single server.
IMPORTANT!: Storing sensitive data (eg GitHub tokens) in variable values may expose that date in command preview and logs. Use secrets for storing such data instead.
There is a special tower variable available which allows to access some system parameters and helper tools. Important! do not redefine the tower variable unless you really need that on purpose.
Following system variables are available:
Keys/Secrets are used to private SSH keys and sensitive data that is used for rendering commands. To configure a new key or secret go to Cetmix Tower/Settings/Keys click Create and put values in the fields:
Keys of type Secret (or “Secret”) are considered “Global” if no partner and no server are selected. Such keys are accessible all across the Tower. Global keys are overridden with partner keys with the same reference. Partner keys in their turn are overridden with server specific keys. Priority order from highest to lowest is:
Secrets are inserted inline in code using the following pattern: #!cxtower.secret.REFERENCE!#. It consists of three dot separated parts and is terminated with a mandatory !# suffix:
Example:
Suppose we have a secret with Key ID set to MY_SECRET_DIR and value suchMuchFolder. In this case the following command:
mkdir /home/#!cxtower.secret.MY_SECRET_DIR!#
will be executed as:
mkdir /home/suchMuchFolder
Cetmix Tower is using SFTP protocol for file transfer operations. Based on initial file location following file sources are available:
To create a new file go to Cetmix Tower/Files/Files click Create and put values in the fields:
Following fields are located in the tabs below:
NB: File operations are performed using user credentials from server configuration. You should take care of filesystem access rights to ensure that file operations are performed without any issues.
File templates are used to create and manage multiple files in bulk. Once a template is modified all related files are automatically updated.
To create a new file template go to Cetmix Tower/Files/Templates click Create and put values in the fields:
Hint: If you want to create a file from template but don’t want further template modifications to be applied to this file remove the value from the Template field before saving it.
Command is a shell command that is executed on remote server. To create a new command go to Cetmix Tower/Commands/Commands click Create and put values in the fields:
To return result from Python assign exit code and message to the COMMAND_RESULT variable of type dict like this:
# Success COMMAND_RESULT = { "exit_code": 0, "message": "This will be logged as a result message because exit code == 0", } # Error COMMAND_RESULT = { "exit_code": 21, "message": "This will be logged as an error message because exit code != 0", }
Flight Plans are used to execute commands in series. They allow to build a flexible condition based execution flow. To create a new flight plan go to Cetmix Tower/Commands/Flight Plans click Create and put values in the fields:
Name: Flight Plan name
Reference: Leave the “reference” field blank to generate a reference automatically.
On Error: Default action to execute when an error happens during the flight plan execution. Possible options:
Note: Comments or user notes.
Servers: List of servers this command can be run on. Leave this field blank to make the command available to all servers.
Tags: Make usage as search more convenient.
Code: List of commands to execute. Each of the commands has the following fields:
{{ odoo_version }} == "17.0" and ( {{ nginx_installed }} or {{ traefik_installed }} )
Server Logs allow to fetch and view logs of a server fast and convenient way. To configure a Server Log open the server form, navigate to the Server Logs tab and add a new record in the list.
Following fields are available:
Developer hint: log output supports HTML formatting. You can implement your custom log formatter by overriding the _format_log_text() function of the cx.tower.server.log model.
Try to avoid using && or ; joined commands unless this is really needed. Use flight plans instead.
Why?
Not recommended:
apt-get update && apt-get upgrade -y && apt-get install doge-meme-generator
Way to go:
apt-get update
apt-get upgrade -y
apt-get install doge-meme-generator
Do not use cd or chdir commands. Use Default Path field in command or Path field in flight plan line.
Why?
Do not do this:
cd /home/{{ tower.server.username }}/memes && cat my_doge_memes.txt
Way to go:
/home/{{ tower.server.username }}/memes
cat my_doge_memes.txt
You can also create a new server from template from code using a designated create_server_from_template function of the cx.tower.server.template model. This function takes the following arguments:
- template_reference (Char): Server template reference - server_name (Char): Name of the new server - **kwargs: - partner (res.partner(), optional): Partner this server belongs to. - ipv4 (Char, optional): IP v4 address. Defaults to None. - ipv6 (Char, optional): IP v6 address. Must be provided in case IP v4 is not. Defaults to None. - ssh_password (Char, optional): SSH password. Defaults to None. Defaults to None. - ssh_private_key_value (Char, optional): SSH private key content. - ssh_private_key_value (cx.tower.key(), optional): SSH private key record. Defaults to None. - configuration_variables (Dict, optional): Custom configuration variable. Following format is used: 'variable_reference': 'variable_value_char' eg: {'branch': 'prod', 'odoo_version': '16.0'}
Here is a short example of an Odoo automated action that creates a new server when a Sales Order is confirmed:
for record in records: # Check confirmed orders if record.state == "sale": params = { "ip_v4_address": "host.docker.internal", "ssh_port": 2222, "ssh_username": "pepe", "ssh_password": "frog", "ssh_auth_mode": "p", "configuration_variables": { "odoo_version": "16.0" }, } # Create a new server from template with the 'demo_template' reference env["cetmix.tower"].create_server_from_template( template_reference="demo_template", server_name=record.name, **params )
There are two action buttons available in the wizard:
You can check command execution logs in the Cetmix Tower/Commands/Command Logs menu. Important! If you want to delete a command you need to delete all its logs manually before doing that.
Select a server in the list view or open a server form view
Open the Actions menu and click Execute Flight Plan
A wizard is opened with the following fields:
Click the Run button to execute a flight plan.
You can check the flight plan results in the Cetmix Tower/Commands/Flight Plan Logs menu. Important! If you want to delete a command you need to delete all its logs manually before doing that.
To check a server log:
You can use various Cetmix Tower functions in Odoo automation. Such as server actions, automated actions or scheduled actions. While you can always call any public function directly most useful helper functions are located in a special abstract model “cetmix.tower”. You can check those functions in the source code in the following file: models/cetmix_tower.py
Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed feedback.
Do not contact contributors directly about support or help with technical issues.
This module is part of the cetmix/cetmix-tower project on GitHub.
You are welcome to contribute.