def _is_twoway_trade(self, instance_id):
     app_name = self.instances[instance_id].get('app_name')
     intf_name = self.instances[instance_id].get('intf_name')
     if instance_id not in self.app_intf_topov_is_twoway_trade:
         topov_datapath = get_cbms_new_app_datapath(app_name)
         topov_capture = topov_datapath.get_capture(intf_name)
         is_twoway_trade = topov_capture.is_twoway_trade
         self.app_intf_topov_is_twoway_trade[instance_id] = is_twoway_trade
         if not is_twoway_trade:
             return is_twoway_trade
         infos = topov_datapath.get_twoway_trade_captures(intf_name)
         master_capture = infos['master']
         for intf, topov_capture in infos['slaves'].iteritems():
             self.app_reverse_intf[instance_id] = {"intf_name": intf, "server_ips": topov_capture.server_ips}
         self.app_intf_server_ips[instance_id] = master_capture.server_ips
     else:
         is_twoway_trade = self.app_intf_topov_is_twoway_trade[instance_id]
     return is_twoway_trade
 def is_double_center(self, instance_id):
     if instance_id in self._caches:
         if self._caches[instance_id]['is_double_live']:
             return True
         else:
             return False
     else:
         instance = self.instance_coll.find_one({'instance_id': instance_id})
         if instance:
             topov = get_cbms_new_app_datapath(instance['app_name'])
             capture = topov.get_capture(instance['intf_name'])
             if capture.is_double_live:
                 self._caches[instance_id] = {'part': '%(app_name)s/%(intf_name)s' % {'app_name': instance['app_name'],
                           'intf_name': instance['intf_name']},
                  'is_double_live': True}
                 return True
             self._caches[instance_id] = {'is_double_live': False}
     return False
    def _get_twoway_trade_info(self, app_name, intf_name):
        topov_datapath = get_cbms_new_app_datapath(app_name)
        topov_capture = topov_datapath.get_capture(intf_name)
        is_twoway_trade = topov_capture.is_twoway_trade
        if is_twoway_trade:
            intfs_infos = []
            infos = topov_datapath.get_twoway_trade_captures(intf_name)
            master_capture = infos['master']
            intfs_infos.append({
                'intf_name': master_capture['name'],
                'server_ips': master_capture.server_ips
            })
            for intf, topov_capture in infos['slaves'].iteritems():
                intfs_infos.append({
                    'intf_name': intf,
                    'server_ips': topov_capture.server_ips
                })

            return {'twoway': True, 'intfs': intfs_infos}
        else:
            return {'twoway': False}