11
11
import uuid
12
12
13
13
from dateutil .parser import parse
14
+ from django .db import IntegrityError
14
15
from django .db .models import DecimalField
15
16
from django .db .models import F
16
17
from django .db .models import Value
@@ -836,7 +837,16 @@ def populate_cluster_table(self, provider, cluster_id, cluster_alias):
836
837
837
838
def populate_node_table (self , cluster , nodes ):
838
839
"""Get or create an entry in the OCP node table."""
839
- LOG .info (log_json (msg = "populating reporting_ocp_nodes table" , schema = self .schema , cluster = cluster ))
840
+
841
+ LOG .info (
842
+ log_json (
843
+ msg = "populating reporting_ocp_nodes table" ,
844
+ schema = self .schema ,
845
+ cluster_id = cluster .cluster_id ,
846
+ cluster_alias = cluster .cluster_alias ,
847
+ )
848
+ )
849
+
840
850
for node in nodes :
841
851
tmp_node = OCPNode .objects .filter (
842
852
node = node [0 ], resource_id = node [1 ], node_capacity_cpu_cores = node [2 ], cluster = cluster
@@ -856,23 +866,50 @@ def populate_node_table(self, cluster, nodes):
856
866
857
867
def populate_pvc_table (self , cluster , pvcs ):
858
868
"""Get or create an entry in the OCP cluster table."""
859
- LOG .info (log_json (msg = "populating reporting_ocp_pvcs table" , schema = self .schema , cluster = cluster ))
869
+
870
+ LOG .info (
871
+ log_json (
872
+ msg = "populating reporting_ocp_pvcs table" ,
873
+ schema = self .schema ,
874
+ cluster_id = cluster .cluster_id ,
875
+ cluster_alias = cluster .cluster_alias ,
876
+ )
877
+ )
878
+
860
879
for pvc in pvcs :
861
- try :
862
- ocppvc = OCPPVC .objects .get (persistent_volume = pvc [0 ], persistent_volume_claim = pvc [1 ], cluster = cluster )
880
+ ocppvc = OCPPVC .objects .filter (
881
+ persistent_volume = pvc [0 ], persistent_volume_claim = pvc [1 ], cluster = cluster
882
+ ).first ()
883
+ if ocppvc :
863
884
if not ocppvc .csi_volume_handle :
864
885
# Update the existing record's csi_volume_handle
865
886
ocppvc .csi_volume_handle = pvc [2 ]
866
887
ocppvc .save (update_fields = ["csi_volume_handle" ])
867
- except OCPPVC .DoesNotExist :
868
- # If the record does not exist, create a new one
869
- OCPPVC .objects .create (
870
- persistent_volume = pvc [0 ], persistent_volume_claim = pvc [1 ], csi_volume_handle = pvc [2 ], cluster = cluster
871
- )
888
+ else :
889
+ # If the record does not exist, try creating a new one
890
+ try :
891
+ OCPPVC .objects .create (
892
+ persistent_volume = pvc [0 ],
893
+ persistent_volume_claim = pvc [1 ],
894
+ csi_volume_handle = pvc [2 ],
895
+ cluster = cluster ,
896
+ )
897
+
898
+ except IntegrityError as e :
899
+ LOG .warning (log_json (msg = "IntegrityError raised when creating pvc" , pvc = pvc ), exc_info = e )
872
900
873
901
def populate_project_table (self , cluster , projects ):
874
902
"""Get or create an entry in the OCP cluster table."""
875
- LOG .info (log_json (msg = "populating reporting_ocp_projects table" , schema = self .schema , cluster = cluster ))
903
+
904
+ LOG .info (
905
+ log_json (
906
+ msg = "populating reporting_ocp_projects table" ,
907
+ schema = self .schema ,
908
+ cluster_id = cluster .cluster_id ,
909
+ cluster_alias = cluster .cluster_alias ,
910
+ )
911
+ )
912
+
876
913
for project in projects :
877
914
OCPProject .objects .get_or_create (project = project , cluster = cluster )
878
915
0 commit comments