Qubell platform client library
Project description
====================
Python-qubell-client
====================
Repository contains:
qubell/api/private - library to access qubell via dev (non-stable) api.
qubell/api/public - library to access qubell via public (stable) api.
stories - tests in python unittests format. Primary goal is to test qubell platform functionality using different api's
Pre-requisites
==============
- python2.7 or greater
- requests
- yaml
- testtools
- nose
::
sudo pip install -r requirements.txt
or
::
sudo easy_install `cat requirements.txt`
Configuration
=============
To configure tests, set up environment variables:
QUBELL_USER, QUBELL_PASSWORD - user to access qubell
QUBELL_API - url to qubell platform
QUBELL_ORG - name of organization to use. Will be created if not exists.
If you atend to create environment, you will also need:
PROVIDER, REGION, JCLOUDS_IDENTITY, JCLOUDS_CREDENTIALS - credentials for amazon ec2. (to create provider)
By default Amazon ec2 used (in us-east zone)
::
export QUBELL_API="http://qubell.com"
export QUBELL_USER="user@gmail.com"
export QUBELL_PASSWORD="password"
export QUBELL_ORG="my-org"
export JCLOUDS_IDENTITY="FFFFFFFFF"
export JCLOUDS_CREDENTIALS="FFFFFFFFFF"
Running tests
=============
First you need prepare environment (create provider, services, etc) It could be done via portal or by running script::
python create_env.py
Run single test::
nosetests -s -v stories.instance.test_actions:BasicInstanceActionsTest.test_workflow_launch
Run all tests::
nosetests -s -v stories
or just::
nosetests
Using client
============
Creating environment
__________________
Package contains script to setup environment in qubell platform. To use it, set environment variables (see below) and run it::
python create_env.py
Building sandboxes
__________________
Sandboxes in qubell platform could be created on different levels. Maximum isolated sandbox could be achieved by separate organization (with it's own environments, users and application).
Organization
____________
Creating organization is simple::
from qubell.api.private.platform import QubellPlatform, Auth
auth = Auth(user="tester@qubell.com", password="password", tenant="https://api.qubell.com")
platform = QubellPlatform(auth=auth)
org = platform.organization(name="test-org")
After executing this code, organization "test-org" would be created (if not exists) or initialized (if exists)
try:
org = platform.get_organization(id="123")
except:
org = platform.create_organization(name="test-org")
Or you can create organization using this code.
Environment
___________
Usual environment consists of cloud account, keystore service and workflow service. So, we need to add theese services to our organization, then add them to our environment. By default we use "default" environment::
access = {
"provider": "aws-ec2",
"usedEnvironments": [],
"ec2SecurityGroup": "default",
"providerCopy": "aws-ec2",
"name": "test-provider",
"jcloudsIdentity": KEY,
"jcloudsCredential": SECRET_KEY,
"jcloudsRegions": "us-east-1"
}
def prepare_env(org):
# Add services to organization
key_service = org.service(type='builtin:cobalt_secure_store', name='Keystore')
wf_service = org.service(type='builtin:workflow_service', name='Workflow', parameters='{}')
prov = org.provider(access)
# Add services to environment
env = org.environment(name='default')
env.clean()
env.serviceAdd(key_service)
env.serviceAdd(wf_service)
env.providerAdd(prov)
# Here we regenerate keypair
env.policyAdd(
{"action": "provisionVms",
"parameter": "publicKeyId",
"value": key_service.regenerate()['id']})
return org.organizationId
prepare_env(org)
Now, platform ready to be used. We need only application with valid manifest.
Application
___________
We need manifest to create application::
manifest = Manifest(url="https://raw.github.com/qubell/contrib-python-qubell-client/master/qm/hierarchical-main.yml")
# Creating application
app = org.application(manifest=manifest, name='first_app')
or
try:
app = org.get_application(id="111")
except:
org.create_application(manifest=manifest, name='first_app')
Application would be crated.
To launch it, use code::
instance = app.launch()
# This way we wait instance to came up in 15 minutes or break.
assert instance.ready(15)
Python-qubell-client
====================
Repository contains:
qubell/api/private - library to access qubell via dev (non-stable) api.
qubell/api/public - library to access qubell via public (stable) api.
stories - tests in python unittests format. Primary goal is to test qubell platform functionality using different api's
Pre-requisites
==============
- python2.7 or greater
- requests
- yaml
- testtools
- nose
::
sudo pip install -r requirements.txt
or
::
sudo easy_install `cat requirements.txt`
Configuration
=============
To configure tests, set up environment variables:
QUBELL_USER, QUBELL_PASSWORD - user to access qubell
QUBELL_API - url to qubell platform
QUBELL_ORG - name of organization to use. Will be created if not exists.
If you atend to create environment, you will also need:
PROVIDER, REGION, JCLOUDS_IDENTITY, JCLOUDS_CREDENTIALS - credentials for amazon ec2. (to create provider)
By default Amazon ec2 used (in us-east zone)
::
export QUBELL_API="http://qubell.com"
export QUBELL_USER="user@gmail.com"
export QUBELL_PASSWORD="password"
export QUBELL_ORG="my-org"
export JCLOUDS_IDENTITY="FFFFFFFFF"
export JCLOUDS_CREDENTIALS="FFFFFFFFFF"
Running tests
=============
First you need prepare environment (create provider, services, etc) It could be done via portal or by running script::
python create_env.py
Run single test::
nosetests -s -v stories.instance.test_actions:BasicInstanceActionsTest.test_workflow_launch
Run all tests::
nosetests -s -v stories
or just::
nosetests
Using client
============
Creating environment
__________________
Package contains script to setup environment in qubell platform. To use it, set environment variables (see below) and run it::
python create_env.py
Building sandboxes
__________________
Sandboxes in qubell platform could be created on different levels. Maximum isolated sandbox could be achieved by separate organization (with it's own environments, users and application).
Organization
____________
Creating organization is simple::
from qubell.api.private.platform import QubellPlatform, Auth
auth = Auth(user="tester@qubell.com", password="password", tenant="https://api.qubell.com")
platform = QubellPlatform(auth=auth)
org = platform.organization(name="test-org")
After executing this code, organization "test-org" would be created (if not exists) or initialized (if exists)
try:
org = platform.get_organization(id="123")
except:
org = platform.create_organization(name="test-org")
Or you can create organization using this code.
Environment
___________
Usual environment consists of cloud account, keystore service and workflow service. So, we need to add theese services to our organization, then add them to our environment. By default we use "default" environment::
access = {
"provider": "aws-ec2",
"usedEnvironments": [],
"ec2SecurityGroup": "default",
"providerCopy": "aws-ec2",
"name": "test-provider",
"jcloudsIdentity": KEY,
"jcloudsCredential": SECRET_KEY,
"jcloudsRegions": "us-east-1"
}
def prepare_env(org):
# Add services to organization
key_service = org.service(type='builtin:cobalt_secure_store', name='Keystore')
wf_service = org.service(type='builtin:workflow_service', name='Workflow', parameters='{}')
prov = org.provider(access)
# Add services to environment
env = org.environment(name='default')
env.clean()
env.serviceAdd(key_service)
env.serviceAdd(wf_service)
env.providerAdd(prov)
# Here we regenerate keypair
env.policyAdd(
{"action": "provisionVms",
"parameter": "publicKeyId",
"value": key_service.regenerate()['id']})
return org.organizationId
prepare_env(org)
Now, platform ready to be used. We need only application with valid manifest.
Application
___________
We need manifest to create application::
manifest = Manifest(url="https://raw.github.com/qubell/contrib-python-qubell-client/master/qm/hierarchical-main.yml")
# Creating application
app = org.application(manifest=manifest, name='first_app')
or
try:
app = org.get_application(id="111")
except:
org.create_application(manifest=manifest, name='first_app')
Application would be crated.
To launch it, use code::
instance = app.launch()
# This way we wait instance to came up in 15 minutes or break.
assert instance.ready(15)
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
Close
Hashes for qubell-api-python-client-1.0.15.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 887cb9f16b1e36f6bb9c85f0d9729ba0da8c6b180bf6c752d8bc4085bb6af674 |
|
MD5 | ab7844162b12dfc824961310774715fe |
|
BLAKE2b-256 | 2001d044626c4b48a6efd60ddb89bc399b6c58d6de6c92aea46aab9474fe8a80 |