From 770c1dd0589843b0dcdc47d7ef846dec2ad87516 Mon Sep 17 00:00:00 2001 From: Dmytro Meita Date: Mon, 23 Dec 2024 20:30:30 +0200 Subject: [PATCH 1/6] [FIX] cetmix_tower_server: Improve test data creation and remove demo data usage This commit addresses comments by improving the creation and usage of test data in the following ways: - Replaced demo data usage: - Removed references to `demo` data (e.g., `self.env.ref("cetmix_tower_server.tag_staging")`) in test cases. - Introduced locally created test records for tags with unique names such as `"Test Staging"` and `"Test Production"`. - Improved reusability: - Created reusable `self.Tag` model in `setUp` for tag creation in tests. - Moved common test data (e.g., tags) to `setUp` for easier maintenance and consistency. - Aligned with TL recommendations: - Ensured test data names are unique to avoid conflicts with existing data. - Simplified test cases by reusing common test setup. Why? - Ensures independence of test cases from demo data. - Makes tests more maintainable and aligned with best practices. - Resolves all comments raised in the PR review. Task: 4212 --- cetmix_tower_server/tests/common.py | 9 ++++++--- cetmix_tower_server/tests/test_plan.py | 20 +++++--------------- cetmix_tower_server/tests/test_server.py | 5 ++--- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/cetmix_tower_server/tests/common.py b/cetmix_tower_server/tests/common.py index 2ad5b4de..abe46bcf 100644 --- a/cetmix_tower_server/tests/common.py +++ b/cetmix_tower_server/tests/common.py @@ -15,6 +15,11 @@ def setUp(self, *args, **kwargs): # Cetmix Tower helper model self.CetmixTower = self.env["cetmix.tower"] + # Tags + self.Tag = self.env["cx.tower.tag"] + self.tag_test_staging = self.Tag.create({"name": "Test Staging"}) + self.tag_test_production = self.Tag.create({"name": "Test Production"}) + # Users self.Users = self.env["res.users"].with_context(no_reset_password=True) self.user_bob = self.Users.create( @@ -150,9 +155,7 @@ def setUp(self, *args, **kwargs): { "name": "Test plan 1", "note": "Create directory and list its content", - "tag_ids": [ - (6, 0, [self.env.ref("cetmix_tower_server.tag_staging").id]) - ], + "tag_ids": [(6, 0, [self.tag_test_staging.id])], } ) self.plan_line_1 = self.plan_line.create( diff --git a/cetmix_tower_server/tests/test_plan.py b/cetmix_tower_server/tests/test_plan.py index fbe7080d..5892da7c 100644 --- a/cetmix_tower_server/tests/test_plan.py +++ b/cetmix_tower_server/tests/test_plan.py @@ -274,9 +274,7 @@ def test_plan_user_access_rule(self): { "name": "Test plan 2", "note": "Create directory and list its content", - "tag_ids": [ - (6, 0, [self.env.ref("cetmix_tower_server.tag_staging").id]) - ], + "tag_ids": [(6, 0, [self.tag_test_staging.id])], } ) # Ensure that defaulf command access_level is equal to 2 @@ -315,9 +313,7 @@ def test_plan_user_access_rule(self): { "name": "Test plan 3", "note": "Create directory and list its content", - "tag_ids": [ - (6, 0, [self.env.ref("cetmix_tower_server.tag_staging").id]) - ], + "tag_ids": [(6, 0, [self.tag_test_staging.id])], } ) self.assertTrue( @@ -431,23 +427,17 @@ def test_multiple_plan_create_write(self): { "name": "Test Plan 1", "note": "Plan 1 Note", - "tag_ids": [ - (6, 0, [self.env.ref("cetmix_tower_server.tag_staging").id]) - ], + "tag_ids": [(6, 0, [self.tag_test_staging.id])], }, { "name": "Test Plan 2", "note": "Plan 2 Note", - "tag_ids": [ - (6, 0, [self.env.ref("cetmix_tower_server.tag_production").id]) - ], + "tag_ids": [(6, 0, [self.tag_test_production.id])], }, { "name": "Test Plan 3", "note": "Plan 3 Note", - "tag_ids": [ - (6, 0, [self.env.ref("cetmix_tower_server.tag_staging").id]) - ], + "tag_ids": [(6, 0, [self.tag_test_staging.id])], }, ] created_plans = self.Plan.create(plans_data) diff --git a/cetmix_tower_server/tests/test_server.py b/cetmix_tower_server/tests/test_server.py index f8d44d50..02f48113 100644 --- a/cetmix_tower_server/tests/test_server.py +++ b/cetmix_tower_server/tests/test_server.py @@ -7,6 +7,7 @@ class TestTowerServer(TestTowerCommon): def setUp(self, *args, **kwargs): super().setUp(*args, **kwargs) self.os_ubuntu_20_04 = self.env["cx.tower.os"].create({"name": "Ubuntu 20.04"}) + self.server_test_2 = self.Server.create( { "name": "Test Server #2", @@ -38,9 +39,7 @@ def setUp(self, *args, **kwargs): }, ), ], - "tag_ids": [ - (6, 0, [self.env.ref("cetmix_tower_server.tag_production").id]) - ], + "tag_ids": [(6, 0, [self.tag_test_production.id])], } ) # Files From e42681b479a0243966277ce10031317a11610cff Mon Sep 17 00:00:00 2001 From: Ivan Sokolov Date: Wed, 11 Dec 2024 15:30:50 +0100 Subject: [PATCH 2/6] [IMP] cetmix_tower_server: Store related keys Improve the way related keys are stored in commands. Store only keys that either global or connected to command servers or to partners connected to command servers. Store related secrets in the file templates. Modify cx.tower.key constraints to ensure that they are working as expected. SQL constraint was useless because both 'partner' and 'server' fields allow NULL values. So an ORM constraint was added to ensure that the key is unique. Delete the constrain inherited from mixin after committing database schema. Task: 4166 --- cetmix_tower_server/README.rst | 831 +++++++++--------- cetmix_tower_server/__init__.py | 2 + .../models/cx_tower_command.py | 27 + .../models/cx_tower_file_template.py | 2 +- cetmix_tower_server/models/cx_tower_key.py | 49 +- .../models/cx_tower_key_mixin.py | 17 +- .../static/description/index.html | 169 ++-- cetmix_tower_server/tests/test_command.py | 120 ++- cetmix_tower_server/tests/test_key.py | 6 +- .../views/cx_tower_file_template_view.xml | 6 + .../models/cx_tower_yaml_mixin.py | 3 +- 11 files changed, 705 insertions(+), 527 deletions(-) diff --git a/cetmix_tower_server/README.rst b/cetmix_tower_server/README.rst index 3e2d9925..ca5ade08 100644 --- a/cetmix_tower_server/README.rst +++ b/cetmix_tower_server/README.rst @@ -17,7 +17,7 @@ Cetmix Tower Server Management :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-cetmix%2Fcetmix--tower-lightgray.png?logo=github - :target: https://github.com/cetmix/cetmix-tower/tree/14.0-dev/cetmix_tower_server + :target: https://github.com/cetmix/cetmix-tower/tree/14.0/cetmix_tower_server :alt: cetmix/cetmix-tower |badge1| |badge2| |badge3| @@ -32,75 +32,74 @@ tied down by vendor or technology constraints. Why Cetmix Tower? ================= -- **Open Source:** `Cetmix Tower `__ is - distributed under the AGPL-3 license -- **Odoo Integration:** Benefit from `Odoo `__ - ecosystem for server management tasks, like deploying servers in - response to specific Odoo-triggered events -- **Extendability:** Build your own `Odoo `__ modules - using `Cetmix Tower `__ to implement your - custom features -- **Beyond Odoo:** While optimized for Odoo, Cetmix Tower can manage - virtually any instance -- **Flexibility:** Use Cetmix Tower alongside other management methods - without restriction, ensuring you're not limited to a single vendor -- **Self-Hosting:** Deploy Cetmix Tower on your own infrastructure for - full control over your server management. -- **Broad Compatibility:** Execute any software that's manageable via - shell commands or API. From Docker or Kubernetes to direct OS package - installations +- **Open Source:** `Cetmix Tower `__ is + distributed under the AGPL-3 license +- **Odoo Integration:** Benefit from `Odoo `__ + ecosystem for server management tasks, like deploying servers in + response to specific Odoo-triggered events +- **Extendability:** Build your own `Odoo `__ modules + using `Cetmix Tower `__ to implement your + custom features +- **Beyond Odoo:** While optimized for Odoo, Cetmix Tower can manage + virtually any instance +- **Flexibility:** Use Cetmix Tower alongside other management methods + without restriction, ensuring you're not limited to a single vendor +- **Self-Hosting:** Deploy Cetmix Tower on your own infrastructure for + full control over your server management. +- **Broad Compatibility:** Execute any software that's manageable via + shell commands or API. From Docker or Kubernetes to direct OS package + installations Server Management ================= -- Variable based flexible configuration -- Create servers using pre-defined templates +- Variable based flexible configuration +- Create servers using pre-defined templates Connectivity ============ -- Password and key based authentication for outgoing SSH connections -- Built-in support of the Python `requests - library `__ for outgoing API - calls +- Password and key based authentication for outgoing SSH connections +- Built-in support of the Python `requests + library `__ for outgoing API calls Commands ======== -- Execute SSH commands on remote servers -- Run Python code on the Tower Odoo server -- Run Flight Plan from command -- Render commands using variables -- Secret keys for private data storage +- Execute SSH commands on remote servers +- Run Python code on the Tower Odoo server +- Run Flight Plan from command +- Render commands using variables +- Secret keys for private data storage Flight Plans ============ -- Execute multiple commands in a row -- Condition based flow: +- Execute multiple commands in a row +- Condition based flow: - - Based on condition using `Python - syntax `__ - - Based on the previous command exit code + - Based on condition using `Python + syntax `__ + - Based on the previous command exit code Files ===== -- Download files from remote server using SFTP -- Upload files to remote server using SFTP -- Support for ``text`` and ``binary`` file format -- Manage files using pre-defined file templates +- Download files from remote server using SFTP +- Upload files to remote server using SFTP +- Support for ``text`` and ``binary`` file format +- Manage files using pre-defined file templates Support and Technical Requirements ================================== -- Cetmix Tower with usability and simplicity in mind, though some - features might require a foundational understanding of server - management principles -- We offer dedicated support to help with any custom setup needs or - questions that may arise -- For additional details, visit our website - `cetmix.com `__ +- Cetmix Tower with usability and simplicity in mind, though some + features might require a foundational understanding of server + management principles +- We offer dedicated support to help with any custom setup needs or + questions that may arise +- For additional details, visit our website + `cetmix.com `__ **Table of contents** @@ -128,21 +127,21 @@ like to provide access to the Cetmix Tower. In the ``Cetmix Tower`` section select one of the following options in the ``Access Level`` field: -- **User**. Members of this group have read access only to the - `Servers <#configure-a-server>`__ which they are added as followers. - They also have access to the entities such as - `Commands <#configure-a-command>`__, `Flight - Plans <#configure-a-flight-plan>`__ or `Server - Logs <#configure-a-server-log>`__ with ``Access Level`` set to - ``User``. -- **Manager**. Members of this group can modify - `Servers <#configure-a-server>`__ which they are added as followers. - They can create new `Servers <#configure-a-server>`__ too however - they cannot delete them. Users of this group have access to the - entities with ``Access Level`` set to ``Manager`` or ``User``. -- **Root**. Members of this group can create, modify or delete any - `Server <#configure-a-server>`__. They also have access to the - entities with any ``Access Level`` set. +- **User**. Members of this group have read access only to the + `Servers <#configure-a-server>`__ which they are added as followers. + They also have access to the entities such as + `Commands <#configure-a-command>`__, `Flight + Plans <#configure-a-flight-plan>`__ or `Server + Logs <#configure-a-server-log>`__ with ``Access Level`` set to + ``User``. +- **Manager**. Members of this group can modify + `Servers <#configure-a-server>`__ which they are added as followers. + They can create new `Servers <#configure-a-server>`__ too however they + cannot delete them. Users of this group have access to the entities + with ``Access Level`` set to ``Manager`` or ``User``. +- **Root**. Members of this group can create, modify or delete any + `Server <#configure-a-server>`__. They also have access to the + entities with any ``Access Level`` set. **NB:** Please keep in mind that some of the entities can have their additional access management variations. @@ -159,32 +158,32 @@ Fill the values it the tabs below: **General Settings** -- **Partner**: Partner this server belongs to -- **Operating System**: Operating system that runs on the server -- **Tags**: User-defined search tags -- **IPv4 Address** -- **IPv6 Address**: Will be used if no IPv4 address is specified -- **SSH Auth Mode**: Available options are "Password" and "Key" -- **SSH Port** -- **SSH Username** -- **Use sudo**: If sudo is required by default for running all commands - on this server -- **SSH Password**: Used if Auth Mode is set to "Password" and for - running ``sudo`` commands with password -- **SSH Private Key**: Used for authentication is SSH Auth Mode is set - to "Key" -- **Note**: Comments or user notes +- **Partner**: Partner this server belongs to +- **Operating System**: Operating system that runs on the server +- **Tags**: User-defined search tags +- **IPv4 Address** +- **IPv6 Address**: Will be used if no IPv4 address is specified +- **SSH Auth Mode**: Available options are "Password" and "Key" +- **SSH Port** +- **SSH Username** +- **Use sudo**: If sudo is required by default for running all commands + on this server +- **SSH Password**: Used if Auth Mode is set to "Password" and for + running ``sudo`` commands with password +- **SSH Private Key**: Used for authentication is SSH Auth Mode is set + to "Key" +- **Note**: Comments or user notes 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: -- Undefined -- Stopped -- Starting -- Running -- Stopping -- Restarting +- Undefined +- Stopped +- Starting +- Running +- Stopping +- Restarting Default status is 'Undefined'. @@ -209,12 +208,12 @@ Log <#configure-a-server-log>`__ section for more details. Following action buttons are located in the top of the form: -- **Command Logs**: Shows all `Command <#configure-a-command>`__ logs - for this server -- **Flight Plan Logs**: Shows all `Flight - Plan <#configure-a-flight-plan>`__ logs for this server -- **Files**: Shows all `Files <#configure-a-file>`__ that belong to - this server +- **Command Logs**: Shows all `Command <#configure-a-command>`__ logs + for this server +- **Flight Plan Logs**: Shows all `Flight + Plan <#configure-a-flight-plan>`__ logs for this server +- **Files**: Shows all `Files <#configure-a-file>`__ that belong to this + server Configure a Server Template --------------------------- @@ -227,18 +226,18 @@ Fill the values it the tabs below: **General Settings** -- **Flight Plan**: Select a flight plan to be executed after a server - is created -- **Operating System**: Default operating system for new servers -- **Tags**: Default search tags for new servers -- **SSH Auth Mode**: Default SSH auth mode for new servers. Available - options are "Password" and "Key" -- **SSH Port**: Default SSH port for new servers -- **SSH Username**: Default SSH username for new servers -- **Use sudo**: Default sudo mode for new servers -- **SSH Password**: Default SSH password for new servers -- **SSH Private Key**: Default SSH private key for new servers -- **Note**: Comments or user notes +- **Flight Plan**: Select a flight plan to be executed after a server is + created +- **Operating System**: Default operating system for new servers +- **Tags**: Default search tags for new servers +- **SSH Auth Mode**: Default SSH auth mode for new servers. Available + options are "Password" and "Key" +- **SSH Port**: Default SSH port for new servers +- **SSH Username**: Default SSH username for new servers +- **Use sudo**: Default sudo mode for new servers +- **SSH Password**: Default SSH password for new servers +- **SSH Private Key**: Default SSH private key for new servers +- **Note**: Comments or user notes **Variables** @@ -257,11 +256,11 @@ Configure Variables To configure variables go to the ``Cetmix Tower -> Settings`` and select the ``Variables`` menu. Click ``Create`` and put values in the fields: -- **Name**: Readable name -- **Reference**: Unique identifier used to address variable in - conditions and expressions. Leave blank to generate automatically - based on name -- **Note**: Put your notes here +- **Name**: Readable name +- **Reference**: Unique identifier used to address variable in + conditions and expressions. Leave blank to generate automatically + based on name +- **Note**: Put your notes here Configure Tags -------------- @@ -269,12 +268,12 @@ Configure Tags To configure variables go to the ``Cetmix Tower -> Settings`` and select the ``Tags`` menu. Click ``Create`` and put values in the fields: -- **Name**: Readable name -- **Reference**: Unique identifier used to address the tag in - conditions and expressions. Leave this field blank to generate it - automatically based on the name -- **Color**: Select a color for the tag -- **Servers**: Select the servers associated with the tag. +- **Name**: Readable name +- **Reference**: Unique identifier used to address the tag in conditions + and expressions. Leave this field blank to generate it automatically + based on the name +- **Color**: Select a color for the tag +- **Servers**: Select the servers associated with the tag. Configure OSs (Operating Systems) --------------------------------- @@ -283,12 +282,12 @@ To configure operating systems, go to the ``Cetmix Tower -> Settings`` and select the ``OSs`` menu. Click ``Create`` and fill in the values for the following fields: -- **Name**: Readable name -- **Reference**: Unique identifier used to address the OS in conditions - and expressions. Leave this field blank to generate it automatically - based on the name. -- **Color**: Select a color for the OS. -- **Previous Version**: Select the previous version of the current OS. +- **Name**: Readable name +- **Reference**: Unique identifier used to address the OS in conditions + and expressions. Leave this field blank to generate it automatically + based on the name. +- **Color**: Select a color for the OS. +- **Previous Version**: Select the previous version of the current OS. Variables Applicability ~~~~~~~~~~~~~~~~~~~~~~~ @@ -296,15 +295,15 @@ Variables Applicability `Cetmix Tower `__ supports ``jinja2`` syntax for variables. You can use variables to render: -- Commands. Eg ``ls -lh {{ file_store_location }}`` -- Files. Eg a "Dockerfile" file can have the following text in it: - ``ODOO_VERSION = {{ odoo_default_version }}`` -- File Templates. You can use variables for both file name and file - location on server. Eg ``File Name`` value is - ``backup_{{ instance_name }}_{{ odoo_db_name }}`` and - ``Directory on server`` is ``{{ file_cron_location }}`` -- Other Variables. Eg for an ``odoo_config_location`` variable can have - a value of ``{{ odoo_root}}/conf`` +- Commands. Eg ``ls -lh {{ file_store_location }}`` +- Files. Eg a "Dockerfile" file can have the following text in it: + ``ODOO_VERSION = {{ odoo_default_version }}`` +- File Templates. You can use variables for both file name and file + location on server. Eg ``File Name`` value is + ``backup_{{ instance_name }}_{{ odoo_db_name }}`` and + ``Directory on server`` is ``{{ file_cron_location }}`` +- Other Variables. Eg for an ``odoo_config_location`` variable can have + a value of ``{{ odoo_root}}/conf`` You can use any ``jinja2`` supported expressions. For example ``if else`` statements: @@ -325,8 +324,8 @@ Variable Rendering Modes There are two rendering modes available: -- Generic (or ssh) mode -- Pythonic mode +- Generic (or ssh) mode +- Pythonic mode Let use the following code as example: @@ -372,10 +371,10 @@ Variable Types Following types of variable values available in `Cetmix Tower `__: -- Local values. Those are values that are defined at a record level. - For example for a server or an action. -- Global values. Those are values that are defined at the `Cetmix - Tower `__ level. +- Local values. Those are values that are defined at a record level. For + example for a server or an action. +- Global values. Those are values that are defined at the `Cetmix + Tower `__ level. 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 @@ -396,20 +395,20 @@ the ``tower`` variable unless you really need that on purpose. Following system variables are available: -- Server properties +- Server properties - - ``tower.server.name`` Current server name - - ``tower.server.reference`` Current server reference - - ``tower.server.username`` Current server SSH Username​ - - ``tower.server.ipv4`` Current server IPv4 Address​ - - ``tower.server.ipv6`` Current server IPv6 Address​ - - ``tower.server.partner_name`` Current server partner name + - ``tower.server.name`` Current server name + - ``tower.server.reference`` Current server reference + - ``tower.server.username`` Current server SSH Username​ + - ``tower.server.ipv4`` Current server IPv4 Address​ + - ``tower.server.ipv6`` Current server IPv6 Address​ + - ``tower.server.partner_name`` Current server partner name -- Helper tools +- Helper tools - - ``tower.tools.uuid`` Generates a random UUID4 - - ``tower.tools.today`` Current date - - ``tower.tools.now`` Current date time + - ``tower.tools.uuid`` Generates a random UUID4 + - ``tower.tools.today`` Current date + - ``tower.tools.now`` Current date time Configure a Key/Secret ---------------------- @@ -419,28 +418,28 @@ 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: -- **Name**: Readable name -- **Key Type**: Following values are available: - - - ``SSH Key`` is used to store SSH private keys. They are selectable - in `Server settings <#configure-a-server>`__ - - ``Secret`` used to store sensitive information that can be used - inline in commands. Eg a token or a password. Secrets cannot be - previewed in command preview and are replaced with placeholder in - `command <#configure-a-command>`__ logs. - -- **Reference**: Key/secret record reference -- **Reference Code**: Complete reference code for inline usage -- **Value**: Key value. **IMPORTANT:** This is a write only field. - Please ensure that you have saved your key/secret before saving it. - Once saved it cannot be read from the user interface any longer. -- **Used For**: ``SSH Key`` type only. List of - `Servers <#configure-a-server>`__ where this SSH key is used -- **Partner**: ``Secret`` type only. If selected this secret is used - only for the `Servers <#configure-a-server>`__ of selected partner -- **Server**: ``Secret`` type only. If selected this secret is used - only for selected `Server <#configure-a-server>`__ -- **Note**: Put your notes here +- **Name**: Readable name +- **Key Type**: Following values are available: + + - ``SSH Key`` is used to store SSH private keys. They are selectable + in `Server settings <#configure-a-server>`__ + - ``Secret`` used to store sensitive information that can be used + inline in commands. Eg a token or a password. Secrets cannot be + previewed in command preview and are replaced with placeholder in + `command <#configure-a-command>`__ logs. + +- **Reference**: Key/secret record reference +- **Reference Code**: Complete reference code for inline usage +- **Value**: Key value. **IMPORTANT:** This is a write only field. + Please ensure that you have saved your key/secret before saving it. + Once saved it cannot be read from the user interface any longer. +- **Used For**: ``SSH Key`` type only. List of + `Servers <#configure-a-server>`__ where this SSH key is used +- **Partner**: ``Secret`` type only. If selected this secret is used + only for the `Servers <#configure-a-server>`__ of selected partner +- **Server**: ``Secret`` type only. If selected this secret is used only + for selected `Server <#configure-a-server>`__ +- **Note**: Put your notes here Keys of type ``Secret`` ~~~~~~~~~~~~~~~~~~~~~~~ @@ -459,9 +458,9 @@ 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: -- ``#!cxtower`` is used to declare a special Tower construction -- ``secret`` is used to declare its type (secret) -- ``REFERENCE`` secret id as it's written in the **Key ID** field +- ``#!cxtower`` is used to declare a special Tower construction +- ``secret`` is used to declare its type (secret) +- ``REFERENCE`` secret id as it's written in the **Key ID** field **Example:** @@ -485,49 +484,49 @@ Configure a File file transfer operations. Based on initial file location following file sources are available: -- Server. These are files that are initially located on remote server - and are fetched to `Cetmix Tower `__. For - example log files. +- Server. These are files that are initially located on remote server + and are fetched to `Cetmix Tower `__. For + example log files. -- Tower. These are files that are initially formed in `Cetmix - Tower `__ and are uploaded to remote - server. For example configuration files. Such files are rendered - using variables and can be created and managed using file templates. +- Tower. These are files that are initially formed in `Cetmix + Tower `__ and are uploaded to remote server. + For example configuration files. Such files are rendered using + variables and can be created and managed using file templates. To create a new file go to ``Cetmix Tower -> Files -> Files`` click ``Create`` and put values in the fields: -- **Name**: Filesystem filename -- **Source**: File source. Available options are ``Server`` and - ``Tower``. Check above for more details. -- **File type**: Type of file contents. Possible options: - - - **Text**: Regular text. Eg configuration file or log - - **Binary**: Binary file. Eg file archive or pdf document - -- **File**: Is used to store binary file data. -- **Template**: File template used to render this file. If selected - file will be automatically updated every time template is modified. -- **Server**: Server where this file is located -- **Directory on Server**: This is where the file is located on the - remote server -- **Full Server Path**: Full path to file on the remote server - including filename -- **Auto Sync**: If enabled the file will be automatically uploaded to - the remote server on after it is modified in `Cetmix - Tower `__. Used only with ``Tower`` source. -- **Keep when deleted**: If enabled, file will be kept on remote server - after removing it in the Odoo +- **Name**: Filesystem filename +- **Source**: File source. Available options are ``Server`` and + ``Tower``. Check above for more details. +- **File type**: Type of file contents. Possible options: + + - **Text**: Regular text. Eg configuration file or log + - **Binary**: Binary file. Eg file archive or pdf document + +- **File**: Is used to store binary file data. +- **Template**: File template used to render this file. If selected file + will be automatically updated every time template is modified. +- **Server**: Server where this file is located +- **Directory on Server**: This is where the file is located on the + remote server +- **Full Server Path**: Full path to file on the remote server including + filename +- **Auto Sync**: If enabled the file will be automatically uploaded to + the remote server on after it is modified in `Cetmix + Tower `__. Used only with ``Tower`` source. +- **Keep when deleted**: If enabled, file will be kept on remote server + after removing it in the Odoo Following fields are located in the tabs below: -- **Code**: Raw file content. This field is editable for the ``Tower`` - files and readonly for ``Server`` ones. This field supports - `Variables <#configure-variables>`__. -- **Preview**: This is a rendered file content as it will be uploaded - to server. Used only with ``Tower`` source. -- **Server Version**: Current file content fetched from server. Used - only with ``Tower`` source. +- **Code**: Raw file content. This field is editable for the ``Tower`` + files and readonly for ``Server`` ones. This field supports + `Variables <#configure-variables>`__. +- **Preview**: This is a rendered file content as it will be uploaded to + server. Used only with ``Tower`` source. +- **Server Version**: Current file content fetched from server. Used + only with ``Tower`` source. **NB**: File operations are performed using user credentials from server configuration. You should take care of filesystem access rights to @@ -543,27 +542,27 @@ To create a new file template go to ``Cetmix Tower -> Files -> Templates`` click ``Create`` and put values in the fields: -- **Name**: Template name -- **Reference**: Leave the "reference" field blank to generate a - reference automatically. -- **File Name**: Filesystem name of the file(s) created from this - template. This field supports `Variables <#configure-variables>`__. -- **Directory on server**: Directory on remote server where this file - will be stored. This field supports - `Variables <#configure-variables>`__. -- **Source**: File source. Available options are ``Server`` and - ``Tower``. Check above for more details. -- **File type**: Type of file contents. Possible options: - - - **Text**: Regular text. Eg configuration file or log - - **Binary**: Binary file. Eg file archive or pdf document - -- **Tags**: Make usage as search more convenient -- **Note**: Comments or user notes -- **Code**: Raw file content. This field supports - `Variables <#configure-variables>`__. -- **Keep when deleted**: If enabled, file(s) created from this template - will be kept on remote server after removing it(them) in the Odoo +- **Name**: Template name +- **Reference**: Leave the "reference" field blank to generate a + reference automatically. +- **File Name**: Filesystem name of the file(s) created from this + template. This field supports `Variables <#configure-variables>`__. +- **Directory on server**: Directory on remote server where this file + will be stored. This field supports + `Variables <#configure-variables>`__. +- **Source**: File source. Available options are ``Server`` and + ``Tower``. Check above for more details. +- **File type**: Type of file contents. Possible options: + + - **Text**: Regular text. Eg configuration file or log + - **Binary**: Binary file. Eg file archive or pdf document + +- **Tags**: Make usage as search more convenient +- **Note**: Comments or user notes +- **Code**: Raw file content. This field supports + `Variables <#configure-variables>`__. +- **Keep when deleted**: If enabled, file(s) created from this template + will be kept on remote server after removing it(them) in the Odoo **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 @@ -576,62 +575,59 @@ 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: -- **Name**: Command readable name. +- **Name**: Command readable name. -- **Reference**: Leave the "reference" field blank to generate a - reference automatically. +- **Reference**: Leave the "reference" field blank to generate a + reference automatically. -- **Allow Parallel Run**: If disabled only one copy of this command can - be run on the same server at the same time. Otherwise the same - command can be run in parallel. +- **Allow Parallel Run**: If disabled only one copy of this command can + be run on the same server at the same time. Otherwise the same command + can be run in parallel. -- **Note**: Comments or user notes. +- **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. +- **Servers**: List of servers this command can be run on. Leave this + field blank to make the command available to all servers. -- **OSes**: List of operating systems this command is available. Leave - this field blank to make the command available for all OSes. +- **OSes**: List of operating systems this command is available. Leave + this field blank to make the command available for all OSes. -- **Tags**: Make usage as search more convenient. +- **Tags**: Make usage as search more convenient. -- **Action**: Action executed by the command. Possible options: +- **Action**: Action executed by the command. Possible options: - - ``SSH command``: Execute a shell command using ssh connection on - remote server. - - ``Execute Python code``: Execute a Python code on the Tower - Server. - - ``Create file using template``: Create or update a file using - selected file template and push / pull it to remote server / - tower. If the file already exists on server it will be - overwritten. - - ``Run flight plan``: Allow to start Flight Plan execution from - command (). + - ``SSH command``: Execute a shell command using ssh connection on + remote server. + - ``Execute Python code``: Execute a Python code on the Tower Server. + - ``Create file using template``: Create or update a file using + selected file template and push / pull it to remote server / tower. + If the file already exists on server it will be overwritten. + - ``Run flight plan``: Allow to start Flight Plan execution from + command (). -- **Default Path**: Specify path where command will be executed. This - field supports `Variables <#configure-variables>`__. Important: - ensure ssh user has access to the location even if executing command - using sudo. +- **Default Path**: Specify path where command will be executed. This + field supports `Variables <#configure-variables>`__. Important: ensure + ssh user has access to the location even if executing command using + sudo. -- **Code**: Code to execute. Can be an SSH command or Python code based - on selected action. This field supports - `Variables <#configure-variables>`__. **Important!** Variables used - in command are rendered in `different - modes <#variable-rendering-modes>`__ based on the command action. +- **Code**: Code to execute. Can be an SSH command or Python code based + on selected action. This field supports + `Variables <#configure-variables>`__. **Important!** Variables used in + command are rendered in `different + modes <#variable-rendering-modes>`__ based on the command action. -- **File Template**: File template that will be used to create or - update file. Check `File Templates <#file-templates>`__ for more - details. +- **File Template**: File template that will be used to create or update + file. Check `File Templates <#file-templates>`__ for more details. -- **Server Status**: Server status to be set after command execution. - Possible options: +- **Server Status**: Server status to be set after command execution. + Possible options: - - ``Undefined``. Default status. - - ``Stopped``. Server is stopped. - - ``Starting``. Server is starting. - - ``Running``. Server is running. - - ``Stopping``. Server is stopping. - - ``Restarting``. Server is restarting. + - ``Undefined``. Default status. + - ``Stopped``. Server is stopped. + - ``Starting``. Server is starting. + - ``Running``. Server is running. + - ``Stopping``. Server is stopping. + - ``Restarting``. Server is restarting. To return result from Python assign exit code and message to the COMMAND_RESULT variable of type ``dict`` like this: @@ -658,66 +654,65 @@ 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 +- **Name**: Flight Plan name -- **Reference**: Leave the "reference" field blank to generate a - reference automatically. +- **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: +- **On Error**: Default action to execute when an error happens during + the flight plan execution. Possible options: - - ``Exit with command code``. Will terminate the flight plan - execution and return an exit code of the failed command. - - ``Exit with custom code``. Will terminate the flight plan - execution and return the custom code configured in the field next - to this one. - - ``Run next command``. Will continue flight plan execution. + - ``Exit with command code``. Will terminate the flight plan execution + and return an exit code of the failed command. + - ``Exit with custom code``. Will terminate the flight plan execution + and return the custom code configured in the field next to this one. + - ``Run next command``. Will continue flight plan execution. -- **Note**: Comments or user notes. +- **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. +- **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. +- **Tags**: Make usage as search more convenient. -- **Code**: List of commands to execute. Each of the commands has the - following fields: +- **Code**: List of commands to execute. Each of the commands has the + following fields: - - **Sequence**: Order this command is executed. Lower value = higher - priority. - - **Condition**: `Python - expression `__ - to be matched for the command to be executed. Leave this field - blank for unconditional command execution. This field supports - `Variables <#configure-variables>`__. Example: + - **Sequence**: Order this command is executed. Lower value = higher + priority. + - **Condition**: `Python + expression `__ + to be matched for the command to be executed. Leave this field blank + for unconditional command execution. This field supports + `Variables <#configure-variables>`__. Example: - .. code:: python + .. code:: python - {{ odoo_version }} == "17.0" and ( {{ nginx_installed }} or {{ traefik_installed }} ) + {{ odoo_version }} == "17.0" and ( {{ nginx_installed }} or {{ traefik_installed }} ) - - **Command**: `Command <#configure-a-command>`__ to be executed. - - **Path**: Specify path where command will be executed. Overrides - ``Default Path`` of the command. This field supports - `Variables <#configure-variables>`__. - - **Use Sudo**: Use ``sudo`` if required to run this command. - - **Post Run Actions**: List of conditional actions to be triggered - after the command is executed. Each of the actions has the - following fields: + - **Command**: `Command <#configure-a-command>`__ to be executed. + - **Path**: Specify path where command will be executed. Overrides + ``Default Path`` of the command. This field supports + `Variables <#configure-variables>`__. + - **Use Sudo**: Use ``sudo`` if required to run this command. + - **Post Run Actions**: List of conditional actions to be triggered + after the command is executed. Each of the actions has the following + fields: - - **Sequence**: Order this actions is triggered. Lower value = - higher priority. - - **Condition**: Uses command exit code. - - **Action**: Action to execute if condition is met. Also, if - variables with values are specified, these variables will be - updated (for existing variables on the server) or added (for - new variables) to the server variables. Possible options: + - **Sequence**: Order this actions is triggered. Lower value = + higher priority. + - **Condition**: Uses command exit code. + - **Action**: Action to execute if condition is met. Also, if + variables with values are specified, these variables will be + updated (for existing variables on the server) or added (for new + variables) to the server variables. Possible options: - - ``Exit with command code``. Will terminate the flight plan - execution and return an exit code of the failed command. - - ``Exit with custom code``. Will terminate the flight plan - execution and return the custom code configured in the field - next to this one. - - ``Run next command``. Will continue flight plan execution. + - ``Exit with command code``. Will terminate the flight plan + execution and return an exit code of the failed command. + - ``Exit with custom code``. Will terminate the flight plan + execution and return the custom code configured in the field + next to this one. + - ``Run next command``. Will continue flight plan execution. Configure a Server Log ---------------------- @@ -730,38 +725,36 @@ way. To configure a Server Log open the server form, navigate to the Following fields are available: -- **Name**: Readable name of the log -- **Access Level**: Minimum access level required to access this - record. Please check the `User Access - Settings <#user-access-configuration>`__ section for more details. - Possible options: - - - ``User``. User must have at least ``Cetmix Tower / User`` access - group configured in the User Settings. - - ``Manager``. User must have at least ``Cetmix Tower / Manager`` - access group configured in the User Settings. - - ``Root``. User must have ``Cetmix Tower / Root`` access group - configured in the User Settings. - -- **Log Type**: Defines the way logs are fetched. Possible options: - - - ``Command``. A command is run with its output being saved to the - log - - ``File``. Log is fetched from a file - -- **Command**: A command that is used to fetched the logs. This option - is available only for ``Log Type`` set to ``Command``. Important: - please ensure that selected command can be executed multiple times in - parallel to avoid any potential issues. -- **Use Sudo**: Use ``sudo`` if required to run this command. -- **File**: A file that is used to fetch the log. This option is not - available when configuring a log for a `Server - Template <#configure-a-server-template>`__ -- **File Template**: A file template that is used to create a file when - a new `Server <#configure-a-server>`__ is created from a `Server - Template <#configure-a-server-template>`__. This option is available - only when configuring a log for a `Server - Template <#configure-a-server-template>`__ +- **Name**: Readable name of the log +- **Access Level**: Minimum access level required to access this record. + Please check the `User Access Settings <#user-access-configuration>`__ + section for more details. Possible options: + + - ``User``. User must have at least ``Cetmix Tower / User`` access + group configured in the User Settings. + - ``Manager``. User must have at least ``Cetmix Tower / Manager`` + access group configured in the User Settings. + - ``Root``. User must have ``Cetmix Tower / Root`` access group + configured in the User Settings. + +- **Log Type**: Defines the way logs are fetched. Possible options: + + - ``Command``. A command is run with its output being saved to the log + - ``File``. Log is fetched from a file + +- **Command**: A command that is used to fetched the logs. This option + is available only for ``Log Type`` set to ``Command``. Important: + please ensure that selected command can be executed multiple times in + parallel to avoid any potential issues. +- **Use Sudo**: Use ``sudo`` if required to run this command. +- **File**: A file that is used to fetch the log. This option is not + available when configuring a log for a `Server + Template <#configure-a-server-template>`__ +- **File Template**: A file template that is used to create a file when + a new `Server <#configure-a-server>`__ is created from a `Server + Template <#configure-a-server-template>`__. This option is available + only when configuring a log for a `Server + Template <#configure-a-server-template>`__ **Developer hint**: log output supports HTML formatting. You can implement your custom log formatter by overriding the @@ -778,9 +771,9 @@ needed. Use flight plans instead. **Why?** -- Simple commands are easier to reuse across multiple flight plans. -- Commands run with ``sudo`` with password are be split and executed - one by one anyway. +- Simple commands are easier to reuse across multiple flight plans. +- Commands run with ``sudo`` with password are be split and executed one + by one anyway. **Not recommended:** @@ -810,8 +803,8 @@ command or ``Path`` field in flight plan line. **Why?** -- Tower will automatically adjust the command to ensure it is properly - executed in the specified location. +- Tower will automatically adjust the command to ensure it is properly + executed in the specified location. **Do not do this:** @@ -821,21 +814,21 @@ command or ``Path`` field in flight plan line. **Way to go:** -- Add the following value in the ``Default Path`` command field or - ``Path`` field of a flight plan line: +- Add the following value in the ``Default Path`` command field or + ``Path`` field of a flight plan line: .. code:: bash /home/{{ tower.server.username }}/memes -- Leave the command code as follows: +- Leave the command code as follows: .. code:: bash cat my_doge_memes.txt -.. |User profile| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0-dev/cetmix_tower_server/static/description/images/user_profile.png -.. |Server logs tab| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0-dev/cetmix_tower_server/static/description/images/server_log_tab.png +.. |User profile| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0/cetmix_tower_server/static/description/images/user_profile.png +.. |Server logs tab| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0/cetmix_tower_server/static/description/images/server_log_tab.png Usage ===== @@ -843,16 +836,16 @@ Usage Create a new Server from a Server Template ------------------------------------------ -- Go to the ``Cetmix Tower/Servers/Templates`` menu and select a - `Server Template `__ -- Click "Create Server" button. A pop-up wizard will open with server - parameters populated from the template -- Put the new server name, check the parameters and click "Confirm" - button -- New server will be created -- If a `Flight Plan `__ is - defined in the server template it will be automatically executed - after a new server is created +- Go to the ``Cetmix Tower/Servers/Templates`` menu and select a `Server + Template `__ +- Click "Create Server" button. A pop-up wizard will open with server + parameters populated from the template +- Put the new server name, check the parameters and click "Confirm" + button +- New server will be created +- If a `Flight Plan `__ is + defined in the server template it will be automatically executed after + a new server is created You can also create a new server from template from code using a designated ``create_server_from_template`` function of the @@ -909,34 +902,34 @@ server when a Sales Order is confirmed: Run a Command ------------- -- Select a server in the list view or open a server form view -- Open the ``Actions`` menu and click ``Execute Command`` -- A wizard is opened with the following fields: - - - **Servers**: Servers on which this command will be executed - - **Tags**: If selected only commands with these tags will be shown - - **Sudo**: ``sudo`` option for running this command - - **Command**: Command to execute - - **Show shared**: By default only commands available for the - selected server(s) are selectable. Activate this checkbox to - select any command - - **Path**: Directory where command will be executed. Important: - this field does not support variables! Ensure that user has access - to this location even if you run command using sudo. - - **Code**: Raw command code - - **Preview**: Command code rendered using server variables. - **IMPORTANT:** If several servers are selected preview will not be - rendered. However during the command execution command code will - be rendered for each server separately. +- Select a server in the list view or open a server form view +- Open the ``Actions`` menu and click ``Execute Command`` +- A wizard is opened with the following fields: + + - **Servers**: Servers on which this command will be executed + - **Tags**: If selected only commands with these tags will be shown + - **Sudo**: ``sudo`` option for running this command + - **Command**: Command to execute + - **Show shared**: By default only commands available for the selected + server(s) are selectable. Activate this checkbox to select any + command + - **Path**: Directory where command will be executed. Important: this + field does not support variables! Ensure that user has access to + this location even if you run command using sudo. + - **Code**: Raw command code + - **Preview**: Command code rendered using server variables. + **IMPORTANT:** If several servers are selected preview will not be + rendered. However during the command execution command code will be + rendered for each server separately. There are two action buttons available in the wizard: -- **Run**. Executes a command using server "run" method and log command - result into the "Command Log". -- **Run in wizard**. Executes a command directly in the wizard and show - command log in a new wizard window. **IMPORTANT:** Button will be - show only if single server is selected. If you try to run a command - for several servers from code, you will get a ValidationError. +- **Run**. Executes a command using server "run" method and log command + result into the "Command Log". +- **Run in wizard**. Executes a command directly in the wizard and show + command log in a new wizard window. **IMPORTANT:** Button will be show + only if single server is selected. If you try to run a command for + several servers from code, you will get a ValidationError. You can check command execution logs in the ``Cetmix Tower/Commands/Command Logs`` menu. Important! If you want to @@ -946,44 +939,44 @@ that. Run a Flight Plan ----------------- -- Select a server in the list view or open a server form view +- Select a server in the list view or open a server form view -- Open the ``Actions`` menu and click ``Execute Flight Plan`` +- Open the ``Actions`` menu and click ``Execute Flight Plan`` -- A wizard is opened with the following fields: +- A wizard is opened with the following fields: - - **Servers**: Servers on which this command will be executed - - **Tags**: If selected only commands with these tags will be shown - - **Plan**: Flight plan to execute - - **Show shared**: By default only flight plans available for the - selected server(s) are selectable. Activate this checkbox to - select any flight plan - - **Commands**: Commands that will be executed in this flight plan. - This field is read only + - **Servers**: Servers on which this command will be executed + - **Tags**: If selected only commands with these tags will be shown + - **Plan**: Flight plan to execute + - **Show shared**: By default only flight plans available for the + selected server(s) are selectable. Activate this checkbox to select + any flight plan + - **Commands**: Commands that will be executed in this flight plan. + This field is read only - Click the **Run** button to execute a flight plan. + 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. + 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. Check a Server Log ------------------ To check a server log: -- Navigate to the ``Server Logs`` tab on the Server form -- Click on the log **(1)** you would like to check to open in in a pop - up window. Or click on the ``Open`` button **(2)** to open it in the - full form view +- Navigate to the ``Server Logs`` tab on the Server form +- Click on the log **(1)** you would like to check to open in in a pop + up window. Or click on the ``Open`` button **(2)** to open it in the + full form view |Open server log| -- Click the ``Refresh`` button to update the log. You can also click - the ``Refresh All`` button **(3)** located above the log list in - order to refresh all logs at once. Log output will be displayed in - the HTML field below. +- Click the ``Refresh`` button to update the log. You can also click the + ``Refresh All`` button **(3)** located above the log list in order to + refresh all logs at once. Log output will be displayed in the HTML + field below. |Update server log| @@ -997,9 +990,9 @@ 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`` -.. |Automatic action| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0-dev/cetmix_tower_server/static/description/images/server_from_template_auto_action.png -.. |Open server log| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0-dev/cetmix_tower_server/static/description/images/server_log_usage_1.png -.. |Update server log| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0-dev/cetmix_tower_server/static/description/images/server_log_usage_2.png +.. |Automatic action| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0/cetmix_tower_server/static/description/images/server_from_template_auto_action.png +.. |Open server log| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0/cetmix_tower_server/static/description/images/server_log_usage_1.png +.. |Update server log| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0/cetmix_tower_server/static/description/images/server_log_usage_2.png Bug Tracker =========== @@ -1007,7 +1000,7 @@ Bug Tracker 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -1022,6 +1015,6 @@ Authors Maintainers ----------- -This module is part of the `cetmix/cetmix-tower `_ project on GitHub. +This module is part of the `cetmix/cetmix-tower `_ project on GitHub. You are welcome to contribute. diff --git a/cetmix_tower_server/__init__.py b/cetmix_tower_server/__init__.py index aee8895e..d8b99ed9 100644 --- a/cetmix_tower_server/__init__.py +++ b/cetmix_tower_server/__init__.py @@ -1,2 +1,4 @@ +# pylint: disable=E8103 + from . import models from . import wizards diff --git a/cetmix_tower_server/models/cx_tower_command.py b/cetmix_tower_server/models/cx_tower_command.py index d2abb924..e5b6d928 100644 --- a/cetmix_tower_server/models/cx_tower_command.py +++ b/cetmix_tower_server/models/cx_tower_command.py @@ -76,6 +76,8 @@ def _selection_action(self): column1="command_id", column2="server_id", string="Servers", + help="Servers on which the command will be executed.\n" + "If empty, command canbe executed on all servers", ) tag_ids = fields.Many2many( comodel_name="cx.tower.tag", @@ -133,6 +135,7 @@ def _compute_variable_ids(self): for record in self: record.variable_ids = record._prepare_variable_commands(["code", "path"]) + # TODO: move this up server_status = fields.Selection( selection=lambda self: self.env["cx.tower.server"]._selection_status(), string="Server Status", @@ -142,6 +145,17 @@ def _compute_variable_ids(self): ), ) + # Depend on related servers and partners + @api.depends( + "code", + "server_ids", + "server_ids.partner_id", + "secret_ids.server_id", + "secret_ids.partner_id", + ) + def _compute_secret_ids(self): + return super()._compute_secret_ids() + @api.depends("action") def _compute_code(self): """ @@ -201,3 +215,16 @@ def action_open_command_logs(self): ) action["domain"] = [("command_id", "=", self.id)] return action + + def _compose_secret_search_domain(self, key_refs): + # Check server anb partner specific secrets + return [ + ("reference", "in", key_refs), + "|", + "|", + ("server_id", "in", self.server_ids.ids), + ("partner_id", "in", self.server_ids.partner_id.ids), + "&", + ("server_id", "=", False), + ("partner_id", "=", False), + ] diff --git a/cetmix_tower_server/models/cx_tower_file_template.py b/cetmix_tower_server/models/cx_tower_file_template.py index 6436e607..96a99b92 100644 --- a/cetmix_tower_server/models/cx_tower_file_template.py +++ b/cetmix_tower_server/models/cx_tower_file_template.py @@ -9,7 +9,7 @@ class CxTowerFileTemplate(models.Model): _name = "cx.tower.file.template" - _inherit = ["cx.tower.reference.mixin"] + _inherit = ["cx.tower.reference.mixin", "cx.tower.key.mixin"] _description = "Cx Tower File Template" def _compute_file_count(self): diff --git a/cetmix_tower_server/models/cx_tower_key.py b/cetmix_tower_server/models/cx_tower_key.py index 4c35baa4..9898e6c9 100644 --- a/cetmix_tower_server/models/cx_tower_key.py +++ b/cetmix_tower_server/models/cx_tower_key.py @@ -3,6 +3,7 @@ import re from odoo import _, api, fields, models +from odoo.exceptions import ValidationError from odoo.osv.expression import OR @@ -47,13 +48,49 @@ class CxTowerKey(models.Model): ) note = fields.Text() - _sql_constraints = [ - ( - "reference_unique", - "UNIQUE(reference, partner_id, server_id)", - "Reference must be unique", + def init(self): + """ + Remove constraint defined from the mixin + """ + self._cr.execute( + """ + DO $$ + BEGIN + IF EXISTS ( + SELECT 1 + FROM information_schema.table_constraints + WHERE table_name = 'cx_tower_key' AND + constraint_name = 'cx_tower_key_reference_unique' + ) THEN + ALTER TABLE cx_tower_key + DROP CONSTRAINT cx_tower_key_reference_unique; + END IF; + END$$; + """ ) - ] + + @api.constrains("reference", "partner_id", "server_id") + def _check_reference_unique(self): + """ORM constraint to ensure uniqueness""" + + # Need to check archive records as well + for rec in self.with_context(active_test=False): + if ( + self.search_count( + [ + ("reference", "=", rec.reference), + ("partner_id", "=", rec.partner_id.id), + ("server_id", "=", rec.server_id.id), + ] + ) + > 1 + ): + raise ValidationError( + _( + "Reference must be unique for the combination of partner" + " and server" + ) + ) def _compute_reference_code(self): """Compute key reference diff --git a/cetmix_tower_server/models/cx_tower_key_mixin.py b/cetmix_tower_server/models/cx_tower_key_mixin.py index 483e1e15..8ea106a0 100644 --- a/cetmix_tower_server/models/cx_tower_key_mixin.py +++ b/cetmix_tower_server/models/cx_tower_key_mixin.py @@ -54,8 +54,15 @@ def _extract_secret_ids(self, code): if key_parts: key_refs.append(key_parts[1]) - return key_model.search( - [ - ("reference", "in", key_refs), - ] - ) + return key_model.search(self._compose_secret_search_domain(key_refs)) + + def _compose_secret_search_domain(self, key_refs): + """Compose domain for searching secrets by references. + + Args: + key_refs (List[str]): List of secret references. + + Returns: + List: final domain for searching secrets. + """ + return [("reference", "in", key_refs)] diff --git a/cetmix_tower_server/static/description/index.html b/cetmix_tower_server/static/description/index.html index dd902635..552a6273 100644 --- a/cetmix_tower_server/static/description/index.html +++ b/cetmix_tower_server/static/description/index.html @@ -369,7 +369,7 @@

