Aoc python sdk, require Python 2.7 or 3.4+
-
pip install aoc_sdk-1.0.0-py2.py3-none-any.whl
-
tar xvzf aoc-sdk-1.0.0.tar.gz cd aoc-sdk-1.0.0 python setup.py install -
git clone https://github.com/arcfraofficial/aoc-python-sdk.git cd aoc-python-sdk python setup.py install -
pip install git+https://github.com/arcfraofficial/aoc-python-sdk.git
-
pip install aoc-sdk
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 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)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.tokenvms = vm_api.get_vms({
"where": {
"id": "vm_id"
},
"first":1,
})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 responseDirectly 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)