Importer implementations.

class EmptyImporter(session, readonly_session, model, dao, _, *args, **kwargs)[source]

Bases: object

Imports an empty model.


Runs the import.

class InventoryImporter(session, readonly_session, model, dao, service_config, inventory_index_id, *args, **kwargs)[source]

Bases: object

Imports data from Inventory.

_add_to_cache(resource, resource_id)[source]

Add a resource to the cache for parent lookup.

  • resource (object) – Resource to put in the cache.
  • resource_id (int) – The database key for the resource.

Convert an AppEngine resource to a database object.

Parameters:gae_resource (dict) – An appengine resource to store.

Convert a backendservice to a database object.

Parameters:backendservice (object) – Backendservice to store.

Convert a billing account to a database object.

Parameters:billing_account (object) – billing account to store.

Convert a bucket to a database object.

Parameters:bucket (object) – Bucket to store.

Convert a cloudsqlinstance to a database object.

Parameters:cloudsqlinstance (object) – Cloudsql to store.

Convert a computeproject to a database object.

Parameters:computeproject (object) – computeproject to store.

Convert a dataset to a database object.

Parameters:dataset (object) – Dataset to store.

Convert a dataset policy to a database object.

Parameters:dataset_policy (object) – Dataset policy to store.

Convert a disk to a database object.

Parameters:disk (object) – Disk to store.

Convert a description of enabled APIs to a database object.

Parameters:enabled_apis (object) – Enabled APIs description to store.

Convert a firewall to a database object.

Parameters:firewall (object) – Firewall to store.

Convert a folder to a database object.

Parameters:folder (object) – Folder to store.

Convert a forwarding rule to a database object.

Parameters:forwardingrule (object) – ForwardingRule to store.

Convert an IAM policy to a database object.

Parameters:iam_policy (object) – IAM policy to store.

Convert a image to a database object.

Parameters:image (object) – Image to store.

Convert a instance to a database object.

Parameters:instance (object) – Instance to store.

Convert a instancegroup to a database object.

Parameters:instancegroup (object) – Instancegroup to store.

Convert a instancegroupmanager to a database object.

Parameters:instancegroupmanager (object) – InstanceGroupManager to store.

Convert a instancetemplate to a database object.

Parameters:instancetemplate (object) – InstanceTemplate to store.

Convert an AppEngine resource to a database object.

Parameters:cluster (dict) – A Kubernetes cluster resource to store.

Convert a lien to a database object.

Parameters:lien (object) – Lien to store.

Convert a network to a database object.

Parameters:network (object) – Network to store.

Not Implemented

Parameters:gcsobject (object) – Object to store.

Convert an organization a database object.

Parameters:organization (object) – Organization to store.

Convert a project to a database object.

Parameters:project (object) – Project to store.

Convert a role to a database object.

Parameters:role (object) – Role to store.

Executed after all roles were handled. Performs bulk insert.


Executed before roles are handled. Prepares for bulk insert.


Convert Kubernetes Service Config to a database object.

Parameters:service_config (dict) – A Service Config resource to store.

Convert a service account to a database object.

Parameters:service_account (object) – Service account to store.

Convert a service account key to a database object.

Parameters:service_account_key (object) – Service account key to store.

Convert a log sink to a database object.

Parameters:sink (object) – Sink to store.

Convert a snapshot to a database object.

Parameters:snapshot (object) – Snapshot to store.

Convert a subnetwork to a database object.

Parameters:subnetwork (object) – Subnetwork to store.

Returns the parent object, full resource name and type name.

  • resource (object) – Resource whose full resource name and parent
  • be returned. (should) –

full resource name for the provided resource.

Return type:



Return the parent object for a resource from cache.

Parameters:resource (object) – Resource whose parent to look for.
Returns:cached object and full resource name
Return type:tuple

Check to see if the session contains Role with primary key = role_name.

Parameters:role_name (str) – The role name (Primary key of the role table).
Whether or not session contains Role with
primary key = role_name.
Return type:bool

Checks if the resource is an inventory root. Result is cached.

Parameters:resource (object) – Resource to check.
Returns:Whether the resource is root or not
Return type:bool
_store_gsuite_membership(child, parent)[source]

Store a gsuite principal such as a group, user or member.

  • child (object) – member item.
  • parent (object) – parent part of membership.

Flush storing gsuite memberships.


Prepare storing gsuite memberships.


Store a gsuite principal such as a group, user or member.

Parameters:principal (object) – object to store.
Raises:Exception – if the principal type is unknown.

Store the iam policy of the resource.

Parameters:policy (object) – IAM policy to store.
Raises:KeyError – if member could not be found in any cache.

Executed after iam policies are inserted.


Executed before iam policies are inserted.

_store_resource(resource, last_res_type=None)[source]

Store an inventory resource in the database.

  • resource (object) – Resource object to convert from.
  • last_res_type (str) – Previously processed resource type used to spot transition between types to execute pre/handler/post accordingly.

Resource type that was processed during the execution.

Return type:



Return the type/name for that resource.

Parameters:resource (object) – Resource to retrieve type/name for.
Returns:type/name representation of the resource.
Return type:str
static model_action_wrapper(session, inventory_iterable, pre_action, action, post_action, flush_count)[source]

Model action wrapper. This is used to reduce code duplication.

  • session (Session) – Database session.
  • inventory_iterable (Iterable) – Inventory iterable.
  • pre_action (func) – Action taken before iterating the inventory list.
  • action (func) – Action taken during the iteration of the inventory list.
  • post_action (func) – Action taken after iterating the inventory list.
  • flush_count (int) – Flush every flush_count times.

Number of item iterated.

Return type:



Runs the import.

Raises:NotImplementedError – If the importer encounters an unknown inventory type.
class ResourceCache[source]

Bases: dict

Resource cache.

__setitem__(key, value)[source]

Overriding to assert the keys does not exist previously.

  • key (object) – Key into the dict.
  • value (object) – Value to set.

Exception – If the key already exists in the dict.


Helper to resolve client provided import sources.

Parameters:source (str) – Source to import from.
Returns:Chosen by source.
Return type:Importer