Outscale Gateway python SDK
Project description
Outscale Python SDK
This python SDK helps you to perform actions on Outscale API.
You will need to have an Outscale account, please visit Outscale website.
Installation
You can install the pre-built python package through this command:
$ pip install osc-sdk-python
Building
To build the package yourself:
$ make package
You can then install it with:
$ pip install dist/osc_sdk_python-0.21.1-py3-none-any.whl
Configuration & Credentials
When you use the cli you can choose a profile. Profiles can be set with environment variables or in a file. It checks environment variables before loading the file.
In the file, you can set a default profile, naming default
. It will be used if you don't precise profile in command line.
Environment variables
$ export OSC_ACCESS_KEY=<ACCESS_KEY>
$ export OSC_SECRET_KEY=<SECRET_KEY>
$ # optional
$ export OSC_REGION=<REGION> (default: eu-west-2)
Credentials files
$ cat ~/.osc/config.json
{
"default": {
"access_key": "<ACCESS_KEY>",
"secret_key": "<SECRET_KEY>",
"region": "<REGION>"
},
"profile_1": {
"access_key": "<ACCESS_KEY>",
"secret_key": "<SECRET_KEY>",
"region": "<REGION>"
},
"profile_2": {
"access_key": "<ACCESS_KEY>",
"secret_key": "<SECRET_KEY>",
"region": "<REGION>"
}
}
Notes:
- if ~/.osc/config.json is not found, ~/.oapi_credentials will be used
- Environment variables have priority over Credentials files.
Basic Authentication
You can also use osc-sdk-python with basic authentication mechanism using your account's email and password. Note that some calls may be blocked with this method. More details in authentication documentation.
Example:
gw = Gateway(email="your@email.com", password="youAccountPassword")
keys = gw.ReadAccessKeys()
Example
A simple example which prints all your Virtual Machine and Volume ids.
from osc_sdk_python import Gateway
if __name__ == '__main__':
gw = Gateway()
print("your virtual machines:")
for vm in gw.ReadVms()["Vms"]:
print(vm["VmId"])
print("\nyour volumes:")
for volume in gw.ReadVolumes()["Volumes"]:
print(volume["VolumeId"])
Usage example, check Outscale API documentation for more details.
from osc_sdk_python import Gateway
if __name__ == '__main__':
gw = Gateway(**{'profile': 'profile_1'})
# Calls with api Action as method
result = gw.ReadSecurityGroups(Filters={'SecurityGroupNames': ['default']})
result = gw.CreateVms(ImageId='ami-3e158364', VmType='tinav4.c2r4')
# Or raw calls:
result = gw.raw('ReadVms')
result = gw.raw('CreateVms', ImageId='ami-xx', BlockDeviceMappings=[{'/dev/sda1': {'Size': 10}}], SecurityGroupIds=['sg-aaa', 'sg-bbb'], Wrong='wrong')
Another example with logs
from osc_sdk_python import *
if __name__ == '__main__':
gw = Gateway(**{'profile': 'profile_1'})
# what can contain LOG_KEEP_ONLY_LAST_REQ or LOG_ALL
# here we pront log in memory, in standard output and in satndard error
gw.log.config(type=LOG_MEMORY | LOG_STDIO | LOG_STDERR, what=LOG_KEEP_ONLY_LAST_REQ)
# Or raw calls:
result = gw.raw('ReadVms')
last_request = gw.log.str()
print(last_request)
Known Issues
UTF-8
Some people my encounter some issue with utf-8 which looks like this
Problem reading (…)osc_sdk_python/osc-api/outscale.yaml:'ascii' codec can't decode byte 0xe2 in position 14856: ordinal not in range(128)
To avoid this issue, configure you locals as follow:
LC_ALL=en_US.UTF-8
if you don't want your locals to be set system wide you can proceed as follow:
LC_ALL=en_US.UTF-8 pip install osc-sdk-python
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
File details
Details for the file osc_sdk_python-0.21.1.tar.gz
.
File metadata
- Download URL: osc_sdk_python-0.21.1.tar.gz
- Upload date:
- Size: 67.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b5742b4e0453150495cff7d7541af3213c930fe6064c18ae7fc27a9b46e5ba3 |
|
MD5 | 7cfc1cd974d6593d8b7620ed5993be65 |
|
BLAKE2b-256 | 3dbb6da9a98e9e68c2db9cee3dbe4409209444898021bc5cd90a0a6e26eae702 |
File details
Details for the file osc_sdk_python-0.21.1-py3-none-any.whl
.
File metadata
- Download URL: osc_sdk_python-0.21.1-py3-none-any.whl
- Upload date:
- Size: 68.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb64000d5ae0742844a81d11dfb02b370249242b6590b5b2def7486418e2a406 |
|
MD5 | 29ad5877a889a328e62185505897296f |
|
BLAKE2b-256 | f4933d114a768a4a1897dc8fd1cce0f0104a40fedc8fb1c1111fc759a0b91167 |