2222
2323
2424def 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 ):
2626 for col_header in values_for_column_drgv2 .keys ():
2727 if (col_header == "Region" ):
2828 values_for_column_drgv2 [col_header ].append (region )
2929 elif (col_header == "Compartment Name" ):
3030 values_for_column_drgv2 [col_header ].append (comp_name )
3131 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+
3337 elif (col_header == "Attached To" ):
3438 if (drg_attachment_info is None ):
3539 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,
5357 if (drg_rt_info == None ):
5458 values_for_column_drgv2 [col_header ].append ("" )
5559 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+
5765 elif (col_header == 'Import DRG Route Distribution Name' ):
5866 if import_drg_route_distribution_info == None :
5967 values_for_column_drgv2 [col_header ].append ("" )
6068 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 )
6273 elif (col_header == "Import DRG Route Distribution Statements" ):
6374 statement_val = ''
6475 if (drg_route_distribution_statements == None ):
@@ -90,7 +101,7 @@ def print_drgv2(values_for_column_drgv2, region, comp_name, vcn_info, drg_info,
90101
91102
92103def 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 ):
94105 drg_info = None
95106 for col_header in values_for_column_vcns .keys ():
96107
@@ -106,10 +117,17 @@ def print_vcns(values_for_column_vcns, region, comp_name, vnc,vcn_info, drg_atta
106117 values_for_column_vcns [col_header ].append ("n" )
107118 else :
108119 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
111125 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+
113131 values_for_column_vcns [col_header ].append (val )
114132 else :
115133 values_for_column_vcns [col_header ].append ("n" )
@@ -620,6 +638,10 @@ def export_major_objects(inputfile, outdir, service_dir, config, signer, ct, exp
620638
621639 print ("Tabs- VCNs and DRGs would be overwritten during export process!!!\n " )
622640
641+ export_compartment_ids = []
642+ for comp in export_compartments :
643+ export_compartment_ids .append (ct .ntk_compartment_ids [comp ])
644+
623645 # Fetch DRGs
624646 for reg in export_regions :
625647 current_region = reg
@@ -637,6 +659,7 @@ def export_major_objects(inputfile, outdir, service_dir, config, signer, ct, exp
637659 ntk_compartment_name ],
638660 attachment_type = "ALL" ) # ,lifecycle_state ="ATTACHED")#,attachment_type="ALL")
639661 rpc_execution = True
662+ write_drg_ocids = False
640663 for drg_attachment_info in DRG_Attachments .data :
641664 if (drg_attachment_info .lifecycle_state != "ATTACHED" ):
642665 continue
@@ -647,6 +670,11 @@ def export_major_objects(inputfile, outdir, service_dir, config, signer, ct, exp
647670 # Attachment Data
648671 drg_display_name = drg_info .display_name
649672 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+
650678 for key , val in ct .ntk_compartment_ids .items ():
651679 if val == drg_comp_id :
652680 if ("::" in key ):
@@ -660,7 +688,7 @@ def export_major_objects(inputfile, outdir, service_dir, config, signer, ct, exp
660688 if (drg_id not in drg_ocid ):
661689 oci_obj_names [reg ].write ("\n DRG Version::::" + drg_display_name + "::::" + drg_version )
662690 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 :
664692 importCommands [reg ].write ( f'\n { tf_or_tofu } import "{ tf_resource } " { str (drg_info .id )} ' )
665693 drg_ocid .append (drg_id )
666694
@@ -700,15 +728,17 @@ def export_major_objects(inputfile, outdir, service_dir, config, signer, ct, exp
700728 drg_route_table_info = vnc .get_drg_route_table (drg_route_table_id ).data
701729
702730 import_drg_route_distribution_id = drg_route_table_info .import_drg_route_distribution_id
731+
703732 if (import_drg_route_distribution_id != None ):
704733 import_drg_route_distribution_info = vnc .get_drg_route_distribution (
705734 import_drg_route_distribution_id ).data
735+
706736 drg_route_distribution_statements = vnc .list_drg_route_distribution_statements (
707737 import_drg_route_distribution_info .id )
708738
709739 tf_name = commonTools .check_tf_variable (
710740 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 ):
712742 tf_resource = f'module.drg-route-distributions[\\ "{ tf_name } \\ "].oci_core_drg_route_distribution.drg_route_distribution'
713743 if tf_resource not in state ["resources" ]:
714744 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
722752
723753 print_drgv2 (values_for_column_drgv2 , region , drg_comp_name , vcn_info , drg_info , drg_attachment_info ,
724754 drg_route_table_info , import_drg_route_distribution_info ,
725- drg_route_distribution_statements )
755+ drg_route_distribution_statements , write_drg_ocids )
726756
727757 # RPC
728758 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
747777
748778 tf_name = commonTools .check_tf_variable (
749779 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 ):
751781 tf_resource = f'module.drg-route-distributions[\\ "{ tf_name } \\ "].oci_core_drg_route_distribution.drg_route_distribution'
752782 if tf_resource not in state ["resources" ]:
753783 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
784814 drg_info = vnc .get_drg (drg_id ).data
785815 drg_display_name = drg_info .display_name
786816
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+
787824 if drg_info .default_drg_route_tables is not None :
788825 DRG_RTs = oci .pagination .list_call_get_all_results (vnc .list_drg_route_tables ,
789826 drg_id = drg_id )
@@ -820,7 +857,7 @@ def export_major_objects(inputfile, outdir, service_dir, config, signer, ct, exp
820857 print_drgv2 (values_for_column_drgv2 , region , drg_comp_name , vcn_info , drg_info ,
821858 drg_attachment_info , drg_route_table_info ,
822859 import_drg_route_distribution_info ,
823- drg_route_distribution_statements )
860+ drg_route_distribution_statements , write_drg_ocids )
824861
825862 commonTools .write_to_cd3 (values_for_column_drgv2 , cd3file , "DRGs" )
826863 print ("RPCs exported to CD3\n " )
@@ -861,6 +898,14 @@ def export_major_objects(inputfile, outdir, service_dir, config, signer, ct, exp
861898 if (drg_attachment_info .lifecycle_state != "ATTACHED" ):
862899 continue
863900
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+
864909 # igw_display_name = "n"
865910 IGWs = oci .pagination .list_call_get_all_results (vnc .list_internet_gateways ,
866911 compartment_id = ct .ntk_compartment_ids [
@@ -933,7 +978,7 @@ def export_major_objects(inputfile, outdir, service_dir, config, signer, ct, exp
933978
934979 # Fill VCNs Tab
935980 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 )
937982
938983 commonTools .write_to_cd3 (values_for_column_vcns , cd3file , "VCNs" )
939984 print ("VCNs exported to CD3\n " )
0 commit comments