Package: opera-api
xOpera APIAn HTTP API interface to theoperaorchestrator - single user, single project, single deployment.Table of ContentsIntroductionPrerequisitesInstallation and QuickstartDevelopmentUsageLicenseContactAcknowledgementIntroductionopera-apiaims to be a lightweight xOpera orchestrator API.
ThexOpera documentationis available on GitHub pages.The xOpera API is not a pure orchestration service REST API and cannot deploy multiple projects from different
users.
It is just a wrapper around user's current orchestration environment, where he has his files and his version
ofoperaorchestrator and can manage just one state at a time.
The reason behind this implementation is that this API does not have to support multiuser experience and is mean to be
the component that integrates into xOpera SaaS API in the way that for each user's project a new separated Docker
container with xOpera API is created, which can ensure that users' orchestration environments are isolated.xOpera SaaSis then the component that brings multiuser and multitenant experience by using xOpera API that mimics
CLI commands, which is nicer than calling xOpera CLI.Prerequisitesopera-apirequires Python 3 and a virtual environment.
In a typical modern Linux environment, we should already be set.
In Ubuntu, however, we might need to run the following commands:$sudoaptupdate$sudoaptinstall-ypython3-venvpython3-wheelpython-wheel-commonInstallation and QuickstartThe xOpera API is available on PyPI as a Python package named [opera-api].
Apart from the latestPyPI productionversion, you can also find the latest opera-apiPyPI developmentversion,
which includes pre-releases so that you will be able to test the latest features before they are officially released.The simplest way to testopera-apiis to install it into Python virtual environment:$python3-mvenv.venv&&..venv/bin/activate(.venv)$pipinstallopera-apiAfter that you can navigate to the folder with your TOSCA CSAR or service template and run the API that will create the
wrapper around your environment.(.venv)$gitclonegit@github.com:xlab-si/xopera-api.git(.venv)$cdxopera-api/tests/integration/hello-world(.venv)$opera-api2022-04-04 12:45:34,097 - INFO - opera.api.cli - Running in production mode: tornado backend.Now open another terminal window and deploy the example through some API endpoints usingcurl:(.venv)$(.venv)$curl-XPOSTlocalhost:8080/deploy-H"Content-Type: application/json"-d'{"service_template": "service.yaml", "inputs": {}}'{"clean_state": false,"id": "a3e64611-01e0-417a-9b08-87b08b73883c","inputs": {},"operation": "deploy","service_template": "service.yaml","state": "pending","timestamp": "2022-04-04T10:47:49.919002+00:00"}(.venv)$curllocalhost:8080/info{"content_root": ".","csar_valid": true,"inputs": {},"service_template": "service.yaml","service_template_metadata": {"template_author": "XLAB","template_name": "hello-world","template_version": "1.0"},"status": "deployed"}(.venv)$curllocalhost:8080/status...And that's it.You can also run xOpera API in a Docker container (using publicghcr.io/xlab-si/xopera-apiDocker image) and mount
your TOSCA CSAR:#runxOperaAPIinDockerandnavigatetolocalhost:8080/swagger$dockerrun--namexopera-api-p8080:8080-v$(pwd)/tests/integration/hello-world:/hello-world-eOPERA_API_DEBUG_MODE=trueghcr.io/xlab-si/xopera-api$curllocalhost:8080/statusIf you wish to deploy another project navigate to its folder and run another instance of xOpera API.
If you want to useoperaorchestrator (with xOpera CLI) go toxopera-operarepository.
If you want to use just xOpera TOSCA parser go toxopera-tosca-parserrepository.
For xOpera examples navigate toxopera-examplesrepository.
You can also take a look at thexOpera SaaScomponent, which is designed for business partners and enterprise users.
To find more about xOpera project visit ourxOpera documentation.DevelopmentRequires Python >= 3.7.To begin:python3 -m venv .venvsource .venv/bin/activatepip install -r requirements.txtOpenAPI base code is generated withgenerate.shand isnotchecked in to the repository.Other useful commands:#openapi-generatorbasicsjava -jar openapi-generator-cli-4.3.0.jarjava -jar openapi-generator-cli-4.3.0.jar help generatejava -jar openapi-generator-cli-4.3.0.jar validate --input-spec openapi-spec.yml --recommendjava -jar openapi-generator-cli-4.3.0.jar config-help --generator-name python-flask --full-detailsUsageUse xOpera API with Docker:docker-compose up --build -ddocker cp test.csar xopera-api_api_1:/app/docker exec xopera-api_api_1 unzip test.csardocker logs -f xopera-api_api_1#preparerequestinputs:service_template,inputs(inJSONobjectform,notastring)curl -XPOST localhost:8080/validate -H "Content-Type: application/json" -d @inputs-request.jsoncurl -XPOST localhost:8080/deploy -H "Content-Type: application/json" -d @inputs-request.jsoncurl localhost:8080/statuscurl localhost:8080/outputscurl localhost:8080/infocurl -XPOST localhost:8080/undeployWith a local development installation:./generate.shpython3 -m venv .venvsource .venv/bin/activatepip install wheelpip install -r requirements.txtcd src/python3 -m opera.api.clicurl localhost:8080You can also run in debug mode and use other env vars:(.venv)$gitclonegit@github.com:xlab-si/xopera-api.git(.venv)$cdxopera-api/tests/integration/hello-world(.venv)$OPERA_API_DEBUG_MODE=trueOPERA_API_PORT=8000OPERA_API_SWAGGER_URL=docsopera-api2022-06-09 12:18:33,658 - INFO - opera.api.cli - Running in debug mode: flask backend.* Serving Flask app 'opera.api.cli' (lazy loading)...(.venv)$curllocalhost:8000/version"0.6.9"LicenseThis work is licensed under theApache License 2.0.ContactYou can contact the xOpera team by sending an email toxopera@xlab.si.AcknowledgementThis project has received funding from the European Union’s Horizon 2020 research and innovation programme under Grant
Agreements No. 825040 (RADON), No. 825480 (SODALITE) and No. 101000162 (PIACERE).