
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 Cells 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 Cells
The Cells API implements pagination. This means that by default, it does not return all cells known to Craton. To ignore page limits and offsets, we can allow cratonclient to do handle pagination for us:
for cell in craton.cells.list():
print_cell_info(cell)
By default ~cratonclient.v1.cells.CellManager.list
will handle
pagination for you. If, instead, you want to handle it yourself you will
want to do something akin to:
= list(craton.cells.list(autopaginate=False))
first_page_of_cells = first_page_of_cells[-1].id
marker_id = list(craton.cells.list(
second_page_of_cells =False,
autopaginate=marker_id,
marker
))= second_page_of_cells[-1].id
marker_id = list(craton.cells.list(
third_page_of_cells =False,
autopaginate=marker_id,
marker
))# etc.
A more realistic example, however, might look like this:
= None
cells_list = None
marker while cells_list and cells_list is not None:
= list(craton.cells.list(
cells_list =marker,
marker=False,
autopaginate
))# do something with cells_list
if cells_list:
= cells_list[-1].id marker
This will have the effect of stopping the while loop when you
eventually receive an empty list from
craton.cells.list(...)
.
Creating Cells
Cells live below a Region in Craton. To create a cell, the only
required items are a name
for the cell, a cloud ID, and a
region ID. The name must be unique among cells in the same project.
= craton.cells.create(
cell ='my-cell-0',
name=cloud_id,
cloud_id=region_id,
region_id='This is my cell, there are many like it, but this is mine.',
note={
variables'some-var': 'some-var-value',
}, )
Retrieving a Specific Cell
Cells can be retrieved by id.
= craton.cells.get(1) cell
Using a Cell's Variables
Once we have a cell we can introspect its variables like so:
= craton.cells.get(cell_id)
cell = cell.variables.get() cell_vars
To update them:
= {
updated_vars 'var-a': 'new-var-a',
'var-b': 'new-var-b',
'updated-var': 'updated value',
}**updated_vars) cell.variables.update(
To delete them:
'var-a', 'var-b', 'updated-var') cell.variables.delete(
Updating a Cell
We can update a cell's attributes (but not its variables) like so:
craton.cells.update(
cell_id,='new name',
name='Updated note.',
note )
Most attributes that you can specify on creation can also be specified for updating the cell as well.
Deleting a Cell
We can delete with only its id:
craton.cells.delete(cell_id)