Cetmix Tower Server Management

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! source digest: sha256:4b055a9f60e7fa95ab04b470c0bf1fad7de7a7b795f211ba8d282abb73b0a212 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 cetmix/cetmix-tower

+

Beta License: AGPL-3 cetmix/cetmix-tower

Cetmix Tower offers a streamlined solution for managing remote servers via SSH or API calls directly from Odoo. It is designed for versatility across @@ -410,8 +410,7 @@

Connectivity

  • Password and key based authentication for outgoing SSH connections
  • Built-in support of the Python requests -library for outgoing API -calls
  • +library for outgoing API calls
@@ -470,7 +469,7 @@

User access configuration

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.

-

User profile

+

User profile

In the Cetmix Tower section select one of the following options in the Access Level field:

    @@ -483,9 +482,9 @@

    User access configuration

    User.
  • Manager. Members of this group can modify Servers which they are added as followers. -They can create new Servers too however -they cannot delete them. Users of this group have access to the -entities with Access Level set to Manager or User.
  • +They can create new Servers too however they +cannot delete them. Users of this group have access to the entities +with Access Level set to Manager or User.
  • Root. Members of this group can create, modify or delete any Server. They also have access to the entities with any Access Level set.
  • @@ -549,8 +548,8 @@

    Configure a Server

    for this server
  • Flight Plan Logs: Shows all Flight Plan logs for this server
  • -
  • Files: Shows all Files that belong to -this server
  • +
  • Files: Shows all Files that belong to this +server
