def delete_health_monitor(self, context, id, edge_id): monitor_binding = vcns_db.get_vcns_edge_monitor_binding( context.session, id, edge_id) monitor_vseid = monitor_binding['monitor_vseid'] try: self.vcns.delete_health_monitor(edge_id, monitor_vseid) except vcns_exc.VcnsApiException: with excutils.save_and_reraise_exception(): LOG.exception(_("Failed to delete monitor")) vcns_db.delete_vcns_edge_monitor_binding( context.session, id, edge_id)
def update_health_monitor(self, context, edge_id, old_health_monitor, health_monitor): monitor_binding = vcns_db.get_vcns_edge_monitor_binding( context.session, old_health_monitor['id'], edge_id) monitor_vseid = monitor_binding['monitor_vseid'] monitor_new = self._convert_lb_monitor( context, health_monitor) try: self.vcns.update_health_monitor( edge_id, monitor_vseid, monitor_new) except vcns_exc.VcnsApiException: with excutils.save_and_reraise_exception(): LOG.exception(_("Failed to update monitor on edge: %s"), edge_id)
def get_health_monitor(self, context, id, edge_id): monitor_binding = vcns_db.get_vcns_edge_monitor_binding( context.session, id, edge_id) if not monitor_binding: msg = (_("monitor_binding not found with id: %(id)s " "edge_id: %(edge_id)s") % {'id': id, 'edge_id': edge_id}) LOG.error(msg) raise vcns_exc.VcnsNotFound( resource='router_service_binding', msg=msg) monitor_vseid = monitor_binding['monitor_vseid'] try: response = self.vcns.get_health_monitor(edge_id, monitor_vseid)[1] except vcns_exc.VcnsApiException as e: with excutils.save_and_reraise_exception(): LOG.exception(_("Failed to get monitor on edge: %s"), e.response) return self._restore_lb_monitor(context, edge_id, response)
def _convert_lb_pool(self, context, edge_id, pool, members): vsepool = { 'name': pool.get('name'), 'algorithm': BALANCE_MAP.get( pool.get('lb_method'), 'round-robin'), 'member': [], 'monitorId': [] } for member in members: vsepool['member'].append({ 'ipAddress': member['address'], 'port': member['protocol_port'] }) ##TODO(linb) right now, vse only accept at most one monitor per pool monitors = pool.get('health_monitors') if not monitors: return vsepool monitorid_map = vcns_db.get_vcns_edge_monitor_binding( context.session, monitors[0], edge_id) vsepool['monitorId'].append(monitorid_map['monitor_vseid']) return vsepool