AOC APIs
Project description
Aoc Python SDK
Aoc python sdk, require Python 2.7 or 3.4+
Installation
-
install from whl
pip install aoc_sdk-1.0.0-py2.py3-none-any.whl
-
install from tar.gz
tar xvzf aoc-sdk-1.0.0.tar.gz cd aoc-sdk-1.0.0 python setup.py install
-
install from source code
git clone https://github.com/arcfraofficial/aoc-python-sdk.git cd aoc-python-sdk python setup.py install -
install from source code by pip
pip install git+https://github.com/arcfraofficial/aoc-python-sdk.git
-
install from pypi
pip install aoc-sdk
Usage
Create instance
Create ApiClient instance
from aoc.configuration import Configuration
from aoc import ApiClient
configuration = Configuration(host="http://aoc.arcfra.com/v2/api")
client = ApiClient(configuration)
If using self-signed certificate, update configuration to skip ssl check
configuration = Configuration(host="http://aoc.arcfra.com/v2/api")
configuration.verify_ssl = False
client = ApiClient(configuration)
Create relatd Api instance
Create related Api instance depends on usage, for example, to use vm related operation, create a
VmApi。
from aoc.api.vm_api import VmApi
vm_api = VmApi(client)
Authentication
a
loginfunction is provided inutilspackage and can use to authenticate an api_client
from aoc.utils import wait_tasks, login
conf = Configuration(host="http://aoc.arcfra.com/v2/api")
api_client = ApiClient(conf)
login(api_client, "your_username", "your_password")
or directly update api_key field of Configuration, token can be retrieved from
loginapi fromUserApi
from aoc.api.user_api import UserApi
from aoc.models import UserSource
user_api = UserApi(client)
login_res = user_api.login({
"username": "your_username",
"password": "your_password",
"source": UserSource.LOCAL
})
configuration.api_key["Authorization"] = login_res.data.token
Sending Request
List elements
vms = vm_api.get_vms({
"where": {
"id": "vm_id"
},
"first":1,
})
Mutation and async task
Mostly mutation will response as async task earlier to avoid request hanging when executing long-running operation.
start_res = vm_api.start_vm({
"where": {
"id": "stopped_vm_id"
},
})
'''
start_res = {
task_id: <task_id>
data: {
...
}
}
'''
A utils named function
wait_tasksis export from utils package
from aoc.utils import wait_tasks
try:
wait_tasks([res.task_id for res in start_res], api_client)
except ApiException as e:
# handling exception
# handling response
async request
Directly call api funtion will block process until response, to make request async, add kwargs async_req=True Then function will return an
ApplyResultand can use get function to retrieve response
vms = vm_api.get_vms(
{
"where": {
"id": "vm_id"
}
},
async_req=True
)
print(vms.get()[0].name)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aoc_sdk-1.0.0.tar.gz.
File metadata
- Download URL: aoc_sdk-1.0.0.tar.gz
- Upload date:
- Size: 1.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a67cf61c098353df0a468b42bfe0844d3f56bdc2e7ec01db20223099d7d14c09
|
|
| MD5 |
e9468922cee1d4f48fea70b784c0df6e
|
|
| BLAKE2b-256 |
f7dda5c6f5bb4eb0469f5dccdee52de180810797a45fe5a5d8dddedf8165eb66
|
File details
Details for the file aoc_sdk-1.0.0-py2.py3-none-any.whl.
File metadata
- Download URL: aoc_sdk-1.0.0-py2.py3-none-any.whl
- Upload date:
- Size: 2.2 MB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04875cc81250d6572da79029eb74540b55d5ae89f1f87b69fa6c5f40ad1675ba
|
|
| MD5 |
4cbcfb7a45560ee7728624812b73920e
|
|
| BLAKE2b-256 |
789376b9b8fb04ef0812232d4555f3afdfc7a10d17e4471f1c20e6c480f4d936
|