def update(self, context, old_hm, new_hm, completor):
        lb_id = new_hm['pool']['loadbalancer_id']
        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)

        edge_id = lb_binding['edge_id']

        hm_binding = nsxv_db.get_nsxv_lbaas_monitor_binding(
            context.session, lb_id, new_hm['pool']['id'], new_hm['id'],
            edge_id)

        edge_monitor = self._convert_lbaas_monitor(new_hm)

        try:
            with locking.LockManager.get_lock(edge_id):
                self.vcns.update_health_monitor(edge_id,
                                                hm_binding['edge_mon_id'],
                                                edge_monitor)

        except nsxv_exc.VcnsApiException:
            with excutils.save_and_reraise_exception():
                completor(success=False)
                LOG.error('Failed to update monitor on edge: %s', edge_id)

        completor(success=True)
    def update(self, context, old_hm, new_hm):
        listener = new_hm.pool.listener
        lb_id = listener.loadbalancer_id
        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)

        edge_id = lb_binding['edge_id']

        hm_binding = nsxv_db.get_nsxv_lbaas_monitor_binding(
            context.session, lb_id, listener.id, new_hm.pool.id, new_hm.id,
            edge_id)

        edge_monitor = self._convert_lbaas_monitor(new_hm)

        try:
            with locking.LockManager.get_lock(edge_id):
                self.vcns.update_health_monitor(edge_id,
                                                hm_binding['edge_mon_id'],
                                                edge_monitor)

        except nsxv_exc.VcnsApiException:
            with excutils.save_and_reraise_exception():
                self.lbv2_driver.health_monitor.failed_completion(context,
                                                                new_hm)
                LOG.error(
                    _LE('Failed to update monitor on edge: %s'), edge_id)

        self.lbv2_driver.health_monitor.successful_completion(context, new_hm)
Beispiel #3
0
    def create(self, context, hm):
        lb_id = hm.pool.loadbalancer_id
        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)
        edge_id = lb_binding['edge_id']

        pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding(
            context.session, lb_id, hm.pool.id)
        if not pool_binding:
            self.lbv2_driver.health_monitor.failed_completion(context, hm)
            msg = _('Failed to create health monitor on edge: %s. '
                    'Binding not found') % edge_id
            LOG.error(msg)
            raise n_exc.BadRequest(resource='edge-lbaas', msg=msg)

        edge_pool_id = pool_binding['edge_pool_id']

        hm_binding = nsxv_db.get_nsxv_lbaas_monitor_binding(
            context.session, lb_id, hm.pool.id, hm.id, edge_id)
        edge_mon_id = None

        if hm_binding:
            edge_mon_id = hm_binding['edge_mon_id']
        else:
            edge_monitor = self._convert_lbaas_monitor(hm)
            try:
                with locking.LockManager.get_lock(edge_id):
                    h = self.vcns.create_health_monitor(edge_id,
                                                        edge_monitor)[0]
                    edge_mon_id = lb_common.extract_resource_id(h['location'])

                nsxv_db.add_nsxv_lbaas_monitor_binding(context.session, lb_id,
                                                       hm.pool.id, hm.id,
                                                       edge_id, edge_mon_id)

            except nsxv_exc.VcnsApiException:
                with excutils.save_and_reraise_exception():
                    self.lbv2_driver.health_monitor.failed_completion(
                        context, hm)
                    LOG.error('Failed to create health monitor on edge: %s',
                              edge_id)

        try:
            # Associate monitor with Edge pool
            with locking.LockManager.get_lock(edge_id):
                edge_pool = self.vcns.get_pool(edge_id, edge_pool_id)[1]
                if edge_pool.get('monitorId'):
                    edge_pool['monitorId'].append(edge_mon_id)
                else:
                    edge_pool['monitorId'] = [edge_mon_id]

                self.vcns.update_pool(edge_id, edge_pool_id, edge_pool)

        except nsxv_exc.VcnsApiException:
            with excutils.save_and_reraise_exception():
                self.lbv2_driver.health_monitor.failed_completion(context, hm)
                LOG.error('Failed to create health monitor on edge: %s',
                          edge_id)

        self.lbv2_driver.health_monitor.successful_completion(context, hm)
