Orpy API bindings¶
You can use this library to interact with the INDIGO PaaS Orchestrator:
>>> from orpy.client import client
>>> orpy = client.OrpyClient(
... url=ORCHESTRATOR_URL,
... token=ORCHESTRATOR_TOKEN)
>>> deployments = orpy.deployments.list()
>>> deployments[0]
<Deployment cloudProviderName=provider-BARI, createdBy={u'subject': u'de28e179-ec86-4915-a748-7a37f8d80311', u'issuer': u'https://iam.deep-hybrid-datacloud.eu/'}, creationTime=2019-05-27T11:31+0000, links=[{u'href': u'https://paas.cloud.cnaf.infn.it/orchestrator/deployments/11e98073-06f3-6797-9258-0242ac140005', u'rel': u'self'}, {u'href': u'https://paas.cloud.cnaf.infn.it/orchestrator/deployments/11e98073-06f3-6797-9258-0242ac140005/resources', u'rel': u'resources'}, {u'href': u'https://paas.cloud.cnaf.infn.it/orchestrator/deployments/11e98073-06f3-6797-9258-0242ac140005/template', u'rel': u'template'}], outputs={}, physicalId=11e98073-06f3-6797-9258-0242ac140005, status=CREATE_FAILED, statusReason=Error while checking the deployment status; nested exception is feign.RetryableException: mesos.ui.sav.sk executing GET https://mesos.ui.sav.sk/marathon/v2/groups/11e98073-06f3-6797-9258-0242ac140005, task=NONE, updateTime=2019-05-29T02:05+0000, uuid=11e98073-06f3-6797-9258-0242ac140005>
>>> deployments[0].status
CREATE_FAILED
Orpy Client¶
Use this to interact with the INDIGO-DatatCloud orchestrator.
INDIGO-DataCloud PaaS orchestrator client module.
-
class
orpy.client.client.
OrpyClient
(url, oidc_agent=None, token=None, oidc_session=None, debug=False)¶ An INDIGO-DataCloud PaaS orchestrator client class.
- If you want an authenticated client, when creating the object you MUST pass either:
- An orpy.oidc.OpenIDConnectAgent object (oidc_agent parameter)
- An orpy.oidc.OpenIDConnectSession object (oidc_session parameter)
- An access token for authentication (token parameter)
The first method is the preferred, you can create an object this way (assuming that the oidc-agent account is named “oidc-agent-account”:
from orpy import oidc from orpy.client import client oidc_agent = oidc.OpenIDConnectAgent(“oidc-agent-account”)
cli = client.OrpyClient(url, oidc_agent=oidc_agent)
The second method is only useful when you are programming a library and have access to a requests.Request like object session, like the ones used by Flask Dance:
from orpy import oidc from orpy.client import client oidc_session = oidc.OpenIDConnectSession(flask_blueprint.session)
cli = client.OrpyClient(url oidc_session=oidc_session)
Note that passing more than one of the above methods will result in a warning, not an error. In that case, the preference is the following (note also that if one method fails we will not continue to the next one, so the rest of the methods are actually ignored):
- oidc_agent
- oidc_session
- token
If you do not pass any of these when creating the client, but you want to setup them afterwards, you can do so with the set_authentication method.
-
config
¶ Interface to query for Orchestrator configuration.
Returns: Configuration interface. Return type: orpy.info.Config
-
deployments
¶ Interface to query for deployments.
Returns: Deployments interface. Return type: orpy.client.deployments.Deployments
-
info
¶ Interface to query for Orchestrator information.
Returns: Information interface. Return type: orpy.info.Info
-
request
(url, method, authenticated=True, payload=None, **kwargs)¶ Send an HTTP request with the specified characteristics.
Wrapper around requests.Session.request to handle tasks such as setting headers, JSON encoding/decoding, and error handling.
Arguments that are not handled are passed through to the requests library.
Parameters: - url (str) – Path or fully qualified URL of the HTTP request. If only a path is provided then the URL will be prefixed with the attribute self.url. If a fully qualified URL is provided then self.url will be ignored.
- method (str) – The http method to use. (e.g. ‘GET’, ‘POST’)
- authenticated (bool) – Whether the request must be authenticated or not.
- payload – Some data to be represented as JSON. (optional)
- kwargs –
any other parameter that can be passed to
requests.Session.request()
(such as headers). Except:- data will be overwritten by the data in the payload param.
- allow_redirects is ignored as redirects are handled by the session.
Returns: The response to the request.
-
resources
¶ Interface to query for resources.
Returns: Resources interface. Return type: orpy.client.resources.Resources
-
set_authentication
(token=None, agent=None, session=None)¶ Set OIDC authentication options.
Parameters: - oidc_agent (orpy.oidc.OpenIDConnectAgent) – OpenID Connect agent object to use for fetching access tokens.
- oidc_session (orpy.oidc.OpenIDConnectSession) – OpenID Connect session to use for fetching the token.
- token (str) – OpenID Connect access token to use for auth.
-
token
¶ Get an access token to interact with the Orchestrator.
Deployments interface¶
This module contains the client dealing with PaaS Orchestrator deployments.
-
class
orpy.client.deployments.
Deployments
(client)¶ Manage Orchestrator deployments.
-
create
(template, callback_url=None, max_providers_retry=None, keep_last_attemp=True, parameters=None, **kwargs)¶ Create a deployment.
Parameters: - template (str) – The TOSCA template to use.
- callback_url (str) – The orchestrator callback url.
- max_providers_retry (int) – Maximum number of providers to retry.
- keep_last_attemp (bool) – Whether to keep the allocated resources in case of failure.
- kwargs – Other arguments passed to the request client.
Returns: The created deployment
Return type:
-
delete
(uuid, **kwargs)¶ Delete a deployment.
Parameters: - uuid (str) – The UUID of the deployment to delete.
- kwargs – Other arguments passed to the request client.
Returns: None
Return type: None
-
get_template
(uuid, **kwargs)¶ Get the TOSCA template of a deployment.
Parameters: - uuid (str) – The UUID of the deployment.
- kwargs – Other arguments passed to the request client.
Returns: The TOSCA template for the deployment
Return type:
-
list
(**kwargs)¶ List existing deployments.
Parameters: kwargs – Other arguments passed to the request client. Returns: List of orpy.client.base.Deployment Return type: list
-
show
(uuid, **kwargs)¶ Show details about a deployment.
Parameters: - uuid (str) – The UUID of the deployment to show.
- kwargs – Other arguments passed to the request client.
Returns: The deployment requested
Return type:
-
update
(uuid, template, callback_url=None, max_providers_retry=None, keep_last_attemp=True, parameters=None, **kwargs)¶ Update a deployment.
Parameters: - uuid (str) – The UUID of the deployment.
- template (str) – The TOSCA template to use.
- callback_url (str) – The orchestrator callback url.
- max_providers_retry (int) – Maximum number of providers to retry.
- keep_last_attemp (bool) – Whether to keep the allocated resources in case of failure.
- kwargs – Other arguments passed to the request client.
Returns: The updated deployment
Return type:
-
Resources interface¶
This module contains the client dealing with PaaS Orchestrator resources.
-
class
orpy.client.resources.
Resources
(client)¶ Manage Orchestrator deployment resources.
-
list
(uuid, **kwargs)¶ List resources for a deployment.
Parameters: - uuid (str) – The UUID of the deployment get the resources.
- kwargs – Other arguments passed to the request client.
Returns: A list of orpy.client.base.Resource
Return type: list
-
show
(deployment_uuid, resource_uuid, **kwargs)¶ Show details about a resource on a deployment.
Parameters: - resource_uuid (str) – The UUID of the deployment get the resource.
- deployment_uuid (str) – The UUID of the resource.
- kwargs – Other arguments passed to the request client.
Returns: The resource requested
Return type:
-
Information interface¶
This module contains the client dealing with PaaS Orchestrator information.
-
class
orpy.client.info.
Info
(client)¶ Get information about the Orchestrator.
-
get
(**kwargs)¶ Get information about the Orchestrator.
Parameters: kwargs – Other arguments passed to the request client. Returns: Information about the orchestrator. Return type: orpy.client.base.OrchestratorInfo
-
Orchestrator resources objects¶
Module defining base object for all orchestrator resources.
-
class
orpy.client.base.
BaseObject
(info)¶ Base class for all objects that represents orchestrator resoruces.
-
get
(k, default=None)¶ Get an attribute from the resource.
-
set_info
(key, value)¶ Set an objects information with key, value.
Parameters: - key – the element to set
- value – the value for the element
-
to_dict
()¶ Translate the object into a dictionary.
Returns: A dictionary contaning the object representation Return type: dict
-
-
class
orpy.client.base.
Deployment
(info)¶ Object that represents a deployment.
-
get
(k, default=None)¶ Get an attribute from the resource.
-
set_info
(key, value)¶ Set an objects information with key, value.
Parameters: - key – the element to set
- value – the value for the element
-
to_dict
()¶ Translate the object into a dictionary.
Returns: A dictionary contaning the object representation Return type: dict
-
-
class
orpy.client.base.
OrchestratorConfiguration
(info)¶ Object that represents the Orchestrtor information.
-
get
(k, default=None)¶ Get an attribute from the resource.
-
set_info
(key, value)¶ Set an objects information with key, value.
Parameters: - key – the element to set
- value – the value for the element
-
to_dict
()¶ Translate the object into a dictionary.
Returns: A dictionary contaning the object representation Return type: dict
-
-
class
orpy.client.base.
OrchestratorInfo
(info)¶ Object that represents the Orchestrtor information.
-
get
(k, default=None)¶ Get an attribute from the resource.
-
set_info
(key, value)¶ Set an objects information with key, value.
Parameters: - key – the element to set
- value – the value for the element
-
to_dict
()¶ Translate the object into a dictionary.
Returns: A dictionary contaning the object representation Return type: dict
-
-
class
orpy.client.base.
Resource
(info)¶ Object that represents a Resource.
-
get
(k, default=None)¶ Get an attribute from the resource.
-
set_info
(key, value)¶ Set an objects information with key, value.
Parameters: - key – the element to set
- value – the value for the element
-
to_dict
()¶ Translate the object into a dictionary.
Returns: A dictionary contaning the object representation Return type: dict
-
-
class
orpy.client.base.
TOSCATemplate
(info)¶ Object that repesents a TOSCA template.
-
get
(k, default=None)¶ Get an attribute from the resource.
-
set_info
(key, value)¶ Set an objects information with key, value.
Parameters: - key – the element to set
- value – the value for the element
-
to_dict
()¶ Translate the object into a dictionary.
Returns: A dictionary contaning the object representation Return type: dict
-