forked from chemikadze/contrib-python-qubell-client
DmZ/contrib-python-qubell-client
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Python-qubell-client Installation ============ pip install qubell-api-python-client Configuration ============= To configure tests, set up environment variables: QUBELL_USER, QUBELL_PASSWORD - user to access qubell QUBELL_TENANT - url to qubell platform (https://express.qubell.com) QUBELL_ORGANIZATION - name of organization to use. Will be created if not exists. If you attend to create environment, you will also need: PROVIDER_TYPE, PROVIDER_REGION, PROVIDER_IDENTITY, PROVIDER_CREDENTIAL - credentials for amazon ec2. (to create provider) By default Amazon ec2 used (in us-east zone) Example: export QUBELL_TENANT="https://express.qubell.com" export QUBELL_USER="user@gmail.com" export QUBELL_PASSWORD="password" export QUBELL_ORGANIZATION="my-org" # Additional parameters export PROVIDER_TYPE="aws-ec2" export PROVIDER_REGION="us-east-1" export PROVIDER_IDENTITY="FFFFFFFFF" export PROVIDER_CREDENTIAL="FFFFFFFFFF" Running tests ============= Run single test: nosetests -s -v stories.instance.test_actions:BasicInstanceActionsTest.test_workflow_launch Run all tests in folder: nosetests -s -v tests or cd tests nosetests Using client ============ 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). Simple way to create sandbox (see ./contrib-python-qubell-client/sandbox/): Create file containing organization structure, for example: organizations: - name: DEFAULT_ORG applications: - name: super_parent file: ./super_parent.yml - name: middle_child file: ./middle_child.yml - name: child file: ./child.yml environments: - name: default services: - name: Default credentials service - name: Default workflow service - name: child-service services: - name: Default workflow service type: builtin:workflow_service - name: Default credentials service type: builtin:cobalt_secure_store - name: child-service application: child instances: - name: test-instance application: super_parent Now you can create organization, running: ./restore_env.py default.env After, you will have fully configured organization, even with running instances. This example shows how to describe 3-level hearchical application, where child instance launched as service. Coding your own scripts ----------------------- First way of creating sandbox, using restore method: config = {'organizations': [{'name': 'DEFAULT_ORG', 'applications': [{'file': './super_parent.yml', 'name': 'super_parent'}, {'file': './middle_child.yml', 'name': 'middle_child'}, {'file': './child.yml', 'name': 'child'}], 'environments': [{'name': 'default', 'services': [{'name': 'Default credentials service'}, {'name': 'Default workflow service'}, {'name': 'child-service'}]}], 'instances': [{'application': 'super_parent', 'name': 'test-instance'}], 'providers': [{'ec2SecurityGroup': 'default', 'jcloudsCredential': 'AAAAAAAAA', 'jcloudsIdentity': 'BBBBBBBBBBB', 'jcloudsRegions': 'us-east-1', 'name': 'generated-provider-for-tests', 'provider': 'aws-ec2', 'providerCopy': 'aws-ec2'}], 'services': [{'name': 'Default workflow service', 'type': 'builtin:workflow_service'}, {'name': 'Default credentials service', 'type': 'builtin:cobalt_secure_store'}, {'application': 'child', 'name': 'child-service'}]}]} from qubell.api.private.platform import QubellPlatform from qubell.api.globals import QUBELL platform = QubellPlatform.connect(user=QUBELL['user'], password=QUBELL['password'], tenant=QUBELL['tenant']) platform.restore(config) # Let's check what we've got print platform.organizations['DEFAULT_ORG'].name for ins in platform.organizations['DEFAULT_ORG'].instances: print ins.name Second way, using get/create methods: from qubell.api.private.platform import QubellPlatform from qubell.api.private.manifest import Manifest from qubell.api.globals import QUBELL, PROVIDER_CONFIG, DEFAULT_WORKFLOW_SERVICE, DEFAULT_CREDENTIAL_SERVICE, DEFAULT_CLOUD_ACCOUNT_SERVICE from qubell.api.private.service import CLOUD_ACCOUNT_TYPE, WORKFLOW_SERVICE_TYPE, COBALT_SECURE_STORE_TYPE # Connect to platform platform = QubellPlatform.connect(user=QUBELL['user'], password=QUBELL['password'], tenant=QUBELL['tenant']) ##### Organization org = platform.organization(name='DEFAULT_ORG') # After executing this code, organization "DEFAULT_ORG" would be created (if not exists) or initialized (if exists) ##### Environment # Usually environment consists of cloud account, keystore service and workflow service. So, we need to add these services to our organization, then add them to our environment: def prepare_env(org): # Add services to organization key_service = org.service(type=COBALT_SECURE_STORE_TYPE, name=DEFAULT_CREDENTIAL_SERVICE()) wf_service = org.service(type=WORKFLOW_SERVICE_TYPE, name=DEFAULT_WORKFLOW_SERVICE()) cloud_account = org.service(type=CLOUD_ACCOUNT_TYPE, name=DEFAULT_CLOUD_ACCOUNT_SERVICE(), parameters=PROVIDER_CONFIG) # Add services to environment env = org.environment(name='new-environment') env.clean() env.add_service(key_service) env.add_service(wf_service) env.add_service(cloud_account) # Here we regenerate keypair env.add_policy( {"action": "provisionVms", "parameter": "publicKeyId", "value": key_service.regenerate()['id']}) return env environment = 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.githubusercontent.com/qubell/contrib-python-qubell-client/master/sandbox/child.yml') # Creating application app = org.application(manifest=manifest, name='first_app') # Application will be created. # Let's start instance using in env1 : instance = org.create_instance(application=app, environment=environment) # This way we wait instance to came up in 15 minutes or break. assert instance.ready(15) print instance.return_values['child_out.child_output']
About
No description, website, or topics provided.
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published
Languages
- Python 99.9%
- Shell 0.1%