Beispiel #4
0
    def update(self, context, old_hm, new_hm):
        lb_id = new_hm.pool.loadbalancer_id
        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)

        edge_id = lb_binding['edge_id']

        hm_binding = nsxv_db.get_nsxv_lbaas_monitor_binding(
            context.session, lb_id, new_hm.pool.id, new_hm.id, edge_id)

        edge_monitor = self._convert_lbaas_monitor(new_hm)

        try:
            with locking.LockManager.get_lock(edge_id):
                self.vcns.update_health_monitor(edge_id,
                                                hm_binding['edge_mon_id'],
                                                edge_monitor)

        except nsxv_exc.VcnsApiException:
            with excutils.save_and_reraise_exception():
                self.lbv2_driver.health_monitor.failed_completion(
                    context, new_hm)
                LOG.error('Failed to update monitor on edge: %s', edge_id)

        self.lbv2_driver.health_monitor.successful_completion(context, new_hm)
Beispiel #5
0
    def update(self, context, old_hm, new_hm, completor):
        lb_id = new_hm['pool']['loadbalancer_id']
        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)

        edge_id = lb_binding['edge_id']

        hm_binding = nsxv_db.get_nsxv_lbaas_monitor_binding(
            context.session, lb_id, new_hm['pool']['id'],
            new_hm['id'], edge_id)

        edge_monitor = self._convert_lbaas_monitor(new_hm)

        try:
            with locking.LockManager.get_lock(edge_id):
                self.vcns.update_health_monitor(edge_id,
                                                hm_binding['edge_mon_id'],
                                                edge_monitor)

        except nsxv_exc.VcnsApiException:
            with excutils.save_and_reraise_exception():
                completor(success=False)
                LOG.error('Failed to update monitor on edge: %s', edge_id)

        completor(success=True)
Beispiel #6
0
    def create(self, context, hm, completor):
        lb_id = hm['pool']['loadbalancer_id']
        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)
        edge_id = lb_binding['edge_id']
        pool_id = hm['pool']['id']
        pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding(
            context.session, lb_id, pool_id)
        if not pool_binding:
            completor(success=False)
            msg = _('Failed to create health monitor on edge: %s. '
                    'Binding not found') % edge_id
            LOG.error(msg)
            raise n_exc.BadRequest(resource='edge-lbaas', msg=msg)

        edge_pool_id = pool_binding['edge_pool_id']

        hm_binding = nsxv_db.get_nsxv_lbaas_monitor_binding(
            context.session, lb_id, pool_id, hm['id'], edge_id)
        edge_mon_id = None

        if hm_binding:
            edge_mon_id = hm_binding['edge_mon_id']
        else:
            edge_monitor = self._convert_lbaas_monitor(hm)
            try:
                with locking.LockManager.get_lock(edge_id):
                    h = self.vcns.create_health_monitor(edge_id,
                                                        edge_monitor)[0]
                    edge_mon_id = lb_common.extract_resource_id(h['location'])

                nsxv_db.add_nsxv_lbaas_monitor_binding(
                    context.session, lb_id, pool_id, hm['id'], edge_id,
                    edge_mon_id)

            except nsxv_exc.VcnsApiException:
                with excutils.save_and_reraise_exception():
                    completor(success=False)
                    LOG.error('Failed to create health monitor on edge: %s',
                              edge_id)

        try:
            # Associate monitor with Edge pool
            with locking.LockManager.get_lock(edge_id):
                edge_pool = self.vcns.get_pool(edge_id, edge_pool_id)[1]
                if edge_pool.get('monitorId'):
                    edge_pool['monitorId'].append(edge_mon_id)
                else:
                    edge_pool['monitorId'] = [edge_mon_id]

                self.vcns.update_pool(edge_id, edge_pool_id, edge_pool)

        except nsxv_exc.VcnsApiException:
            with excutils.save_and_reraise_exception():
                completor(success=False)
                LOG.error('Failed to create health monitor on edge: %s',
                          edge_id)

        completor(success=True)
    def create(self, context, hm):
        listener = hm.pool.listener
        lb_id = listener.loadbalancer_id
        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)
        pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding(
            context.session, lb_id, listener.id, hm.pool.id)

        edge_id = lb_binding['edge_id']
        edge_pool_id = pool_binding['edge_pool_id']

        hm_binding = nsxv_db.get_nsxv_lbaas_monitor_binding(
            context.session, lb_id, listener.id, hm.pool.id, hm.id, edge_id)
        edge_mon_id = None

        if hm_binding:
            edge_mon_id = hm_binding['edge_mon_id']
        else:
            edge_monitor = self._convert_lbaas_monitor(hm)
            try:
                with locking.LockManager.get_lock(edge_id):
                    h = self.vcns.create_health_monitor(edge_id,
                                                        edge_monitor)[0]
                    edge_mon_id = lb_common.extract_resource_id(h['location'])

                nsxv_db.add_nsxv_lbaas_monitor_binding(
                    context.session, lb_id, listener.id, hm.pool.id, hm.id,
                    edge_id, edge_mon_id)

            except nsxv_exc.VcnsApiException:
                with excutils.save_and_reraise_exception():
                    self.lbv2_driver.health_monitor.failed_completion(
                        context, hm)
                    LOG.error(_LE('Failed to create health monitor on edge: %s'
                                  ), edge_id)

        try:
            # Associate monitor with Edge pool
            with locking.LockManager.get_lock(edge_id):
                edge_pool = self.vcns.get_pool(edge_id, edge_pool_id)[1]
                if edge_pool.get('monitorId'):
                    edge_pool['monitorId'].append(edge_mon_id)
                else:
                    edge_pool['monitorId'] = [edge_mon_id]

                self.vcns.update_pool(edge_id, edge_pool_id, edge_pool)

        except nsxv_exc.VcnsApiException:
            with excutils.save_and_reraise_exception():
                self.lbv2_driver.health_monitor.failed_completion(context, hm)
                LOG.error(
                    _LE('Failed to create health monitor on edge: %s'),
                    edge_id)

        self.lbv2_driver.health_monitor.successful_completion(context, hm)
