diff --git a/addons/cetmix_tower_ovh/README.rst b/addons/cetmix_tower_ovh/README.rst new file mode 100644 index 0000000..71f7e15 --- /dev/null +++ b/addons/cetmix_tower_ovh/README.rst @@ -0,0 +1,263 @@ +================ +Cetmix Tower OVH +================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:857636ba9899c2980b8ee24c3cf12b3854a7a31704c39395c7f81648d1b3ca57 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :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/18.0/cetmix_tower_ovh + :alt: cetmix/cetmix-tower + +|badge1| |badge2| |badge3| + +This module integrates the OVH Python client, enabling seamless +interaction with OVH cloud services within the Cetmix Tower. + +**Table of contents** + +.. contents:: + :local: + +Use Cases / Context +=================== + +Although OVH allows API calls without using an SDK, we found that +integrating the OVH SDK into Cetmix Tower makes provisioning, +configuring, and maintaining OVH instances more convenient for the end +user. However, not all Cetmix Tower users require this functionality, so +to avoid overloading the system, we have included it in a separate +module. + +Configuration +============= + +Setting up OVH Access +===================== + +Create OVH API Credentials +-------------------------- + +To use the OVH integration with Cetmix Tower, you need to create OVH API +credentials: + +- Follow the `official OVH + documentation `__ + (https://docs.ovh.com/gb/en/api/first-steps/) for creating an + application and generating API keys +- It's recommended to create a dedicated application with appropriate + permissions for Cetmix Tower +- Store your Application Key, Application Secret, and Consumer Key + securely—you'll need them in the next step + +Configure OVH Secrets in Cetmix Tower +------------------------------------- + +Create three secrets in Cetmix Tower to store your OVH credentials: + +- Navigate to ``Cetmix Tower > Settings > Keys and Secrets`` +- Create a new Secret with: + + - Name: ``OVH Application Key`` + - Reference: ``ovh_application_key`` + - Key Type: ``Secret`` + +- Enter your OVH Application Key in the Secret Value tab +- Similarly, create another Secret with: + + - Name: ``OVH Application Secret`` + - Reference: ``ovh_application_secret`` + - Key Type: ``Secret`` + +- Enter your OVH Application Secret in the Secret Value tab +- Finally, create a Secret with: + + - Name: ``OVH Consumer Key`` + - Reference: ``ovh_consumer_key`` + - Key Type: ``Secret`` + +- Enter your OVH Consumer Key in the Secret Value tab + +.. + + Note: These secrets will be accessible as + ``#!cxtower.secret.ovh_application_key!#``, + ``#!cxtower.secret.ovh_application_secret!#``, and + ``#!cxtower.secret.ovh_consumer_key!#`` in your commands. + +Configure OVH Endpoint +---------------------- + +Create a variable to define your OVH API endpoint (region): + +- Navigate to ``Cetmix Tower > Settings > Variables`` +- Create a new Variable with: + + - Name: ``OVH Endpoint`` + - Reference: ``ovh_endpoint`` + - Type: ``String`` + +- Set your OVH endpoint (e.g., ``ovh-eu``, ``ovh-ca``, ``ovh-us``) as + the value + +Usage +===== + +Cetmix Tower OVHcloud Command Usage +=================================== + + **Disclaimer**: The following example demonstrates one of many + possible commands you can create and run with this module. The + ``ovh`` Python library provides access to the full range of OVHcloud + APIs – this is just a starting point to help you get familiar with + the integration. + +Example of Cetmix Tower Python Command to Create DNS Records +------------------------------------------------------------ + +- **Navigate to Command Creation** + + - Go to ``Cetmix Tower > Commands > Commands`` + - Click the ``Create`` button + +- **Configure Command Settings** + + - Set a descriptive ``Name`` (e.g., "List OVHcloud Instances") + - Leave ``Reference`` blank to generate automatically (or set a custom + reference) + - Select ``Action``: "Execute Python code" + - Set ``Access Level``: Choose appropriate level (e.g., "Manager") + - Optional: Set ``Default Path`` if needed + - Optional: Add ``Tags`` (e.g., "ovh", "cloud", "instance") for better + organization + +- **Add Required Variables** + + - In the ``Variables`` tab, add the previously configured variable: + + - ``ovh_endpoint`` (e.g., "ovh-eu") + +- **Add Required Secrets** + + - In the ``Secrets`` field, add the previously configured secrets: + + - ``ovh_application_key`` + - ``ovh_application_secret`` + - ``ovh_consumer_key`` + +- **Write Python Code** + + - Go to the ``Code`` tab + - Enter the following Python code: + + .. code:: python + + # List OVHcloud instances using ovh API + result = {"exit_code": 0, "message": None} + + client = ovh.Client( + endpoint={{ ovh_endpoint }}, + application_key=#!cxtower.secret.ovh_application_key!#, + application_secret=#!cxtower.secret.ovh_application_secret!#, + consumer_key=#!cxtower.secret.ovh_consumer_key!# + ) + + # Required variables: + # - domain_name: The main domain (e.g., "example.com") + # - subdomain: The subdomain to create (e.g., "test") + + try: + # Create a new subdomain by adding a DNS entry (A record as example) + ip_address = "1.2.3.4" # Replace with the desired IP address + response = client.post( + "/domain/zone/" + domain_name + "/record", + fieldType="A", + subDomain=subdomain, + target=ip_address, + ttl=3600 + ) + # Refresh the zone to apply changes + client.post("/domain/zone/" + domain_name + "/refresh") + result["message"] = "Subdomain '" + subdomain + "." + domain_name + "' created and DNS zone refreshed." + except Exception as e: + result["exit_code"] = 1 + result["message"] = "Error: " + str(e) + +- **Save the Command** + + - Click the ``Save`` button to create the command + +Running the OVHcloud Instance Command +------------------------------------- + +- **Navigate to Server** + + - Go to ``Cetmix Tower > Servers > Servers`` + - Open the server where you want to run the command + +- **Execute Command from Server** + + - Click the ``Command`` button at the top of the server form + - In the popup dialog: + + - Select your OVHcloud instance command from the dropdown + - Verify the variable values (if any need adjustment) + - Click ``Run`` to execute + +- **View Command Results** + + - After execution, the command log will display showing: + + - The command executed + - Execution status + - Output message containing OVHcloud instance details if successful + +Changelog +========= + + + +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Cetmix +* Giovanni Serra + +Maintainers +----------- + +.. |maintainer-GSLabIt| image:: https://github.com/GSLabIt.png?size=40px + :target: https://github.com/GSLabIt + :alt: GSLabIt + +Current maintainer: + +|maintainer-GSLabIt| + +This module is part of the `cetmix/cetmix-tower `_ project on GitHub. + +You are welcome to contribute. diff --git a/addons/cetmix_tower_ovh/__init__.py b/addons/cetmix_tower_ovh/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/addons/cetmix_tower_ovh/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/addons/cetmix_tower_ovh/__manifest__.py b/addons/cetmix_tower_ovh/__manifest__.py new file mode 100644 index 0000000..fe1a3ec --- /dev/null +++ b/addons/cetmix_tower_ovh/__manifest__.py @@ -0,0 +1,24 @@ +# Copyright 2024 Cetmix OÜ +# Copyright 2025 Giovanni Serra +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Cetmix Tower OVH", + "summary": """Cetmix Tower OVH API integration""", + "version": "18.0.1.0.1", + "category": "Productivity", + "license": "AGPL-3", + "author": "Cetmix, Giovanni Serra", + "maintainers": ["GSLabIt"], + "website": "https://tower.cetmix.com", + "images": ["static/description/banner.png"], + "application": False, + "installable": True, + "demo": [ + "demo/demo_data.xml", + ], + "external_dependencies": {"python": ["ovh"]}, + "depends": [ + "cetmix_tower_server", + ], +} diff --git a/addons/cetmix_tower_ovh/demo/demo_data.xml b/addons/cetmix_tower_ovh/demo/demo_data.xml new file mode 100644 index 0000000..9aea62f --- /dev/null +++ b/addons/cetmix_tower_ovh/demo/demo_data.xml @@ -0,0 +1,179 @@ + + + + + OVH Application Key + ovh_application_key + s + + + + + OVH Application Secret + ovh_application_secret + s + + + + + OVH Consumer Key + ovh_consumer_key + s + + + + + + + OVH Endpoint + ovh_endpoint + o + + + + OVH Zone Name + ovh_zone_name + + + + + + + your_zone.name + + + + + ovh-eu + ovh-eu + ovh-eu + 10 + + + + ovh-us + ovh-us + ovh-us + 20 + + + + ovh-ca + ovh-ca + ovh-ca + 30 + + + + soyoustart-eu + soyoustart-eu + soyoustart-eu + 40 + + + + soyoustart-ca + soyoustart-ca + soyoustart-ca + 50 + + + + kimsufi-eu + kimsufi-eu + kimsufi-eu + 60 + + + + kimsufi-ca + kimsufi-ca + kimsufi-ca + 70 + + + + + + Register OVH DNS Record + python_code + +# ---------------- +# Tower properties +# ---------------- +cetmix_tower = env["cetmix.tower"] + +# Ensure the domain in your server URL matches your OVH DNS Zone name! +# Example: If your DNS Zone is "example.com", your URL should be "*.example.com" + +instance_url = {{ tower.server.url }} +ovh_endpoint = env["cx.tower.variable.option"].get_by_reference("option_ovh_endpoint_eu").value_char +ovh_application_key = #!cxtower.secret.ovh_application_key!# +ovh_application_secret = #!cxtower.secret.ovh_application_secret!# +ovh_consumer_key = #!cxtower.secret.ovh_consumer_key!# +ovh_zone_name = {{ ovh_zone_name }} +# ---------------- +# Request settings +# ---------------- + +path = "/domain/zone/"+ovh_zone_name+"/record" + +# Subdomain extraction with tldextract: +sub_domain = tldextract.extract(instance_url).subdomain + +# Send request to Ovh +exit_code = 0 +message = "" + +try: + client = ovh.Client( + endpoint=ovh_endpoint, + application_key=ovh_application_key, + application_secret=ovh_application_secret, + consumer_key=ovh_consumer_key + ) + records = client.get(path, subDomain=sub_domain, fieldType="A") + if not records: + records = client.post( + path, + fieldType="A", + subDomain=sub_domain, + target={{ tower.server.ipv4 }}, + ttl=3600 + ) + client.post("/domain/zone/" + ovh_zone_name + "/refresh") + if records: + exit_code = 0 + message = "subDomain " + sub_domain + " registered" + else: + exit_code = 0 + message = "subDomain " + sub_domain + " already exists" +except Exception as e: + exit_code = 500 + message = str(e) + +result = { + "exit_code": exit_code, + "message": message, +} + + + + + + Register or check DNS A record for current server in OVH DNS zone + + diff --git a/addons/cetmix_tower_ovh/i18n/cetmix_tower_ovh.pot b/addons/cetmix_tower_ovh/i18n/cetmix_tower_ovh.pot new file mode 100644 index 0000000..6ce0ddf --- /dev/null +++ b/addons/cetmix_tower_ovh/i18n/cetmix_tower_ovh.pot @@ -0,0 +1,30 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * cetmix_tower_ovh +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: cetmix_tower_ovh +#: model:ir.model,name:cetmix_tower_ovh.model_cx_tower_command +msgid "Cetmix Tower Command" +msgstr "" + +#. module: cetmix_tower_ovh +#. odoo-python +#: code:addons/cetmix_tower_ovh/models/cx_tower_command.py:0 +msgid "" +"Python 'ovh' library for OVH services. Available methods: " +"'Client'
Supports OVH services
Please check the OVH Documentation for detailed information about the " +"services and methods." +msgstr "" diff --git a/addons/cetmix_tower_ovh/i18n/it.po b/addons/cetmix_tower_ovh/i18n/it.po new file mode 100644 index 0000000..f93bd29 --- /dev/null +++ b/addons/cetmix_tower_ovh/i18n/it.po @@ -0,0 +1,54 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * cetmix_tower_ovh +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: \n" +"PO-Revision-Date: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Language: it\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 2.3\n" + +#. module: cetmix_tower_ovh +#: model:ir.model,name:cetmix_tower_ovh.model_cx_tower_command +msgid "Cetmix Tower Command" +msgstr "Comando Cetmix Tower" + +#. module: cetmix_tower_ovh +#. odoo-python +#: code:addons/cetmix_tower_ovh/models/cx_tower_command.py:0 +#, python-format +msgid "Python 'ovh' library for OVH services. Available methods: 'Client'
Supports OVH services
Please check the OVH Documentation for detailed information about the services and methods." +msgstr "Libreria Python 'ovh' per servizi OVH. Metodi disponibili: 'Client'
Supporta i servizi OVH
Verificare la documentazione OVH per informazioni dettagliate sui servizi e i metodi." + +#~ msgid "Display Name" +#~ msgstr "Nome visualizzato" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "Ultima modifica il" + +#~ msgid "" +#~ "# - ovh: Python 'ovh' library for OVH services. Available methods: " +#~ "'Client'\n" +#~ "# Supports OVH services\n" +#~ "# - tldextract: Python 'tldextract' library. Available methods: " +#~ "'extract'\n" +#~ "# Supports domain extraction" +#~ msgstr "" +#~ "# - ovh: libreria Python 'ovh' per i servizi OVH. Metodi disponibili: " +#~ "'Client'\n" +#~ "# Supporta servizi OVH\n" +#~ "# - tldextract: libreria Python 'tldextract'. Metodi disponibili: " +#~ "'extract'\n" +#~ "# Supporta estrazione dominio" diff --git a/addons/cetmix_tower_ovh/models/__init__.py b/addons/cetmix_tower_ovh/models/__init__.py new file mode 100644 index 0000000..e868e3a --- /dev/null +++ b/addons/cetmix_tower_ovh/models/__init__.py @@ -0,0 +1 @@ +from . import cx_tower_command # noqa: F401 diff --git a/addons/cetmix_tower_ovh/models/cx_tower_command.py b/addons/cetmix_tower_ovh/models/cx_tower_command.py new file mode 100644 index 0000000..7d7b5de --- /dev/null +++ b/addons/cetmix_tower_ovh/models/cx_tower_command.py @@ -0,0 +1,39 @@ +# Copyright 2024 Cetmix OÜ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import _, models +from odoo.tools.safe_eval import wrap_module + +# Wrap ovh safely +ovh = wrap_module(__import__("ovh"), ["Client"]) + + +class CxTowerCommand(models.Model): + """Extends cx.tower.command to add OVH functionality.""" + + _inherit = "cx.tower.command" + + def _custom_python_libraries(self): + """ + Add the ovh library to the available libraries. + """ + python_libraries = super()._custom_python_libraries() + python_libraries.update( + { + "cetmix_tower_ovh": { + "ovh": { + "import": ovh, + "help": _( + "Python 'ovh' library for OVH services. " + "Available methods: 'Client'
" + "Supports OVH services
" + "Please check the OVH Documentation for detailed " + "information about the services and methods." + ), + } + } + } + ) + return python_libraries diff --git a/addons/cetmix_tower_ovh/pyproject.toml b/addons/cetmix_tower_ovh/pyproject.toml new file mode 100644 index 0000000..4231d0c --- /dev/null +++ b/addons/cetmix_tower_ovh/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/addons/cetmix_tower_ovh/readme/CONFIGURE.md b/addons/cetmix_tower_ovh/readme/CONFIGURE.md new file mode 100644 index 0000000..575663c --- /dev/null +++ b/addons/cetmix_tower_ovh/readme/CONFIGURE.md @@ -0,0 +1,44 @@ + +# Setting up OVH Access + +## Create OVH API Credentials + +To use the OVH integration with Cetmix Tower, you need to create OVH API credentials: + +- Follow the [official OVH documentation](https://docs.ovh.com/gb/en/api/first-steps/) (https://docs.ovh.com/gb/en/api/first-steps/) for creating an application and generating API keys +- It's recommended to create a dedicated application with appropriate permissions for Cetmix Tower +- Store your Application Key, Application Secret, and Consumer Key securely—you'll need them in the next step + +## Configure OVH Secrets in Cetmix Tower + +Create three secrets in Cetmix Tower to store your OVH credentials: + +- Navigate to `Cetmix Tower > Settings > Keys and Secrets` +- Create a new Secret with: + - Name: `OVH Application Key` + - Reference: `ovh_application_key` + - Key Type: `Secret` +- Enter your OVH Application Key in the Secret Value tab +- Similarly, create another Secret with: + - Name: `OVH Application Secret` + - Reference: `ovh_application_secret` + - Key Type: `Secret` +- Enter your OVH Application Secret in the Secret Value tab +- Finally, create a Secret with: + - Name: `OVH Consumer Key` + - Reference: `ovh_consumer_key` + - Key Type: `Secret` +- Enter your OVH Consumer Key in the Secret Value tab + +> Note: These secrets will be accessible as `#!cxtower.secret.ovh_application_key!#`, `#!cxtower.secret.ovh_application_secret!#`, and `#!cxtower.secret.ovh_consumer_key!#` in your commands. + +## Configure OVH Endpoint + +Create a variable to define your OVH API endpoint (region): + +- Navigate to `Cetmix Tower > Settings > Variables` +- Create a new Variable with: + - Name: `OVH Endpoint` + - Reference: `ovh_endpoint` + - Type: `String` +- Set your OVH endpoint (e.g., `ovh-eu`, `ovh-ca`, `ovh-us`) as the value diff --git a/addons/cetmix_tower_ovh/readme/CONTEXT.md b/addons/cetmix_tower_ovh/readme/CONTEXT.md new file mode 100644 index 0000000..4ddde14 --- /dev/null +++ b/addons/cetmix_tower_ovh/readme/CONTEXT.md @@ -0,0 +1 @@ +Although OVH allows API calls without using an SDK, we found that integrating the OVH SDK into Cetmix Tower makes provisioning, configuring, and maintaining OVH instances more convenient for the end user. However, not all Cetmix Tower users require this functionality, so to avoid overloading the system, we have included it in a separate module. diff --git a/addons/cetmix_tower_ovh/readme/DESCRIPTION.md b/addons/cetmix_tower_ovh/readme/DESCRIPTION.md new file mode 100644 index 0000000..e0643cb --- /dev/null +++ b/addons/cetmix_tower_ovh/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module integrates the OVH Python client, enabling seamless interaction with OVH cloud services within the Cetmix Tower. diff --git a/addons/cetmix_tower_ovh/readme/HISTORY.md b/addons/cetmix_tower_ovh/readme/HISTORY.md new file mode 100644 index 0000000..e69de29 diff --git a/addons/cetmix_tower_ovh/readme/USAGE.md b/addons/cetmix_tower_ovh/readme/USAGE.md new file mode 100644 index 0000000..e991cc0 --- /dev/null +++ b/addons/cetmix_tower_ovh/readme/USAGE.md @@ -0,0 +1,86 @@ +# Cetmix Tower OVHcloud Command Usage + +> **Disclaimer**: The following example demonstrates one of many possible commands you can create and run with this module. The `ovh` Python library provides access to the full range of OVHcloud APIs – this is just a starting point to help you get familiar with the integration. + +## Example of Cetmix Tower Python Command to Create DNS Records + +* **Navigate to Command Creation** + * Go to `Cetmix Tower > Commands > Commands` + * Click the `Create` button + +* **Configure Command Settings** + * Set a descriptive `Name` (e.g., "List OVHcloud Instances") + * Leave `Reference` blank to generate automatically (or set a custom reference) + * Select `Action`: "Execute Python code" + * Set `Access Level`: Choose appropriate level (e.g., "Manager") + * Optional: Set `Default Path` if needed + * Optional: Add `Tags` (e.g., "ovh", "cloud", "instance") for better organization + +* **Add Required Variables** + * In the `Variables` tab, add the previously configured variable: + * `ovh_endpoint` (e.g., "ovh-eu") + +* **Add Required Secrets** + * In the `Secrets` field, add the previously configured secrets: + * `ovh_application_key` + * `ovh_application_secret` + * `ovh_consumer_key` + +* **Write Python Code** + * Go to the `Code` tab + * Enter the following Python code: + + ```python + # List OVHcloud instances using ovh API + result = {"exit_code": 0, "message": None} + + client = ovh.Client( + endpoint={{ ovh_endpoint }}, + application_key=#!cxtower.secret.ovh_application_key!#, + application_secret=#!cxtower.secret.ovh_application_secret!#, + consumer_key=#!cxtower.secret.ovh_consumer_key!# + ) + + # Required variables: + # - domain_name: The main domain (e.g., "example.com") + # - subdomain: The subdomain to create (e.g., "test") + + try: + # Create a new subdomain by adding a DNS entry (A record as example) + ip_address = "1.2.3.4" # Replace with the desired IP address + response = client.post( + "/domain/zone/" + domain_name + "/record", + fieldType="A", + subDomain=subdomain, + target=ip_address, + ttl=3600 + ) + # Refresh the zone to apply changes + client.post("/domain/zone/" + domain_name + "/refresh") + result["message"] = "Subdomain '" + subdomain + "." + domain_name + "' created and DNS zone refreshed." + except Exception as e: + result["exit_code"] = 1 + result["message"] = "Error: " + str(e) + ``` + +* **Save the Command** + * Click the `Save` button to create the command + +## Running the OVHcloud Instance Command + +* **Navigate to Server** + * Go to `Cetmix Tower > Servers > Servers` + * Open the server where you want to run the command + +* **Execute Command from Server** + * Click the `Command` button at the top of the server form + * In the popup dialog: + * Select your OVHcloud instance command from the dropdown + * Verify the variable values (if any need adjustment) + * Click `Run` to execute + +* **View Command Results** + * After execution, the command log will display showing: + * The command executed + * Execution status + * Output message containing OVHcloud instance details if successful diff --git a/addons/cetmix_tower_ovh/readme/newsfragments/.gitkeep b/addons/cetmix_tower_ovh/readme/newsfragments/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/addons/cetmix_tower_ovh/static/description/banner.png b/addons/cetmix_tower_ovh/static/description/banner.png new file mode 100644 index 0000000..4bcd7b8 Binary files /dev/null and b/addons/cetmix_tower_ovh/static/description/banner.png differ diff --git a/addons/cetmix_tower_ovh/static/description/icon.png b/addons/cetmix_tower_ovh/static/description/icon.png new file mode 100644 index 0000000..2507f55 Binary files /dev/null and b/addons/cetmix_tower_ovh/static/description/icon.png differ diff --git a/addons/cetmix_tower_ovh/static/description/index.html b/addons/cetmix_tower_ovh/static/description/index.html new file mode 100644 index 0000000..2499bfd --- /dev/null +++ b/addons/cetmix_tower_ovh/static/description/index.html @@ -0,0 +1,635 @@ + + + + + +Cetmix Tower OVH + + + +
+

Cetmix Tower OVH

+ + +

Beta License: AGPL-3 cetmix/cetmix-tower

+

This module integrates the OVH Python client, enabling seamless +interaction with OVH cloud services within the Cetmix Tower.

+

Table of contents

+ +
+

Use Cases / Context

+

Although OVH allows API calls without using an SDK, we found that +integrating the OVH SDK into Cetmix Tower makes provisioning, +configuring, and maintaining OVH instances more convenient for the end +user. However, not all Cetmix Tower users require this functionality, so +to avoid overloading the system, we have included it in a separate +module.

+
+ +
+

Setting up OVH Access

+
+

Create OVH API Credentials

+

To use the OVH integration with Cetmix Tower, you need to create OVH API +credentials:

+
    +
  • Follow the official OVH +documentation +(https://docs.ovh.com/gb/en/api/first-steps/) for creating an +application and generating API keys
  • +
  • It’s recommended to create a dedicated application with appropriate +permissions for Cetmix Tower
  • +
  • Store your Application Key, Application Secret, and Consumer Key +securely—you’ll need them in the next step
  • +
+
+
+

Configure OVH Secrets in Cetmix Tower

+

Create three secrets in Cetmix Tower to store your OVH credentials:

+
    +
  • Navigate to Cetmix Tower > Settings > Keys and Secrets
  • +
  • Create a new Secret with:
      +
    • Name: OVH Application Key
    • +
    • Reference: ovh_application_key
    • +
    • Key Type: Secret
    • +
    +
  • +
  • Enter your OVH Application Key in the Secret Value tab
  • +
  • Similarly, create another Secret with:
      +
    • Name: OVH Application Secret
    • +
    • Reference: ovh_application_secret
    • +
    • Key Type: Secret
    • +
    +
  • +
  • Enter your OVH Application Secret in the Secret Value tab
  • +
  • Finally, create a Secret with:
      +
    • Name: OVH Consumer Key
    • +
    • Reference: ovh_consumer_key
    • +
    • Key Type: Secret
    • +
    +
  • +
  • Enter your OVH Consumer Key in the Secret Value tab
  • +
+ +
+Note: These secrets will be accessible as +#!cxtower.secret.ovh_application_key!#, +#!cxtower.secret.ovh_application_secret!#, and +#!cxtower.secret.ovh_consumer_key!# in your commands.
+
+
+

Configure OVH Endpoint

+

Create a variable to define your OVH API endpoint (region):

+
    +
  • Navigate to Cetmix Tower > Settings > Variables
  • +
  • Create a new Variable with:
      +
    • Name: OVH Endpoint
    • +
    • Reference: ovh_endpoint
    • +
    • Type: String
    • +
    +
  • +
  • Set your OVH endpoint (e.g., ovh-eu, ovh-ca, ovh-us) as +the value
  • +
+
+
+
+

Usage

+
+
+

Cetmix Tower OVHcloud Command Usage

+
+Disclaimer: The following example demonstrates one of many +possible commands you can create and run with this module. The +ovh Python library provides access to the full range of OVHcloud +APIs – this is just a starting point to help you get familiar with +the integration.
+
+

Example of Cetmix Tower Python Command to Create DNS Records

+
    +
  • Navigate to Command Creation

    +
      +
    • Go to Cetmix Tower > Commands > Commands
    • +
    • Click the Create button
    • +
    +
  • +
  • Configure Command Settings

    +
      +
    • Set a descriptive Name (e.g., “List OVHcloud Instances”)
    • +
    • Leave Reference blank to generate automatically (or set a custom +reference)
    • +
    • Select Action: “Execute Python code”
    • +
    • Set Access Level: Choose appropriate level (e.g., “Manager”)
    • +
    • Optional: Set Default Path if needed
    • +
    • Optional: Add Tags (e.g., “ovh”, “cloud”, “instance”) for better +organization
    • +
    +
  • +
  • Add Required Variables

    +
      +
    • In the Variables tab, add the previously configured variable:
        +
      • ovh_endpoint (e.g., “ovh-eu”)
      • +
      +
    • +
    +
  • +
  • Add Required Secrets

    +
      +
    • In the Secrets field, add the previously configured secrets:
        +
      • ovh_application_key
      • +
      • ovh_application_secret
      • +
      • ovh_consumer_key
      • +
      +
    • +
    +
  • +
  • Write Python Code

    +
      +
    • Go to the Code tab
    • +
    • Enter the following Python code:
    • +
    +
    +# List OVHcloud instances using ovh API
    + result = {"exit_code": 0, "message": None}
    +
    +client = ovh.Client(
    + endpoint={{ ovh_endpoint }},
    + application_key=#!cxtower.secret.ovh_application_key!#,
    + application_secret=#!cxtower.secret.ovh_application_secret!#,
    + consumer_key=#!cxtower.secret.ovh_consumer_key!#
    +)
    +
    +# Required variables:
    +# - domain_name: The main domain (e.g., "example.com")
    +# - subdomain: The subdomain to create (e.g., "test")
    +
    +try:
    +  # Create a new subdomain by adding a DNS entry (A record as example)
    +  ip_address = "1.2.3.4"  # Replace with the desired IP address
    +  response = client.post(
    +     "/domain/zone/" + domain_name + "/record",
    +     fieldType="A",
    +     subDomain=subdomain,
    +     target=ip_address,
    +     ttl=3600
    +  )
    +  # Refresh the zone to apply changes
    +  client.post("/domain/zone/" + domain_name + "/refresh")
    +  result["message"] = "Subdomain '" + subdomain + "." + domain_name + "' created and DNS zone refreshed."
    +except Exception as e:
    +  result["exit_code"] = 1
    +  result["message"] = "Error: " + str(e)
    +
    +
  • +
  • Save the Command

    +
      +
    • Click the Save button to create the command
    • +
    +
  • +
+
+
+

Running the OVHcloud Instance Command

+
    +
  • Navigate to Server
      +
    • Go to Cetmix Tower > Servers > Servers
    • +
    • Open the server where you want to run the command
    • +
    +
  • +
  • Execute Command from Server
      +
    • Click the Command button at the top of the server form
    • +
    • In the popup dialog:
        +
      • Select your OVHcloud instance command from the dropdown
      • +
      • Verify the variable values (if any need adjustment)
      • +
      • Click Run to execute
      • +
      +
    • +
    +
  • +
  • View Command Results
      +
    • After execution, the command log will display showing:
        +
      • The command executed
      • +
      • Execution status
      • +
      • Output message containing OVHcloud instance details if successful
      • +
      +
    • +
    +
  • +
+
+
+ +
+

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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Cetmix
  • +
  • Giovanni Serra
  • +
+
+
+

Maintainers

+

Current maintainer:

+

GSLabIt

+

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

+

You are welcome to contribute.

+
+
+
+ + diff --git a/addons/cetmix_tower_ovh/tests/__init__.py b/addons/cetmix_tower_ovh/tests/__init__.py new file mode 100644 index 0000000..44a0931 --- /dev/null +++ b/addons/cetmix_tower_ovh/tests/__init__.py @@ -0,0 +1 @@ +from . import test_ovh_integration diff --git a/addons/cetmix_tower_ovh/tests/test_ovh_integration.py b/addons/cetmix_tower_ovh/tests/test_ovh_integration.py new file mode 100644 index 0000000..8d33d4f --- /dev/null +++ b/addons/cetmix_tower_ovh/tests/test_ovh_integration.py @@ -0,0 +1,63 @@ +# Copyright 2024 Cetmix OÜ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo.tests import common + + +class TestOvhIntegration(common.TransactionCase): + """Test OVH integration with Cetmix Tower commands.""" + + def setUp(self): + super().setUp() + # Create a test command + self.command = self.env["cx.tower.command"].create( + { + "name": "Test OVH Command", + "action": "python_code", + } + ) + self.eval_context = self.env[ + "cx.tower.command" + ]._get_python_command_eval_context() + + def test_ovh_in_evaluation_context(self): + """Test that ovh is added to the evaluation context.""" + self.assertIn("ovh", self.eval_context) + ovh_obj = self.eval_context["ovh"] + self.assertTrue(hasattr(ovh_obj, "Client")) + + def test_ovh_in_evaluation_context_with_server(self): + """Test that ovh is added to the evaluation context when server is provided.""" + test_server = self.env["cx.tower.server"].create( + { + "name": "Test OVH Server", + "reference": "test_ovh_server", + "ip_v4_address": "localhost", + "ssh_username": "admin", + "ssh_password": "password", + "ssh_auth_mode": "p", + "host_key": "test_key", + } + ) + eval_context = self.env["cx.tower.command"]._get_python_command_eval_context( + server=test_server + ) + + self.assertIn("ovh", eval_context) + ovh_obj = eval_context["ovh"] + self.assertTrue(hasattr(ovh_obj, "Client")) + self.assertEqual(eval_context["server"], test_server) + + def test_ovh_client_instantiation(self): + """Test that ovh.Client can be instantiated from context.""" + ovh_mod = self.eval_context["ovh"] + # Only test instantiation, do not require credentials + try: + client = ovh_mod.Client( + endpoint="ovh-eu", + application_key="a", + application_secret="b", + consumer_key="c", + ) + self.assertIsNotNone(client) + except Exception as e: + self.fail(f"ovh.Client instantiation failed: {e}")