22
22
23
23
24
24
def print_drgv2 (values_for_column_drgv2 , region , comp_name , vcn_info , drg_info , drg_attachment_info , drg_rt_info ,
25
- import_drg_route_distribution_info , drg_route_distribution_statements ):
25
+ import_drg_route_distribution_info , drg_route_distribution_statements , write_drg_ocids ):
26
26
for col_header in values_for_column_drgv2 .keys ():
27
27
if (col_header == "Region" ):
28
28
values_for_column_drgv2 [col_header ].append (region )
29
29
elif (col_header == "Compartment Name" ):
30
30
values_for_column_drgv2 [col_header ].append (comp_name )
31
31
elif (col_header == "DRG Name" ):
32
- values_for_column_drgv2 [col_header ].append (drg_info .display_name )
32
+ if write_drg_ocids == True :
33
+ values_for_column_drgv2 [col_header ].append (drg_info .id )
34
+ else :
35
+ values_for_column_drgv2 [col_header ].append (drg_info .display_name )
36
+
33
37
elif (col_header == "Attached To" ):
34
38
if (drg_attachment_info is None ):
35
39
values_for_column_drgv2 [col_header ].append ('' )
@@ -53,12 +57,19 @@ def print_drgv2(values_for_column_drgv2, region, comp_name, vcn_info, drg_info,
53
57
if (drg_rt_info == None ):
54
58
values_for_column_drgv2 [col_header ].append ("" )
55
59
else :
56
- values_for_column_drgv2 [col_header ].append (drg_rt_info .display_name )
60
+ if write_drg_ocids == True :
61
+ values_for_column_drgv2 [col_header ].append (drg_rt_info .id )
62
+ else :
63
+ values_for_column_drgv2 [col_header ].append (drg_rt_info .display_name )
64
+
57
65
elif (col_header == 'Import DRG Route Distribution Name' ):
58
66
if import_drg_route_distribution_info == None :
59
67
values_for_column_drgv2 [col_header ].append ("" )
60
68
else :
61
- values_for_column_drgv2 [col_header ].append (import_drg_route_distribution_info .display_name )
69
+ if write_drg_ocids == True :
70
+ values_for_column_drgv2 [col_header ].append (import_drg_route_distribution_info .id )
71
+ else :
72
+ values_for_column_drgv2 [col_header ].append (import_drg_route_distribution_info .display_name )
62
73
elif (col_header == "Import DRG Route Distribution Statements" ):
63
74
statement_val = ''
64
75
if (drg_route_distribution_statements == None ):
@@ -90,7 +101,7 @@ def print_drgv2(values_for_column_drgv2, region, comp_name, vcn_info, drg_info,
90
101
91
102
92
103
def print_vcns (values_for_column_vcns , region , comp_name , vnc ,vcn_info , drg_attachment_info , igw_info , ngw_info , sgw_info ,
93
- lpg_display_names ,state ):
104
+ lpg_display_names ,state , write_drg_ocids ):
94
105
drg_info = None
95
106
for col_header in values_for_column_vcns .keys ():
96
107
@@ -106,10 +117,17 @@ def print_vcns(values_for_column_vcns, region, comp_name, vnc,vcn_info, drg_atta
106
117
values_for_column_vcns [col_header ].append ("n" )
107
118
else :
108
119
route_table_id = drg_attachment_info .route_table_id
109
- if (route_table_id is not None ):
110
- val = drg_info .display_name + "::" + vnc .get_route_table (route_table_id ).data .display_name
120
+ if write_drg_ocids == True :
121
+ if (route_table_id is not None ):
122
+ val = drg_info .id + "::" + vnc .get_route_table (route_table_id ).data .display_name
123
+ else :
124
+ val = drg_info .id
111
125
else :
112
- val = drg_info .display_name
126
+ if (route_table_id is not None ):
127
+ val = drg_info .display_name + "::" + vnc .get_route_table (route_table_id ).data .display_name
128
+ else :
129
+ val = drg_info .display_name
130
+
113
131
values_for_column_vcns [col_header ].append (val )
114
132
else :
115
133
values_for_column_vcns [col_header ].append ("n" )
@@ -620,6 +638,10 @@ def export_major_objects(inputfile, outdir, service_dir, config, signer, ct, exp
620
638
621
639
print ("Tabs- VCNs and DRGs would be overwritten during export process!!!\n " )
622
640
641
+ export_compartment_ids = []
642
+ for comp in export_compartments :
643
+ export_compartment_ids .append (ct .ntk_compartment_ids [comp ])
644
+
623
645
# Fetch DRGs
624
646
for reg in export_regions :
625
647
current_region = reg
@@ -637,6 +659,7 @@ def export_major_objects(inputfile, outdir, service_dir, config, signer, ct, exp
637
659
ntk_compartment_name ],
638
660
attachment_type = "ALL" ) # ,lifecycle_state ="ATTACHED")#,attachment_type="ALL")
639
661
rpc_execution = True
662
+ write_drg_ocids = False
640
663
for drg_attachment_info in DRG_Attachments .data :
641
664
if (drg_attachment_info .lifecycle_state != "ATTACHED" ):
642
665
continue
@@ -647,6 +670,11 @@ def export_major_objects(inputfile, outdir, service_dir, config, signer, ct, exp
647
670
# Attachment Data
648
671
drg_display_name = drg_info .display_name
649
672
drg_comp_id = drg_info .compartment_id
673
+
674
+ if drg_comp_id not in export_compartment_ids :
675
+ drg_display_name = drg_id
676
+ write_drg_ocids = True
677
+
650
678
for key , val in ct .ntk_compartment_ids .items ():
651
679
if val == drg_comp_id :
652
680
if ("::" in key ):
@@ -660,7 +688,7 @@ def export_major_objects(inputfile, outdir, service_dir, config, signer, ct, exp
660
688
if (drg_id not in drg_ocid ):
661
689
oci_obj_names [reg ].write ("\n DRG Version::::" + drg_display_name + "::::" + drg_version )
662
690
tf_resource = f'module.drgs[\\ "{ tf_name } \\ "].oci_core_drg.drg'
663
- if tf_resource not in state ["resources" ]:
691
+ if tf_resource not in state ["resources" ] and write_drg_ocids == False :
664
692
importCommands [reg ].write ( f'\n { tf_or_tofu } import "{ tf_resource } " { str (drg_info .id )} ' )
665
693
drg_ocid .append (drg_id )
666
694
@@ -700,15 +728,17 @@ def export_major_objects(inputfile, outdir, service_dir, config, signer, ct, exp
700
728
drg_route_table_info = vnc .get_drg_route_table (drg_route_table_id ).data
701
729
702
730
import_drg_route_distribution_id = drg_route_table_info .import_drg_route_distribution_id
731
+
703
732
if (import_drg_route_distribution_id != None ):
704
733
import_drg_route_distribution_info = vnc .get_drg_route_distribution (
705
734
import_drg_route_distribution_id ).data
735
+
706
736
drg_route_distribution_statements = vnc .list_drg_route_distribution_statements (
707
737
import_drg_route_distribution_info .id )
708
738
709
739
tf_name = commonTools .check_tf_variable (
710
740
drg_display_name + "_" + import_drg_route_distribution_info .display_name )
711
- if (import_drg_route_distribution_info .display_name not in commonTools .drg_auto_RDs ):
741
+ if (import_drg_route_distribution_info .display_name not in commonTools .drg_auto_RDs and "ocid1.drg.oc" not in drg_display_name ):
712
742
tf_resource = f'module.drg-route-distributions[\\ "{ tf_name } \\ "].oci_core_drg_route_distribution.drg_route_distribution'
713
743
if tf_resource not in state ["resources" ]:
714
744
importCommands [reg ].write (f'\n { tf_or_tofu } import "{ tf_resource } " { str (import_drg_route_distribution_info .id )} ' )
@@ -722,7 +752,7 @@ def export_major_objects(inputfile, outdir, service_dir, config, signer, ct, exp
722
752
723
753
print_drgv2 (values_for_column_drgv2 , region , drg_comp_name , vcn_info , drg_info , drg_attachment_info ,
724
754
drg_route_table_info , import_drg_route_distribution_info ,
725
- drg_route_distribution_statements )
755
+ drg_route_distribution_statements , write_drg_ocids )
726
756
727
757
# RPC
728
758
elif attach_type .upper () == "REMOTE_PEERING_CONNECTION" and rpc_execution :
@@ -747,7 +777,7 @@ def export_major_objects(inputfile, outdir, service_dir, config, signer, ct, exp
747
777
748
778
tf_name = commonTools .check_tf_variable (
749
779
drg_display_name + "_" + import_drg_route_distribution_info .display_name )
750
- if (import_drg_route_distribution_info .display_name not in commonTools .drg_auto_RDs ):
780
+ if (import_drg_route_distribution_info .display_name not in commonTools .drg_auto_RDs and write_drg_ocids == False ):
751
781
tf_resource = f'module.drg-route-distributions[\\ "{ tf_name } \\ "].oci_core_drg_route_distribution.drg_route_distribution'
752
782
if tf_resource not in state ["resources" ]:
753
783
importCommands [reg ].write (f'\n { tf_or_tofu } import "{ tf_resource } " { str (import_drg_route_distribution_info .id )} ' )
@@ -784,6 +814,13 @@ def export_major_objects(inputfile, outdir, service_dir, config, signer, ct, exp
784
814
drg_info = vnc .get_drg (drg_id ).data
785
815
drg_display_name = drg_info .display_name
786
816
817
+ #Do not process if DRG (and its RTs/RDs are in different compartment than the export_compartments list
818
+ drg_comp_id = drg_info .compartment_id
819
+ if drg_comp_id not in export_compartment_ids :
820
+ continue
821
+
822
+ write_drg_ocids = False
823
+
787
824
if drg_info .default_drg_route_tables is not None :
788
825
DRG_RTs = oci .pagination .list_call_get_all_results (vnc .list_drg_route_tables ,
789
826
drg_id = drg_id )
@@ -820,7 +857,7 @@ def export_major_objects(inputfile, outdir, service_dir, config, signer, ct, exp
820
857
print_drgv2 (values_for_column_drgv2 , region , drg_comp_name , vcn_info , drg_info ,
821
858
drg_attachment_info , drg_route_table_info ,
822
859
import_drg_route_distribution_info ,
823
- drg_route_distribution_statements )
860
+ drg_route_distribution_statements , write_drg_ocids )
824
861
825
862
commonTools .write_to_cd3 (values_for_column_drgv2 , cd3file , "DRGs" )
826
863
print ("RPCs exported to CD3\n " )
@@ -861,6 +898,14 @@ def export_major_objects(inputfile, outdir, service_dir, config, signer, ct, exp
861
898
if (drg_attachment_info .lifecycle_state != "ATTACHED" ):
862
899
continue
863
900
901
+ write_drg_ocids = False
902
+ if drg_attachment_info != None :
903
+ drg_id = drg_attachment_info .drg_id
904
+ drg_info = vnc .get_drg (drg_id ).data
905
+ drg_comp_id = drg_info .compartment_id
906
+ if drg_comp_id not in export_compartment_ids :
907
+ write_drg_ocids = True
908
+
864
909
# igw_display_name = "n"
865
910
IGWs = oci .pagination .list_call_get_all_results (vnc .list_internet_gateways ,
866
911
compartment_id = ct .ntk_compartment_ids [
@@ -933,7 +978,7 @@ def export_major_objects(inputfile, outdir, service_dir, config, signer, ct, exp
933
978
934
979
# Fill VCNs Tab
935
980
print_vcns (values_for_column_vcns , region , ntk_compartment_name , vnc ,vcn_info , drg_attachment_info , igw_info , ngw_info ,
936
- sgw_info , lpg_display_names ,state )
981
+ sgw_info , lpg_display_names ,state , write_drg_ocids )
937
982
938
983
commonTools .write_to_cd3 (values_for_column_vcns , cd3file , "VCNs" )
939
984
print ("VCNs exported to CD3\n " )
0 commit comments