/
README
299 lines (215 loc) · 10.1 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
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"
CLI Tool
========
Many operations are available direcly through CLI interface, like creating orgs,
initializing cloud accounts, and importing/exporting applications.
$ nomi
Usage: nomi [OPTIONS] COMMAND [ARGS]...
CLI for tonomi.com using contrib-python-qubell-client
To enable completion:
eval "$(_NOMI_COMPLETE=source nomi)"
Options:
--tenant TEXT Tenant url to use, QUBELL_TENANT by default
--user TEXT User to use, QUBELL_USER by default
--password TEXT Password to use, QUBELL_PASSWORD by default
--organization TEXT Organization to use, QUBELL_ORGANIZATION by default
--debug Debug mode, also QUBELL_LOG_LEVEL can be used.
--help Show this message and exit.
Commands:
instance
application
environment
organization
platform
zone
manifest
Commands are documented via help:
$ nomi instance --help
Usage: nomi instance [OPTIONS] COMMAND [ARGS]...
...
Features:
instance
describe Show details about instance
destroy Destroy instance
launch Launch instance in application
list List instances in current organization or application
logs Get activity logs
parameters Get default launch parameters for application
remove Force remove instance
wait-status Wait until instance status becomes 'Status' or timeout reached
application
delete Delete application
export Save manifest of applications to files
import Upload manifest to application.
list List applications in organization
environment
clear Clean environment.
clone Copy environment
create Create environment
delete Delete environment
describe Show services, markers and properties of environment
export Save environment to file
get-keypair Download keypair
import Import environment from file
init Add basic services to environment (WF, CA, KS services)
list List environments
make-default
organization
create Create organization
import-kit Import starter kit
init Initialize cloud account service
list List organizations
restore Restore configuration from ENV file
platform
show-account Exports current account configuration inshell-friendly form. Takes into
account explicit top-level flags like --organization
zone
list List available zones
manifest
validate Validate manifest
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']