@@ -30,16 +30,17 @@ This SDK requires a [Cloudcraft API key](https://developers.cloudcraft.co/#authe
30
30
## Installation
31
31
32
32
```
33
- python -m pip install cloudcraftco
33
+ python3.10 -m pip install cloudcraftco
34
34
```
35
35
36
36
## Usage
37
37
38
38
The API is accessed through the ` Cloudcraft ` class. An API key available through the Cloudcraft user interface is required when instantiating ` Cloudcraft ` . It can be passed to the class as an argument or through the ` CLOUDCRAFT_API_KEY ` environment variable:
39
39
40
40
``` python
41
- from cloudcraftco import Cloudcraft
41
+ from cloudcraftco.cloudcraft import Cloudcraft
42
42
43
+ # assumes CLOUDCRAFT_API_KEY exported
43
44
cloudcraft = Cloudcraft()
44
45
45
46
profile = cloudcraft.read_user_profile()
@@ -52,7 +53,7 @@ profile = cloudcraft.read_user_profile()
52
53
The package can be initialized with several options:
53
54
54
55
``` python
55
- from cloudcraftco import Cloudcraft
56
+ from cloudcraftco.cloudcraft import Cloudcraft
56
57
57
58
cloudcraft = Cloudcraft({" api_key" : " api-key-value" , " timeout" : 30000 })
58
59
```
@@ -85,6 +86,9 @@ Options may also be specified by environment variable...
85
86
#### List blueprints
86
87
87
88
``` python
89
+ from cloudcraftco.cloudcraft import Cloudcraft
90
+
91
+ # assumes CLOUDCRAFT_API_KEY exported
88
92
cloudcraft = Cloudcraft()
89
93
90
94
blueprints = cloudcraft.list_blueprints()
@@ -93,6 +97,9 @@ blueprints = cloudcraft.list_blueprints()
93
97
#### Retrieve blueprint
94
98
95
99
``` python
100
+ from cloudcraftco.cloudcraft import Cloudcraft
101
+
102
+ # assumes CLOUDCRAFT_API_KEY exported
96
103
cloudcraft = Cloudcraft()
97
104
98
105
blueprint_id = " BLUEPRINT-ID" # valid blueprint uuid
@@ -102,6 +109,9 @@ blueprint = cloudcraft.read_blueprint(blueprint_id)
102
109
#### Create blueprint
103
110
104
111
``` python
112
+ from cloudcraftco.cloudcraft import Cloudcraft
113
+
114
+ # assumes CLOUDCRAFT_API_KEY exported
105
115
cloudcraft = Cloudcraft()
106
116
107
117
data = {" data" : {" grid" : " standard" , " name" : " New blueprint" }}
@@ -111,16 +121,34 @@ blueprint = cloudcraft.create_blueprint(data)
111
121
#### Update blueprint
112
122
113
123
``` python
124
+ from cloudcraftco.cloudcraft import Cloudcraft
125
+
126
+ # assumes CLOUDCRAFT_API_KEY exported
114
127
cloudcraft = Cloudcraft()
115
128
116
129
blueprint_id = " BLUEPRINT-ID" # valid blueprint uuid
117
130
data = {" data" : {" grid" : " standard" , " name" : " Updated blueprint" }}
118
131
cloudcraft.update_blueprint(blueprint_id, data)
119
132
```
120
133
134
+ #### Delete blueprint
135
+
136
+ ``` python
137
+ from cloudcraftco.cloudcraft import Cloudcraft
138
+
139
+ # assumes CLOUDCRAFT_API_KEY exported
140
+ cloudcraft = Cloudcraft()
141
+
142
+ blueprint_id = " BLUEPRINT-ID" # valid blueprint uuid
143
+ cloudcraft.delete_blueprint(blueprint_id)
144
+ ```
145
+
121
146
#### Export blueprint as image
122
147
123
148
``` python
149
+ from cloudcraftco.cloudcraft import Cloudcraft
150
+
151
+ # assumes CLOUDCRAFT_API_KEY exported
124
152
cloudcraft = Cloudcraft()
125
153
script_dir = os.path.dirname(os.path.realpath(__file__ )) + os.sep
126
154
@@ -133,20 +161,14 @@ with open(bp_file, "wb") as binary_file:
133
161
binary_file.write(export)
134
162
```
135
163
136
- #### Delete blueprint
137
-
138
- ``` python
139
- cloudcraft = Cloudcraft()
140
-
141
- blueprint_id = " BLUEPRINT-ID" # valid blueprint uuid
142
- cloudcraft.delete_blueprint(blueprint_id)
143
- ```
144
-
145
164
### AWS Accounts
146
165
147
166
#### Add AWS account
148
167
149
168
``` python
169
+ from cloudcraftco.cloudcraft import Cloudcraft
170
+
171
+ # assumes CLOUDCRAFT_API_KEY exported
150
172
cloudcraft = Cloudcraft()
151
173
152
174
# role must exist and match your api_key/account
@@ -158,14 +180,57 @@ result = cloudcraft.create_aws_account(data)
158
180
#### List AWS accounts
159
181
160
182
``` python
183
+ from cloudcraftco.cloudcraft import Cloudcraft
184
+
185
+ # assumes CLOUDCRAFT_API_KEY exported
161
186
cloudcraft = Cloudcraft()
162
187
163
188
accounts = cloudcraft.list_aws_accounts()
164
189
```
165
190
191
+ #### Update AWS account
192
+
193
+ ``` python
194
+ from cloudcraftco.cloudcraft import Cloudcraft
195
+
196
+ # assumes CLOUDCRAFT_API_KEY exported
197
+ cloudcraft = Cloudcraft()
198
+
199
+ account_id = " AWS-ACCOUNT" # valid account uuid for api-key
200
+ role = " AWS-ROLE" # valid role for AWS Account
201
+ data = {" name" : " Updated Playground AWS Account" , " roleArn" : role}
202
+ result = cloudcraft.update_aws_account(account_id, data)
203
+ ```
204
+
205
+ #### Delete AWS account
206
+
207
+ ``` python
208
+ from cloudcraftco.cloudcraft import Cloudcraft
209
+
210
+ # assumes CLOUDCRAFT_API_KEY exported
211
+ cloudcraft = Cloudcraft()
212
+
213
+ account_id = " AWS-ACCOUNT" # valid account uuid for api-key
214
+ cloudcraft.delete_aws_account(account_id)
215
+ ```
216
+
217
+ #### Get my AWS IAM Role parameters
218
+
219
+ ``` python
220
+ from cloudcraftco.cloudcraft import Cloudcraft
221
+
222
+ # assumes CLOUDCRAFT_API_KEY exported
223
+ cloudcraft = Cloudcraft()
224
+
225
+ iam_parameters = cloudcraft.read_aws_role_parameters()
226
+ ```
227
+
166
228
#### Snapshot AWS account
167
229
168
230
``` python
231
+ from cloudcraftco.cloudcraft import Cloudcraft
232
+
233
+ # assumes CLOUDCRAFT_API_KEY exported
169
234
cloudcraft = Cloudcraft()
170
235
script_dir = os.path.dirname(os.path.realpath(__file__ )) + os.sep
171
236
@@ -179,39 +244,95 @@ with open(ss_file, "wb") as binary_file:
179
244
binary_file.write(snapshot)
180
245
```
181
246
182
- #### Update AWS account
247
+ ### Azure Accounts
248
+
249
+ #### Add Azure account
183
250
184
251
``` python
252
+ from cloudcraftco.cloudcraft import Cloudcraft
253
+
254
+ # assumes CLOUDCRAFT_API_KEY exported
185
255
cloudcraft = Cloudcraft()
186
256
187
- account_id = " AWS-ACCOUNT" # valid account uuid for api-key
188
- role = " AWS-ROLE" # valid role for AWS Account
189
- data = {" name" : " Updated Playground AWS Account." , " roleArn" : role}
190
- result = cloudcraft.update_aws_account(account_id, data)
257
+ # id and secret values must be valid
258
+ data = {
259
+ " name" : " Azure Account" ,
260
+ " subscriptionId" : " subscriptionId" ,
261
+ " directoryId" : " directoryId" ,
262
+ " applicationId" : " applicationId" ,
263
+ " clientSecret" : " clientSecret"
264
+ }
265
+ result = cloudcraft.create_azure_account(data)
191
266
```
192
267
193
- #### Delete AWS account
268
+ #### List Azure accounts
194
269
195
270
``` python
271
+ from cloudcraftco.cloudcraft import Cloudcraft
272
+
273
+ # assumes CLOUDCRAFT_API_KEY exported
196
274
cloudcraft = Cloudcraft()
197
275
198
- account_id = " AWS-ACCOUNT" # valid account uuid for api-key
199
- cloudcraft.delete_aws_account(account_id)
276
+ accounts = cloudcraft.list_azure_accounts()
200
277
```
201
278
202
- #### Get my AWS IAM Role parameters
279
+ #### Update Azure account
203
280
204
281
``` python
282
+ from cloudcraftco.cloudcraft import Cloudcraft
283
+
284
+ # assumes CLOUDCRAFT_API_KEY exported
205
285
cloudcraft = Cloudcraft()
206
286
207
- iam_parameters = cloudcraft.read_aws_role_parameters()
287
+ account_id = " AZURE-ACCOUNT" # valid account uuid for api-key
288
+ data = {
289
+ " name" : " Updated Azure Account" ,
290
+ " subscriptionId" : " subscriptionId" ,
291
+ " directoryId" : " directoryId" ,
292
+ " applicationId" : " applicationId" ,
293
+ }
294
+ result = cloudcraft.update_azure_account(account_id, data)
295
+ ```
296
+
297
+ #### Delete Azure account
298
+
299
+ ``` python
300
+ from cloudcraftco.cloudcraft import Cloudcraft
301
+
302
+ # assumes CLOUDCRAFT_API_KEY exported
303
+ cloudcraft = Cloudcraft()
304
+
305
+ account_id = " AZURE-ACCOUNT" # valid account uuid for api-key
306
+ cloudcraft.delete_azure_account(account_id)
307
+ ```
308
+
309
+ #### Snapshot Azure account
310
+
311
+ ``` python
312
+ from cloudcraftco.cloudcraft import Cloudcraft
313
+
314
+ # assumes CLOUDCRAFT_API_KEY exported
315
+ cloudcraft = Cloudcraft()
316
+ script_dir = os.path.dirname(os.path.realpath(__file__ )) + os.sep
317
+
318
+ ss_account = " AZURE-ACCOUNT" # valid account uuid for api-key
319
+ ss_location = " canadaeast"
320
+ ss_format = " png"
321
+ ss_file = script_dir + ss_location + " ." + ss_format
322
+ snapshot = cloudcraft.snapshot_azure_account(ss_account, ss_location, ss_format)
323
+
324
+ with open (ss_file, " wb" ) as binary_file:
325
+ binary_file.write(snapshot)
208
326
```
209
327
210
328
### Budgets
211
329
212
330
#### Export budget for a blueprint
213
331
214
332
``` python
333
+ from cloudcraftco.cloudcraft import Cloudcraft
334
+
335
+ # assumes CLOUDCRAFT_API_KEY exported
215
336
cloudcraft = Cloudcraft()
216
337
script_dir = os.path.dirname(os.path.realpath(__file__ )) + os.sep
217
338
@@ -229,6 +350,9 @@ with open(bp_file, "wb") as binary_file:
229
350
#### Get Cloudcraft account info
230
351
231
352
``` python
353
+ from cloudcraftco.cloudcraft import Cloudcraft
354
+
355
+ # assumes CLOUDCRAFT_API_KEY exported
232
356
cloudcraft = Cloudcraft()
233
357
234
358
profile = cloudcraft.read_user_profile()
@@ -264,14 +388,21 @@ Testing accounts requires care, since creating an account requires valid role.
264
388
% cd {repo-directory}
265
389
% poetry env use python3.10
266
390
% poetry shell
391
+ % poetry install
267
392
% export CLOUDCRAFT_API_KEY={{ api-key }}
268
- % export CLOUDCRAFT_TEST_ROLE={{ your-test-role-arn }}
269
- % python3 dev_playgrounds/accounts.py
270
393
% python3 dev_playgrounds/blueprints.py
271
394
% python3 dev_playgrounds/budgets.py
272
395
% python3 dev_playgrounds/exports.py
273
- % python3 dev_playgrounds/snapshots.py
396
+ % python3 dev_playgrounds/snapshots_aws.py
397
+ % python3 dev_playgrounds/snapshots_azure.py
274
398
% python3 dev_playgrounds/users.py
399
+ % export CLOUDCRAFT_TEST_ROLE={{ your-role-arn }}
400
+ % python3 dev_playgrounds/accounts_aws.py
401
+ % export CLOUDCRAFT_TEST_SUBSCRIPTION={{ your-subscription-id }}
402
+ % export CLOUDCRAFT_TEST_DIRECTORY={{ your-directory-id }}
403
+ % export CLOUDCRAFT_TEST_APPLICATION={{ your-application-id }}
404
+ % export CLOUDCRAFT_TEST_SECRET={{ your-client-secret }}
405
+ % python3 dev_playgrounds/accounts_azure.py
275
406
```
276
407
277
408
### Running Tests
0 commit comments