def import_role_relations(self, obj, d): if obj.venture_id: # first venturerole in hierarchy, connect it to venture venture_ci = cdb.CI.objects.get( content_type=self.venture_content_type, object_id=obj.venture_id) cir = cdb.CIRelation() cir.readonly = True cir.parent = venture_ci cir.child = d cir.type = cdb.CI_RELATION_TYPES.HASROLE.id try: cir.save() except IntegrityError: pass if obj.parent: cir = cdb.CIRelation() cir.readonly = True cir.child = d cir.parent = cdb.CI.objects.filter( content_type_id=self.venture_role_content_type, object_id=obj.parent.id)[0] cir.type = cdb.CI_RELATION_TYPES.CONTAINS.id try: cir.save() except IntegrityError: pass
def import_venture_relations(self, obj, d): """ Must be called after datacenter """ if obj.data_center_id: datacenter_ci = cdb.CI.objects.filter( content_type=self.datacenter_content_type, object_id=obj.data_center_id).all()[0] cir = cdb.CIRelation() cir.readonly = True cir.parent = datacenter_ci cir.child = d cir.type = cdb.CI_RELATION_TYPES.REQUIRES.id try: cir.save() except IntegrityError: pass if obj.parent: logger.info('Saving relation: %s' % obj) cir = cdb.CIRelation() cir.readonly = True cir.child = d cir.parent = cdb.CI.objects.filter( content_type_id=self.venture_content_type, object_id=obj.parent.id)[0] cir.type = cdb.CI_RELATION_TYPES.CONTAINS.id try: cir.save() except IntegrityError: pass
def import_device_relations(self, obj, d): """ Must be called after ventures """ for x in cdb.CIRelation.objects.filter( child=d, readonly=True): x.delete() if obj.venture_id: venture_ci = cdb.CI.objects.get( content_type=self.venture_content_type, object_id=obj.venture_id) cir = cdb.CIRelation() cir.readonly = True cir.parent = venture_ci cir.child = d cir.type = cdb.CI_RELATION_TYPES.CONTAINS.id try: cir.save() except IntegrityError: pass if obj.venture_role_id: venture_role_ci = cdb.CI.objects.get( content_type=self.venture_role_content_type, object_id=obj.venture_role_id) cir = cdb.CIRelation() cir.readonly = True cir.parent = venture_role_ci cir.child = d cir.type = cdb.CI_RELATION_TYPES.HASROLE.id try: cir.save() except IntegrityError: pass if obj.parent: logger.info('Saving relation: %s' % obj) cir = cdb.CIRelation() cir.readonly = True cir.child = d cir.parent = cdb.CI.objects.get( content_type=self.device_content_type, object_id=obj.parent.id) cir.type = cdb.CI_RELATION_TYPES.CONTAINS.id try: cir.save() except IntegrityError: pass
def import_service_relations(self, obj, d): if obj.business_line: bline = cdb.CI.objects.get( content_type=self.business_line_content_type, name=obj.business_line, ) cir = cdb.CIRelation() cir.parent = bline cir.child = d cir.readonly = True cir.type = cdb.CI_RELATION_TYPES.CONTAINS.id cir.save()
def import_network_relations(self, network): """ Must be called after device_relations! """ """ Make relations using network->ipaddresses->device """ for ip in ndb.IPAddress.objects.filter( device__isnull=False, network=network.content_object).all(): # make relations network->device ci_device = cdb.CI.objects.get( content_type=self.device_content_type, object_id=ip.device.id, ) cir = cdb.CIRelation() cir.readonly = True cir.parent = network cir.child = ci_device cir.type = cdb.CI_RELATION_TYPES.CONTAINS.id try: cir.save() except IntegrityError: pass