in cartography/intel/gcp/compute.py [0:0]
def load_gcp_instances(neo4j_session, data, gcp_update_tag):
"""
Ingest GCP instance objects to Neo4j
:param neo4j_session: The Neo4j session object
:param data: List of GCP instances to ingest. Basically the output of
https://cloud.google.com/compute/docs/reference/rest/v1/instances/list
:param gcp_update_tag: The timestamp value to set our new Neo4j nodes with
:return: Nothing
"""
query = """
MERGE (p:GCPProject{id:{ProjectId}})
ON CREATE SET p.firstseen = timestamp()
SET p.lastupdated = {gcp_update_tag}
MERGE (i:Instance:GCPInstance{id:{PartialUri}})
ON CREATE SET i.firstseen = timestamp(),
i.partial_uri = {PartialUri}
SET i.self_link = {SelfLink},
i.instancename = {InstanceName},
i.hostname = {Hostname},
i.zone_name = {ZoneName},
i.project_id = {ProjectId},
i.lastupdated = {gcp_update_tag}
WITH i, p
MERGE (p)-[r:RESOURCE]->(i)
ON CREATE SET r.firstseen = timestamp()
SET r.lastupdated = {gcp_update_tag}
"""
for instance in data:
neo4j_session.run(
query,
ProjectId=instance['project_id'],
PartialUri=instance['partial_uri'],
SelfLink=instance['selfLink'],
InstanceName=instance['name'],
ZoneName=instance['zone_name'],
Hostname=instance.get('hostname', None),
gcp_update_tag=gcp_update_tag
)
_attach_instance_tags(neo4j_session, instance, gcp_update_tag)
_attach_gcp_nics(neo4j_session, instance, gcp_update_tag)
_attach_gcp_vpc(neo4j_session, instance['partial_uri'], gcp_update_tag)