diff --git a/addons/cetmix_tower_aws/README.rst b/addons/cetmix_tower_aws/README.rst new file mode 100644 index 0000000..30a7885 --- /dev/null +++ b/addons/cetmix_tower_aws/README.rst @@ -0,0 +1,308 @@ +================ +Cetmix Tower AWS +================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:e427fa4368b78aacbc6faa6232b54496e83fbe4905ddef4cc17f3913e5ee3ee0 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_aws + :alt: cetmix/cetmix-tower + +|badge1| |badge2| |badge3| + +**⚠️ DISCLAIMER: TECHNICAL MODULE** + +This module integrates Boto3 library, the Amazon Web Services (AWS) +Software Development Kit (SDK) for Python, into the Cetmix Tower. + + **This is a technical module intended for system administrators or + DevOps professionals.** It may involve server configuration, + infrastructure management, or advanced setup outside the standard + Odoo interface. Not intended for direct use by end users. + +**Table of contents** + +.. contents:: + :local: + +Use Cases / Context +=================== + +Although Amazon Web Services (AWS) allows API calls without using an +SDK, we found that integrating the Amazon SDK into Cetmix Tower makes +provisioning, configuring, and maintaining AWS 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 +============= + +**Prerequisites** + +The module has ``boto3`` defined in its external dependencies, which +means, you should install the Python ``boto3`` package manually if you +don't have automatic package installation configured in your Odoo +environment. Run ``pip install boto3`` to install it. + +**Setting up AWS Access** + +1. **Create AWS Access Keys** + + To use the AWS integration with Cetmix Tower, you need to create AWS + access keys: + + - Follow the `official AWS + documentation `__ + (https://docs.aws.amazon.com/IAM/latest/UserGuide/security-creds.html) + for creating IAM access keys + - It's recommended to create a dedicated IAM user with appropriate + permissions for Cetmix Tower + - Store your access key ID and secret access key securely - you'll + need them in the next step + +2. **Configure AWS Secrets in Cetmix Tower** + + Create two secrets in Cetmix Tower to store your AWS credentials: + + - Navigate to ``Cetmix Tower > Settings > Keys and Secrets`` + - Create a new Secret with: + + - Name: ``AWS Access Key`` + - Reference: ``aws_access_key`` + - Key Type: ``Secret`` + + - Enter your AWS access key ID in the Secret Value tab + - Similarly, create another Secret with: + + - Name: ``AWS Secret Access Key`` + - Reference: ``aws_secret_access_key`` + - Key Type: ``Secret`` + + - Enter your AWS secret access key in the Secret Value tab + + .. + + Note: These secrets will be accessible as + ``#!cxtower.secret.aws_access_key!#`` and + ``#!cxtower.secret.aws_secret_access_key!#`` in your commands. + +3. **Configure AWS Region** + + Create a variable to define your AWS region: + + - Navigate to ``Cetmix Tower > Settings > Variables`` + - Create a new Variable with: + + - Name: ``AWS Region Name`` + - Reference: ``aws_region_name`` + - Type: ``String`` + + - Set your AWS region (e.g., ``us-east-1``, ``eu-west-1``) as the + value + +Usage +===== + +Please check the `official Boto3 +Documentation `__ +(https://boto3.amazonaws.com/v1/documentation/api/latest/index.html) for +the detailed information about the services and methods provided by the +Boto3 library. + + **Disclaimer**: The following example demonstrates one of many + possible commands you can create and run with this module. The boto3 + library provides access to the full range of AWS services and methods + - this is just a starting point to help you get familiar with the + integration. + +Example of Cetmix Tower Python Command to List EC2 Instances +------------------------------------------------------------ + +Navigate to Command Creation +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +- Go to ``Cetmix Tower > Commands > Commands`` +- Click the ``Create`` button + +Configure Command Settings +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +- Set a descriptive ``Name`` (e.g., "List AWS EC2 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., "aws", "ec2") for better organization + +Add Required Variables +~~~~~~~~~~~~~~~~~~~~~~ + +- In the ``Variables`` tab, add the previously configured variable: + + - ``aws_region_name`` + +Add Required Secrets +~~~~~~~~~~~~~~~~~~~~ + +- In the ``Secrets`` field, add the previously configured secrets: + + - ``aws_access_key`` + - ``aws_secret_access_key`` + +Write Python Code +~~~~~~~~~~~~~~~~~ + +- Go to the ``Code`` tab + +- Enter the following Python code: + + .. code:: python + + # List EC2 instances using boto3 + result = {"exit_code": 0, "message": None} + + session = boto3.Session( + aws_access_key_id=#!cxtower.secret.aws_access_key!#, + aws_secret_access_key=#!cxtower.secret.aws_secret_access_key!#, + region_name={{ aws_region_name }} + ) + ec2 = session.client('ec2') + instances = ec2.describe_instances() + + instance_details = [] + for reservation in instances['Reservations']: + for instance in reservation['Instances']: + instance_detail = "Instance ID: " + instance['InstanceId'] + instance_detail += ", Type: " + instance.get('InstanceType', 'Unknown') + instance_detail += ", State: " + instance.get('State', {}).get('Name', 'Unknown') + instance_details.append(instance_detail) + + if instance_details: + result["message"] = "Found " + str(len(instance_details)) + " EC2 instances:\n" + "\n".join(instance_details) + else: + result["message"] = "No EC2 instances found" + +Save the Command +~~~~~~~~~~~~~~~~ + +- Click the ``Save`` button to create the command + +Running the AWS EC2 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 AWS EC2 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 EC2 instance details if successful + +Example Output +-------------- + +For a successful execution with EC2 instances: + +.. code:: bash + + Found 3 EC2 instances: + Instance ID: i-0abc123def456789, Type: t2.micro, State: running + Instance ID: i-0def456abc789123, Type: t3.medium, State: stopped + Instance ID: i-0789abc123def456, Type: m5.large, State: running + +For a successful execution with no EC2 instances: + +.. code:: bash + + No EC2 instances found + +Creating Additional AWS Commands +-------------------------------- + +The cetmix_tower_aws module provides access to the boto3 Python library +for AWS service integration. Here are some common services you can use: + +.. code:: python + + # Standard client initialization pattern + client = boto3.client( + 'service_name', # Replace with: ec2, s3, rds, cloudwatch, etc. + region_name={{ aws_region_name }}, + aws_access_key_id=#!cxtower.secret.aws_access_key!#, + aws_secret_access_key=#!cxtower.secret.aws_secret_access_key!# + ) + + # Or use resource interface for object-oriented access + resource = boto3.resource( + 'service_name', # Replace with: ec2, s3, etc. + region_name={{ aws_region_name }}, + aws_access_key_id=#!cxtower.secret.aws_access_key!#, + aws_secret_access_key=#!cxtower.secret.aws_secret_access_key!# + ) + +Popular AWS services include: EC2 (compute), S3 (storage), RDS +(databases), and CloudWatch (monitoring). + +For more details, see the `AWS Boto3 +Documentation `__. + +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 + +Maintainers +----------- + +This module is part of the `cetmix/cetmix-tower `_ project on GitHub. + +You are welcome to contribute. diff --git a/addons/cetmix_tower_aws/__init__.py b/addons/cetmix_tower_aws/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/addons/cetmix_tower_aws/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/addons/cetmix_tower_aws/__manifest__.py b/addons/cetmix_tower_aws/__manifest__.py new file mode 100644 index 0000000..04e3a1f --- /dev/null +++ b/addons/cetmix_tower_aws/__manifest__.py @@ -0,0 +1,24 @@ +# Copyright 2024 Cetmix OÜ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Cetmix Tower AWS", + "summary": """Cetmix Tower AWS EC2 API integration""", + "version": "18.0.1.0.1", + "category": "Productivity", + "license": "AGPL-3", + "author": "Cetmix", + "website": "https://tower.cetmix.com", + "live_test_url": "https://tower.cetmix.com/download", + "images": ["static/description/banner.png"], + "installable": True, + "external_dependencies": { + "python": ["boto3"], + }, + "depends": [ + "cetmix_tower_server", + ], + "demo": [ + "demo/demo_data.xml", + ], +} diff --git a/addons/cetmix_tower_aws/demo/demo_data.xml b/addons/cetmix_tower_aws/demo/demo_data.xml new file mode 100644 index 0000000..6408168 --- /dev/null +++ b/addons/cetmix_tower_aws/demo/demo_data.xml @@ -0,0 +1,74 @@ + + + + + AWS Access Key + aws_access_key + s + AKIAIOSFODNN7EXAMPLE + + + + AWS Secret Access Key + aws_secret_access_key + s + wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY + + + + + AWS Region Name + aws_region_name + + + + + + us-east-1 + + + + + List AWS EC2 Instances + python_code + +# List EC2 instances using boto3 +result = {"exit_code": 0, "message": None} + +session = boto3.Session( + aws_access_key_id=#!cxtower.secret.aws_access_key!#, + aws_secret_access_key=#!cxtower.secret.aws_secret_access_key!#, + region_name={{ aws_region_name }} +) +ec2 = session.client('ec2') +instances = ec2.describe_instances() + +instance_details = [] +for reservation in instances['Reservations']: + for instance in reservation['Instances']: + instance_detail = "Instance ID: " + instance['InstanceId'] + instance_detail += ", Type: " + instance.get('InstanceType', 'Unknown') + instance_detail += ", State: " + instance.get('State', {}).get('Name', 'Unknown') + instance_details.append(instance_detail) + +if instance_details: + result["message"] = "Found " + str(len(instance_details)) + " EC2 instances:\n" + "\n".join(instance_details) +else: + result["message"] = "No EC2 instances found" + + 1 + + List EC2 instances using boto3 AWS SDK + + diff --git a/addons/cetmix_tower_aws/i18n/cetmix_tower_aws.pot b/addons/cetmix_tower_aws/i18n/cetmix_tower_aws.pot new file mode 100644 index 0000000..e751860 --- /dev/null +++ b/addons/cetmix_tower_aws/i18n/cetmix_tower_aws.pot @@ -0,0 +1,31 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * cetmix_tower_aws +# +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_aws +#: model:ir.model,name:cetmix_tower_aws.model_cx_tower_command +msgid "Cetmix Tower Command" +msgstr "" + +#. module: cetmix_tower_aws +#. odoo-python +#: code:addons/cetmix_tower_aws/models/cx_tower_command.py:0 +msgid "" +"Python 'boto3' library for AWS services. Available methods: 'client', " +"'resource', 'Session'
Supports AWS services like EC2, S3, RDS, Lambda, " +"CloudWatch, etc.
Please check the Boto3 Documentation for the detailed information about " +"the services and methods." +msgstr "" diff --git a/addons/cetmix_tower_aws/i18n/it.po b/addons/cetmix_tower_aws/i18n/it.po new file mode 100644 index 0000000..cc3f90d --- /dev/null +++ b/addons/cetmix_tower_aws/i18n/it.po @@ -0,0 +1,39 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * cetmix_tower_aws +# +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" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 2.3\n" +"Language: it\n" + +#. module: cetmix_tower_aws +#: model:ir.model,name:cetmix_tower_aws.model_cx_tower_command +msgid "Cetmix Tower Command" +msgstr "Comando Cetmix Tower" + +#. module: cetmix_tower_aws +#. odoo-python +#: code:addons/cetmix_tower_aws/models/cx_tower_command.py:0 +#, python-format +msgid "Python 'boto3' library for AWS services. Available methods: 'client', 'resource', 'Session'
Supports AWS services like EC2, S3, RDS, Lambda, CloudWatch, etc.
Please check the Boto3 Documentation for the detailed information about the services and methods." +msgstr "Libreria Python 'boto3' per servizi AWS. Metodi disponibili: 'client', 'resource', 'Session'
Supporta servizi AWS come EC2, S3, RDS, Lambda, CloudWatch, ecc.
Consultare la documentazione Boto3 per informazioni dettagliate su servizi e metodi." + +#~ msgid "" +#~ "# - boto3: Python 'boto3' library for AWS services. Available methods: " +#~ "'client', 'resource', 'Session'\n" +#~ "# Supports AWS services like EC2, S3, RDS, Lambda, CloudWatch, etc." +#~ msgstr "" +#~ "# - boto3: libreria Python 'boto3' per servizi AWS. Metodi disponibili: " +#~ "'client', 'resource', 'Session'\n" +#~ "# Supporta servizi AWS come EC2, S3, RDS, Lambda, CloudWatch, ecc." diff --git a/addons/cetmix_tower_aws/models/__init__.py b/addons/cetmix_tower_aws/models/__init__.py new file mode 100644 index 0000000..3b8ff9d --- /dev/null +++ b/addons/cetmix_tower_aws/models/__init__.py @@ -0,0 +1 @@ +from . import cx_tower_command diff --git a/addons/cetmix_tower_aws/models/cx_tower_command.py b/addons/cetmix_tower_aws/models/cx_tower_command.py new file mode 100644 index 0000000..b6126d9 --- /dev/null +++ b/addons/cetmix_tower_aws/models/cx_tower_command.py @@ -0,0 +1,40 @@ +# 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 boto3 safely +boto3 = wrap_module(__import__("boto3"), ["client", "resource", "Session"]) + + +class CxTowerCommand(models.Model): + """Extends cx.tower.command to add AWS boto3 functionality.""" + + _inherit = "cx.tower.command" + + def _custom_python_libraries(self): + """ + Add the boto3 library to the available libraries. + """ + custom_python_libraries = super()._custom_python_libraries() + custom_python_libraries.update( + { + "cetmix_tower_aws": { + "boto3": { + "import": boto3, + "help": _( + "Python 'boto3' library for AWS services. " + "Available methods: 'client', 'resource', 'Session'
" + "Supports AWS services like EC2, S3, RDS, Lambda, " + "CloudWatch, etc.
" + "Please check the Boto3 Documentation for the detailed " + "information about the services and methods." + ), + }, + } + } + ) + return custom_python_libraries diff --git a/addons/cetmix_tower_aws/pyproject.toml b/addons/cetmix_tower_aws/pyproject.toml new file mode 100644 index 0000000..4231d0c --- /dev/null +++ b/addons/cetmix_tower_aws/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/addons/cetmix_tower_aws/readme/CONFIGURE.md b/addons/cetmix_tower_aws/readme/CONFIGURE.md new file mode 100644 index 0000000..507f735 --- /dev/null +++ b/addons/cetmix_tower_aws/readme/CONFIGURE.md @@ -0,0 +1,42 @@ +**Prerequisites** + +The module has `boto3` defined in its external dependencies, which means, you should install the Python `boto3` package manually if you don't have automatic package installation configured in your Odoo environment. Run `pip install boto3` to install it. + +**Setting up AWS Access** + +1. **Create AWS Access Keys** + + To use the AWS integration with Cetmix Tower, you need to create AWS access keys: + + - Follow the [official AWS documentation](https://docs.aws.amazon.com/IAM/latest/UserGuide/security-creds.html) (https://docs.aws.amazon.com/IAM/latest/UserGuide/security-creds.html) for creating IAM access keys + - It's recommended to create a dedicated IAM user with appropriate permissions for Cetmix Tower + - Store your access key ID and secret access key securely - you'll need them in the next step + +2. **Configure AWS Secrets in Cetmix Tower** + + Create two secrets in Cetmix Tower to store your AWS credentials: + + - Navigate to `Cetmix Tower > Settings > Keys and Secrets` + - Create a new Secret with: + - Name: `AWS Access Key` + - Reference: `aws_access_key` + - Key Type: `Secret` + - Enter your AWS access key ID in the Secret Value tab + - Similarly, create another Secret with: + - Name: `AWS Secret Access Key` + - Reference: `aws_secret_access_key` + - Key Type: `Secret` + - Enter your AWS secret access key in the Secret Value tab + + > Note: These secrets will be accessible as `#!cxtower.secret.aws_access_key!#` and `#!cxtower.secret.aws_secret_access_key!#` in your commands. + +3. **Configure AWS Region** + + Create a variable to define your AWS region: + + - Navigate to `Cetmix Tower > Settings > Variables` + - Create a new Variable with: + - Name: `AWS Region Name` + - Reference: `aws_region_name` + - Type: `String` + - Set your AWS region (e.g., `us-east-1`, `eu-west-1`) as the value diff --git a/addons/cetmix_tower_aws/readme/CONTEXT.md b/addons/cetmix_tower_aws/readme/CONTEXT.md new file mode 100644 index 0000000..b7f251f --- /dev/null +++ b/addons/cetmix_tower_aws/readme/CONTEXT.md @@ -0,0 +1,5 @@ +Although Amazon Web Services (AWS) allows API calls without using an SDK, we found that +integrating the Amazon SDK into Cetmix Tower makes provisioning, configuring, and +maintaining AWS 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_aws/readme/DESCRIPTION.md b/addons/cetmix_tower_aws/readme/DESCRIPTION.md new file mode 100644 index 0000000..3edf51d --- /dev/null +++ b/addons/cetmix_tower_aws/readme/DESCRIPTION.md @@ -0,0 +1,6 @@ +**⚠️ DISCLAIMER: TECHNICAL MODULE** + +This module integrates Boto3 library, the Amazon Web Services (AWS) Software Development Kit (SDK) for Python, into the Cetmix Tower. + +> **This is a technical module intended for system administrators or DevOps professionals.** It may involve server configuration, infrastructure management, or advanced setup outside the standard Odoo interface. Not intended for direct use by end users. + diff --git a/addons/cetmix_tower_aws/readme/HISTORY.md b/addons/cetmix_tower_aws/readme/HISTORY.md new file mode 100644 index 0000000..e69de29 diff --git a/addons/cetmix_tower_aws/readme/USAGE.md b/addons/cetmix_tower_aws/readme/USAGE.md new file mode 100644 index 0000000..92cc9b9 --- /dev/null +++ b/addons/cetmix_tower_aws/readme/USAGE.md @@ -0,0 +1,121 @@ +Please check the [official Boto3 Documentation](https://boto3.amazonaws.com/v1/documentation/api/latest/index.html) (https://boto3.amazonaws.com/v1/documentation/api/latest/index.html) for the detailed information about the services and methods provided by the Boto3 library. + +> **Disclaimer**: The following example demonstrates one of many possible commands you can create and run with this module. The boto3 library provides access to the full range of AWS services and methods - this is just a starting point to help you get familiar with the integration. + +## Example of Cetmix Tower Python Command to List EC2 Instances + +### Navigate to Command Creation +- Go to `Cetmix Tower > Commands > Commands` +- Click the `Create` button + +### Configure Command Settings +- Set a descriptive `Name` (e.g., "List AWS EC2 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., "aws", "ec2") for better organization + +### Add Required Variables +- In the `Variables` tab, add the previously configured variable: + - `aws_region_name` + +### Add Required Secrets +- In the `Secrets` field, add the previously configured secrets: + - `aws_access_key` + - `aws_secret_access_key` + +### Write Python Code +- Go to the `Code` tab +- Enter the following Python code: + + ```python + # List EC2 instances using boto3 + result = {"exit_code": 0, "message": None} + + session = boto3.Session( + aws_access_key_id=#!cxtower.secret.aws_access_key!#, + aws_secret_access_key=#!cxtower.secret.aws_secret_access_key!#, + region_name={{ aws_region_name }} + ) + ec2 = session.client('ec2') + instances = ec2.describe_instances() + + instance_details = [] + for reservation in instances['Reservations']: + for instance in reservation['Instances']: + instance_detail = "Instance ID: " + instance['InstanceId'] + instance_detail += ", Type: " + instance.get('InstanceType', 'Unknown') + instance_detail += ", State: " + instance.get('State', {}).get('Name', 'Unknown') + instance_details.append(instance_detail) + + if instance_details: + result["message"] = "Found " + str(len(instance_details)) + " EC2 instances:\n" + "\n".join(instance_details) + else: + result["message"] = "No EC2 instances found" + ``` + +### Save the Command +- Click the `Save` button to create the command + +## Running the AWS EC2 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 AWS EC2 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 EC2 instance details if successful + +## Example Output + +For a successful execution with EC2 instances: + +```bash +Found 3 EC2 instances: +Instance ID: i-0abc123def456789, Type: t2.micro, State: running +Instance ID: i-0def456abc789123, Type: t3.medium, State: stopped +Instance ID: i-0789abc123def456, Type: m5.large, State: running +``` + +For a successful execution with no EC2 instances: + +```bash +No EC2 instances found +``` + +## Creating Additional AWS Commands + +The cetmix_tower_aws module provides access to the boto3 Python library for AWS service integration. Here are some common services you can use: + +```python +# Standard client initialization pattern +client = boto3.client( + 'service_name', # Replace with: ec2, s3, rds, cloudwatch, etc. + region_name={{ aws_region_name }}, + aws_access_key_id=#!cxtower.secret.aws_access_key!#, + aws_secret_access_key=#!cxtower.secret.aws_secret_access_key!# +) + +# Or use resource interface for object-oriented access +resource = boto3.resource( + 'service_name', # Replace with: ec2, s3, etc. + region_name={{ aws_region_name }}, + aws_access_key_id=#!cxtower.secret.aws_access_key!#, + aws_secret_access_key=#!cxtower.secret.aws_secret_access_key!# +) +``` + +Popular AWS services include: EC2 (compute), S3 (storage), RDS (databases), and CloudWatch (monitoring). + +For more details, see the [AWS Boto3 Documentation](https://boto3.amazonaws.com/v1/documentation/api/latest/index.html). diff --git a/addons/cetmix_tower_aws/readme/newsfragments/.gitkeep b/addons/cetmix_tower_aws/readme/newsfragments/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/addons/cetmix_tower_aws/static/description/banner.png b/addons/cetmix_tower_aws/static/description/banner.png new file mode 100644 index 0000000..6208375 Binary files /dev/null and b/addons/cetmix_tower_aws/static/description/banner.png differ diff --git a/addons/cetmix_tower_aws/static/description/icon.png b/addons/cetmix_tower_aws/static/description/icon.png new file mode 100644 index 0000000..2507f55 Binary files /dev/null and b/addons/cetmix_tower_aws/static/description/icon.png differ diff --git a/addons/cetmix_tower_aws/static/description/index.html b/addons/cetmix_tower_aws/static/description/index.html new file mode 100644 index 0000000..c7b841e --- /dev/null +++ b/addons/cetmix_tower_aws/static/description/index.html @@ -0,0 +1,684 @@ + + + + + +Cetmix Tower AWS + + + +
+