Beispiel #8
0
    def delete(self, context, hm):
        pool_id = hm.pool.id
        lb_id = hm.pool.loadbalancer_id
        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)
        edge_id = lb_binding['edge_id']

        pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding(
            context.session, lb_id, pool_id)
        if not pool_binding:
            nsxv_db.del_nsxv_lbaas_monitor_binding(context.session, lb_id,
                                                   pool_id, hm.id, edge_id)
            self.lbv2_driver.health_monitor.successful_completion(context,
                                                                  hm,
                                                                  delete=True)
            return

        edge_pool_id = pool_binding['edge_pool_id']

        hm_binding = nsxv_db.get_nsxv_lbaas_monitor_binding(
            context.session, lb_id, pool_id, hm.id, edge_id)

        edge_pool = self.vcns.get_pool(edge_id, edge_pool_id)[1]
        if hm_binding['edge_mon_id'] in edge_pool['monitorId']:
            edge_pool['monitorId'].remove(hm_binding['edge_mon_id'])

            try:
                with locking.LockManager.get_lock(edge_id):
                    self.vcns.update_pool(edge_id, edge_pool_id, edge_pool)
            except nsxv_exc.VcnsApiException:
                with excutils.save_and_reraise_exception():
                    self.lbv2_driver.health_monitor.failed_completion(
                        context, hm)
                    LOG.error('Failed to delete monitor mapping on edge: %s',
                              edge_id)

        # If this monitor is not used on this edge anymore, delete it
        if not edge_pool['monitorId']:
            try:
                with locking.LockManager.get_lock(edge_id):
                    self.vcns.delete_health_monitor(hm_binding['edge_id'],
                                                    hm_binding['edge_mon_id'])
            except nsxv_exc.VcnsApiException:
                with excutils.save_and_reraise_exception():
                    self.lbv2_driver.health_monitor.failed_completion(
                        context, hm)
                    LOG.error('Failed to delete monitor on edge: %s', edge_id)

        nsxv_db.del_nsxv_lbaas_monitor_binding(context.session, lb_id, pool_id,
                                               hm.id, edge_id)
        self.lbv2_driver.health_monitor.successful_completion(context,
                                                              hm,
                                                              delete=True)
