Example #1
0
    def _delete_pool(self, pools):

        pls = util.trata_param_pool(pools)

        pl = pool.Pool(self._lb)
        mon = monitor.Monitor(self._lb)

        try:
            monitor_associations = pl.get_monitor_association(
                names=pls['pools_names'])
        except Exception, e:
            log.error(e)
            raise base_exceptions.CommandErrorException(e)
Example #2
0
    def __delete_pool(self, pools):

        pls = util.trata_param_pool(pools)

        pl = pool.Pool(self._lb)
        mon = monitor.Monitor(self._lb)

        try:
            self._lb._channel.System.Session.start_transaction()
            monitor_associations = pl.get_monitor_association(
                names=pls['pools_names'])
            pl.remove_monitor_association(names=pls['pools_names'])
        except Exception, e:
            log.error(e)
            self._lb._channel.System.Session.rollback_transaction()
            raise base_exceptions.CommandErrorException(e)
Example #3
0
    def _cleanup_pool(self, pools):

        pls = util.trata_param_pool(pools)

        pl = pool.Pool(self._lb)
        mon = monitor.Monitor(self._lb)

        ids = list()

        for idx, pool_name in enumerate(pls['pools_names']):

            try:
                monitor_associations = pl.get_monitor_association(
                    names=[pool_name])
            except:
                pass

            can_delete = True
            try:
                pl.delete(names=[pool_name])
            except Exception, e:
                can_delete = False
                if 'cannot be deleted because it is in use by a Virtual Server' in str(
                        e.message):
                    log.warning(
                        'Pool cannot be deleted because it is in use by a Virtual Server'
                    )
                    pass
                elif 'is referenced by one or more virtual servers' in str(
                        e.message):
                    log.warning(
                        'Pool cannot be deleted because it is referenced by one or more virtual servers'
                    )
                    pass
                elif 'is referenced by one or more rules' in str(e.message):
                    log.warning(
                        'Pool cannot be deleted because is referenced by one or more rules'
                    )
                    pass
                elif 'was not found.' in str(e.message):
                    log.warning('Pool already deleted')
                    can_delete = True
                    pass
                else:
                    log.error(e)
                    raise e

            if can_delete:
                ids.append(pools['pools'][idx]['id'])

            try:
                template_names = [
                    m for m in list(
                        itertools.chain(*[
                            m['monitor_rule']['monitor_templates']
                            for m in monitor_associations
                        ])) if 'MONITOR' in m
                ]
                if template_names:
                    mon.delete_template(template_names=template_names)
            except:
                pass
Example #4
0
    def __update_pool(self, pools):
        monitor_associations = []
        pls = util.trata_param_pool(pools)

        pl = pool.Pool(self._lb)
        mon = monitor.Monitor(self._lb)

        # get template currents
        monitor_associations_old = pl.get_monitor_association(
            names=pls['pools_names'])

        # creates templates
        monitor_associations, monitor_associations_nodes, templates_extra = mon.prepare_template(
            names=pls['pools_names'],
            members=pls['pools_members']['members'],
            healthcheck=pls['pools_healthcheck'])

        mon.create_template(templates_extra=templates_extra)

        try:
            self._lb._channel.System.Session.start_transaction()

            pl.set_monitor_association(
                monitor_associations=monitor_associations)

            pl.set_lb_method(names=pls['pools_names'],
                             lbmethod=pls['pools_lbmethod'])

            pl.set_service_down_action(names=pls['pools_names'],
                                       actions=pls['pools_actions'])

            plm = poolmember.PoolMember(self._lb)

            if pls['pools_members']['members_remove']:
                plm.remove(names=pls['pools_names'],
                           members=pls['pools_members']['members_remove'])

            if pls['pools_members']['members_new']:
                plm.create(names=pls['pools_names'],
                           members=pls['pools_members']['members_new'])

            plm.set_connection_limit(
                names=pls['pools_names'],
                members=pls['pools_members']['members'],
                connection_limit=pls['pools_members']['limit'])

            plm.set_priority(names=pls['pools_names'],
                             members=pls['pools_members']['members'],
                             priority=pls['pools_members']['priority'])

            plm.set_ratio(names=pls['pools_names'],
                          members=pls['pools_members']['members'],
                          ratio=pls['pools_members']['weight'])

            # plm.set_member_description(
            #     names=pls['pools_names'],
            #     members=pls['pools_members']['members'],
            #     description=pls['pools_members']['description'])

            plm.set_states(names=pls['pools_names'],
                           members=pls['pools_members']['members'],
                           monitor_state=pls['pools_members']['monitor'],
                           session_state=pls['pools_members']['session'])

        except Exception, e:
            self._lb._channel.System.Session.rollback_transaction()

            # delete templates created
            template_names = [
                m for m in list(
                    itertools.chain(*[
                        m['monitor_rule']['monitor_templates']
                        for m in monitor_associations
                    ])) if 'MONITOR' in m
            ]
            if template_names:
                mon.delete_template(template_names=template_names)
            log.error(e)
            raise base_exceptions.CommandErrorException(e)