Skip to content

Odoo Automation Integration

Being an Odoo application, Cetmix Tower benefits from deep integration with Odoo automation. To make the integration process easier, it provides a set of helper functions that can be used in Odoo automated, server or scheduled actions. These functions are located in the special "cetmix.tower" model.

Create a new Server from a Server Template

server_create_from_template(self, template_reference, server_name, **kwargs)

Arguments

Parameter Type Description
template_reference Char Server template reference
server_name Char Name of the new server

Keyword Arguments

Parameter Type Default Description
partner res.partner(), optional None Partner this server belongs to.
ipv4 Char, optional None IP v4 address. Defaults to None.
ipv6 Char, optional None IP v6 address. Must be provided if IP v4 is not. Defaults to None.
ssh_password Char, optional None SSH password. Defaults to None.
ssh_key Char, optional None SSH private key reference. Defaults to None.
configuration_variables Dict, optional None Custom configuration variables in following format: {"variable_reference": "variable_value_char"}
Eg: {"branch": "prod", "odoo_version": "16.0"}

Returns

cx.tower.server: The newly created server record.

Example

Automated action that creates a new server from template when a Sales Order is confirmed in Odoo.

# This is a shortcut to the cetmix.tower helper model
cetmix_tower = env["cetmix.tower"]

for quotation in records:

    # Check confirmed orders
    if quotation.state == "sale":

        # Suppose there are special custom fields in 'res.partner' and 'sale.order' models
        params = {
        "ipv4": quotation.partner_id.ip_v4_address,
        "ssh_username": quotation.partner_id.ssh_username or "pepe",
        "ssh_password": quotation.partner_id.ssh_password or "frog",
        "ssh_auth_mode": "p",  # Password authentication
        "configuration_variables": {
            "odoo_version": "18.0",
            "odoo_edition": "ce",
            "odoo_workers": "4",
            "odoo_cron_threads": "2",
            },
        }

        # Create a new server from the 'demo_template' Server Template
        new_server = cetmix_tower.server_create_from_template(
        template_reference="demo_template",
        server_name=record.name,
        **params
        )

        # Link new server to the quotation
        if new_server:
            quotation.server_id = new_server.id

Set a Variable value for a Server

server_set_variable_value(self, server_reference, variable_reference, value)

Arguments

Parameter Type Description
server_reference Char Server reference
variable_reference Char Variable reference
value Char Variable value

Returns

Dict: {exit_code: Char, message: Char}

Get a Variable value for a Server

server_get_variable_value(self, server_reference, variable_reference)

Arguments

Parameter Type Description
server_reference Char Server reference
variable_reference Char Variable reference

Returns

Char: Variable value or None if the variable is not set.

Example

Automated action Odoo workers for all partner servers. If this number is more than the maximum allowed number for this partner it will be set to the maximum allowed number.

# This is a shortcut to the cetmix.tower helper model
cetmix_tower = env["cetmix.tower"]

for partner in records:
    if not partner.servers_ids:
        continue

    for server in partner.servers_ids:

        # Get current number of Odoo workers
        current_odoo_workers = cetmix_tower.server_get_variable_value(server.reference, "odoo_workers")

        # Remember that result is a Char or None
        if current_odoo_workers and int(current_odoo_workers) > partner.max_odoo_workers:
            # Set the maximum number of Odoo workers
            cetmix_tower.server_set_variable_value(
                server_reference=server.reference,
                variable_reference="odoo_workers",
                value=partner.max_odoo_workers
            )

Check if SSH connection to the Server is available

server_check_ssh_connection(self, server_reference, attempts=5, wait_time=10, try_command=True, try_file=True)

Arguments

Parameter Type Description
server_reference Char Server reference
attempts Int Number of attempts to try the connection. Defaults to 5.
wait_time Int Wait time in seconds between connection attempts. Defaults to 10 seconds.
try_command Bool Try to execute a command. Defaults to True.
try_file Bool Try file operations. Defaults to True.

Returns

Dict: {exit_code: Int, message: Char}

Example

Automated action that checks if partner servers are responding.

# This is a shortcut to the cetmix.tower helper model
cetmix_tower = env["cetmix.tower"]

for partner in records:
    if not partner.servers_ids:
        continue

    for server in partner.servers_ids:
        result = cetmix_tower.server_check_ssh_connection(server.reference, attempts=3, wait_time=5, try_command=False, try_file=False)

        # Post a message if the server is not responding
        if result["exit_code"] != 0:
            # NB: Odoo automated actions don't support f-strings, so we use the old way
            partner.message_post(subject="Server is not responding" + server.name, body=result.get("message", "No error message"))