
This corrects some typos in earlier documentation patches, removes outdated API reference documentation, and organizes all API reference documentation under one chapter. This also leaves room for future API versions and more specific API reference documentation being broken out into sub-sections. Change-Id: I5391a1acc7d1669207b3d10039a196d026216f40
3.2 KiB
Using the Clouds API
Here we will assume that we already have a ~cratonclient.client.Client
instance configured with the appropriate authentication method (as
demonstrated in usage-auth
).
Listing Clouds
The Clouds API implements pagination. This means that by default, it does not return all clouds known to Craton. To ignore page limits and offsets, we can allow cratonclient to do handle pagination for us:
for cloud in craton.clouds.list():
print_cloud_info(cloud)
By default ~cratonclient.v1.clouds.CloudManager.list
will handle
pagination for you. If, instead, you want to handle it yourself you will
want to do something akin to:
= list(craton.clouds.list(autopaginate=False))
first_page_of_clouds = first_page_of_clouds[-1].id
marker_id = list(craton.clouds.list(
second_page_of_clouds =False,
autopaginate=marker_id,
marker
))= second_page_of_clouds[-1].id
marker_id = list(craton.clouds.list(
third_page_of_clouds =False,
autopaginate=marker_id,
marker
))# etc.
A more realistic example, however, might look like this:
= None
clouds_list = None
marker while clouds_list and clouds_list is not None:
= list(craton.clouds.list(
clouds_list =marker,
marker=False,
autopaginate
))# do something with clouds_list
if clouds_list:
= clouds_list[-1].id marker
This will have the effect of stopping the while loop when you
eventually receive an empty list from
craton.clouds.list(...)
.
Creating Clouds
Clouds are the top-level item in Craton. To create a cloud, the only
required item is a name
for the cloud. This must be unique
among clouds in the same project.
= craton.clouds.create(
cloud ='my-cloud-0',
name='This is my cloud, there are many like it, but this is mine.',
note={
variables'some-var': 'some-var-value',
}, )
Retrieving a Specific Cloud
Clouds can be retrieved by id.
= craton.clouds.get(1) cloud
Using a Cloud's Variables
Once we have a cloud we can introspect its variables like so:
= craton.clouds.get(cloud_id)
cloud = cloud.variables.get() cloud_vars
To update them:
= {
updated_vars 'var-a': 'new-var-a',
'var-b': 'new-var-b',
'updated-var': 'updated value',
}**updated_vars) cloud.variables.update(
To delete them:
'var-a', 'var-b', 'updated-var') cloud.variables.delete(
Updating a Cloud
We can update a cloud's attributes (but not its variables) like so:
craton.clouds.update(
cloud_id,='new name',
name='Updated note.',
note )
Most attributes that you can specify on creation can also be specified for updating the cloud as well.
Deleting a Cloud
We can delete with only its id:
craton.clouds.delete(cloud_id)