CloudStackAIO.CloudStack module¶
-
class
CloudStackAIO.CloudStack.
CloudStack
(end_point: str, api_key: str, api_secret: str, event_loop: Optional[asyncio.events.AbstractEventLoop] = None, async_poll_latency: int = 2, max_page_size: int = 500)[source]¶ Bases:
object
Client object to access a CloudStack API
Parameters: - end_point (str) – URL to reach the CloudStack API
- api_key (str) – APIKey to access the CloudStack API (usually available from your cloud provider)
- api_secret – Secret to access the CloudStack API (usually available from your cloud provider)
- event_loop (Optional[asyncio.AbstractEventLoop]) – asyncio event loop to utilize
- async_poll_latency (int) – Time in seconds to wait before polling CloudStack API to fetch results of asynchronous API calls
- max_page_size (int) –
Some API calls are paginated like listVirtualMachines, this number specifies the maximum number of item returned in one API call. The client automatically takes care of the pagination by splitting it into separate API calls
and returns the entire list
Example: event_loop = asyncio.get_event_loop() cloud_stack_client = CloudStack(end_point='https://api.exoscale.ch/compute', api_key='<Your API key>', api_secret='Your API secret', event_loop=event_loop)
-
_close_session
() → None[source]¶ According to the aiohttp documentation all opened sessions need to be closed, before leaving the program. This function takes care that the client session is closed. This async co-routine is automatically scheduled, when the client object is destroyed.
-
_handle_response
(response: aiohttp.client_reqrep.ClientResponse, await_final_result: bool) → dict[source]¶ Handles the response returned from the CloudStack API. Some CloudStack APIs are implemented asynchronous, which means that the API call returns just a job id. The actually expected API response is postponed and a specific asyncJobResults API has to be polled using the job id to get the final result once the API call has been processed.
Parameters: - response (aiohttp.client_reqrep.ClientResponse) – The response returned by the aiohttp call.
- await_final_result (bool) – Specifier that indicates whether the function should poll the asyncJobResult API until the asynchronous API call has been processed
Returns: Dictionary containing the JSON response of the API call
Return type:
-
_sign
(url_parameters: dict) → dict[source]¶ According to the CloudStack documentation, each request needs to be signed in order to authenticate the user account executing the API command. The signature is generated using a combination of the api secret and an SHA-1 hash of the url parameters including the command string. In order to generate a unique identifier, the url parameters have to be transformed to lower case and ordered alphabetically.
Parameters: url_parameters (dict) – The url parameters of the API call including the command string Returns: The url parameters including a new key, which contains the signature Return type: dict
-
static
_transform_data
(data: dict) → dict[source]¶ Each CloudStack API call returns a nested dictionary structure. The first level contains only one key indicating the API that originated the response. This function removes that first level from the data returned to the caller.
Parameters: data (dict) – Response of the API call Returns: Simplified response without the information about the API that originated the response. Return type: dict
-
client_session
¶
-
event_loop
¶
-
request
(command: str, **kwargs) → dict[source]¶ Async co-routine to perform requests to a CloudStackAPI. The parameters needs to include the command string, which refers to the API to be called. In principle any available and future CloudStack API can be called. The **kwargs magic allows us to all add supported parameters to the given API call. A list of all available APIs can found at https://cloudstack.apache.org/api/apidocs-4.8/TOC_User.html
Parameters: - command (str) – Command string indicating the CloudStack API to be called.
- kwargs – Parameters to be passed to the CloudStack API
Returns: Dictionary containing the decoded json reply of the CloudStack API
Return type: