altimeter.core.resource package

Submodules

altimeter.core.resource.exceptions module

Resource related Exceptions.

exception MultipleResourceSpecClassesFoundException

Bases: altimeter.core.exceptions.AltimeterException

More than one ResourceSpec class exist for a given specification.

exception ResourceSpecClassNotFoundException

Bases: altimeter.core.exceptions.AltimeterException

A specified ResourceSpecClass can not be found.

altimeter.core.resource.resource module

class Resource(**data)

Bases: altimeter.core.base_model.BaseImmutableModel

A Resource defines a single scanned resource which is directly translatable to a graph node. It contains an id, type name and list of Links.

Parameters
  • resource_id – id of this resource

  • type – type name of this resource

  • link_collection – a LinkCollection representing links from this resource

resource_id: str
to_lpg(vertices, edges)

Graph this Resource as a dictionary into the vertices and edges lists.

Parameters
  • vertices (List[Dict]) – List containing dictionaries representing a vertex

  • edges (List[Dict]) – List containing dictionaries representing an edge

Return type

None

to_rdf(namespace, graph, node_cache)

Graph this Resource as a URIRef on a Graph.

Parameters
  • namespace (Namespace) – RDF namespace to use for predicates and objects when graphing this resource’s links

  • graph (Graph) – RDF graph

  • node_cache (NodeCache) – NodeCache to use for any cached URIRef lookups

Return type

None

type: str

altimeter.core.resource.resource_spec module

A ResourceSpec defines how an individual resource (e.g. EC2 Instances) JSON is converted into graph data. It contains a Schema which contains a set of Fields defining the transformation.

class ResourceSpec

Bases: abc.ABC

A ResourceSpec defines how an individual resource (e.g. EC2 Instances) JSON is converted into graph data. It contains a Schema which contains a set of Fields defining the transformation.

allow_clobber: List[Type] = []
classmethod generate_id(short_resource_id, context)

Generate a full id for this type given a short_resource_id.

Parameters
  • short_resource_id (str) – short resource id for this resource

  • context (Dict[str, Any]) – contains auxiliary information which can be passed through the parse process.

Return type

str

Returns

full resource id string

static get_by_class_name(class_name)

Get a ResourceSpec class by class name.

Parameters

class_name (str) – class name to match

Return type

Type[ResourceSpec]

Returns

ResourceSpec subclass

Raises
  • MultipleResourceSpecClassesFoundException if more than one match was found. – this indicates a code bug.

  • ResourceSpecClassNotFoundException if no ResourceSpec class was found.

static get_by_full_type_name(type_name)

Get a ResourceSpec classes by full_type name.

Parameters

type_name (str) – type name of ResourceSpec to find

Return type

List[Type[ResourceSpec]]

Returns

list of ResourceSpec classes matching type_name

Raises
  • ResourceSpecClassNotFoundException if no ResourceSpec classes could be

  • found matching type_name.

classmethod get_full_type_name()

Get the fully qualified type name for this class. Generally this is something like aws:ec2:type_name.

Return type

str

Returns

full resource type name string

static merge_resources(resource_id, resources)

Merge multiple resources with the same id into one. This is permissible in two cases:

1) If all resources have the same value for ‘get_full_type’ and no key/values conflict they will be merged into a single resource by combining all key/values into a single resource

2) If all resources do not have the same value for ‘get_full_type’, if classes have the allow_clobber attribute set depending on the values a resource may be created.

Parameters
  • resource_id (str) – common resource id

  • resources (List[Resource]) – list of Resources to merge

Return type

Resource

Returns

merged Resource object

Raises

UnmergableDuplicateResourceIdsFoundException if resources could not be merged.

abstract classmethod scan(scan_accessor)

Scan for this ResourceSpec using scan_accessor and return a list of Resource objects

Parameters

scan_accessor (Any) – scan accessor object for accessing required APIs

Return type

List[Resource]

Returns

List of Resource objects

schema: altimeter.core.graph.schema.Schema = <altimeter.core.graph.schema.Schema object>
type_name: str = ''
get_concrete_subclasses(cls)

Get all concrete subclasses of a class.

Parameters

cls (Type[Any]) – class to find subclasses of

Return type

List[Type]

Returns

list of classes which are concrete subclasses of cls

Module contents