Cetmix Tower AWS

+ + +

Beta License: AGPL-3 cetmix/cetmix-tower

+

⚠️ DISCLAIMER: TECHNICAL MODULE

+

This module integrates Boto3 library, the Amazon Web Services (AWS) +Software Development Kit (SDK) for Python, into the Cetmix Tower.

+
+This is a technical module intended for system administrators or +DevOps professionals. It may involve server configuration, +infrastructure management, or advanced setup outside the standard +Odoo interface. Not intended for direct use by end users.
+

Table of contents

+ +
+

Use Cases / Context

+

Although Amazon Web Services (AWS) allows API calls without using an +SDK, we found that integrating the Amazon SDK into Cetmix Tower makes +provisioning, configuring, and maintaining AWS 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

+

Prerequisites

+

The module has boto3 defined in its external dependencies, which +means, you should install the Python boto3 package manually if you +don’t have automatic package installation configured in your Odoo +environment. Run pip install boto3 to install it.

+

Setting up AWS Access

+
    +
  1. Create AWS Access Keys

    +

    To use the AWS integration with Cetmix Tower, you need to create AWS +access keys:

    + +
  2. +
  3. Configure AWS Secrets in Cetmix Tower

    +

    Create two secrets in Cetmix Tower to store your AWS credentials:

    +
      +
    • Navigate to Cetmix Tower > Settings > Keys and Secrets
    • +
    • Create a new Secret with:
        +
      • Name: AWS Access Key
      • +
      • Reference: aws_access_key
      • +
      • Key Type: Secret
      • +
      +
    • +
    • Enter your AWS access key ID in the Secret Value tab
    • +
    • Similarly, create another Secret with:
        +
      • Name: AWS Secret Access Key
      • +
      • Reference: aws_secret_access_key
      • +
      • Key Type: Secret
      • +
      +
    • +
    • Enter your AWS secret access key in the Secret Value tab
    • +
    + +
    +

    Note: These secrets will be accessible as +#!cxtower.secret.aws_access_key!# and +#!cxtower.secret.aws_secret_access_key!# in your commands.

    +
    +
  4. +
  5. Configure AWS Region

    +

    Create a variable to define your AWS region:

    +
      +
    • Navigate to Cetmix Tower > Settings > Variables
    • +
    • Create a new Variable with:
        +
      • Name: AWS Region Name
      • +
      • Reference: aws_region_name
      • +
      • Type: String
      • +
      +
    • +
    • Set your AWS region (e.g., us-east-1, eu-west-1) as the +value
    • +
    +
  6. +
