@@ -145,10 +145,13 @@ def processGuestNetwork(self, dbag):
145145 dp ['gateway' ] = d ['router_guest_gateway' ]
146146 dp ['nic_dev_id' ] = d ['device' ][3 ]
147147 dp ['nw_type' ] = 'guest'
148+ dp = PrivateGatewayHack .update_network_type_for_privategateway (dbag , dp )
148149 qf = QueueFile ()
149150 qf .load ({'ip_address' : [dp ], 'type' : 'ips' })
150151 if 'domain_name' not in d .keys () or d ['domain_name' ] == '' :
151152 d ['domain_name' ] = "cloudnine.internal"
153+
154+ d = PrivateGatewayHack .update_network_type_for_privategateway (dbag , d )
152155 return cs_guestnetwork .merge (dbag , d )
153156
154157 def process_dhcp_entry (self , dbag ):
@@ -274,3 +277,46 @@ def __moveFile(self, origPath, path):
274277 os .makedirs (path )
275278 timestamp = str (int (round (time .time ())))
276279 os .rename (origPath , path + "/" + self .fileName + "." + timestamp )
280+
281+
282+ class PrivateGatewayHack :
283+
284+
285+ @classmethod
286+ def update_network_type_for_privategateway (cls , dbag , data ):
287+ ip = data ['router_guest_ip' ] if 'router_guest_ip' in data .keys () else data ['public_ip' ]
288+
289+ initial_data = cls .load_inital_data ()
290+ has_private_gw_ip = cls .if_config_has_privategateway (initial_data )
291+ private_gw_matches = 'privategateway' in initial_data ['config' ] and cls .ip_matches_private_gateway_ip (ip , initial_data ['config' ]['privategateway' ])
292+
293+ if has_private_gw_ip and private_gw_matches :
294+ data ['nw_type' ] = "public"
295+ logging .debug ("Updating nw_type for ip %s" % ip )
296+ else :
297+ logging .debug ("Not updating nw_type for ip %s because has_private_gw_ip = %s and private_gw_matches = %s " % (ip , has_private_gw_ip , private_gw_matches ))
298+ return data
299+
300+
301+ @classmethod
302+ def if_config_has_privategateway (cls , dbag ):
303+ return 'privategateway' in dbag ['config' ].keys () and dbag ['config' ]['privategateway' ] != "None"
304+
305+
306+ @classmethod
307+ def ip_matches_private_gateway_ip (cls , ip , private_gateway_ip ):
308+ new_ip_matches_private_gateway_ip = False
309+ if ip == private_gateway_ip :
310+ new_ip_matches_private_gateway_ip = True
311+ return new_ip_matches_private_gateway_ip
312+
313+
314+ @classmethod
315+ def load_inital_data (cls ):
316+ initial_data_bag = DataBag ()
317+ initial_data_bag .setKey ('cmdline' )
318+ initial_data_bag .load ()
319+ initial_data = initial_data_bag .getDataBag ()
320+ logging .debug ("Initial data = %s" % initial_data )
321+
322+ return initial_data
0 commit comments