@@ -561,8 +560,8 @@

Configure a Server Template

Fill the values it the tabs below:

General Settings

    -
  • Flight Plan: Select a flight plan to be executed after a server -is created
  • +
  • Flight Plan: Select a flight plan to be executed after a server is +created
  • Operating System: Default operating system for new servers
  • Tags: Default search tags for new servers
  • SSH Auth Mode: Default SSH auth mode for new servers. Available @@ -600,9 +599,9 @@

    Configure Tags

    the Tags menu. Click Create and put values in the fields:

    • Name: Readable name
    • -
    • Reference: Unique identifier used to address the tag in -conditions and expressions. Leave this field blank to generate it -automatically based on the name
    • +
    • Reference: Unique identifier used to address the tag in conditions +and expressions. Leave this field blank to generate it automatically +based on the name
    • Color: Select a color for the tag
    • Servers: Select the servers associated with the tag.
    @@ -692,8 +691,8 @@

    Variable Types

    Following types of variable values available in Cetmix Tower:

      -
    • Local values. Those are values that are defined at a record level. -For example for a server or an action.
    • +
    • Local values. Those are values that are defined at a record level. For +example for a server or an action.
    • Global values. Those are values that are defined at the Cetmix Tower level.
    @@ -757,8 +756,8 @@

    Configure a Key/Secret

    Servers where this SSH key is used
  • Partner: Secret type only. If selected this secret is used only for the Servers of selected partner
  • -
  • Server: Secret type only. If selected this secret is used -only for selected Server
  • +
  • Server: Secret type only. If selected this secret is used only +for selected Server
  • Note: Put your notes here
@@ -803,9 +802,9 @@

Configure a File