+
+
+

Usage

+

Please check the official Boto3 +Documentation +(https://boto3.amazonaws.com/v1/documentation/api/latest/index.html) for +the detailed information about the services and methods provided by the +Boto3 library.

+
+Disclaimer: The following example demonstrates one of many +possible commands you can create and run with this module. The boto3 +library provides access to the full range of AWS services and methods +- this is just a starting point to help you get familiar with the +integration.
+
+

Example of Cetmix Tower Python Command to List EC2 Instances

+ +
+

Configure Command Settings

+
    +
  • Set a descriptive Name (e.g., “List AWS EC2 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., “aws”, “ec2”) for better organization
  • +
+
+
+

Add Required Variables

+
    +
  • In the Variables tab, add the previously configured variable:
      +
    • aws_region_name
    • +
    +
  • +
+
+
+

Add Required Secrets

+
    +
  • In the Secrets field, add the previously configured secrets:
      +
    • aws_access_key
    • +
    • aws_secret_access_key
    • +
    +
  • +
+
+
+

Write Python Code

+
    +
  • Go to the Code tab

    +
  • +
  • Enter the following Python code:

    +
    +# List EC2 instances using boto3
    +result = {"exit_code": 0, "message": None}
    +
    +session = boto3.Session(
    +    aws_access_key_id=#!cxtower.secret.aws_access_key!#,
    +    aws_secret_access_key=#!cxtower.secret.aws_secret_access_key!#,
    +    region_name={{ aws_region_name }}
    +)
    +ec2 = session.client('ec2')
    +instances = ec2.describe_instances()
    +
    +instance_details = []
    +for reservation in instances['Reservations']:
    +    for instance in reservation['Instances']:
    +        instance_detail = "Instance ID: " + instance['InstanceId']
    +        instance_detail += ", Type: " + instance.get('InstanceType', 'Unknown')
    +        instance_detail += ", State: " + instance.get('State', {}).get('Name', 'Unknown')
    +        instance_details.append(instance_detail)
    +
    +if instance_details:
    +    result["message"] = "Found " + str(len(instance_details)) + " EC2 instances:\n" + "\n".join(instance_details)
    +else:
    +    result["message"] = "No EC2 instances found"
    +
    +
  • +
+
+
+

Save the Command

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

Running the AWS EC2 Command

+ +
+

Execute Command from Server

+
    +
  • Click the Command button at the top of the server form
  • +
  • In the popup dialog:
      +
    • Select your AWS EC2 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 EC2 instance details if successful
    • +
    +
  • +
+
+
+
+

Example Output

+

For a successful execution with EC2 instances:

+
+Found 3 EC2 instances:
+Instance ID: i-0abc123def456789, Type: t2.micro, State: running
+Instance ID: i-0def456abc789123, Type: t3.medium, State: stopped
+Instance ID: i-0789abc123def456, Type: m5.large, State: running
+
+

For a successful execution with no EC2 instances:

+
+No EC2 instances found
+
+
+
+

Creating Additional AWS Commands

+

The cetmix_tower_aws module provides access to the boto3 Python library +for AWS service integration. Here are some common services you can use:

+
+# Standard client initialization pattern
+client = boto3.client(
+    'service_name',  # Replace with: ec2, s3, rds, cloudwatch, etc.
+    region_name={{ aws_region_name }},
+    aws_access_key_id=#!cxtower.secret.aws_access_key!#,
+    aws_secret_access_key=#!cxtower.secret.aws_secret_access_key!#
+)
+
+# Or use resource interface for object-oriented access
+resource = boto3.resource(
+    'service_name',  # Replace with: ec2, s3, etc.
+    region_name={{ aws_region_name }},
+    aws_access_key_id=#!cxtower.secret.aws_access_key!#,
+    aws_secret_access_key=#!cxtower.secret.aws_secret_access_key!#
+)
+
+

Popular AWS services include: EC2 (compute), S3 (storage), RDS +(databases), and CloudWatch (monitoring).

+

For more details, see the AWS Boto3 +Documentation.

+
+
+ +
+

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
  • +
+
+
+

Maintainers

+

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

+

You are welcome to contribute.

+
+
+
+ + diff --git a/addons/cetmix_tower_aws/tests/__init__.py b/addons/cetmix_tower_aws/tests/__init__.py new file mode 100644 index 0000000..bcd6c6b --- /dev/null +++ b/addons/cetmix_tower_aws/tests/__init__.py @@ -0,0 +1 @@ +from . import test_boto3_integration diff --git a/addons/cetmix_tower_aws/tests/test_boto3_integration.py b/addons/cetmix_tower_aws/tests/test_boto3_integration.py new file mode 100644 index 0000000..136f0f0 --- /dev/null +++ b/addons/cetmix_tower_aws/tests/test_boto3_integration.py @@ -0,0 +1,64 @@ +# Copyright 2024 Cetmix OÜ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo.tests import common + + +class TestBoto3Integration(common.TransactionCase): + """Test boto3 integration with Cetmix Tower commands.""" + + def setUp(self): + super().setUp() + # Create a test command + self.command = self.env["cx.tower.command"].create( + { + "name": "Test AWS Command", + "action": "python_code", + } + ) + self.eval_context = self.env[ + "cx.tower.command" + ]._get_python_command_eval_context() + + def test_boto3_in_evaluation_context(self): + """Test that boto3 is added to the evaluation context.""" + # Get evaluation context + # Check if boto3 is in the evaluation context + self.assertIn("boto3", self.eval_context) + # Check available methods + boto3_obj = self.eval_context["boto3"] + self.assertTrue(hasattr(boto3_obj, "client")) + self.assertTrue(hasattr(boto3_obj, "resource")) + self.assertTrue(hasattr(boto3_obj, "Session")) + + def test_boto3_in_evaluation_context_with_server(self): + """Test that boto3 is added to the evaluation context + when server is provided.""" + # Create a test server + test_server = self.env["cx.tower.server"].create( + { + "name": "Test AWS Server", + "reference": "test_aws_server", + "ip_v4_address": "localhost", + "ssh_username": "admin", + "ssh_password": "password", + "ssh_auth_mode": "p", + "host_key": "test_key", + } + ) + + # Get evaluation context with server + eval_context = self.env["cx.tower.command"]._get_python_command_eval_context( + server=test_server + ) + + # Check if boto3 is in the evaluation context + self.assertIn("boto3", eval_context) + + # Check available methods + boto3_obj = eval_context["boto3"] + self.assertTrue(hasattr(boto3_obj, "client")) + self.assertTrue(hasattr(boto3_obj, "resource")) + self.assertTrue(hasattr(boto3_obj, "Session")) + + # Verify server is correctly passed to the context + self.assertEqual(eval_context["server"], test_server)