Beispiel #9
0
    def delete(self, context, hm, completor):
        pool_id = hm['pool']['id']
        lb_id = hm['pool']['loadbalancer_id']
        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)
        edge_id = lb_binding['edge_id']

        pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding(
            context.session, lb_id, pool_id)
        if not pool_binding:
            nsxv_db.del_nsxv_lbaas_monitor_binding(
                context.session, lb_id, pool_id, hm['id'], edge_id)
            completor(success=True)
            return

        edge_pool_id = pool_binding['edge_pool_id']

        hm_binding = nsxv_db.get_nsxv_lbaas_monitor_binding(
            context.session, lb_id, pool_id, hm['id'], edge_id)

        edge_pool = self.vcns.get_pool(edge_id, edge_pool_id)[1]
        if hm_binding and hm_binding['edge_mon_id'] in edge_pool['monitorId']:
            edge_pool['monitorId'].remove(hm_binding['edge_mon_id'])

            try:
                with locking.LockManager.get_lock(edge_id):
                    self.vcns.update_pool(edge_id, edge_pool_id, edge_pool)
            except nsxv_exc.VcnsApiException:
                with excutils.save_and_reraise_exception():
                    completor(success=False)
                    LOG.error('Failed to delete monitor mapping on edge: %s',
                              edge_id)

        # If this monitor is not used on this edge anymore, delete it
        if hm_binding and not edge_pool['monitorId']:
            try:
                with locking.LockManager.get_lock(edge_id):
                    self.vcns.delete_health_monitor(hm_binding['edge_id'],
                                                    hm_binding['edge_mon_id'])
            except nsxv_exc.VcnsApiException:
                with excutils.save_and_reraise_exception():
                    completor(success=False)
                    LOG.error('Failed to delete monitor on edge: %s', edge_id)

        nsxv_db.del_nsxv_lbaas_monitor_binding(
            context.session, lb_id, pool_id, hm['id'], edge_id)
        completor(success=True)
Beispiel #10
0
    def delete(self, context, hm):
        listener = hm.pool.listener
        lb_id = listener.loadbalancer_id
        lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
            context.session, lb_id)
        pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding(
            context.session, lb_id, listener.id, hm.pool.id)

        edge_id = lb_binding['edge_id']
        edge_pool_id = pool_binding['edge_pool_id']

        hm_binding = nsxv_db.get_nsxv_lbaas_monitor_binding(
            context.session, lb_id, listener.id, hm.pool.id, hm.id, edge_id)

        edge_pool = self.vcns.get_pool(edge_id, edge_pool_id)[1]
        edge_pool['monitorId'].remove(hm_binding['edge_mon_id'])

        try:
            with locking.LockManager.get_lock(edge_id):
                self.vcns.update_pool(edge_id, edge_pool_id, edge_pool)
        except nsxv_exc.VcnsApiException:
            with excutils.save_and_reraise_exception():
                self.lbv2_driver.health_monitor.failed_completion(context, hm)
                LOG.error(
                    _LE('Failed to delete monitor mapping on edge: %s'),
                    edge_id)

        # If this monitor is not used on this edge anymore, delete it
        if not edge_pool['monitorId']:
            try:
                with locking.LockManager.get_lock(edge_id):
                    self.vcns.delete_health_monitor(hm_binding['edge_id'],
                                                    hm_binding['edge_mon_id'])
            except nsxv_exc.VcnsApiException:
                with excutils.save_and_reraise_exception():
                    self.lbv2_driver.health_monitor.failed_completion(context,
                                                                    hm)
                    LOG.error(
                        _LE('Failed to delete monitor on edge: %s'), edge_id)

        nsxv_db.del_nsxv_lbaas_monitor_binding(
            context.session, lb_id, listener.id, hm.pool.id, hm.id, edge_id)
        self.lbv2_driver.health_monitor.successful_completion(
            context, hm, delete=True)