and are fetched to Cetmix Tower. For example log files.
  • Tower. These are files that are initially formed in Cetmix -Tower and are uploaded to remote -server. For example configuration files. Such files are rendered -using variables and can be created and managed using file templates.
  • +Tower and are uploaded to remote server. +For example configuration files. Such files are rendered using +variables and can be created and managed using file templates.

    To create a new file go to Cetmix Tower -> Files -> Files click Create and put values in the fields:

    @@ -819,13 +818,13 @@

    Configure a File

  • File: Is used to store binary file data.
  • -
  • Template: File template used to render this file. If selected -file will be automatically updated every time template is modified.
  • +
  • Template: File template used to render this file. If selected file +will be automatically updated every time template is modified.
  • Server: Server where this file is located
  • Directory on Server: This is where the file is located on the remote server
  • -
  • Full Server Path: Full path to file on the remote server -including filename
  • +
  • Full Server Path: Full path to file on the remote server including +filename
  • Auto Sync: If enabled the file will be automatically uploaded to the remote server on after it is modified in Cetmix Tower. Used only with Tower source.
  • @@ -837,8 +836,8 @@

    Configure a File

  • Code: Raw file content. This field is editable for the Tower files and readonly for Server ones. This field supports Variables.
  • -
  • Preview: This is a rendered file content as it will be uploaded -to server. Used only with Tower source.
  • +
  • Preview: This is a rendered file content as it will be uploaded to +server. Used only with Tower source.
  • Server Version: Current file content fetched from server. Used only with Tower source.
  • @@ -890,8 +889,8 @@

    Configure a Command

  • Reference: Leave the “reference” field blank to generate a reference automatically.
  • Allow Parallel Run: If disabled only one copy of this command can -be run on the same server at the same time. Otherwise the same -command can be run in parallel.
  • +be run on the same server at the same time. Otherwise the same command +can be run in parallel.
  • 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.
  • @@ -901,28 +900,25 @@

    Configure a Command

  • Action: Action executed by the command. Possible options:
    • SSH command: Execute a shell command using ssh connection on remote server.
    • -
    • Execute Python code: Execute a Python code on the Tower -Server.
    • +
    • Execute Python code: Execute a Python code on the Tower Server.
    • Create file using template: Create or update a file using -selected file template and push / pull it to remote server / -tower. If the file already exists on server it will be -overwritten.
    • +selected file template and push / pull it to remote server / tower. +If the file already exists on server it will be overwritten.
    • Run flight plan: Allow to start Flight Plan execution from command ().
  • Default Path: Specify path where command will be executed. This -field supports Variables. Important: -ensure ssh user has access to the location even if executing command -using sudo.
  • +field supports Variables. Important: ensure +ssh user has access to the location even if executing command using +sudo.
  • Code: Code to execute. Can be an SSH command or Python code based on selected action. This field supports -Variables. Important! Variables used -in command are rendered in different +Variables. Important! Variables used in +command are rendered in different modes based on the command action.
  • -
  • File Template: File template that will be used to create or -update file. Check File Templates for more -details.
  • +
  • File Template: File template that will be used to create or update +file. Check File Templates for more details.
  • Server Status: Server status to be set after command execution. Possible options:
    • Undefined. Default status.
    • @@ -965,11 +961,10 @@

      Configure a Flight Plan

    • On Error: Default action to execute when an error happens during the flight plan execution. Possible options:

        -
      • Exit with command code. Will terminate the flight plan -execution and return an exit code of the failed command.
      • -
      • Exit with custom code. Will terminate the flight plan -execution and return the custom code configured in the field next -to this one.
      • +
      • Exit with command code. Will terminate the flight plan execution +and return an exit code of the failed command.
      • +
      • Exit with custom code. Will terminate the flight plan execution +and return the custom code configured in the field next to this one.
      • Run next command. Will continue flight plan execution.
    • @@ -987,8 +982,8 @@

      Configure a Flight Plan

      priority.
    • Condition: Python expression -to be matched for the command to be executed. Leave this field -blank for unconditional command execution. This field supports +to be matched for the command to be executed. Leave this field blank +for unconditional command execution. This field supports Variables. Example:
    @@ -1001,15 +996,15 @@ 

    Configure a Flight Plan

    Variables.
  • Use Sudo: Use sudo if required to run this command.
  • Post Run Actions: List of conditional actions to be triggered -after the command is executed. Each of the actions has the -following fields:
      +after the command is executed. Each of the actions has the following +fields:
      • Sequence: Order this actions is triggered. Lower value = higher priority.
      • Condition: Uses command exit code.
      • Action: Action to execute if condition is met. Also, if variables with values are specified, these variables will be -updated (for existing variables on the server) or added (for -new variables) to the server variables. Possible options:
          +updated (for existing variables on the server) or added (for new +variables) to the server variables. Possible options:
          • Exit with command code. Will terminate the flight plan execution and return an exit code of the failed command.
          • Exit with custom code. Will terminate the flight plan @@ -1029,14 +1024,13 @@

            Configure a Server Log

            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.

            -

            Server logs tab

            +

            Server logs tab

            Following fields are available:

            • Name: Readable name of the log
            • -
            • Access Level: Minimum access level required to access this -record. Please check the User Access -Settings section for more details. -Possible options:
                +
              • Access Level: Minimum access level required to access this record. +Please check the User Access Settings +section for more details. Possible options:
                • User. User must have at least Cetmix Tower / User access group configured in the User Settings.
                • Manager. User must have at least Cetmix Tower / Manager @@ -1046,8 +1040,7 @@

                  Configure a Server Log

              • Log Type: Defines the way logs are fetched. Possible options:
                  -
                • Command. A command is run with its output being saved to the -log
                • +
                • Command. A command is run with its output being saved to the log
                • File. Log is fetched from a file
              • @@ -1078,8 +1071,8 @@

                Use simple commands

                Why?

                • Simple commands are easier to reuse across multiple flight plans.
                • -
                • Commands run with sudo with password are be split and executed -one by one anyway.
                • +
                • Commands run with sudo with password are be split and executed one +by one anyway.

                Not recommended:

                @@ -1131,16 +1124,16 @@ 

                Usage

                Create a new Server from a Server Template

                  -
                • Go to the Cetmix Tower/Servers/Templates menu and select a -Server Template
                • +
                • Go to the Cetmix Tower/Servers/Templates menu and select a Server +Template
                • Click “Create Server” button. A pop-up wizard will open with server parameters populated from the template
                • Put the new server name, check the parameters and click “Confirm” button
                • New server will be created
                • If a Flight Plan is -defined in the server template it will be automatically executed -after a new server is created
                • +defined in the server template it will be automatically executed after +a new server is created

                You can also create a new server from template from code using a designated create_server_from_template function of the @@ -1164,7 +1157,7 @@

                Create a new Server from a Server Template

                Here is a short example of an Odoo automated action that creates a new server when a Sales Order is confirmed:

                -

                Automatic action

                +

                Automatic action

                 for record in records:
                 
                @@ -1199,17 +1192,17 @@ 

                Run a Command

              • Tags: If selected only commands with these tags will be shown
              • Sudo: sudo option for running this command
              • Command: Command to execute
              • -
              • Show shared: By default only commands available for the -selected server(s) are selectable. Activate this checkbox to -select any command
              • -
              • Path: Directory where command will be executed. Important: -this field does not support variables! Ensure that user has access -to this location even if you run command using sudo.
              • +
              • Show shared: By default only commands available for the selected +server(s) are selectable. Activate this checkbox to select any +command
              • +
              • Path: Directory where command will be executed. Important: this +field does not support variables! Ensure that user has access to +this location even if you run command using sudo.
              • Code: Raw command code
              • Preview: Command code rendered using server variables. IMPORTANT: If several servers are selected preview will not be -rendered. However during the command execution command code will -be rendered for each server separately.
              • +rendered. However during the command execution command code will be +rendered for each server separately.
            @@ -1218,9 +1211,9 @@

            Run a Command

          • Run. Executes a command using server “run” method and log command result into the “Command Log”.
          • Run in wizard. Executes a command directly in the wizard and show -command log in a new wizard window. IMPORTANT: Button will be -show only if single server is selected. If you try to run a command -for several servers from code, you will get a ValidationError.
          • +command log in a new wizard window. IMPORTANT: Button will be show +only if single server is selected. If you try to run a command for +several servers from code, you will get a ValidationError.

          You can check command execution logs in the Cetmix Tower/Commands/Command Logs menu. Important! If you want to @@ -1240,8 +1233,8 @@

          Run a Flight Plan

        • Tags: If selected only commands with these tags will be shown
        • Plan: Flight plan to execute
        • Show shared: By default only flight plans available for the -selected server(s) are selectable. Activate this checkbox to -select any flight plan
        • +selected server(s) are selectable. Activate this checkbox to select +any flight plan
        • Commands: Commands that will be executed in this flight plan. This field is read only
        @@ -1262,14 +1255,14 @@

        Check a Server Log

        up window. Or click on the Open button (2) to open it in the full form view
      -

      Open server log

      +

      Open server log

        -
      • Click the Refresh button to update the log. You can also click -the Refresh All button (3) located above the log list in -order to refresh all logs at once. Log output will be displayed in -the HTML field below.
      • +
      • Click the Refresh button to update the log. You can also click the +Refresh All button (3) located above the log list in order to +refresh all logs at once. Log output will be displayed in the HTML +field below.
      -

      Update server log

      +

      Update server log

  • Using Cetmix Tower in Odoo automation

    @@ -1286,7 +1279,7 @@

    Bug Tracker

    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.

    +feedback.

    Do not contact contributors directly about support or help with technical issues.

    @@ -1299,7 +1292,7 @@

    Authors

    Maintainers

    -

    This module is part of the cetmix/cetmix-tower project on GitHub.

    +

    This module is part of the cetmix/cetmix-tower project on GitHub.

    You are welcome to contribute.

    diff --git a/cetmix_tower_server/tests/test_command.py b/cetmix_tower_server/tests/test_command.py index 7eac0e7b..111a8a0a 100644 --- a/cetmix_tower_server/tests/test_command.py +++ b/cetmix_tower_server/tests/test_command.py @@ -1156,6 +1156,7 @@ def test_command_with_secret(self): {"name": "Command with keys", "code": code} ) + # -- 1 -- # Assert that the secret key is linked with the command self.assertIn( secret_folder_key, @@ -1163,9 +1164,10 @@ def test_command_with_secret(self): msg="The secret key is not linked with the command.", ) - # Update the command's code to remove the secret reference - code = "cd {{ test_path_ }} && mkdir new_folder" - command_with_keys.code = code + # -- 2 -- + # Update the command's code to remove the secret reference + updated_code = "cd {{ test_path_ }} && mkdir new_folder" + command_with_keys.code = updated_code self.assertFalse( command_with_keys.secret_ids, @@ -1174,3 +1176,115 @@ def test_command_with_secret(self): "removing the secret reference from command." ), ) + + # -- 3 -- + # Create a secret with the same reference but connected to another server + another_server = self.server_test_1.copy({"name": "another server"}) + another_secret = self.Key.create( + { + "name": "another secret", + "reference": secret_folder_key.reference, + "server_id": another_server.id, + "key_type": "k", + } + ) + # Set original code again + command_with_keys.code = code + self.assertEqual( + len(command_with_keys.secret_ids), + 1, + msg="Must be only one secret", + ) + self.assertIn( + secret_folder_key, + command_with_keys.secret_ids, + msg="The secret key is not linked with the command.", + ) + self.assertNotIn( + another_secret, + command_with_keys.secret_ids, + msg="The another secret is linked with the command.", + ) + + # -- 4 -- + # Connect command to server and secret to another server + # and ensure it's unlinked from the command. + yet_one_more_server = self.server_test_1.copy({"name": "yet one more server"}) + + self.write_and_invalidate( + secret_folder_key, **{"server_id": yet_one_more_server.id} + ) + self.write_and_invalidate( + command_with_keys, **{"server_ids": self.server_test_1} + ) + self.assertEqual( + len(command_with_keys.secret_ids), + 0, + msg="Must be no secrets", + ) + + # -- 5 -- + # Add servers back to command and ensure secrets are linked + self.write_and_invalidate( + command_with_keys, + **{"server_ids": another_server | self.server_test_1 | yet_one_more_server}, + ) + self.assertEqual( + len(command_with_keys.secret_ids), + 2, + msg="Must be two secrets", + ) + self.assertIn( + secret_folder_key, + command_with_keys.secret_ids, + msg="The secret key is not linked with the command.", + ) + self.assertIn( + another_secret, + command_with_keys.secret_ids, + msg="The another secret is not linked with the command.", + ) + + # -- 6 -- + # Link another secret to a new partner and ensure + # it's not linked with the command + another_partner = self.env["res.partner"].create({"name": "another partner"}) + self.write_and_invalidate( + another_secret, **{"partner_id": another_partner.id, "server_id": False} + ) + self.assertEqual( + len(command_with_keys.secret_ids), + 1, + msg="Must one secret", + ) + self.assertIn( + secret_folder_key, + command_with_keys.secret_ids, + msg="The secret key is not linked with the command.", + ) + self.assertNotIn( + another_secret, + command_with_keys.secret_ids, + msg="The another secret is linked with the command.", + ) + + # -- 7 -- + # Assign partner to a server and ensure secret is linked + self.write_and_invalidate( + self.server_test_1, **{"partner_id": another_partner.id} + ) + self.assertEqual( + len(command_with_keys.secret_ids), + 2, + msg="Must be two secrets", + ) + self.assertIn( + secret_folder_key, + command_with_keys.secret_ids, + msg="The secret key is not linked with the command.", + ) + self.assertIn( + another_secret, + command_with_keys.secret_ids, + msg="The another secret is not linked with the command.", + ) diff --git a/cetmix_tower_server/tests/test_key.py b/cetmix_tower_server/tests/test_key.py index 22ec6901..2fd98285 100644 --- a/cetmix_tower_server/tests/test_key.py +++ b/cetmix_tower_server/tests/test_key.py @@ -15,14 +15,14 @@ def test_key_creation(self): # -- 1-- # Check new key values - key = self.Key.create( + key_one = self.Key.create( {"name": " test key meme ", "secret_value": "test value", "key_type": "s"} ) self.assertEqual( - key.reference, "test_key_meme", "Reference must be 'test_key_meme'" + key_one.reference, "test_key_meme", "Reference must be 'test_key_meme'" ) self.assertEqual( - key.name, + key_one.name, "test key meme", "Trailing and leading whitespaces must be removed from name", ) diff --git a/cetmix_tower_server/views/cx_tower_file_template_view.xml b/cetmix_tower_server/views/cx_tower_file_template_view.xml index a7932bc2..67988cf5 100644 --- a/cetmix_tower_server/views/cx_tower_file_template_view.xml +++ b/cetmix_tower_server/views/cx_tower_file_template_view.xml @@ -47,6 +47,12 @@ name="keep_when_deleted" attrs="{'invisible': [('source', '=', 'server')]}" /> + diff --git a/cetmix_tower_yaml/models/cx_tower_yaml_mixin.py b/cetmix_tower_yaml/models/cx_tower_yaml_mixin.py index d88c70c1..2e5c2454 100644 --- a/cetmix_tower_yaml/models/cx_tower_yaml_mixin.py +++ b/cetmix_tower_yaml/models/cx_tower_yaml_mixin.py @@ -209,8 +209,7 @@ def _post_process_yaml_dict_values(self, values): ) ) - # Remove model data - # TODO: temp solution, use later for import + # Remove model data because it is not a field if "cetmix_tower_model" in values: values.pop("cetmix_tower_model") From 4c55fa0a4c256f6363ecde35c0acc0aa6c650837 Mon Sep 17 00:00:00 2001 From: Dmytro Meita Date: Mon, 23 Dec 2024 19:40:17 +0200 Subject: [PATCH 3/6] [IMP] cetmix_tower_server: enforce required variable validation This commit addresses an issue where servers could be created even when all required configuration variables were removed during the server creation wizard. Key changes: - Enhanced `_validate_required_variables` to handle cases where all required variables are missing from the configuration: - If all required variables are removed, the creation process is blocked with an appropriate error message listing the missing variables. - The error message includes details of the missing variables for better user understanding. - Updated `_create_new_server` to delegate validation entirely to `_validate_required_variables`, ensuring consistency and avoiding duplication of logic. Steps to reproduce: ------------------- 1. Create a server template with at least one required variable. 2. Open the "Create Server" wizard. 3. Remove all configuration variables from the wizard. 4. Click "Confirm". Expected result: ---------------- An error is raised, and the server is not created: "Please resolve the following issues with configuration variables: - Missing variables: var1, var2, var3" Current result (before this commit): ------------------------------------ The server is created even when required variables are missing. Testing: -------- - Automated tests validate: 1. Server creation with missing required variables raises an error. 2. Removing all required variables blocks server creation. 3. Optional variables can be left empty without affecting creation. - Manual testing ensures: - Correct behavior in the "Create Server" wizard. - User-friendly error messages with detailed information. Task: 4206 --- .../models/cx_tower_server_template.py | 67 +++++--- .../tests/test_server_template.py | 154 ++++++++++++++++++ 2 files changed, 195 insertions(+), 26 deletions(-) diff --git a/cetmix_tower_server/models/cx_tower_server_template.py b/cetmix_tower_server/models/cx_tower_server_template.py index 1236510d..7b1fc6bd 100644 --- a/cetmix_tower_server/models/cx_tower_server_template.py +++ b/cetmix_tower_server/models/cx_tower_server_template.py @@ -202,6 +202,12 @@ def _create_new_server(self, name, **kwargs): Returns: cx.tower.server: newly created server record """ + # Retrieving the passed variables + configuration_variables = kwargs.get("configuration_variables", {}) + + # We validate mandatory variables + self._validate_required_variables(configuration_variables) + servers = ( self.env["cx.tower.server"] .with_context(skip_ssh_settings_check=True) @@ -356,47 +362,56 @@ def _prepare_server_values(self, **kwargs): def _validate_required_variables(self, configuration_variables): """ - Validate that all required variables are present and not empty. + Validate that all required variables are present, not empty, + and that no required variable is entirely missing from the configuration. Args: configuration_variables (dict): A dictionary of variable references and their values. Raises: - ValidationError: If any required variables are missing or empty. + ValidationError: If all required variables are + missing from the configuration, + or if any required variable is empty or missing. """ - missing_variables = [] - empty_variables = [] - - for variable in self.variable_value_ids.filtered("required"): - variable_ref = variable.variable_reference - if variable_ref not in configuration_variables: - missing_variables.append(variable_ref) - elif not configuration_variables[variable_ref]: - empty_variables.append(variable_ref) - - # Construct error message if issues are found - if missing_variables or empty_variables: - self.variable_value_ids = self.variable_value_ids - error_message = _( - "Please resolve the following issues with configuration variables:\n" - ) + required_variables = self.variable_value_ids.filtered("required") + if not required_variables: + return + + required_refs = [var.variable_reference for var in required_variables] + config_refs = list(configuration_variables.keys()) + + missing_variables = [ref for ref in required_refs if ref not in config_refs] + empty_variables = [ + ref + for ref in required_refs + if ref in config_refs and not configuration_variables[ref] + ] + + if not (missing_variables or empty_variables): + return - if missing_variables: - error_message += _( - " - Missing variables: %(variables)s\n", + error_parts = [ + _("Please resolve the following issues with configuration variables:") + ] + + if missing_variables: + error_parts.append( + _( + " - Missing variables: %(variables)s", variables=", ".join(missing_variables), ) + ) - if empty_variables: - error_message += _( + if empty_variables: + error_parts.append( + _( " - Empty values for variables: %(variables)s", variables=", ".join(empty_variables), ) + ) - self.env.context = dict(self.env.context, keep_variable_state=True) - - raise ValidationError(error_message) + raise ValidationError("\n".join(error_parts)) def copy(self, default=None): """Duplicate the server template along with variable values and server logs.""" diff --git a/cetmix_tower_server/tests/test_server_template.py b/cetmix_tower_server/tests/test_server_template.py index 55d6c244..063327bc 100644 --- a/cetmix_tower_server/tests/test_server_template.py +++ b/cetmix_tower_server/tests/test_server_template.py @@ -1,3 +1,5 @@ +from odoo.exceptions import ValidationError + from .common import TestTowerCommon @@ -581,3 +583,155 @@ def test_optional_variable_handling(self): "", "Optional variable should have an empty value.", ) + + def test_server_creation_with_all_required_variables_removed(self): + """ + Test that server creation fails if all required variables + are removed in the wizard. + + Steps: + 1. Create a server template with required variables. + 2. Open the server creation wizard. + 3. Remove all required variables from the wizard. + 4. Attempt to create the server. + + Expected Result: + - ValidationError is raised with a clear message listing missing variables. + """ + # Create a server template with mandatory variables + template = self.ServerTemplate.create( + { + "name": "Template with required variables", + "ssh_port": 22, + "ssh_username": "admin", + "ssh_auth_mode": "p", + "os_id": self.os_debian_10.id, + "variable_value_ids": [ + ( + 0, + 0, + { + "variable_id": self.variable_path.id, + "value_char": "/var/log", + "required": True, + }, + ), + ( + 0, + 0, + { + "variable_id": self.variable_dir.id, + "value_char": "logs", + "required": True, + }, + ), + ], + } + ) + + # Simulating the launch of a wizard with the removal of all variables + configuration_variables = {} # All variables removed + + # Checking that the server cannot be created + with self.assertRaises(ValidationError) as cm: + template._create_new_server( + name="Server with missing variables", + configuration_variables=configuration_variables, + ) + + # Checking that the error message contains all removed variables + error_message = str(cm.exception) + self.assertIn("Please resolve the following issues", error_message) + self.assertIn("Missing variables: test_path_, test_dir", error_message) + + def test_partial_required_variables_provided(self): + """ + Test that server creation fails if only some required variables + are provided, and the error message includes both missing and empty variables. + """ + # Create a template with mandatory variables + template = self.ServerTemplate.create( + { + "name": "Template with partial variables", + "variable_value_ids": [ + ( + 0, + 0, + { + "variable_id": self.variable_path.id, + "value_char": "/var/log", + "required": False, + }, + ), + ( + 0, + 0, + { + "variable_id": self.variable_dir.id, + "required": True, + }, + ), + ], + } + ) + + # Launch the wizard and specify only some of the required variables + configuration_variables = {"test_path_": "/var/log"} # test_dir skipped + + # Checking that the server is not being created + with self.assertRaises(ValidationError) as cm: + template._create_new_server( + name="Server with partial variables", + configuration_variables=configuration_variables, + ) + + # Checking the error message + error_message = str(cm.exception) + self.assertIn("Missing variables: test_dir", error_message) + self.assertNotIn("test_path_", error_message) # test_path_ provided + + def test_empty_values_for_required_variables(self): + """ + Test that server creation fails if required variables + have empty values, and the error message includes these variables. + """ + # Create a template with mandatory variables + template = self.ServerTemplate.create( + { + "name": "Template with empty values", + "variable_value_ids": [ + ( + 0, + 0, + { + "variable_id": self.variable_path.id, + "value_char": "", + "required": True, + }, + ), + ( + 0, + 0, + { + "variable_id": self.variable_dir.id, + "value_char": "", + "required": True, + }, + ), + ], + } + ) + + # Run the wizard with empty values for all variables + configuration_variables = {"test_path_": "", "test_dir": ""} + + # Checking that the server is not being created + with self.assertRaises(ValidationError) as cm: + template._create_new_server( + name="Server with empty variables", + configuration_variables=configuration_variables, + ) + + # Checking the error message + error_message = str(cm.exception) + self.assertIn("Empty values for variables: test_path_, test_dir", error_message) From fb42dd0ea30ad943c11b65e1832c682a917f6e04 Mon Sep 17 00:00:00 2001 From: CetmixGitBot Date: Fri, 3 Jan 2025 09:43:11 +0000 Subject: [PATCH 4/6] [BOT] post-merge updates --- README.md | 2 +- cetmix_tower_server/README.rst | 833 +++++++++--------- cetmix_tower_server/__manifest__.py | 2 +- .../static/description/index.html | 171 ++-- 4 files changed, 511 insertions(+), 497 deletions(-) diff --git a/README.md b/README.md index 83593186..f54b9e23 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ Available addons ---------------- addon | version | maintainers | summary --- | --- | --- | --- -[cetmix_tower_server](cetmix_tower_server/) | 14.0.0.4.0 | | Flexible Server Management directly from Odoo +[cetmix_tower_server](cetmix_tower_server/) | 14.0.0.4.1 | | Flexible Server Management directly from Odoo [cetmix_tower_server_notify_backend](cetmix_tower_server_notify_backend/) | 14.0.1.0.0 | | Backend notifications for Cetmix Tower [cetmix_tower_server_queue](cetmix_tower_server_queue/) | 14.0.1.0.3 | | OCA Queue implementation for Cetmix Tower Server [cetmix_tower_yaml](cetmix_tower_yaml/) | 14.0.1.0.0 | | Cetmix Tower YAML export/import diff --git a/cetmix_tower_server/README.rst b/cetmix_tower_server/README.rst index ca5ade08..fd659d09 100644 --- a/cetmix_tower_server/README.rst +++ b/cetmix_tower_server/README.rst @@ -7,7 +7,7 @@ Cetmix Tower Server Management !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:4b055a9f60e7fa95ab04b470c0bf1fad7de7a7b795f211ba8d282abb73b0a212 + !! source digest: sha256:7f4e1f3db2bff1b2ffc99ccf8dbbc6d6dd67f8a6b6fdbe1c9619ce19065baa08 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -17,7 +17,7 @@ Cetmix Tower Server Management :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-cetmix%2Fcetmix--tower-lightgray.png?logo=github - :target: https://github.com/cetmix/cetmix-tower/tree/14.0/cetmix_tower_server + :target: https://github.com/cetmix/cetmix-tower/tree/14.0-dev/cetmix_tower_server :alt: cetmix/cetmix-tower |badge1| |badge2| |badge3| @@ -32,74 +32,75 @@ tied down by vendor or technology constraints. Why Cetmix Tower? ================= -- **Open Source:** `Cetmix Tower `__ is - distributed under the AGPL-3 license -- **Odoo Integration:** Benefit from `Odoo `__ - ecosystem for server management tasks, like deploying servers in - response to specific Odoo-triggered events -- **Extendability:** Build your own `Odoo `__ modules - using `Cetmix Tower `__ to implement your - custom features -- **Beyond Odoo:** While optimized for Odoo, Cetmix Tower can manage - virtually any instance -- **Flexibility:** Use Cetmix Tower alongside other management methods - without restriction, ensuring you're not limited to a single vendor -- **Self-Hosting:** Deploy Cetmix Tower on your own infrastructure for - full control over your server management. -- **Broad Compatibility:** Execute any software that's manageable via - shell commands or API. From Docker or Kubernetes to direct OS package - installations +- **Open Source:** `Cetmix Tower `__ is + distributed under the AGPL-3 license +- **Odoo Integration:** Benefit from `Odoo `__ + ecosystem for server management tasks, like deploying servers in + response to specific Odoo-triggered events +- **Extendability:** Build your own `Odoo `__ modules + using `Cetmix Tower `__ to implement your + custom features +- **Beyond Odoo:** While optimized for Odoo, Cetmix Tower can manage + virtually any instance +- **Flexibility:** Use Cetmix Tower alongside other management methods + without restriction, ensuring you're not limited to a single vendor +- **Self-Hosting:** Deploy Cetmix Tower on your own infrastructure for + full control over your server management. +- **Broad Compatibility:** Execute any software that's manageable via + shell commands or API. From Docker or Kubernetes to direct OS package + installations Server Management ================= -- Variable based flexible configuration -- Create servers using pre-defined templates +- Variable based flexible configuration +- Create servers using pre-defined templates Connectivity ============ -- Password and key based authentication for outgoing SSH connections -- Built-in support of the Python `requests - library `__ for outgoing API calls +- Password and key based authentication for outgoing SSH connections +- Built-in support of the Python `requests + library `__ for outgoing API + calls Commands ======== -- Execute SSH commands on remote servers -- Run Python code on the Tower Odoo server -- Run Flight Plan from command -- Render commands using variables -- Secret keys for private data storage +- Execute SSH commands on remote servers +- Run Python code on the Tower Odoo server +- Run Flight Plan from command +- Render commands using variables +- Secret keys for private data storage Flight Plans ============ -- Execute multiple commands in a row -- Condition based flow: +- Execute multiple commands in a row +- Condition based flow: - - Based on condition using `Python - syntax `__ - - Based on the previous command exit code + - Based on condition using `Python + syntax `__ + - Based on the previous command exit code Files ===== -- Download files from remote server using SFTP -- Upload files to remote server using SFTP -- Support for ``text`` and ``binary`` file format -- Manage files using pre-defined file templates +- Download files from remote server using SFTP +- Upload files to remote server using SFTP +- Support for ``text`` and ``binary`` file format +- Manage files using pre-defined file templates Support and Technical Requirements ================================== -- Cetmix Tower with usability and simplicity in mind, though some - features might require a foundational understanding of server - management principles -- We offer dedicated support to help with any custom setup needs or - questions that may arise -- For additional details, visit our website - `cetmix.com `__ +- Cetmix Tower with usability and simplicity in mind, though some + features might require a foundational understanding of server + management principles +- We offer dedicated support to help with any custom setup needs or + questions that may arise +- For additional details, visit our website + `cetmix.com `__ **Table of contents** @@ -127,21 +128,21 @@ like to provide access to the Cetmix Tower. In the ``Cetmix Tower`` section select one of the following options in the ``Access Level`` field: -- **User**. Members of this group have read access only to the - `Servers <#configure-a-server>`__ which they are added as followers. - They also have access to the entities such as - `Commands <#configure-a-command>`__, `Flight - Plans <#configure-a-flight-plan>`__ or `Server - Logs <#configure-a-server-log>`__ with ``Access Level`` set to - ``User``. -- **Manager**. Members of this group can modify - `Servers <#configure-a-server>`__ which they are added as followers. - They can create new `Servers <#configure-a-server>`__ too however they - cannot delete them. Users of this group have access to the entities - with ``Access Level`` set to ``Manager`` or ``User``. -- **Root**. Members of this group can create, modify or delete any - `Server <#configure-a-server>`__. They also have access to the - entities with any ``Access Level`` set. +- **User**. Members of this group have read access only to the + `Servers <#configure-a-server>`__ which they are added as followers. + They also have access to the entities such as + `Commands <#configure-a-command>`__, `Flight + Plans <#configure-a-flight-plan>`__ or `Server + Logs <#configure-a-server-log>`__ with ``Access Level`` set to + ``User``. +- **Manager**. Members of this group can modify + `Servers <#configure-a-server>`__ which they are added as followers. + They can create new `Servers <#configure-a-server>`__ too however + they cannot delete them. Users of this group have access to the + entities with ``Access Level`` set to ``Manager`` or ``User``. +- **Root**. Members of this group can create, modify or delete any + `Server <#configure-a-server>`__. They also have access to the + entities with any ``Access Level`` set. **NB:** Please keep in mind that some of the entities can have their additional access management variations. @@ -158,32 +159,32 @@ Fill the values it the tabs below: **General Settings** -- **Partner**: Partner this server belongs to -- **Operating System**: Operating system that runs on the server -- **Tags**: User-defined search tags -- **IPv4 Address** -- **IPv6 Address**: Will be used if no IPv4 address is specified -- **SSH Auth Mode**: Available options are "Password" and "Key" -- **SSH Port** -- **SSH Username** -- **Use sudo**: If sudo is required by default for running all commands - on this server -- **SSH Password**: Used if Auth Mode is set to "Password" and for - running ``sudo`` commands with password -- **SSH Private Key**: Used for authentication is SSH Auth Mode is set - to "Key" -- **Note**: Comments or user notes +- **Partner**: Partner this server belongs to +- **Operating System**: Operating system that runs on the server +- **Tags**: User-defined search tags +- **IPv4 Address** +- **IPv6 Address**: Will be used if no IPv4 address is specified +- **SSH Auth Mode**: Available options are "Password" and "Key" +- **SSH Port** +- **SSH Username** +- **Use sudo**: If sudo is required by default for running all commands + on this server +- **SSH Password**: Used if Auth Mode is set to "Password" and for + running ``sudo`` commands with password +- **SSH Private Key**: Used for authentication is SSH Auth Mode is set + to "Key" +- **Note**: Comments or user notes 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: -- Undefined -- Stopped -- Starting -- Running -- Stopping -- Restarting +- Undefined +- Stopped +- Starting +- Running +- Stopping +- Restarting Default status is 'Undefined'. @@ -208,12 +209,12 @@ Log <#configure-a-server-log>`__ section for more details. Following action buttons are located in the top of the form: -- **Command Logs**: Shows all `Command <#configure-a-command>`__ logs - for this server -- **Flight Plan Logs**: Shows all `Flight - Plan <#configure-a-flight-plan>`__ logs for this server -- **Files**: Shows all `Files <#configure-a-file>`__ that belong to this - server +- **Command Logs**: Shows all `Command <#configure-a-command>`__ logs + for this server +- **Flight Plan Logs**: Shows all `Flight + Plan <#configure-a-flight-plan>`__ logs for this server +- **Files**: Shows all `Files <#configure-a-file>`__ that belong to + this server Configure a Server Template --------------------------- @@ -226,18 +227,18 @@ Fill the values it the tabs below: **General Settings** -- **Flight Plan**: Select a flight plan to be executed after a server is - created -- **Operating System**: Default operating system for new servers -- **Tags**: Default search tags for new servers -- **SSH Auth Mode**: Default SSH auth mode for new servers. Available - options are "Password" and "Key" -- **SSH Port**: Default SSH port for new servers -- **SSH Username**: Default SSH username for new servers -- **Use sudo**: Default sudo mode for new servers -- **SSH Password**: Default SSH password for new servers -- **SSH Private Key**: Default SSH private key for new servers -- **Note**: Comments or user notes +- **Flight Plan**: Select a flight plan to be executed after a server + is created +- **Operating System**: Default operating system for new servers +- **Tags**: Default search tags for new servers +- **SSH Auth Mode**: Default SSH auth mode for new servers. Available + options are "Password" and "Key" +- **SSH Port**: Default SSH port for new servers +- **SSH Username**: Default SSH username for new servers +- **Use sudo**: Default sudo mode for new servers +- **SSH Password**: Default SSH password for new servers +- **SSH Private Key**: Default SSH private key for new servers +- **Note**: Comments or user notes **Variables** @@ -256,11 +257,11 @@ Configure Variables To configure variables go to the ``Cetmix Tower -> Settings`` and select the ``Variables`` menu. Click ``Create`` and put values in the fields: -- **Name**: Readable name -- **Reference**: Unique identifier used to address variable in - conditions and expressions. Leave blank to generate automatically - based on name -- **Note**: Put your notes here +- **Name**: Readable name +- **Reference**: Unique identifier used to address variable in + conditions and expressions. Leave blank to generate automatically + based on name +- **Note**: Put your notes here Configure Tags -------------- @@ -268,12 +269,12 @@ Configure Tags To configure variables go to the ``Cetmix Tower -> Settings`` and select the ``Tags`` menu. Click ``Create`` and put values in the fields: -- **Name**: Readable name -- **Reference**: Unique identifier used to address the tag in conditions - and expressions. Leave this field blank to generate it automatically - based on the name -- **Color**: Select a color for the tag -- **Servers**: Select the servers associated with the tag. +- **Name**: Readable name +- **Reference**: Unique identifier used to address the tag in + conditions and expressions. Leave this field blank to generate it + automatically based on the name +- **Color**: Select a color for the tag +- **Servers**: Select the servers associated with the tag. Configure OSs (Operating Systems) --------------------------------- @@ -282,12 +283,12 @@ To configure operating systems, go to the ``Cetmix Tower -> Settings`` and select the ``OSs`` menu. Click ``Create`` and fill in the values for the following fields: -- **Name**: Readable name -- **Reference**: Unique identifier used to address the OS in conditions - and expressions. Leave this field blank to generate it automatically - based on the name. -- **Color**: Select a color for the OS. -- **Previous Version**: Select the previous version of the current OS. +- **Name**: Readable name +- **Reference**: Unique identifier used to address the OS in conditions + and expressions. Leave this field blank to generate it automatically + based on the name. +- **Color**: Select a color for the OS. +- **Previous Version**: Select the previous version of the current OS. Variables Applicability ~~~~~~~~~~~~~~~~~~~~~~~ @@ -295,15 +296,15 @@ Variables Applicability `Cetmix Tower `__ supports ``jinja2`` syntax for variables. You can use variables to render: -- Commands. Eg ``ls -lh {{ file_store_location }}`` -- Files. Eg a "Dockerfile" file can have the following text in it: - ``ODOO_VERSION = {{ odoo_default_version }}`` -- File Templates. You can use variables for both file name and file - location on server. Eg ``File Name`` value is - ``backup_{{ instance_name }}_{{ odoo_db_name }}`` and - ``Directory on server`` is ``{{ file_cron_location }}`` -- Other Variables. Eg for an ``odoo_config_location`` variable can have - a value of ``{{ odoo_root}}/conf`` +- Commands. Eg ``ls -lh {{ file_store_location }}`` +- Files. Eg a "Dockerfile" file can have the following text in it: + ``ODOO_VERSION = {{ odoo_default_version }}`` +- File Templates. You can use variables for both file name and file + location on server. Eg ``File Name`` value is + ``backup_{{ instance_name }}_{{ odoo_db_name }}`` and + ``Directory on server`` is ``{{ file_cron_location }}`` +- Other Variables. Eg for an ``odoo_config_location`` variable can have + a value of ``{{ odoo_root}}/conf`` You can use any ``jinja2`` supported expressions. For example ``if else`` statements: @@ -324,8 +325,8 @@ Variable Rendering Modes There are two rendering modes available: -- Generic (or ssh) mode -- Pythonic mode +- Generic (or ssh) mode +- Pythonic mode Let use the following code as example: @@ -371,10 +372,10 @@ Variable Types Following types of variable values available in `Cetmix Tower `__: -- Local values. Those are values that are defined at a record level. For - example for a server or an action. -- Global values. Those are values that are defined at the `Cetmix - Tower `__ level. +- Local values. Those are values that are defined at a record level. + For example for a server or an action. +- Global values. Those are values that are defined at the `Cetmix + Tower `__ level. 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 @@ -395,20 +396,20 @@ the ``tower`` variable unless you really need that on purpose. Following system variables are available: -- Server properties +- Server properties - - ``tower.server.name`` Current server name - - ``tower.server.reference`` Current server reference - - ``tower.server.username`` Current server SSH Username​ - - ``tower.server.ipv4`` Current server IPv4 Address​ - - ``tower.server.ipv6`` Current server IPv6 Address​ - - ``tower.server.partner_name`` Current server partner name + - ``tower.server.name`` Current server name + - ``tower.server.reference`` Current server reference + - ``tower.server.username`` Current server SSH Username​ + - ``tower.server.ipv4`` Current server IPv4 Address​ + - ``tower.server.ipv6`` Current server IPv6 Address​ + - ``tower.server.partner_name`` Current server partner name -- Helper tools +- Helper tools - - ``tower.tools.uuid`` Generates a random UUID4 - - ``tower.tools.today`` Current date - - ``tower.tools.now`` Current date time + - ``tower.tools.uuid`` Generates a random UUID4 + - ``tower.tools.today`` Current date + - ``tower.tools.now`` Current date time Configure a Key/Secret ---------------------- @@ -418,28 +419,28 @@ 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: -- **Name**: Readable name -- **Key Type**: Following values are available: - - - ``SSH Key`` is used to store SSH private keys. They are selectable - in `Server settings <#configure-a-server>`__ - - ``Secret`` used to store sensitive information that can be used - inline in commands. Eg a token or a password. Secrets cannot be - previewed in command preview and are replaced with placeholder in - `command <#configure-a-command>`__ logs. - -- **Reference**: Key/secret record reference -- **Reference Code**: Complete reference code for inline usage -- **Value**: Key value. **IMPORTANT:** This is a write only field. - Please ensure that you have saved your key/secret before saving it. - Once saved it cannot be read from the user interface any longer. -- **Used For**: ``SSH Key`` type only. List of - `Servers <#configure-a-server>`__ where this SSH key is used -- **Partner**: ``Secret`` type only. If selected this secret is used - only for the `Servers <#configure-a-server>`__ of selected partner -- **Server**: ``Secret`` type only. If selected this secret is used only - for selected `Server <#configure-a-server>`__ -- **Note**: Put your notes here +- **Name**: Readable name +- **Key Type**: Following values are available: + + - ``SSH Key`` is used to store SSH private keys. They are selectable + in `Server settings <#configure-a-server>`__ + - ``Secret`` used to store sensitive information that can be used + inline in commands. Eg a token or a password. Secrets cannot be + previewed in command preview and are replaced with placeholder in + `command <#configure-a-command>`__ logs. + +- **Reference**: Key/secret record reference +- **Reference Code**: Complete reference code for inline usage +- **Value**: Key value. **IMPORTANT:** This is a write only field. + Please ensure that you have saved your key/secret before saving it. + Once saved it cannot be read from the user interface any longer. +- **Used For**: ``SSH Key`` type only. List of + `Servers <#configure-a-server>`__ where this SSH key is used +- **Partner**: ``Secret`` type only. If selected this secret is used + only for the `Servers <#configure-a-server>`__ of selected partner +- **Server**: ``Secret`` type only. If selected this secret is used + only for selected `Server <#configure-a-server>`__ +- **Note**: Put your notes here Keys of type ``Secret`` ~~~~~~~~~~~~~~~~~~~~~~~ @@ -458,9 +459,9 @@ 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: -- ``#!cxtower`` is used to declare a special Tower construction -- ``secret`` is used to declare its type (secret) -- ``REFERENCE`` secret id as it's written in the **Key ID** field +- ``#!cxtower`` is used to declare a special Tower construction +- ``secret`` is used to declare its type (secret) +- ``REFERENCE`` secret id as it's written in the **Key ID** field **Example:** @@ -484,49 +485,49 @@ Configure a File file transfer operations. Based on initial file location following file sources are available: -- Server. These are files that are initially located on remote server - and are fetched to `Cetmix Tower `__. For - example log files. +- Server. These are files that are initially located on remote server + and are fetched to `Cetmix Tower `__. For + example log files. -- Tower. These are files that are initially formed in `Cetmix - Tower `__ and are uploaded to remote server. - For example configuration files. Such files are rendered using - variables and can be created and managed using file templates. +- Tower. These are files that are initially formed in `Cetmix + Tower `__ and are uploaded to remote + server. For example configuration files. Such files are rendered + using variables and can be created and managed using file templates. To create a new file go to ``Cetmix Tower -> Files -> Files`` click ``Create`` and put values in the fields: -- **Name**: Filesystem filename -- **Source**: File source. Available options are ``Server`` and - ``Tower``. Check above for more details. -- **File type**: Type of file contents. Possible options: - - - **Text**: Regular text. Eg configuration file or log - - **Binary**: Binary file. Eg file archive or pdf document - -- **File**: Is used to store binary file data. -- **Template**: File template used to render this file. If selected file - will be automatically updated every time template is modified. -- **Server**: Server where this file is located -- **Directory on Server**: This is where the file is located on the - remote server -- **Full Server Path**: Full path to file on the remote server including - filename -- **Auto Sync**: If enabled the file will be automatically uploaded to - the remote server on after it is modified in `Cetmix - Tower `__. Used only with ``Tower`` source. -- **Keep when deleted**: If enabled, file will be kept on remote server - after removing it in the Odoo +- **Name**: Filesystem filename +- **Source**: File source. Available options are ``Server`` and + ``Tower``. Check above for more details. +- **File type**: Type of file contents. Possible options: + + - **Text**: Regular text. Eg configuration file or log + - **Binary**: Binary file. Eg file archive or pdf document + +- **File**: Is used to store binary file data. +- **Template**: File template used to render this file. If selected + file will be automatically updated every time template is modified. +- **Server**: Server where this file is located +- **Directory on Server**: This is where the file is located on the + remote server +- **Full Server Path**: Full path to file on the remote server + including filename +- **Auto Sync**: If enabled the file will be automatically uploaded to + the remote server on after it is modified in `Cetmix + Tower `__. Used only with ``Tower`` source. +- **Keep when deleted**: If enabled, file will be kept on remote server + after removing it in the Odoo Following fields are located in the tabs below: -- **Code**: Raw file content. This field is editable for the ``Tower`` - files and readonly for ``Server`` ones. This field supports - `Variables <#configure-variables>`__. -- **Preview**: This is a rendered file content as it will be uploaded to - server. Used only with ``Tower`` source. -- **Server Version**: Current file content fetched from server. Used - only with ``Tower`` source. +- **Code**: Raw file content. This field is editable for the ``Tower`` + files and readonly for ``Server`` ones. This field supports + `Variables <#configure-variables>`__. +- **Preview**: This is a rendered file content as it will be uploaded + to server. Used only with ``Tower`` source. +- **Server Version**: Current file content fetched from server. Used + only with ``Tower`` source. **NB**: File operations are performed using user credentials from server configuration. You should take care of filesystem access rights to @@ -542,27 +543,27 @@ To create a new file template go to ``Cetmix Tower -> Files -> Templates`` click ``Create`` and put values in the fields: -- **Name**: Template name -- **Reference**: Leave the "reference" field blank to generate a - reference automatically. -- **File Name**: Filesystem name of the file(s) created from this - template. This field supports `Variables <#configure-variables>`__. -- **Directory on server**: Directory on remote server where this file - will be stored. This field supports - `Variables <#configure-variables>`__. -- **Source**: File source. Available options are ``Server`` and - ``Tower``. Check above for more details. -- **File type**: Type of file contents. Possible options: - - - **Text**: Regular text. Eg configuration file or log - - **Binary**: Binary file. Eg file archive or pdf document - -- **Tags**: Make usage as search more convenient -- **Note**: Comments or user notes -- **Code**: Raw file content. This field supports - `Variables <#configure-variables>`__. -- **Keep when deleted**: If enabled, file(s) created from this template - will be kept on remote server after removing it(them) in the Odoo +- **Name**: Template name +- **Reference**: Leave the "reference" field blank to generate a + reference automatically. +- **File Name**: Filesystem name of the file(s) created from this + template. This field supports `Variables <#configure-variables>`__. +- **Directory on server**: Directory on remote server where this file + will be stored. This field supports + `Variables <#configure-variables>`__. +- **Source**: File source. Available options are ``Server`` and + ``Tower``. Check above for more details. +- **File type**: Type of file contents. Possible options: + + - **Text**: Regular text. Eg configuration file or log + - **Binary**: Binary file. Eg file archive or pdf document + +- **Tags**: Make usage as search more convenient +- **Note**: Comments or user notes +- **Code**: Raw file content. This field supports + `Variables <#configure-variables>`__. +- **Keep when deleted**: If enabled, file(s) created from this template + will be kept on remote server after removing it(them) in the Odoo **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 @@ -575,59 +576,62 @@ 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: -- **Name**: Command readable name. +- **Name**: Command readable name. -- **Reference**: Leave the "reference" field blank to generate a - reference automatically. +- **Reference**: Leave the "reference" field blank to generate a + reference automatically. -- **Allow Parallel Run**: If disabled only one copy of this command can - be run on the same server at the same time. Otherwise the same command - can be run in parallel. +- **Allow Parallel Run**: If disabled only one copy of this command can + be run on the same server at the same time. Otherwise the same + command can be run in parallel. -- **Note**: Comments or user notes. +- **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. +- **Servers**: List of servers this command can be run on. Leave this + field blank to make the command available to all servers. -- **OSes**: List of operating systems this command is available. Leave - this field blank to make the command available for all OSes. +- **OSes**: List of operating systems this command is available. Leave + this field blank to make the command available for all OSes. -- **Tags**: Make usage as search more convenient. +- **Tags**: Make usage as search more convenient. -- **Action**: Action executed by the command. Possible options: +- **Action**: Action executed by the command. Possible options: - - ``SSH command``: Execute a shell command using ssh connection on - remote server. - - ``Execute Python code``: Execute a Python code on the Tower Server. - - ``Create file using template``: Create or update a file using - selected file template and push / pull it to remote server / tower. - If the file already exists on server it will be overwritten. - - ``Run flight plan``: Allow to start Flight Plan execution from - command (). + - ``SSH command``: Execute a shell command using ssh connection on + remote server. + - ``Execute Python code``: Execute a Python code on the Tower + Server. + - ``Create file using template``: Create or update a file using + selected file template and push / pull it to remote server / + tower. If the file already exists on server it will be + overwritten. + - ``Run flight plan``: Allow to start Flight Plan execution from + command (). -- **Default Path**: Specify path where command will be executed. This - field supports `Variables <#configure-variables>`__. Important: ensure - ssh user has access to the location even if executing command using - sudo. +- **Default Path**: Specify path where command will be executed. This + field supports `Variables <#configure-variables>`__. Important: + ensure ssh user has access to the location even if executing command + using sudo. -- **Code**: Code to execute. Can be an SSH command or Python code based - on selected action. This field supports - `Variables <#configure-variables>`__. **Important!** Variables used in - command are rendered in `different - modes <#variable-rendering-modes>`__ based on the command action. +- **Code**: Code to execute. Can be an SSH command or Python code based + on selected action. This field supports + `Variables <#configure-variables>`__. **Important!** Variables used + in command are rendered in `different + modes <#variable-rendering-modes>`__ based on the command action. -- **File Template**: File template that will be used to create or update - file. Check `File Templates <#file-templates>`__ for more details. +- **File Template**: File template that will be used to create or + update file. Check `File Templates <#file-templates>`__ for more + details. -- **Server Status**: Server status to be set after command execution. - Possible options: +- **Server Status**: Server status to be set after command execution. + Possible options: - - ``Undefined``. Default status. - - ``Stopped``. Server is stopped. - - ``Starting``. Server is starting. - - ``Running``. Server is running. - - ``Stopping``. Server is stopping. - - ``Restarting``. Server is restarting. + - ``Undefined``. Default status. + - ``Stopped``. Server is stopped. + - ``Starting``. Server is starting. + - ``Running``. Server is running. + - ``Stopping``. Server is stopping. + - ``Restarting``. Server is restarting. To return result from Python assign exit code and message to the COMMAND_RESULT variable of type ``dict`` like this: @@ -654,65 +658,66 @@ 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 +- **Name**: Flight Plan name -- **Reference**: Leave the "reference" field blank to generate a - reference automatically. +- **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: +- **On Error**: Default action to execute when an error happens during + the flight plan execution. Possible options: - - ``Exit with command code``. Will terminate the flight plan execution - and return an exit code of the failed command. - - ``Exit with custom code``. Will terminate the flight plan execution - and return the custom code configured in the field next to this one. - - ``Run next command``. Will continue flight plan execution. + - ``Exit with command code``. Will terminate the flight plan + execution and return an exit code of the failed command. + - ``Exit with custom code``. Will terminate the flight plan + execution and return the custom code configured in the field next + to this one. + - ``Run next command``. Will continue flight plan execution. -- **Note**: Comments or user notes. +- **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. +- **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. +- **Tags**: Make usage as search more convenient. -- **Code**: List of commands to execute. Each of the commands has the - following fields: +- **Code**: List of commands to execute. Each of the commands has the + following fields: - - **Sequence**: Order this command is executed. Lower value = higher - priority. - - **Condition**: `Python - expression `__ - to be matched for the command to be executed. Leave this field blank - for unconditional command execution. This field supports - `Variables <#configure-variables>`__. Example: + - **Sequence**: Order this command is executed. Lower value = higher + priority. + - **Condition**: `Python + expression `__ + to be matched for the command to be executed. Leave this field + blank for unconditional command execution. This field supports + `Variables <#configure-variables>`__. Example: - .. code:: python + .. code:: python - {{ odoo_version }} == "17.0" and ( {{ nginx_installed }} or {{ traefik_installed }} ) + {{ odoo_version }} == "17.0" and ( {{ nginx_installed }} or {{ traefik_installed }} ) - - **Command**: `Command <#configure-a-command>`__ to be executed. - - **Path**: Specify path where command will be executed. Overrides - ``Default Path`` of the command. This field supports - `Variables <#configure-variables>`__. - - **Use Sudo**: Use ``sudo`` if required to run this command. - - **Post Run Actions**: List of conditional actions to be triggered - after the command is executed. Each of the actions has the following - fields: + - **Command**: `Command <#configure-a-command>`__ to be executed. + - **Path**: Specify path where command will be executed. Overrides + ``Default Path`` of the command. This field supports + `Variables <#configure-variables>`__. + - **Use Sudo**: Use ``sudo`` if required to run this command. + - **Post Run Actions**: List of conditional actions to be triggered + after the command is executed. Each of the actions has the + following fields: - - **Sequence**: Order this actions is triggered. Lower value = - higher priority. - - **Condition**: Uses command exit code. - - **Action**: Action to execute if condition is met. Also, if - variables with values are specified, these variables will be - updated (for existing variables on the server) or added (for new - variables) to the server variables. Possible options: + - **Sequence**: Order this actions is triggered. Lower value = + higher priority. + - **Condition**: Uses command exit code. + - **Action**: Action to execute if condition is met. Also, if + variables with values are specified, these variables will be + updated (for existing variables on the server) or added (for + new variables) to the server variables. Possible options: - - ``Exit with command code``. Will terminate the flight plan - execution and return an exit code of the failed command. - - ``Exit with custom code``. Will terminate the flight plan - execution and return the custom code configured in the field - next to this one. - - ``Run next command``. Will continue flight plan execution. + - ``Exit with command code``. Will terminate the flight plan + execution and return an exit code of the failed command. + - ``Exit with custom code``. Will terminate the flight plan + execution and return the custom code configured in the field + next to this one. + - ``Run next command``. Will continue flight plan execution. Configure a Server Log ---------------------- @@ -725,36 +730,38 @@ way. To configure a Server Log open the server form, navigate to the Following fields are available: -- **Name**: Readable name of the log -- **Access Level**: Minimum access level required to access this record. - Please check the `User Access Settings <#user-access-configuration>`__ - section for more details. Possible options: - - - ``User``. User must have at least ``Cetmix Tower / User`` access - group configured in the User Settings. - - ``Manager``. User must have at least ``Cetmix Tower / Manager`` - access group configured in the User Settings. - - ``Root``. User must have ``Cetmix Tower / Root`` access group - configured in the User Settings. - -- **Log Type**: Defines the way logs are fetched. Possible options: - - - ``Command``. A command is run with its output being saved to the log - - ``File``. Log is fetched from a file - -- **Command**: A command that is used to fetched the logs. This option - is available only for ``Log Type`` set to ``Command``. Important: - please ensure that selected command can be executed multiple times in - parallel to avoid any potential issues. -- **Use Sudo**: Use ``sudo`` if required to run this command. -- **File**: A file that is used to fetch the log. This option is not - available when configuring a log for a `Server - Template <#configure-a-server-template>`__ -- **File Template**: A file template that is used to create a file when - a new `Server <#configure-a-server>`__ is created from a `Server - Template <#configure-a-server-template>`__. This option is available - only when configuring a log for a `Server - Template <#configure-a-server-template>`__ +- **Name**: Readable name of the log +- **Access Level**: Minimum access level required to access this + record. Please check the `User Access + Settings <#user-access-configuration>`__ section for more details. + Possible options: + + - ``User``. User must have at least ``Cetmix Tower / User`` access + group configured in the User Settings. + - ``Manager``. User must have at least ``Cetmix Tower / Manager`` + access group configured in the User Settings. + - ``Root``. User must have ``Cetmix Tower / Root`` access group + configured in the User Settings. + +- **Log Type**: Defines the way logs are fetched. Possible options: + + - ``Command``. A command is run with its output being saved to the + log + - ``File``. Log is fetched from a file + +- **Command**: A command that is used to fetched the logs. This option + is available only for ``Log Type`` set to ``Command``. Important: + please ensure that selected command can be executed multiple times in + parallel to avoid any potential issues. +- **Use Sudo**: Use ``sudo`` if required to run this command. +- **File**: A file that is used to fetch the log. This option is not + available when configuring a log for a `Server + Template <#configure-a-server-template>`__ +- **File Template**: A file template that is used to create a file when + a new `Server <#configure-a-server>`__ is created from a `Server + Template <#configure-a-server-template>`__. This option is available + only when configuring a log for a `Server + Template <#configure-a-server-template>`__ **Developer hint**: log output supports HTML formatting. You can implement your custom log formatter by overriding the @@ -771,9 +778,9 @@ needed. Use flight plans instead. **Why?** -- Simple commands are easier to reuse across multiple flight plans. -- Commands run with ``sudo`` with password are be split and executed one - by one anyway. +- Simple commands are easier to reuse across multiple flight plans. +- Commands run with ``sudo`` with password are be split and executed + one by one anyway. **Not recommended:** @@ -803,8 +810,8 @@ command or ``Path`` field in flight plan line. **Why?** -- Tower will automatically adjust the command to ensure it is properly - executed in the specified location. +- Tower will automatically adjust the command to ensure it is properly + executed in the specified location. **Do not do this:** @@ -814,21 +821,21 @@ command or ``Path`` field in flight plan line. **Way to go:** -- Add the following value in the ``Default Path`` command field or - ``Path`` field of a flight plan line: +- Add the following value in the ``Default Path`` command field or + ``Path`` field of a flight plan line: .. code:: bash /home/{{ tower.server.username }}/memes -- Leave the command code as follows: +- Leave the command code as follows: .. code:: bash cat my_doge_memes.txt -.. |User profile| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0/cetmix_tower_server/static/description/images/user_profile.png -.. |Server logs tab| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0/cetmix_tower_server/static/description/images/server_log_tab.png +.. |User profile| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0-dev/cetmix_tower_server/static/description/images/user_profile.png +.. |Server logs tab| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0-dev/cetmix_tower_server/static/description/images/server_log_tab.png Usage ===== @@ -836,16 +843,16 @@ Usage Create a new Server from a Server Template ------------------------------------------ -- Go to the ``Cetmix Tower/Servers/Templates`` menu and select a `Server - Template `__ -- Click "Create Server" button. A pop-up wizard will open with server - parameters populated from the template -- Put the new server name, check the parameters and click "Confirm" - button -- New server will be created -- If a `Flight Plan `__ is - defined in the server template it will be automatically executed after - a new server is created +- Go to the ``Cetmix Tower/Servers/Templates`` menu and select a + `Server Template `__ +- Click "Create Server" button. A pop-up wizard will open with server + parameters populated from the template +- Put the new server name, check the parameters and click "Confirm" + button +- New server will be created +- If a `Flight Plan `__ is + defined in the server template it will be automatically executed + after a new server is created You can also create a new server from template from code using a designated ``create_server_from_template`` function of the @@ -902,34 +909,34 @@ server when a Sales Order is confirmed: Run a Command ------------- -- Select a server in the list view or open a server form view -- Open the ``Actions`` menu and click ``Execute Command`` -- A wizard is opened with the following fields: - - - **Servers**: Servers on which this command will be executed - - **Tags**: If selected only commands with these tags will be shown - - **Sudo**: ``sudo`` option for running this command - - **Command**: Command to execute - - **Show shared**: By default only commands available for the selected - server(s) are selectable. Activate this checkbox to select any - command - - **Path**: Directory where command will be executed. Important: this - field does not support variables! Ensure that user has access to - this location even if you run command using sudo. - - **Code**: Raw command code - - **Preview**: Command code rendered using server variables. - **IMPORTANT:** If several servers are selected preview will not be - rendered. However during the command execution command code will be - rendered for each server separately. +- Select a server in the list view or open a server form view +- Open the ``Actions`` menu and click ``Execute Command`` +- A wizard is opened with the following fields: + + - **Servers**: Servers on which this command will be executed + - **Tags**: If selected only commands with these tags will be shown + - **Sudo**: ``sudo`` option for running this command + - **Command**: Command to execute + - **Show shared**: By default only commands available for the + selected server(s) are selectable. Activate this checkbox to + select any command + - **Path**: Directory where command will be executed. Important: + this field does not support variables! Ensure that user has access + to this location even if you run command using sudo. + - **Code**: Raw command code + - **Preview**: Command code rendered using server variables. + **IMPORTANT:** If several servers are selected preview will not be + rendered. However during the command execution command code will + be rendered for each server separately. There are two action buttons available in the wizard: -- **Run**. Executes a command using server "run" method and log command - result into the "Command Log". -- **Run in wizard**. Executes a command directly in the wizard and show - command log in a new wizard window. **IMPORTANT:** Button will be show - only if single server is selected. If you try to run a command for - several servers from code, you will get a ValidationError. +- **Run**. Executes a command using server "run" method and log command + result into the "Command Log". +- **Run in wizard**. Executes a command directly in the wizard and show + command log in a new wizard window. **IMPORTANT:** Button will be + show only if single server is selected. If you try to run a command + for several servers from code, you will get a ValidationError. You can check command execution logs in the ``Cetmix Tower/Commands/Command Logs`` menu. Important! If you want to @@ -939,44 +946,44 @@ that. Run a Flight Plan ----------------- -- Select a server in the list view or open a server form view +- Select a server in the list view or open a server form view -- Open the ``Actions`` menu and click ``Execute Flight Plan`` +- Open the ``Actions`` menu and click ``Execute Flight Plan`` -- A wizard is opened with the following fields: +- A wizard is opened with the following fields: - - **Servers**: Servers on which this command will be executed - - **Tags**: If selected only commands with these tags will be shown - - **Plan**: Flight plan to execute - - **Show shared**: By default only flight plans available for the - selected server(s) are selectable. Activate this checkbox to select - any flight plan - - **Commands**: Commands that will be executed in this flight plan. - This field is read only + - **Servers**: Servers on which this command will be executed + - **Tags**: If selected only commands with these tags will be shown + - **Plan**: Flight plan to execute + - **Show shared**: By default only flight plans available for the + selected server(s) are selectable. Activate this checkbox to + select any flight plan + - **Commands**: Commands that will be executed in this flight plan. + This field is read only - Click the **Run** button to execute a flight plan. + 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. + 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. Check a Server Log ------------------ To check a server log: -- Navigate to the ``Server Logs`` tab on the Server form -- Click on the log **(1)** you would like to check to open in in a pop - up window. Or click on the ``Open`` button **(2)** to open it in the - full form view +- Navigate to the ``Server Logs`` tab on the Server form +- Click on the log **(1)** you would like to check to open in in a pop + up window. Or click on the ``Open`` button **(2)** to open it in the + full form view |Open server log| -- Click the ``Refresh`` button to update the log. You can also click the - ``Refresh All`` button **(3)** located above the log list in order to - refresh all logs at once. Log output will be displayed in the HTML - field below. +- Click the ``Refresh`` button to update the log. You can also click + the ``Refresh All`` button **(3)** located above the log list in + order to refresh all logs at once. Log output will be displayed in + the HTML field below. |Update server log| @@ -990,9 +997,9 @@ 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`` -.. |Automatic action| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0/cetmix_tower_server/static/description/images/server_from_template_auto_action.png -.. |Open server log| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0/cetmix_tower_server/static/description/images/server_log_usage_1.png -.. |Update server log| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0/cetmix_tower_server/static/description/images/server_log_usage_2.png +.. |Automatic action| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0-dev/cetmix_tower_server/static/description/images/server_from_template_auto_action.png +.. |Open server log| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0-dev/cetmix_tower_server/static/description/images/server_log_usage_1.png +.. |Update server log| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0-dev/cetmix_tower_server/static/description/images/server_log_usage_2.png Bug Tracker =========== @@ -1000,7 +1007,7 @@ Bug Tracker 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -1015,6 +1022,6 @@ Authors Maintainers ----------- -This module is part of the `cetmix/cetmix-tower `_ project on GitHub. +This module is part of the `cetmix/cetmix-tower `_ project on GitHub. You are welcome to contribute. diff --git a/cetmix_tower_server/__manifest__.py b/cetmix_tower_server/__manifest__.py index 6516470b..ac60a042 100644 --- a/cetmix_tower_server/__manifest__.py +++ b/cetmix_tower_server/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Cetmix Tower Server Management", "summary": "Flexible Server Management directly from Odoo", - "version": "14.0.0.4.0", + "version": "14.0.0.4.1", "category": "Productivity", "website": "https://cetmix.com", "author": "Cetmix", diff --git a/cetmix_tower_server/static/description/index.html b/cetmix_tower_server/static/description/index.html index 552a6273..765fc3bd 100644 --- a/cetmix_tower_server/static/description/index.html +++ b/cetmix_tower_server/static/description/index.html @@ -367,9 +367,9 @@

    Cetmix Tower Server Management

    !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:4b055a9f60e7fa95ab04b470c0bf1fad7de7a7b795f211ba8d282abb73b0a212 +!! source digest: sha256:7f4e1f3db2bff1b2ffc99ccf8dbbc6d6dd67f8a6b6fdbe1c9619ce19065baa08 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

    Beta License: AGPL-3 cetmix/cetmix-tower

    +

    Beta License: AGPL-3 cetmix/cetmix-tower

    Cetmix Tower offers a streamlined solution for managing remote servers via SSH or API calls directly from Odoo. It is designed for versatility across @@ -410,7 +410,8 @@

    Connectivity

    • Password and key based authentication for outgoing SSH connections
    • Built-in support of the Python requests -library for outgoing API calls
    • +library for outgoing API +calls
    @@ -469,7 +470,7 @@

    User access configuration

    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.

    -

    User profile

    +

    User profile

    In the Cetmix Tower section select one of the following options in the Access Level field:

      @@ -482,9 +483,9 @@

      User access configuration

      User.
    • Manager. Members of this group can modify Servers which they are added as followers. -They can create new Servers too however they -cannot delete them. Users of this group have access to the entities -with Access Level set to Manager or User.
    • +They can create new Servers too however +they cannot delete them. Users of this group have access to the +entities with Access Level set to Manager or User.
    • Root. Members of this group can create, modify or delete any Server. They also have access to the entities with any Access Level set.
    • @@ -548,8 +549,8 @@

      Configure a Server

      for this server
    • Flight Plan Logs: Shows all Flight Plan logs for this server
    • -
    • Files: Shows all Files that belong to this -server
    • +
    • Files: Shows all Files that belong to +this server
    @@ -560,8 +561,8 @@

    Configure a Server Template

    Fill the values it the tabs below:

    General Settings

      -
    • Flight Plan: Select a flight plan to be executed after a server is -created
    • +
    • Flight Plan: Select a flight plan to be executed after a server +is created
    • Operating System: Default operating system for new servers
    • Tags: Default search tags for new servers
    • SSH Auth Mode: Default SSH auth mode for new servers. Available @@ -599,9 +600,9 @@

      Configure Tags

      the Tags menu. Click Create and put values in the fields:

      • Name: Readable name
      • -
      • Reference: Unique identifier used to address the tag in conditions -and expressions. Leave this field blank to generate it automatically -based on the name
      • +
      • Reference: Unique identifier used to address the tag in +conditions and expressions. Leave this field blank to generate it +automatically based on the name
      • Color: Select a color for the tag
      • Servers: Select the servers associated with the tag.
      @@ -691,8 +692,8 @@

      Variable Types

      Following types of variable values available in Cetmix Tower:

        -
      • Local values. Those are values that are defined at a record level. For -example for a server or an action.
      • +
      • Local values. Those are values that are defined at a record level. +For example for a server or an action.
      • Global values. Those are values that are defined at the Cetmix Tower level.
      @@ -756,8 +757,8 @@

      Configure a Key/Secret

      Servers where this SSH key is used
    • Partner: Secret type only. If selected this secret is used only for the Servers of selected partner
    • -
    • Server: Secret type only. If selected this secret is used only -for selected Server
    • +
    • Server: Secret type only. If selected this secret is used +only for selected Server
    • Note: Put your notes here
    @@ -802,9 +803,9 @@

    Configure a File

    and are fetched to Cetmix Tower. For example log files.
  • Tower. These are files that are initially formed in Cetmix -Tower and are uploaded to remote server. -For example configuration files. Such files are rendered using -variables and can be created and managed using file templates.
  • +Tower and are uploaded to remote +server. For example configuration files. Such files are rendered +using variables and can be created and managed using file templates.

    To create a new file go to Cetmix Tower -> Files -> Files click Create and put values in the fields:

    @@ -818,13 +819,13 @@

    Configure a File

  • File: Is used to store binary file data.
  • -
  • Template: File template used to render this file. If selected file -will be automatically updated every time template is modified.
  • +
  • Template: File template used to render this file. If selected +file will be automatically updated every time template is modified.
  • Server: Server where this file is located
  • Directory on Server: This is where the file is located on the remote server
  • -
  • Full Server Path: Full path to file on the remote server including -filename
  • +
  • Full Server Path: Full path to file on the remote server +including filename
  • Auto Sync: If enabled the file will be automatically uploaded to the remote server on after it is modified in Cetmix Tower. Used only with Tower source.
  • @@ -836,8 +837,8 @@

    Configure a File

  • Code: Raw file content. This field is editable for the Tower files and readonly for Server ones. This field supports Variables.
  • -
  • Preview: This is a rendered file content as it will be uploaded to -server. Used only with Tower source.
  • +
  • Preview: This is a rendered file content as it will be uploaded +to server. Used only with Tower source.
  • Server Version: Current file content fetched from server. Used only with Tower source.
  • @@ -889,8 +890,8 @@

    Configure a Command

  • Reference: Leave the “reference” field blank to generate a reference automatically.
  • Allow Parallel Run: If disabled only one copy of this command can -be run on the same server at the same time. Otherwise the same command -can be run in parallel.
  • +be run on the same server at the same time. Otherwise the same +command can be run in parallel.
  • 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.
  • @@ -900,25 +901,28 @@

    Configure a Command

  • Action: Action executed by the command. Possible options:
    • SSH command: Execute a shell command using ssh connection on remote server.
    • -
    • Execute Python code: Execute a Python code on the Tower Server.
    • +
    • Execute Python code: Execute a Python code on the Tower +Server.
    • Create file using template: Create or update a file using -selected file template and push / pull it to remote server / tower. -If the file already exists on server it will be overwritten.
    • +selected file template and push / pull it to remote server / +tower. If the file already exists on server it will be +overwritten.
    • Run flight plan: Allow to start Flight Plan execution from command ().
  • Default Path: Specify path where command will be executed. This -field supports Variables. Important: ensure -ssh user has access to the location even if executing command using -sudo.
  • +field supports Variables. Important: +ensure ssh user has access to the location even if executing command +using sudo.
  • Code: Code to execute. Can be an SSH command or Python code based on selected action. This field supports -Variables. Important! Variables used in -command are rendered in different +Variables. Important! Variables used +in command are rendered in different modes based on the command action.
  • -
  • File Template: File template that will be used to create or update -file. Check File Templates for more details.
  • +
  • File Template: File template that will be used to create or +update file. Check File Templates for more +details.
  • Server Status: Server status to be set after command execution. Possible options:
    • Undefined. Default status.
    • @@ -961,10 +965,11 @@

      Configure a Flight Plan

    • On Error: Default action to execute when an error happens during the flight plan execution. Possible options:

        -
      • Exit with command code. Will terminate the flight plan execution -and return an exit code of the failed command.
      • -
      • Exit with custom code. Will terminate the flight plan execution -and return the custom code configured in the field next to this one.
      • +
      • Exit with command code. Will terminate the flight plan +execution and return an exit code of the failed command.
      • +
      • Exit with custom code. Will terminate the flight plan +execution and return the custom code configured in the field next +to this one.
      • Run next command. Will continue flight plan execution.
    • @@ -982,8 +987,8 @@

      Configure a Flight Plan

      priority.
    • Condition: Python expression -to be matched for the command to be executed. Leave this field blank -for unconditional command execution. This field supports +to be matched for the command to be executed. Leave this field +blank for unconditional command execution. This field supports Variables. Example:
    @@ -996,15 +1001,15 @@ 

    Configure a Flight Plan

    Variables.
  • Use Sudo: Use sudo if required to run this command.
  • Post Run Actions: List of conditional actions to be triggered -after the command is executed. Each of the actions has the following -fields:
      +after the command is executed. Each of the actions has the +following fields:
      • Sequence: Order this actions is triggered. Lower value = higher priority.
      • Condition: Uses command exit code.
      • Action: Action to execute if condition is met. Also, if variables with values are specified, these variables will be -updated (for existing variables on the server) or added (for new -variables) to the server variables. Possible options:
          +updated (for existing variables on the server) or added (for +new variables) to the server variables. Possible options:
          • Exit with command code. Will terminate the flight plan execution and return an exit code of the failed command.
          • Exit with custom code. Will terminate the flight plan @@ -1024,13 +1029,14 @@

            Configure a Server Log

            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.

            -

            Server logs tab

            +

            Server logs tab

            Following fields are available:

            • Name: Readable name of the log
            • -
            • Access Level: Minimum access level required to access this record. -Please check the User Access Settings -section for more details. Possible options:
                +
              • Access Level: Minimum access level required to access this +record. Please check the User Access +Settings section for more details. +Possible options:
                • User. User must have at least Cetmix Tower / User access group configured in the User Settings.
                • Manager. User must have at least Cetmix Tower / Manager @@ -1040,7 +1046,8 @@

                  Configure a Server Log

              • Log Type: Defines the way logs are fetched. Possible options:
                  -
                • Command. A command is run with its output being saved to the log
                • +
                • Command. A command is run with its output being saved to the +log
                • File. Log is fetched from a file
              • @@ -1071,8 +1078,8 @@

                Use simple commands

                Why?

                • Simple commands are easier to reuse across multiple flight plans.
                • -
                • Commands run with sudo with password are be split and executed one -by one anyway.
                • +
                • Commands run with sudo with password are be split and executed +one by one anyway.

                Not recommended:

                @@ -1124,16 +1131,16 @@ 

                Usage

                Create a new Server from a Server Template

                  -
                • Go to the Cetmix Tower/Servers/Templates menu and select a Server -Template
                • +
                • Go to the Cetmix Tower/Servers/Templates menu and select a +Server Template
                • Click “Create Server” button. A pop-up wizard will open with server parameters populated from the template
                • Put the new server name, check the parameters and click “Confirm” button
                • New server will be created
                • If a Flight Plan is -defined in the server template it will be automatically executed after -a new server is created
                • +defined in the server template it will be automatically executed +after a new server is created

                You can also create a new server from template from code using a designated create_server_from_template function of the @@ -1157,7 +1164,7 @@

                Create a new Server from a Server Template

                Here is a short example of an Odoo automated action that creates a new server when a Sales Order is confirmed:

                -

                Automatic action

                +

                Automatic action

                 for record in records:
                 
                @@ -1192,17 +1199,17 @@ 

                Run a Command

              • Tags: If selected only commands with these tags will be shown
              • Sudo: sudo option for running this command
              • Command: Command to execute
              • -
              • Show shared: By default only commands available for the selected -server(s) are selectable. Activate this checkbox to select any -command
              • -
              • Path: Directory where command will be executed. Important: this -field does not support variables! Ensure that user has access to -this location even if you run command using sudo.
              • +
              • Show shared: By default only commands available for the +selected server(s) are selectable. Activate this checkbox to +select any command
              • +
              • Path: Directory where command will be executed. Important: +this field does not support variables! Ensure that user has access +to this location even if you run command using sudo.
              • Code: Raw command code
              • Preview: Command code rendered using server variables. IMPORTANT: If several servers are selected preview will not be -rendered. However during the command execution command code will be -rendered for each server separately.
              • +rendered. However during the command execution command code will +be rendered for each server separately.
            @@ -1211,9 +1218,9 @@

            Run a Command

          • Run. Executes a command using server “run” method and log command result into the “Command Log”.
          • Run in wizard. Executes a command directly in the wizard and show -command log in a new wizard window. IMPORTANT: Button will be show -only if single server is selected. If you try to run a command for -several servers from code, you will get a ValidationError.
          • +command log in a new wizard window. IMPORTANT: Button will be +show only if single server is selected. If you try to run a command +for several servers from code, you will get a ValidationError.

          You can check command execution logs in the Cetmix Tower/Commands/Command Logs menu. Important! If you want to @@ -1233,8 +1240,8 @@

          Run a Flight Plan

        • Tags: If selected only commands with these tags will be shown
        • Plan: Flight plan to execute
        • Show shared: By default only flight plans available for the -selected server(s) are selectable. Activate this checkbox to select -any flight plan
        • +selected server(s) are selectable. Activate this checkbox to +select any flight plan
        • Commands: Commands that will be executed in this flight plan. This field is read only
        @@ -1255,14 +1262,14 @@

        Check a Server Log

        up window. Or click on the Open button (2) to open it in the full form view
      -

      Open server log

      +

      Open server log

        -
      • Click the Refresh button to update the log. You can also click the -Refresh All button (3) located above the log list in order to -refresh all logs at once. Log output will be displayed in the HTML -field below.
      • +
      • Click the Refresh button to update the log. You can also click +the Refresh All button (3) located above the log list in +order to refresh all logs at once. Log output will be displayed in +the HTML field below.
      -

      Update server log

      +

      Update server log

  • Using Cetmix Tower in Odoo automation

    @@ -1279,7 +1286,7 @@

    Bug Tracker

    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.

    +feedback.

    Do not contact contributors directly about support or help with technical issues.

    @@ -1292,7 +1299,7 @@

    Authors

    Maintainers

    -

    This module is part of the cetmix/cetmix-tower project on GitHub.

    +

    This module is part of the cetmix/cetmix-tower project on GitHub.

    You are welcome to contribute.

    From 4e8478b92f4806e1a4bc170e3a339d10b991bb5c Mon Sep 17 00:00:00 2001 From: Nikola Date: Thu, 12 Dec 2024 08:36:57 +0100 Subject: [PATCH 5/6] [ADD] cetmix_tower_server: add variable options selection Add functionality to allow users to select from predefined options for variables, eliminating the need for manual value entry. This simplifies data entry and ensures consistency, especially for variables with a limited set of possible values. Task: 4164 --- cetmix_tower_server/README.rst | 24 ++- cetmix_tower_server/demo/demo_data.xml | 31 ++++ cetmix_tower_server/models/__init__.py | 1 + .../models/cx_tower_variable.py | 12 ++ .../models/cx_tower_variable_option.py | 48 +++++ .../models/cx_tower_variable_value.py | 50 +++++- .../security/ir.model.access.csv | 2 + .../static/description/index.html | 169 +++++++++--------- cetmix_tower_server/tests/__init__.py | 1 + cetmix_tower_server/tests/test_variable.py | 3 +- .../tests/test_variable_option.py | 38 ++++ .../views/cx_tower_command_log_view.xml | 1 + .../views/cx_tower_server_view.xml | 20 ++- .../views/cx_tower_variable_view.xml | 69 +++---- setup/_metapackage/VERSION.txt | 1 - setup/_metapackage/setup.py | 21 --- 16 files changed, 335 insertions(+), 156 deletions(-) create mode 100644 cetmix_tower_server/models/cx_tower_variable_option.py create mode 100644 cetmix_tower_server/tests/test_variable_option.py delete mode 100644 setup/_metapackage/VERSION.txt delete mode 100644 setup/_metapackage/setup.py diff --git a/cetmix_tower_server/README.rst b/cetmix_tower_server/README.rst index 3e2d9925..f16fd996 100644 --- a/cetmix_tower_server/README.rst +++ b/cetmix_tower_server/README.rst @@ -2,7 +2,7 @@ Cetmix Tower Server Management ============================== -.. +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! @@ -194,6 +194,16 @@ Configure `configuration variables <#configure-variables>`__ values to be used when rendering `commands <#configure-a-command>`__ and `files <#configure-a-file>`__ on this server. +- Users can select from predefined values in the "Option" field when options are available for a variable. +- If options exist: + + - The "Value" field becomes synchronized with the selected option. + - Users cannot manually enter a value but can select from available options. +- If no options exist: + + - The "Option" field is locked for changes. + - Users can manually input values in the "Value" field. + **Secrets** Configure secret values to used when rendering commands and files on @@ -261,6 +271,10 @@ the ``Variables`` menu. Click ``Create`` and put values in the fields: - **Reference**: Unique identifier used to address variable in conditions and expressions. Leave blank to generate automatically based on name +- **Variable Type**: Select the type of the variable. + + - **String**: The default type where the variable has Values. + - **Option**: Allows the variable to hold a value selected from a predefined list of Options. - **Note**: Put your notes here Configure Tags @@ -884,7 +898,7 @@ server when a Sales Order is confirmed: .. code:: python for record in records: - + # Check confirmed orders if record.state == "sale": params = { @@ -897,14 +911,14 @@ server when a Sales Order is confirmed: "odoo_version": "16.0" }, } - - # Create a new server from template with the 'demo_template' reference + + # Create a new server from template with the 'demo_template' reference env["cetmix.tower"].server_create_from_template( template_reference="demo_template", server_name=record.name, **params ) - + Run a Command ------------- diff --git a/cetmix_tower_server/demo/demo_data.xml b/cetmix_tower_server/demo/demo_data.xml index 96150eef..e8d23c3e 100644 --- a/cetmix_tower_server/demo/demo_data.xml +++ b/cetmix_tower_server/demo/demo_data.xml @@ -170,6 +170,11 @@ URL + + Odoo Version + odoo__version + o + Version @@ -564,4 +569,30 @@ else: final_value + + + + 14.0 + 10 + + + + 15.0 + 20 + + + + 16.0 + 30 + + + + 17.0 + 40 + + + + 18.0 + 50 + diff --git a/cetmix_tower_server/models/__init__.py b/cetmix_tower_server/models/__init__.py index 393c3f2d..f3c632f5 100644 --- a/cetmix_tower_server/models/__init__.py +++ b/cetmix_tower_server/models/__init__.py @@ -23,3 +23,4 @@ from . import cx_tower_server_log from . import cx_tower_server_template from . import cetmix_tower +from . import cx_tower_variable_option diff --git a/cetmix_tower_server/models/cx_tower_variable.py b/cetmix_tower_server/models/cx_tower_variable.py index 85e02238..6923b67e 100644 --- a/cetmix_tower_server/models/cx_tower_variable.py +++ b/cetmix_tower_server/models/cx_tower_variable.py @@ -18,6 +18,18 @@ class TowerVariable(models.Model): value_ids_count = fields.Integer( string="Value Count", compute="_compute_value_ids_count", store=True ) + option_ids = fields.One2many( + comodel_name="cx.tower.variable.option", + inverse_name="variable_id", + string="Options", + auto_join=True, + ) + variable_type = fields.Selection( + selection=[("s", "String"), ("o", "Options")], + default="s", + required=True, + string="Type", + ) note = fields.Text() _sql_constraints = [("name_uniq", "unique (name)", "Variable names must be unique")] diff --git a/cetmix_tower_server/models/cx_tower_variable_option.py b/cetmix_tower_server/models/cx_tower_variable_option.py new file mode 100644 index 00000000..534e035f --- /dev/null +++ b/cetmix_tower_server/models/cx_tower_variable_option.py @@ -0,0 +1,48 @@ +# Copyright (C) 2022 Cetmix OÜ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo import fields, models + + +class TowerVariableOption(models.Model): + """ + Model to manage variable options in the Cetmix Tower. + + The model allows defining options + that are linked to tower variables and can be used to + manage configurations or settings for those variables. + + Attributes: + name (str): The value of the option (e.g., "17.0"). + variable_id (Many2one): A reference to the 'cx.tower.variable' + model that associates this option with a particular tower variable. + sequence (int): A sequence number to control the ordering + of the options. + + SQL Constraints: + - Ensures that the combination of `name` and `variable_id` + is unique across the system. + """ + + _name = "cx.tower.variable.option" + _description = "Cetmix Tower Variable Options" + _order = "sequence, name" + + name = fields.Char(string="Option Value", required=True) + variable_id = fields.Many2one( + comodel_name="cx.tower.variable", + required=True, + ondelete="cascade", + ) + sequence = fields.Integer(default=10) + + # Define a SQL constraint to ensure the combination of + # 'name' and 'variable_id' is unique + _sql_constraints = [ + ( + "unique_variable_option", + "unique (name, variable_id)", + "The combination of Name and Variable must be unique.", + ) + ] diff --git a/cetmix_tower_server/models/cx_tower_variable_value.py b/cetmix_tower_server/models/cx_tower_variable_value.py index 0c1bc1a2..f95dacb1 100644 --- a/cetmix_tower_server/models/cx_tower_variable_value.py +++ b/cetmix_tower_server/models/cx_tower_variable_value.py @@ -32,10 +32,20 @@ class TowerVariableValue(models.Model): inverse="_inverse_is_global", store=True, ) - - value_char = fields.Char(string="Value") note = fields.Text(related="variable_id.note", readonly=True) active = fields.Boolean(default=True) + variable_type = fields.Selection( + selection=[("s", "String"), ("o", "Options")], + related="variable_id.variable_type", + readonly=True, + ) + option_id = fields.Many2one( + comodel_name="cx.tower.variable.option", ondelete="restrict" + ) + option_ids_domain = fields.Binary(compute="_compute_option_ids_domain") + value_char = fields.Char( + string="Value", compute="_compute_value_char", store=True, readonly=False + ) # Direct model relations. # Following functions should be updated when a new m2o field is added: @@ -92,6 +102,42 @@ class TowerVariableValue(models.Model): ), ] + @api.depends("option_id", "variable_id.option_ids") + def _compute_option_ids_domain(self): + """ + Compute the domain for the `option_ids_domain` field based on the related + `option_id` and the `option_ids` of the associated `variable_id`. + """ + for rec in self: + allowed_option_ids = rec.variable_id.option_ids.ids + rec.option_ids_domain = [("id", "in", allowed_option_ids)] + + @api.depends("option_id", "variable_id.option_ids") + def _compute_value_char(self): + """ + Compute the 'value_char' field, which holds the string representation + of the selected option for the variable. + """ + for rec in self: + if rec.variable_id.option_ids and rec.option_id: + rec.value_char = rec.option_id.name + elif not rec.variable_id.option_ids: + rec.value_char = rec.value_char or "" + rec.option_id = None + + @api.onchange("variable_id") + def _onchange_variable_id(self): + """ + Reset option_id when variable changes or + doesn't have options + """ + for rec in self: + if rec.variable_id.option_ids: + allowed_option_ids = rec.variable_id.option_ids.ids + rec.option_ids_domain = [("id", "in", allowed_option_ids)] + else: + rec.option_id = None + @api.constrains("is_global", "value_char") def _constraint_global_unique(self): """Ensure that there is only one global value exist for the same variable diff --git a/cetmix_tower_server/security/ir.model.access.csv b/cetmix_tower_server/security/ir.model.access.csv index 45313075..9ff67441 100644 --- a/cetmix_tower_server/security/ir.model.access.csv +++ b/cetmix_tower_server/security/ir.model.access.csv @@ -50,3 +50,5 @@ access_server_template_manager,Server Template->Manager,model_cx_tower_server_te access_server_template_root,Server Template->Root,model_cx_tower_server_template,group_root,1,1,1,1 access_create_server_from_template_manager,Create Server From Template->Manager,model_cx_tower_server_template_create_wizard,group_manager,1,1,1,1 access_create_server_from_template_line_manager,Create Server From Template Line->Manager,model_cx_tower_server_template_create_wizard_line,group_manager,1,1,1,1 +access_cx_tower_variable_option_user,Variable Option->User,model_cx_tower_variable_option,group_user,1,0,0,0 +access_cx_tower_variable_option_manager,Variable Option->Manager,model_cx_tower_variable_option,group_manager,1,1,1,1 diff --git a/cetmix_tower_server/static/description/index.html b/cetmix_tower_server/static/description/index.html index dd902635..552a6273 100644 --- a/cetmix_tower_server/static/description/index.html +++ b/cetmix_tower_server/static/description/index.html @@ -369,7 +369,7 @@

    Cetmix Tower Server Management

    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! source digest: sha256:4b055a9f60e7fa95ab04b470c0bf1fad7de7a7b795f211ba8d282abb73b0a212 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

    Beta License: AGPL-3 cetmix/cetmix-tower

    +

    Beta License: AGPL-3 cetmix/cetmix-tower

    Cetmix Tower offers a streamlined solution for managing remote servers via SSH or API calls directly from Odoo. It is designed for versatility across @@ -410,8 +410,7 @@

    Connectivity

    • Password and key based authentication for outgoing SSH connections
    • Built-in support of the Python requests -library for outgoing API -calls
    • +library for outgoing API calls
    @@ -470,7 +469,7 @@

    User access configuration

    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.

    -

    User profile

    +

    User profile

    In the Cetmix Tower section select one of the following options in the Access Level field:

      @@ -483,9 +482,9 @@

      User access configuration

      User.
    • Manager. Members of this group can modify Servers which they are added as followers. -They can create new Servers too however -they cannot delete them. Users of this group have access to the -entities with Access Level set to Manager or User.
    • +They can create new Servers too however they +cannot delete them. Users of this group have access to the entities +with Access Level set to Manager or User.
    • Root. Members of this group can create, modify or delete any Server. They also have access to the entities with any Access Level set.
    • @@ -549,8 +548,8 @@

      Configure a Server

      for this server
    • Flight Plan Logs: Shows all Flight Plan logs for this server
    • -
    • Files: Shows all Files that belong to -this server
    • +
    • Files: Shows all Files that belong to this +server
    @@ -561,8 +560,8 @@

    Configure a Server Template

    Fill the values it the tabs below:

    General Settings

      -
    • Flight Plan: Select a flight plan to be executed after a server -is created
    • +
    • Flight Plan: Select a flight plan to be executed after a server is +created
    • Operating System: Default operating system for new servers
    • Tags: Default search tags for new servers
    • SSH Auth Mode: Default SSH auth mode for new servers. Available @@ -600,9 +599,9 @@

      Configure Tags

      the Tags menu. Click Create and put values in the fields:

      • Name: Readable name
      • -
      • Reference: Unique identifier used to address the tag in -conditions and expressions. Leave this field blank to generate it -automatically based on the name
      • +
      • Reference: Unique identifier used to address the tag in conditions +and expressions. Leave this field blank to generate it automatically +based on the name
      • Color: Select a color for the tag
      • Servers: Select the servers associated with the tag.
      @@ -692,8 +691,8 @@

      Variable Types

      Following types of variable values available in Cetmix Tower:

        -
      • Local values. Those are values that are defined at a record level. -For example for a server or an action.
      • +
      • Local values. Those are values that are defined at a record level. For +example for a server or an action.
      • Global values. Those are values that are defined at the Cetmix Tower level.
      @@ -757,8 +756,8 @@

      Configure a Key/Secret

      Servers where this SSH key is used
    • Partner: Secret type only. If selected this secret is used only for the Servers of selected partner
    • -
    • Server: Secret type only. If selected this secret is used -only for selected Server
    • +
    • Server: Secret type only. If selected this secret is used only +for selected Server
    • Note: Put your notes here
    @@ -803,9 +802,9 @@

    Configure a File

    and are fetched to Cetmix Tower. For example log files.
  • Tower. These are files that are initially formed in Cetmix -Tower and are uploaded to remote -server. For example configuration files. Such files are rendered -using variables and can be created and managed using file templates.
  • +Tower and are uploaded to remote server. +For example configuration files. Such files are rendered using +variables and can be created and managed using file templates.

    To create a new file go to Cetmix Tower -> Files -> Files click Create and put values in the fields:

    @@ -819,13 +818,13 @@

    Configure a File

  • File: Is used to store binary file data.
  • -
  • Template: File template used to render this file. If selected -file will be automatically updated every time template is modified.
  • +
  • Template: File template used to render this file. If selected file +will be automatically updated every time template is modified.
  • Server: Server where this file is located
  • Directory on Server: This is where the file is located on the remote server
  • -
  • Full Server Path: Full path to file on the remote server -including filename
  • +
  • Full Server Path: Full path to file on the remote server including +filename
  • Auto Sync: If enabled the file will be automatically uploaded to the remote server on after it is modified in Cetmix Tower. Used only with Tower source.
  • @@ -837,8 +836,8 @@

    Configure a File

  • Code: Raw file content. This field is editable for the Tower files and readonly for Server ones. This field supports Variables.
  • -
  • Preview: This is a rendered file content as it will be uploaded -to server. Used only with Tower source.
  • +
  • Preview: This is a rendered file content as it will be uploaded to +server. Used only with Tower source.
  • Server Version: Current file content fetched from server. Used only with Tower source.
  • @@ -890,8 +889,8 @@

    Configure a Command

  • Reference: Leave the “reference” field blank to generate a reference automatically.
  • Allow Parallel Run: If disabled only one copy of this command can -be run on the same server at the same time. Otherwise the same -command can be run in parallel.
  • +be run on the same server at the same time. Otherwise the same command +can be run in parallel.
  • 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.
  • @@ -901,28 +900,25 @@

    Configure a Command

  • Action: Action executed by the command. Possible options:
    • SSH command: Execute a shell command using ssh connection on remote server.
    • -
    • Execute Python code: Execute a Python code on the Tower -Server.
    • +
    • Execute Python code: Execute a Python code on the Tower Server.
    • Create file using template: Create or update a file using -selected file template and push / pull it to remote server / -tower. If the file already exists on server it will be -overwritten.
    • +selected file template and push / pull it to remote server / tower. +If the file already exists on server it will be overwritten.
    • Run flight plan: Allow to start Flight Plan execution from command ().
  • Default Path: Specify path where command will be executed. This -field supports Variables. Important: -ensure ssh user has access to the location even if executing command -using sudo.
  • +field supports Variables. Important: ensure +ssh user has access to the location even if executing command using +sudo.
  • Code: Code to execute. Can be an SSH command or Python code based on selected action. This field supports -Variables. Important! Variables used -in command are rendered in different +Variables. Important! Variables used in +command are rendered in different modes based on the command action.
  • -
  • File Template: File template that will be used to create or -update file. Check File Templates for more -details.
  • +
  • File Template: File template that will be used to create or update +file. Check File Templates for more details.
  • Server Status: Server status to be set after command execution. Possible options:
    • Undefined. Default status.
    • @@ -965,11 +961,10 @@

      Configure a Flight Plan

    • On Error: Default action to execute when an error happens during the flight plan execution. Possible options:

        -
      • Exit with command code. Will terminate the flight plan -execution and return an exit code of the failed command.
      • -
      • Exit with custom code. Will terminate the flight plan -execution and return the custom code configured in the field next -to this one.
      • +
      • Exit with command code. Will terminate the flight plan execution +and return an exit code of the failed command.
      • +
      • Exit with custom code. Will terminate the flight plan execution +and return the custom code configured in the field next to this one.
      • Run next command. Will continue flight plan execution.
    • @@ -987,8 +982,8 @@

      Configure a Flight Plan

      priority.
    • Condition: Python expression -to be matched for the command to be executed. Leave this field -blank for unconditional command execution. This field supports +to be matched for the command to be executed. Leave this field blank +for unconditional command execution. This field supports Variables. Example:
    @@ -1001,15 +996,15 @@ 

    Configure a Flight Plan

    Variables.
  • Use Sudo: Use sudo if required to run this command.
  • Post Run Actions: List of conditional actions to be triggered -after the command is executed. Each of the actions has the -following fields:
      +after the command is executed. Each of the actions has the following +fields:
      • Sequence: Order this actions is triggered. Lower value = higher priority.
      • Condition: Uses command exit code.
      • Action: Action to execute if condition is met. Also, if variables with values are specified, these variables will be -updated (for existing variables on the server) or added (for -new variables) to the server variables. Possible options:
          +updated (for existing variables on the server) or added (for new +variables) to the server variables. Possible options:
          • Exit with command code. Will terminate the flight plan execution and return an exit code of the failed command.
          • Exit with custom code. Will terminate the flight plan @@ -1029,14 +1024,13 @@

            Configure a Server Log

            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.

            -

            Server logs tab

            +

            Server logs tab

            Following fields are available:

            • Name: Readable name of the log
            • -
            • Access Level: Minimum access level required to access this -record. Please check the User Access -Settings section for more details. -Possible options:
                +
              • Access Level: Minimum access level required to access this record. +Please check the User Access Settings +section for more details. Possible options:
                • User. User must have at least Cetmix Tower / User access group configured in the User Settings.
                • Manager. User must have at least Cetmix Tower / Manager @@ -1046,8 +1040,7 @@

                  Configure a Server Log

              • Log Type: Defines the way logs are fetched. Possible options:
                  -
                • Command. A command is run with its output being saved to the -log
                • +
                • Command. A command is run with its output being saved to the log
                • File. Log is fetched from a file
              • @@ -1078,8 +1071,8 @@

                Use simple commands

                Why?

                • Simple commands are easier to reuse across multiple flight plans.
                • -
                • Commands run with sudo with password are be split and executed -one by one anyway.
                • +
                • Commands run with sudo with password are be split and executed one +by one anyway.

                Not recommended:

                @@ -1131,16 +1124,16 @@ 

                Usage

                Create a new Server from a Server Template

                  -
                • Go to the Cetmix Tower/Servers/Templates menu and select a -Server Template
                • +
                • Go to the Cetmix Tower/Servers/Templates menu and select a Server +Template
                • Click “Create Server” button. A pop-up wizard will open with server parameters populated from the template
                • Put the new server name, check the parameters and click “Confirm” button
                • New server will be created
                • If a Flight Plan is -defined in the server template it will be automatically executed -after a new server is created
                • +defined in the server template it will be automatically executed after +a new server is created

                You can also create a new server from template from code using a designated create_server_from_template function of the @@ -1164,7 +1157,7 @@

                Create a new Server from a Server Template

                Here is a short example of an Odoo automated action that creates a new server when a Sales Order is confirmed:

                -

                Automatic action

                +

                Automatic action

                 for record in records:
                 
                @@ -1199,17 +1192,17 @@ 

                Run a Command

              • Tags: If selected only commands with these tags will be shown
              • Sudo: sudo option for running this command
              • Command: Command to execute
              • -
              • Show shared: By default only commands available for the -selected server(s) are selectable. Activate this checkbox to -select any command
              • -
              • Path: Directory where command will be executed. Important: -this field does not support variables! Ensure that user has access -to this location even if you run command using sudo.
              • +
              • Show shared: By default only commands available for the selected +server(s) are selectable. Activate this checkbox to select any +command
              • +
              • Path: Directory where command will be executed. Important: this +field does not support variables! Ensure that user has access to +this location even if you run command using sudo.
              • Code: Raw command code
              • Preview: Command code rendered using server variables. IMPORTANT: If several servers are selected preview will not be -rendered. However during the command execution command code will -be rendered for each server separately.
              • +rendered. However during the command execution command code will be +rendered for each server separately.
            @@ -1218,9 +1211,9 @@

            Run a Command

          • Run. Executes a command using server “run” method and log command result into the “Command Log”.
          • Run in wizard. Executes a command directly in the wizard and show -command log in a new wizard window. IMPORTANT: Button will be -show only if single server is selected. If you try to run a command -for several servers from code, you will get a ValidationError.
          • +command log in a new wizard window. IMPORTANT: Button will be show +only if single server is selected. If you try to run a command for +several servers from code, you will get a ValidationError.

          You can check command execution logs in the Cetmix Tower/Commands/Command Logs menu. Important! If you want to @@ -1240,8 +1233,8 @@

          Run a Flight Plan

        • Tags: If selected only commands with these tags will be shown
        • Plan: Flight plan to execute
        • Show shared: By default only flight plans available for the -selected server(s) are selectable. Activate this checkbox to -select any flight plan
        • +selected server(s) are selectable. Activate this checkbox to select +any flight plan
        • Commands: Commands that will be executed in this flight plan. This field is read only
        @@ -1262,14 +1255,14 @@

        Check a Server Log

        up window. Or click on the Open button (2) to open it in the full form view
      -

      Open server log

      +

      Open server log

        -
      • Click the Refresh button to update the log. You can also click -the Refresh All button (3) located above the log list in -order to refresh all logs at once. Log output will be displayed in -the HTML field below.
      • +
      • Click the Refresh button to update the log. You can also click the +Refresh All button (3) located above the log list in order to +refresh all logs at once. Log output will be displayed in the HTML +field below.
      -

      Update server log

      +

      Update server log

  • Using Cetmix Tower in Odoo automation

    @@ -1286,7 +1279,7 @@

    Bug Tracker

    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.

    +feedback.

    Do not contact contributors directly about support or help with technical issues.

    @@ -1299,7 +1292,7 @@

    Authors

    Maintainers

    -

    This module is part of the cetmix/cetmix-tower project on GitHub.

    +

    This module is part of the cetmix/cetmix-tower project on GitHub.

    You are welcome to contribute.

    diff --git a/cetmix_tower_server/tests/__init__.py b/cetmix_tower_server/tests/__init__.py index 88087510..89014830 100644 --- a/cetmix_tower_server/tests/__init__.py +++ b/cetmix_tower_server/tests/__init__.py @@ -12,3 +12,4 @@ from . import test_cetmix_tower from . import test_update_related_variable_names from . import test_command_log +from . import test_variable_option diff --git a/cetmix_tower_server/tests/test_variable.py b/cetmix_tower_server/tests/test_variable.py index 4e8931db..b5326135 100644 --- a/cetmix_tower_server/tests/test_variable.py +++ b/cetmix_tower_server/tests/test_variable.py @@ -39,9 +39,10 @@ def check_variable_values(self, vals, server_ids=None): self.assertEqual( len(variable_line), 1, msg="Must be a single variable line" ) + expected_value = val[1] or "" self.assertEqual( variable_line.value_char, - val[1], + expected_value, msg="Variable value does not match provided one", ) diff --git a/cetmix_tower_server/tests/test_variable_option.py b/cetmix_tower_server/tests/test_variable_option.py new file mode 100644 index 00000000..89d7cef6 --- /dev/null +++ b/cetmix_tower_server/tests/test_variable_option.py @@ -0,0 +1,38 @@ +from psycopg2 import IntegrityError + +from .common import TestTowerCommon + + +class TestTowerVariableOption(TestTowerCommon): + """Test case class to validate the behavior of + 'cx.tower.variable.option' model. + """ + + def setUp(self): + super().setUp() + self.variable = self.env["cx.tower.variable"].create( + { + "name": "odoo_versions", + } + ) + + def test_unique_constraint(self): + """Test the unique constraint on name and variable_id.""" + self.env["cx.tower.variable.option"].create( + { + "name": "17.0", + "variable_id": self.variable.id, + } + ) + # Test that creating another option with the same + # 'name' and 'variable_id' raises an IntegrityError + with self.assertRaises( + IntegrityError, + msg="The combination of name and variable_id must be unique.", + ): + self.env["cx.tower.variable.option"].create( + { + "name": "17.0", + "variable_id": self.variable.id, + } + ) diff --git a/cetmix_tower_server/views/cx_tower_command_log_view.xml b/cetmix_tower_server/views/cx_tower_command_log_view.xml index b8b9069f..07686bd8 100644 --- a/cetmix_tower_server/views/cx_tower_command_log_view.xml +++ b/cetmix_tower_server/views/cx_tower_command_log_view.xml @@ -29,6 +29,7 @@ bg_color="bg-dark" attrs="{'invisible': ['|', ('is_running', '=', True), '&', ('is_running', '=', False), ('command_status', '!=', -20)]}" /> + diff --git a/cetmix_tower_server/views/cx_tower_server_view.xml b/cetmix_tower_server/views/cx_tower_server_view.xml index 79e2efb8..5d1eda68 100644 --- a/cetmix_tower_server/views/cx_tower_server_view.xml +++ b/cetmix_tower_server/views/cx_tower_server_view.xml @@ -51,7 +51,8 @@ type="action" name="%(cetmix_tower_server.cx_tower_command_execute_wizard_action)d" >Run - Command + Command +
    Run - Flight Plan + Flight Plan +
    @@ -270,7 +272,18 @@ - + + + +
    @@ -283,7 +296,6 @@ options="{'string': 'Copy reference'}" /> - + - - - - - - - - - - - - - - - - - - -
    + + + + + + + + + + + + + + + + + + + +
    + + + + + + +
    +
    +
    +
    + cx.tower.variable.view.tree cx.tower.variable diff --git a/setup/_metapackage/VERSION.txt b/setup/_metapackage/VERSION.txt deleted file mode 100644 index 5936e26e..00000000 --- a/setup/_metapackage/VERSION.txt +++ /dev/null @@ -1 +0,0 @@ -14.0.20241028.0 \ No newline at end of file diff --git a/setup/_metapackage/setup.py b/setup/_metapackage/setup.py deleted file mode 100644 index 3d2ed405..00000000 --- a/setup/_metapackage/setup.py +++ /dev/null @@ -1,21 +0,0 @@ -import setuptools - -with open('VERSION.txt', 'r') as f: - version = f.read().strip() - -setuptools.setup( - name="odoo14-addons-cetmix-cetmix-tower", - description="Meta package for cetmix-cetmix-tower Odoo addons", - version=version, - install_requires=[ - 'odoo14-addon-cetmix_tower_server', - 'odoo14-addon-cetmix_tower_server_notify_backend', - 'odoo14-addon-cetmix_tower_server_queue', - 'odoo14-addon-cetmix_tower_yaml', - ], - classifiers=[ - 'Programming Language :: Python', - 'Framework :: Odoo', - 'Framework :: Odoo :: 14.0', - ] -) From de3ef9b57e5ca302d16e6aebeec1702c011ef03d Mon Sep 17 00:00:00 2001 From: CetmixGitBot Date: Fri, 3 Jan 2025 14:27:26 +0000 Subject: [PATCH 6/6] [BOT] post-merge updates --- README.md | 2 +- cetmix_tower_server/README.rst | 26 +-- cetmix_tower_server/__manifest__.py | 2 +- .../static/description/index.html | 171 +++++++++--------- setup/_metapackage/VERSION.txt | 1 + setup/_metapackage/setup.py | 21 +++ 6 files changed, 119 insertions(+), 104 deletions(-) create mode 100644 setup/_metapackage/VERSION.txt create mode 100644 setup/_metapackage/setup.py diff --git a/README.md b/README.md index f54b9e23..8654ddde 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ Available addons ---------------- addon | version | maintainers | summary --- | --- | --- | --- -[cetmix_tower_server](cetmix_tower_server/) | 14.0.0.4.1 | | Flexible Server Management directly from Odoo +[cetmix_tower_server](cetmix_tower_server/) | 14.0.0.4.2 | | Flexible Server Management directly from Odoo [cetmix_tower_server_notify_backend](cetmix_tower_server_notify_backend/) | 14.0.1.0.0 | | Backend notifications for Cetmix Tower [cetmix_tower_server_queue](cetmix_tower_server_queue/) | 14.0.1.0.3 | | OCA Queue implementation for Cetmix Tower Server [cetmix_tower_yaml](cetmix_tower_yaml/) | 14.0.1.0.0 | | Cetmix Tower YAML export/import diff --git a/cetmix_tower_server/README.rst b/cetmix_tower_server/README.rst index aa28cdd8..d4e7932b 100644 --- a/cetmix_tower_server/README.rst +++ b/cetmix_tower_server/README.rst @@ -2,12 +2,12 @@ Cetmix Tower Server Management ============================== -.. +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:7f4e1f3db2bff1b2ffc99ccf8dbbc6d6dd67f8a6b6fdbe1c9619ce19065baa08 + !! source digest: sha256:46e220fd464cf2a9911e7720baa63defb7aefd08bb9c32e684b63cc00b9ddd0e !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -194,16 +194,6 @@ Configure `configuration variables <#configure-variables>`__ values to be used when rendering `commands <#configure-a-command>`__ and `files <#configure-a-file>`__ on this server. -- Users can select from predefined values in the "Option" field when options are available for a variable. -- If options exist: - - - The "Value" field becomes synchronized with the selected option. - - Users cannot manually enter a value but can select from available options. -- If no options exist: - - - The "Option" field is locked for changes. - - Users can manually input values in the "Value" field. - **Secrets** Configure secret values to used when rendering commands and files on @@ -271,10 +261,6 @@ the ``Variables`` menu. Click ``Create`` and put values in the fields: - **Reference**: Unique identifier used to address variable in conditions and expressions. Leave blank to generate automatically based on name -- **Variable Type**: Select the type of the variable. - - - **String**: The default type where the variable has Values. - - **Option**: Allows the variable to hold a value selected from a predefined list of Options. - **Note**: Put your notes here Configure Tags @@ -898,7 +884,7 @@ server when a Sales Order is confirmed: .. code:: python for record in records: - + # Check confirmed orders if record.state == "sale": params = { @@ -911,14 +897,14 @@ server when a Sales Order is confirmed: "odoo_version": "16.0" }, } - - # Create a new server from template with the 'demo_template' reference + + # Create a new server from template with the 'demo_template' reference env["cetmix.tower"].server_create_from_template( template_reference="demo_template", server_name=record.name, **params ) - + Run a Command ------------- diff --git a/cetmix_tower_server/__manifest__.py b/cetmix_tower_server/__manifest__.py index ac60a042..299c6b64 100644 --- a/cetmix_tower_server/__manifest__.py +++ b/cetmix_tower_server/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Cetmix Tower Server Management", "summary": "Flexible Server Management directly from Odoo", - "version": "14.0.0.4.1", + "version": "14.0.0.4.2", "category": "Productivity", "website": "https://cetmix.com", "author": "Cetmix", diff --git a/cetmix_tower_server/static/description/index.html b/cetmix_tower_server/static/description/index.html index c7c8f309..ca696470 100644 --- a/cetmix_tower_server/static/description/index.html +++ b/cetmix_tower_server/static/description/index.html @@ -367,9 +367,9 @@

    Cetmix Tower Server Management

    !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:7f4e1f3db2bff1b2ffc99ccf8dbbc6d6dd67f8a6b6fdbe1c9619ce19065baa08 +!! source digest: sha256:46e220fd464cf2a9911e7720baa63defb7aefd08bb9c32e684b63cc00b9ddd0e !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

    Beta License: AGPL-3 cetmix/cetmix-tower

    +

    Beta License: AGPL-3 cetmix/cetmix-tower

    Cetmix Tower offers a streamlined solution for managing remote servers via SSH or API calls directly from Odoo. It is designed for versatility across @@ -410,7 +410,8 @@

    Connectivity

    • Password and key based authentication for outgoing SSH connections
    • Built-in support of the Python requests -library for outgoing API calls
    • +library for outgoing API +calls
    @@ -469,7 +470,7 @@

    User access configuration

    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.

    -

    User profile

    +

    User profile

    In the Cetmix Tower section select one of the following options in the Access Level field:

      @@ -482,9 +483,9 @@

      User access configuration

      User.
    • Manager. Members of this group can modify Servers which they are added as followers. -They can create new Servers too however they -cannot delete them. Users of this group have access to the entities -with Access Level set to Manager or User.
    • +They can create new Servers too however +they cannot delete them. Users of this group have access to the +entities with Access Level set to Manager or User.
    • Root. Members of this group can create, modify or delete any Server. They also have access to the entities with any Access Level set.
    • @@ -548,8 +549,8 @@

      Configure a Server

      for this server
    • Flight Plan Logs: Shows all Flight Plan logs for this server
    • -
    • Files: Shows all Files that belong to this -server
    • +
    • Files: Shows all Files that belong to +this server
    @@ -560,8 +561,8 @@

    Configure a Server Template

    Fill the values it the tabs below:

    General Settings

      -
    • Flight Plan: Select a flight plan to be executed after a server is -created
    • +
    • Flight Plan: Select a flight plan to be executed after a server +is created
    • Operating System: Default operating system for new servers
    • Tags: Default search tags for new servers
    • SSH Auth Mode: Default SSH auth mode for new servers. Available @@ -599,9 +600,9 @@

      Configure Tags

      the Tags menu. Click Create and put values in the fields:

      • Name: Readable name
      • -
      • Reference: Unique identifier used to address the tag in conditions -and expressions. Leave this field blank to generate it automatically -based on the name
      • +
      • Reference: Unique identifier used to address the tag in +conditions and expressions. Leave this field blank to generate it +automatically based on the name
      • Color: Select a color for the tag
      • Servers: Select the servers associated with the tag.
      @@ -691,8 +692,8 @@

      Variable Types

      Following types of variable values available in Cetmix Tower:

        -
      • Local values. Those are values that are defined at a record level. For -example for a server or an action.
      • +
      • Local values. Those are values that are defined at a record level. +For example for a server or an action.
      • Global values. Those are values that are defined at the Cetmix Tower level.
      @@ -756,8 +757,8 @@

      Configure a Key/Secret

      Servers where this SSH key is used
    • Partner: Secret type only. If selected this secret is used only for the Servers of selected partner
    • -
    • Server: Secret type only. If selected this secret is used only -for selected Server
    • +
    • Server: Secret type only. If selected this secret is used +only for selected Server
    • Note: Put your notes here
    @@ -802,9 +803,9 @@

    Configure a File

    and are fetched to Cetmix Tower. For example log files.
  • Tower. These are files that are initially formed in Cetmix -Tower and are uploaded to remote server. -For example configuration files. Such files are rendered using -variables and can be created and managed using file templates.
  • +Tower and are uploaded to remote +server. For example configuration files. Such files are rendered +using variables and can be created and managed using file templates.

    To create a new file go to Cetmix Tower -> Files -> Files click Create and put values in the fields:

    @@ -818,13 +819,13 @@

    Configure a File

  • File: Is used to store binary file data.
  • -
  • Template: File template used to render this file. If selected file -will be automatically updated every time template is modified.
  • +
  • Template: File template used to render this file. If selected +file will be automatically updated every time template is modified.
  • Server: Server where this file is located
  • Directory on Server: This is where the file is located on the remote server
  • -
  • Full Server Path: Full path to file on the remote server including -filename
  • +
  • Full Server Path: Full path to file on the remote server +including filename
  • Auto Sync: If enabled the file will be automatically uploaded to the remote server on after it is modified in Cetmix Tower. Used only with Tower source.
  • @@ -836,8 +837,8 @@

    Configure a File

  • Code: Raw file content. This field is editable for the Tower files and readonly for Server ones. This field supports Variables.
  • -
  • Preview: This is a rendered file content as it will be uploaded to -server. Used only with Tower source.
  • +
  • Preview: This is a rendered file content as it will be uploaded +to server. Used only with Tower source.
  • Server Version: Current file content fetched from server. Used only with Tower source.
  • @@ -889,8 +890,8 @@

    Configure a Command

  • Reference: Leave the “reference” field blank to generate a reference automatically.
  • Allow Parallel Run: If disabled only one copy of this command can -be run on the same server at the same time. Otherwise the same command -can be run in parallel.
  • +be run on the same server at the same time. Otherwise the same +command can be run in parallel.
  • 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.
  • @@ -900,25 +901,28 @@

    Configure a Command

  • Action: Action executed by the command. Possible options:
    • SSH command: Execute a shell command using ssh connection on remote server.
    • -
    • Execute Python code: Execute a Python code on the Tower Server.
    • +
    • Execute Python code: Execute a Python code on the Tower +Server.
    • Create file using template: Create or update a file using -selected file template and push / pull it to remote server / tower. -If the file already exists on server it will be overwritten.
    • +selected file template and push / pull it to remote server / +tower. If the file already exists on server it will be +overwritten.
    • Run flight plan: Allow to start Flight Plan execution from command ().
  • Default Path: Specify path where command will be executed. This -field supports Variables. Important: ensure -ssh user has access to the location even if executing command using -sudo.
  • +field supports Variables. Important: +ensure ssh user has access to the location even if executing command +using sudo.
  • Code: Code to execute. Can be an SSH command or Python code based on selected action. This field supports -Variables. Important! Variables used in -command are rendered in different +Variables. Important! Variables used +in command are rendered in different modes based on the command action.
  • -
  • File Template: File template that will be used to create or update -file. Check File Templates for more details.
  • +
  • File Template: File template that will be used to create or +update file. Check File Templates for more +details.
  • Server Status: Server status to be set after command execution. Possible options:
    • Undefined. Default status.
    • @@ -961,10 +965,11 @@

      Configure a Flight Plan

    • On Error: Default action to execute when an error happens during the flight plan execution. Possible options:

        -
      • Exit with command code. Will terminate the flight plan execution -and return an exit code of the failed command.
      • -
      • Exit with custom code. Will terminate the flight plan execution -and return the custom code configured in the field next to this one.
      • +
      • Exit with command code. Will terminate the flight plan +execution and return an exit code of the failed command.
      • +
      • Exit with custom code. Will terminate the flight plan +execution and return the custom code configured in the field next +to this one.
      • Run next command. Will continue flight plan execution.
    • @@ -982,8 +987,8 @@

      Configure a Flight Plan

      priority.
    • Condition: Python expression -to be matched for the command to be executed. Leave this field blank -for unconditional command execution. This field supports +to be matched for the command to be executed. Leave this field +blank for unconditional command execution. This field supports Variables. Example:
    @@ -996,15 +1001,15 @@ 

    Configure a Flight Plan

    Variables.
  • Use Sudo: Use sudo if required to run this command.
  • Post Run Actions: List of conditional actions to be triggered -after the command is executed. Each of the actions has the following -fields:
      +after the command is executed. Each of the actions has the +following fields:
      • Sequence: Order this actions is triggered. Lower value = higher priority.
      • Condition: Uses command exit code.
      • Action: Action to execute if condition is met. Also, if variables with values are specified, these variables will be -updated (for existing variables on the server) or added (for new -variables) to the server variables. Possible options:
          +updated (for existing variables on the server) or added (for +new variables) to the server variables. Possible options:
          • Exit with command code. Will terminate the flight plan execution and return an exit code of the failed command.
          • Exit with custom code. Will terminate the flight plan @@ -1024,13 +1029,14 @@

            Configure a Server Log

            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.

            -

            Server logs tab

            +

            Server logs tab

            Following fields are available:

            • Name: Readable name of the log
            • -
            • Access Level: Minimum access level required to access this record. -Please check the User Access Settings -section for more details. Possible options:
                +
              • Access Level: Minimum access level required to access this +record. Please check the User Access +Settings section for more details. +Possible options:
                • User. User must have at least Cetmix Tower / User access group configured in the User Settings.
                • Manager. User must have at least Cetmix Tower / Manager @@ -1040,7 +1046,8 @@

                  Configure a Server Log

              • Log Type: Defines the way logs are fetched. Possible options:
                  -
                • Command. A command is run with its output being saved to the log
                • +
                • Command. A command is run with its output being saved to the +log
                • File. Log is fetched from a file
              • @@ -1071,8 +1078,8 @@

                Use simple commands

                Why?

                • Simple commands are easier to reuse across multiple flight plans.
                • -
                • Commands run with sudo with password are be split and executed one -by one anyway.
                • +
                • Commands run with sudo with password are be split and executed +one by one anyway.

                Not recommended:

                @@ -1124,16 +1131,16 @@ 

                Usage

                Create a new Server from a Server Template

                  -
                • Go to the Cetmix Tower/Servers/Templates menu and select a Server -Template
                • +
                • Go to the Cetmix Tower/Servers/Templates menu and select a +Server Template
                • Click “Create Server” button. A pop-up wizard will open with server parameters populated from the template
                • Put the new server name, check the parameters and click “Confirm” button
                • New server will be created
                • If a Flight Plan is -defined in the server template it will be automatically executed after -a new server is created
                • +defined in the server template it will be automatically executed +after a new server is created

                You can also create a new server from template from code using a designated create_server_from_template function of the @@ -1157,7 +1164,7 @@

                Create a new Server from a Server Template

                Here is a short example of an Odoo automated action that creates a new server when a Sales Order is confirmed:

                -

                Automatic action

                +

                Automatic action

                 for record in records:
                 
                @@ -1192,17 +1199,17 @@ 

                Run a Command

              • Tags: If selected only commands with these tags will be shown
              • Sudo: sudo option for running this command
              • Command: Command to execute
              • -
              • Show shared: By default only commands available for the selected -server(s) are selectable. Activate this checkbox to select any -command
              • -
              • Path: Directory where command will be executed. Important: this -field does not support variables! Ensure that user has access to -this location even if you run command using sudo.
              • +
              • Show shared: By default only commands available for the +selected server(s) are selectable. Activate this checkbox to +select any command
              • +
              • Path: Directory where command will be executed. Important: +this field does not support variables! Ensure that user has access +to this location even if you run command using sudo.
              • Code: Raw command code
              • Preview: Command code rendered using server variables. IMPORTANT: If several servers are selected preview will not be -rendered. However during the command execution command code will be -rendered for each server separately.
              • +rendered. However during the command execution command code will +be rendered for each server separately.
            @@ -1211,9 +1218,9 @@

            Run a Command

          • Run. Executes a command using server “run” method and log command result into the “Command Log”.
          • Run in wizard. Executes a command directly in the wizard and show -command log in a new wizard window. IMPORTANT: Button will be show -only if single server is selected. If you try to run a command for -several servers from code, you will get a ValidationError.
          • +command log in a new wizard window. IMPORTANT: Button will be +show only if single server is selected. If you try to run a command +for several servers from code, you will get a ValidationError.

          You can check command execution logs in the Cetmix Tower/Commands/Command Logs menu. Important! If you want to @@ -1233,8 +1240,8 @@

          Run a Flight Plan

        • Tags: If selected only commands with these tags will be shown
        • Plan: Flight plan to execute
        • Show shared: By default only flight plans available for the -selected server(s) are selectable. Activate this checkbox to select -any flight plan
        • +selected server(s) are selectable. Activate this checkbox to +select any flight plan
        • Commands: Commands that will be executed in this flight plan. This field is read only
        @@ -1255,14 +1262,14 @@

        Check a Server Log

        up window. Or click on the Open button (2) to open it in the full form view
      -

      Open server log

      +

      Open server log

        -
      • Click the Refresh button to update the log. You can also click the -Refresh All button (3) located above the log list in order to -refresh all logs at once. Log output will be displayed in the HTML -field below.
      • +
      • Click the Refresh button to update the log. You can also click +the Refresh All button (3) located above the log list in +order to refresh all logs at once. Log output will be displayed in +the HTML field below.
      -

      Update server log

      +

      Update server log

  • Using Cetmix Tower in Odoo automation

    @@ -1279,7 +1286,7 @@

    Bug Tracker

    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.

    +feedback.

    Do not contact contributors directly about support or help with technical issues.

    @@ -1292,7 +1299,7 @@

    Authors

    Maintainers

    -

    This module is part of the cetmix/cetmix-tower project on GitHub.

    +

    This module is part of the cetmix/cetmix-tower project on GitHub.

    You are welcome to contribute.

    diff --git a/setup/_metapackage/VERSION.txt b/setup/_metapackage/VERSION.txt new file mode 100644 index 00000000..791c078e --- /dev/null +++ b/setup/_metapackage/VERSION.txt @@ -0,0 +1 @@ +14.0.20250103.0 \ No newline at end of file diff --git a/setup/_metapackage/setup.py b/setup/_metapackage/setup.py new file mode 100644 index 00000000..3d2ed405 --- /dev/null +++ b/setup/_metapackage/setup.py @@ -0,0 +1,21 @@ +import setuptools + +with open('VERSION.txt', 'r') as f: + version = f.read().strip() + +setuptools.setup( + name="odoo14-addons-cetmix-cetmix-tower", + description="Meta package for cetmix-cetmix-tower Odoo addons", + version=version, + install_requires=[ + 'odoo14-addon-cetmix_tower_server', + 'odoo14-addon-cetmix_tower_server_notify_backend', + 'odoo14-addon-cetmix_tower_server_queue', + 'odoo14-addon-cetmix_tower_yaml', + ], + classifiers=[ + 'Programming Language :: Python', + 'Framework :: Odoo', + 'Framework :: Odoo :: 14.0', + ] +)