google.cloud.forseti.services.inventory.inventory module

Inventory API.

class FirstMessageQueueProgresser(*args, **kwargs)[source]

Bases: google.cloud.forseti.services.inventory.inventory.QueueProgresser

Queue base progresser

Only delivers first message. Then throws away all subsequent messages. This is used to make sure that we’re not creating an internal buffer of infinite size as we’re crawling in background without a queue consumer.

_notify()[source]

Notify status update into queue.

_notify_eof()[source]

Notify end of status updates into queue.

class Inventory(config)[source]

Bases: object

Inventory API implementation.

create(background, model_name)[source]

Create a new inventory,

Parameters:
  • background (bool) – Run import in background, return immediately
  • model_name (str) – Model name to import into
Yields:

object – Yields status updates.

delete(inventory_id)[source]

Delete an inventory by id.

Parameters:inventory_id (str) – Id of the inventory.
Returns:Inventory object that was deleted.
Return type:object
get(inventory_id)[source]

Get inventory metadata by id.

Parameters:inventory_id (str) – Id of the inventory.
Returns:Inventory metadata.
Return type:object
list()[source]

List stored inventory.

Yields:object – Inventory metadata.
purge(retention_days)[source]

Purge the gcp_inventory data that’s older than the retention days.

Parameters:retention_days (string) – Days of inventory tables to retain.
Returns:Purge result.
Return type:str
class Progress(final_message=False, step='', inventory_index_id='')[source]

Bases: object

Progress state.

class QueueProgresser(queue)[source]

Bases: google.cloud.forseti.services.inventory.inventory.Progress

Queue based progresser.

_notify()[source]

Notify status update into queue.

_notify_eof()[source]

Notify end of status updates into queue.

get_summary()[source]

Indicate end of updates, and return self as last state.

Returns:Progresser in its last state.
Return type:object
on_error(error)[source]

Stores the error and updates the counter.

Parameters:error (str) – error message
on_new_object(resource)[source]

Update the status with the new resource.

Parameters:resource (Resource) – db row of Resource
on_warning(warning)[source]

Stores the warning and updates the counter.

Parameters:warning (str) – warning message
run_import(client, model_name, inventory_index_id, background)[source]

Runs the import against an inventory.

Parameters:
  • client (object) – Api client to use.
  • model_name (str) – Model name to create.
  • inventory_index_id (int64) – Inventory index to source.
  • background (bool) – If the import should run in background.
Returns:

RPC response object to indicate status.

Return type:

object

run_inventory(service_config, queue, session, progresser, background)[source]

Runs the inventory given the environment configuration.

Parameters:
  • service_config (object) – Service configuration.
  • queue (object) – Queue to push status updates into.
  • session (object) – Database session.
  • progresser (object) – Progresser implementation to use.
  • background (bool) – whether to run the inventory in background
Returns:

Returns the result of the crawl.

Return type:

QueueProgresser

Raises:

Exception – Reraises any exception.