Python Projects¶
When you choose Python as the language for your project, mp-init will generate a project structure tailored for writing Adapters using Python. A Python-based project structure uses pip for dependency management and the Python Adapter Library to streamline the Adapter development process.
Dependencies¶
- Python3 3.9.0 or later. Updating to the latest stable version is recommended. Python 3.8 and earlier (including Python2) are not supported. For instructions on installing Python, go to Python's installation documentation, and follow the instructions provided for your operating system.
Project Structure¶
All templates generate the base project structure along with some additional files and directories specific to Python (highlighted below):
.
├── Dockerfile
├── adapter_requirements.txt
├── commands.cfg
├── config.json
├── connections.json
├── eula.txt
├── manifest.txt
├── requirements.txt
├── app
│ ├── __init__.py
│ ├── adapter.py
│ └── constants.py
├── conf
│ ├── describeSchema.xsd
│ └── images
│ ├── AdapterKind
│ ├── ResourceKind
│ └── TraversalSpec
├── content
│ ├── alertdefs
│ │ └── alertDefinitionSchema.xsd
│ ├── customgroups
│ ├── dashboards
│ ├── files
│ │ ├── reskndmetric
│ │ ├── solutionconfig
│ │ ├── topowidget
│ │ └── txtwidget
│ ├── policies
│ ├── recommendations
│ ├── reports
│ ├── resources
│ ├── supermetrics
│ ├── symptomdefs
│ └── traversalspecs
│ └── traversalSpecsSchema.xsd
└── resources
└── resources.properties
- app (directory)
- By default, this directory contains a template adapter. The template adapter collects several objects and metrics from
the container that the adapter is running in, and can be used as a starting point for creating a new adapter.
The template adapter uses
vmware-aria-operations-integration-sdk-lib to
streamline the process of building adapter.
The template adapter has comments throughout the code to help new users understand the process of creating their own
adapter using the existing code. For additional guidance creating adapters see our
Guides
section. - adapter_requirements.txt (file)
- This file defines all the dependencies needed by the adapter at run time. This file is copied onto the container where the adapter runs and used by the default Dockerfile to install dependencies into the container image.
- commands.cfg (file)
- This file contains a list of the commands the HTTP server can run, along with the path to the executable related to the
command. By default, all commands are run by executing the
adapter.py
file along with a parameter that defines a command. For example, when the HTTP server receives a request to run a test connection, it reads the commands.cfg key fortest
and runs the process defined by the key value,/usr/local/bin/python app/adapter.py test
.
Templates¶
Sample Adapter¶
The template adapter collects several objects and metrics from the JVM that the adapter is running in,
and can be used as a starting point for creating a new adapter.
The template adapter uses Python Integration SDK library to streamline the process of building adapter.
The template adapter has comments throughout the code to help new users understand the process of creating their own
adapter using the existing code.
For additional guidance creating adapters see our Guides
section.
New Adapter¶
The new adapter comes with the minimum required code to develop your own adapter.
Adapter Methods¶
The methods in the adapter.py source code are required, and should be modified to generate a custom adapter.
Each method fulfills a request from the VMware Aria Operations collector, and can be tested individually using
mp-test
(covered in Testing a Management Pack).
test(adapter_instance)
-
Performs a test connection using the information given to the adapter_instance to verify the adapter instance has been configured properly. A typical test connection will generally consist of:
- Read identifier values from adapter_instance that are required to connect to the target(s)
- Connect to the target(s), and retrieve some sample data
- If any of the above failed, return an error, otherwise pass.
- Disconnect cleanly from the target (ensure this happens even if an error occurs)
get_endpoints(adapter_instance)
- This method is run before the 'test' method, and VMware Aria Operations will use the results to extract a certificate from each URL. If the certificate is not trusted by the VMware Aria Operations Trust Store, the user will be prompted to either accept or reject the certificate. If it is accepted, the certificate will be added to the AdapterInstance object that is passed to the 'test' and 'collect' methods. Any certificate that is encountered in those methods should then be validated against the certificate(s) in the AdapterInstance. This method will only work against HTTPS endpoints, different types of endpoint will not work (e.g., database connections).
collect(adapter_instance)
-
Performs a collection against the target host. A typical collection will generally consist of:
- Read identifier values from adapter_instance that are required to connect to the target(s)
- Connect to the target(s), and retrieve data
- Add the data into the CollectResult as objects, properties, metrics, etc
- Disconnect cleanly from the target (ensure this happens even if an error occurs)
- Return the CollectResult.
get_adapter_definition()
- Optional method that defines the Adapter Instance configuration. The Adapter Instance
configuration is the set of parameters and credentials used to connect to the target and
configure the adapter. It also defines the object types and attribute types present in a
collection. Setting these helps VMware Aria Operations to validate, process, and display
the data correctly. If this method is omitted, a
describe.xml
file should be manually created inside theconf
directory with the same data. Generally, this is only necessary when using advanced features of thedescribe.xml
file that are not present in this method.
Note
The adapter is stateless. This means the adapter cannot store any data for use in later method calls.