예제 #1
0
파일: lbaas.py 프로젝트: BoTranVan/senlin
    def member_remove(self, lb_id, pool_id, member_id):
        """Delete a member from Neutron lbaas pool.

        :param lb_id: The ID of the loadbalancer the operation is targeted at;
        :param pool_id: The ID of the pool from which the member is deleted;
        :param member_id: The ID of the LB member.
        :returns: True if the operation succeeded or False if errors occurred.
        """
        try:
            # FIXME(Yanyan Hu): Currently, Neutron lbaasv2 service can not
            # handle concurrent lb member operations well: new member creation
            # deletion request will directly fail rather than being lined up
            # when another operation is still in progress. In this workaround,
            # loadbalancer status will be checked before deleting lb member
            # request is sent out. If loadbalancer keeps unready till waiting
            # timeout, exception will be raised to fail member_remove.
            res = self._wait_for_lb_ready(lb_id)
            if not res:
                msg = 'Loadbalancer %s is not ready.' % lb_id
                raise exception.Error(msg)
            self.oc().pool_member_delete(pool_id, member_id)
        except (exception.InternalError, exception.Error) as ex:
            LOG.exception('Failed in removing member %(m)s from pool %(p)s: '
                          '%(ex)s', {'m': member_id, 'p': pool_id, 'ex': ex})
            return None
        res = self._wait_for_lb_ready(lb_id, ignore_not_found=True)
        if res is False:
            LOG.error('Failed in deleting pool member (%s).', member_id)
            return None

        return True
예제 #2
0
    def member_add(self, node, lb_id, pool_id, port, subnet):
        """Add a member to Neutron lbaas pool.

        :param node: A node object to be added to the specified pool.
        :param lb_id: The ID of the loadbalancer.
        :param pool_id: The ID of the pool for receiving the node.
        :param port: The port for the new LB member to be created.
        :param subnet: The subnet to be used by the new LB member.
        :returns: The ID of the new LB member or None if errors occurred.
        """
        try:
            subnet_obj = self.nc().subnet_get(subnet)
            net_id = subnet_obj.network_id
            net = self.nc().network_get(net_id)
        except exception.InternalError as ex:
            resource = 'subnet' if subnet in ex.message else 'network'
            msg = ('Failed in getting %(resource)s: %(msg)s.' % {
                'resource': resource,
                'msg': six.text_type(ex)
            })
            LOG.exception(msg)
            return None
        net_name = net.name

        node_detail = node.get_details(oslo_context.get_current())
        addresses = node_detail.get('addresses')
        if net_name not in addresses:
            msg = 'Node is not in subnet %(subnet)s'
            LOG.error(msg, {'subnet': subnet})
            return None

        # Use the first IP address if more than one are found in target network
        address = addresses[net_name][0]['addr']
        try:
            # FIXME(Yanyan Hu): Currently, Neutron lbaasv2 service can not
            # handle concurrent lb member operations well: new member creation
            # deletion request will directly fail rather than being lined up
            # when another operation is still in progress. In this workaround,
            # loadbalancer status will be checked before creating lb member
            # request is sent out. If loadbalancer keeps unready till waiting
            # timeout, exception will be raised to fail member_add.
            res = self._wait_for_lb_ready(lb_id)
            if not res:
                msg = 'Loadbalancer %s is not ready.' % lb_id
                raise exception.Error(msg)
            member = self.nc().pool_member_create(pool_id, address, port,
                                                  subnet_obj.id)
        except (exception.InternalError, exception.Error) as ex:
            msg = ('Failed in creating lb pool member: %s.' %
                   six.text_type(ex))
            LOG.exception(msg)
            return None
        res = self._wait_for_lb_ready(lb_id)
        if res is False:
            LOG.error('Failed in creating pool member (%s).', member.id)
            return None

        return member.id
예제 #3
0
 def test_format_string_error_message(self):
     message = "This format %(message)s should work"
     err = exception.Error(message)
     self.assertEqual(message, str(err))