@@ -38,26 +38,19 @@ def cli(env, context_id, include):
3838 manager = SoftLayer .IPSECManager (env .client )
3939 context = manager .get_tunnel_context (context_id , mask = mask )
4040
41- env .out ('Context Details:' )
4241 env .fout (_get_context_table (context ))
4342
4443 for relation in include :
4544 if relation == 'at' :
46- env .out ('Address Translations:' )
47- env .fout (_get_address_translations_table (
48- context .get ('addressTranslations' , [])))
45+ env .fout (_get_address_translations_table (context .get ('addressTranslations' , [])))
4946 elif relation == 'is' :
50- env .out ('Internal Subnets:' )
51- env .fout (_get_subnets_table (context .get ('internalSubnets' , [])))
47+ env .fout (_get_subnets_table (context .get ('internalSubnets' , []), title = "Internal Subnets" ))
5248 elif relation == 'rs' :
53- env .out ('Remote Subnets:' )
54- env .fout (_get_subnets_table (context .get ('customerSubnets' , [])))
49+ env .fout (_get_subnets_table (context .get ('customerSubnets' , []), title = "Remote Subnets" ))
5550 elif relation == 'sr' :
56- env .out ('Static Subnets:' )
57- env .fout (_get_subnets_table (context .get ('staticRouteSubnets' , [])))
51+ env .fout (_get_subnets_table (context .get ('staticRouteSubnets' , []), title = "Static Subnets" ))
5852 elif relation == 'ss' :
59- env .out ('Service Subnets:' )
60- env .fout (_get_subnets_table (context .get ('serviceSubnets' , [])))
53+ env .fout (_get_subnets_table (context .get ('serviceSubnets' , []), title = "Service Subnets" ))
6154
6255
6356def _get_address_translations_table (address_translations ):
@@ -71,29 +64,24 @@ def _get_address_translations_table(address_translations):
7164 'static IP address id' ,
7265 'remote IP address' ,
7366 'remote IP address id' ,
74- 'note' ])
67+ 'note' ], title = "Address Translations" )
7568 for address_translation in address_translations :
7669 table .add_row ([address_translation .get ('id' , '' ),
77- address_translation .get ('internalIpAddressRecord' , {})
78- .get ('ipAddress' , '' ),
70+ address_translation .get ('internalIpAddressRecord' , {}).get ('ipAddress' , '' ),
7971 address_translation .get ('internalIpAddressId' , '' ),
80- address_translation .get ('customerIpAddressRecord' , {})
81- .get ('ipAddress' , '' ),
72+ address_translation .get ('customerIpAddressRecord' , {}).get ('ipAddress' , '' ),
8273 address_translation .get ('customerIpAddressId' , '' ),
8374 address_translation .get ('notes' , '' )])
8475 return table
8576
8677
87- def _get_subnets_table (subnets ):
78+ def _get_subnets_table (subnets , title ):
8879 """Yields a formatted table to print subnet details.
8980
9081 :param List[dict] subnets: List of subnets.
9182 :return Table: Formatted for subnet output.
9283 """
93- table = formatting .Table (['id' ,
94- 'network identifier' ,
95- 'cidr' ,
96- 'note' ])
84+ table = formatting .Table (['id' , 'network identifier' , 'cidr' , 'note' ], title = title )
9785 for subnet in subnets :
9886 table .add_row ([subnet .get ('id' , '' ),
9987 subnet .get ('networkIdentifier' , '' ),
@@ -163,34 +151,26 @@ def _get_context_table(context):
163151 :param dict context: The tunnel context
164152 :return Table: Formatted for tunnel context output
165153 """
166- table = formatting .KeyValueTable (['name' , 'value' ])
154+ table = formatting .KeyValueTable (['name' , 'value' ], title = 'Context Details' )
167155 table .align ['name' ] = 'r'
168156 table .align ['value' ] = 'l'
169157
170158 table .add_row (['id' , context .get ('id' , '' )])
171159 table .add_row (['name' , context .get ('name' , '' )])
172160 table .add_row (['friendly name' , context .get ('friendlyName' , '' )])
173- table .add_row (['internal peer IP address' ,
174- context .get ('internalPeerIpAddress' , '' )])
175- table .add_row (['remote peer IP address' ,
176- context .get ('customerPeerIpAddress' , '' )])
177- table .add_row (['advanced configuration flag' ,
178- context .get ('advancedConfigurationFlag' , '' )])
161+ table .add_row (['internal peer IP address' , context .get ('internalPeerIpAddress' , '' )])
162+ table .add_row (['remote peer IP address' , context .get ('customerPeerIpAddress' , '' )])
163+ table .add_row (['advanced configuration flag' , context .get ('advancedConfigurationFlag' , '' )])
179164 table .add_row (['preshared key' , context .get ('presharedKey' , '' )])
180- table .add_row (['phase 1 authentication' ,
181- context .get ('phaseOneAuthentication' , '' )])
182- table .add_row (['phase 1 diffie hellman group' ,
183- context .get ('phaseOneDiffieHellmanGroup' , '' )])
165+ table .add_row (['phase 1 authentication' , context .get ('phaseOneAuthentication' , '' )])
166+ table .add_row (['phase 1 diffie hellman group' , context .get ('phaseOneDiffieHellmanGroup' , '' )])
184167 table .add_row (['phase 1 encryption' , context .get ('phaseOneEncryption' , '' )])
185168 table .add_row (['phase 1 key life' , context .get ('phaseOneKeylife' , '' )])
186- table .add_row (['phase 2 authentication' ,
187- context .get ('phaseTwoAuthentication' , '' )])
188- table .add_row (['phase 2 diffie hellman group' ,
189- context .get ('phaseTwoDiffieHellmanGroup' , '' )])
169+ table .add_row (['phase 2 authentication' , context .get ('phaseTwoAuthentication' , '' )])
170+ table .add_row (['phase 2 diffie hellman group' , context .get ('phaseTwoDiffieHellmanGroup' , '' )])
190171 table .add_row (['phase 2 encryption' , context .get ('phaseTwoEncryption' , '' )])
191172 table .add_row (['phase 2 key life' , context .get ('phaseTwoKeylife' , '' )])
192- table .add_row (['phase 2 perfect forward secrecy' ,
193- context .get ('phaseTwoPerfectForwardSecrecy' , '' )])
173+ table .add_row (['phase 2 perfect forward secrecy' , context .get ('phaseTwoPerfectForwardSecrecy' , '' )])
194174 table .add_row (['created' , context .get ('createDate' )])
195175 table .add_row (['modified' , context .get ('modifyDate' )])
196176 return table
0 commit comments