Example #1
0
    def delete_pool_health_monitor(self, context, id, pool_id):
        try:
            pool = self._api.loadbalancer_pool_read(id=pool_id)
        except vnc_exc.NoIdError:
            raise loadbalancer.PoolNotFound(pool_id=id)
        tenant_id = str(uuid.UUID(context.tenant_id))
        if not context.is_admin and tenant_id != pool.parent_uuid:
            raise loadbalancer.PoolNotFound(pool_id=id)

        try:
            monitor = self._api.loadbalancer_healthmonitor_read(id=id)
        except vnc_exc.NoIdError:
            raise loadbalancer.HealthMonitorNotFound(monitor_id=id)

        in_list = False
        for mref in pool.get_loadbalancer_healthmonitor_refs():
            if mref['uuid'] == id:
                in_list = True
                break

        if not in_list:
            raise loadbalancer.PoolMonitorAssociationNotFound(
                monitor_id=id, pool_id=pool_id)

        pool.del_loadbalancer_healthmonitor(monitor)
        self._api.loadbalancer_pool_update(pool)
Example #2
0
    def get_pool_health_monitor(self, context, id, pool_id, fields=None):
        """ Query a specific pool, health_monitor association.
        """
        try:
            pool = self._api.loadbalancer_pool_read(id=pool_id)
        except vnc_exc.NoIdError:
            raise loadbalancer.PoolNotFound(pool_id=id)
        tenant_id = str(uuid.UUID(context.tenant_id))
        if not context.is_admin and tenant_id != pool.parent_uuid:
            raise loadbalancer.PoolNotFound(pool_id=id)

        in_list = False
        for mref in pool.get_loadbalancer_healthmonitor_refs() or []:
            if mref['uuid'] == id:
                in_list = True
                break

        if not in_list:
            raise loadbalancer.PoolMonitorAssociationNotFound(
                monitor_id=id, pool_id=pool_id)

        res = {
            'pool_id': pool_id,
            'monitor_id': id,
            'status': self._pool_manager._get_object_status(pool),
            'tenant_id': pool.parent_uuid.replace('-', '')
        }
        return self._pool_manager._fields(res, fields)
Example #3
0
    def create_pool_health_monitor(self, context, health_monitor, pool_id):
        """ Associate an health monitor with a pool.
        """
        m = health_monitor['health_monitor']
        try:
            pool = self._api.loadbalancer_pool_read(id=pool_id)
        except vnc_exc.NoIdError:
            raise loadbalancer.PoolNotFound(pool_id=pool_id)

        try:
            monitor = self._api.loadbalancer_healthmonitor_read(id=m['id'])
        except vnc_exc.NoIdError:
            raise loadbalancer.HealthMonitorNotFound(monitor_id=m['id'])

        if not context.is_admin:
            tenant_id = str(uuid.UUID(context.tenant_id))
            if tenant_id != pool.parent_uuid or \
                    tenant_id != monitor.parent_uuid:
                raise n_exc.NotAuthorized()

        pool_refs = monitor.get_loadbalancer_pool_back_refs()
        if pool_refs is not None:
            for ref in pool_refs:
                if ref['uuid'] == pool_id:
                    raise loadbalancer.PoolMonitorAssociationExists(
                        monitor_id=m['id'], pool_id=pool_id)

        pool.add_loadbalancer_healthmonitor(monitor)
        self._api.loadbalancer_pool_update(pool)

        res = {
            'id': monitor.uuid,
            'tenant_id': monitor.parent_uuid.replace('-', '')
        }
        return res
Example #4
0
    def create(self, context, member):
        """
        Create a loadbalancer_member object.
        """
        m = member['member']
        try:
            pool = self._api.loadbalancer_pool_read(id=m['pool_id'])
        except NoIdError:
            raise loadbalancer.PoolNotFound(pool_id=m['pool_id'])

        tenant_id = self._get_tenant_id_for_create(context, m)
        if str(uuid.UUID(tenant_id)) != pool.parent_uuid:
            raise n_exc.NotAuthorized()

        obj_uuid = uuidutils.generate_uuid()
        props = self.make_properties(m)
        id_perms = IdPermsType(enable=True)

        member_db = LoadbalancerMember(obj_uuid,
                                       pool,
                                       loadbalancer_member_properties=props,
                                       id_perms=id_perms)
        member_db.uuid = obj_uuid

        self._api.loadbalancer_member_create(member_db)
        return self.make_dict(member_db)
Example #5
0
    def update_object(self, vip_db, id, v):
        if 'pool_id' in v and self._get_vip_pool_id(vip_db) != v['pool_id']:
            try:
                pool = self._api.loadbalancer_pool_read(id=v['pool_id'])
            except NoIdError:
                raise loadbalancer.PoolNotFound(pool_id=v['pool_id'])
            if vip_db.parent_uuid != pool.parent_uuid:
                raise n_exc.NotAuthorized()

            # check that the pool has no vip configured
            if pool.get_virtual_ip_back_refs():
                raise loadbalancer.VipExists(pool_id=pool_obj.uuid)

            # check that the protocol matches
            pool_props = pool.get_loadbalancer_pool_properties()
            vip_props = vip_db.get_virtual_ip_properties()
            if pool_props.get_protocol() != vip_props.get_protocol():
                raise loadbalancer.ProtocolMismatch(
                    vip_proto=vip_props.get_protocol(),
                    pool_proto=pool_props.get_protocol())

            # update vip
            vip_db.set_loadbalancer_pool(pool)
            return True

        return False
Example #6
0
 def _get_resource(self, context, model, id):
     try:
         r = self._get_by_id(context, model, id)
     except exc.NoResultFound:
         with excutils.save_and_reraise_exception():
             if issubclass(model, Vip):
                 raise loadbalancer.VipNotFound(vip_id=id)
             elif issubclass(model, Pool):
                 raise loadbalancer.PoolNotFound(pool_id=id)
             elif issubclass(model, Member):
                 raise loadbalancer.MemberNotFound(member_id=id)
             elif issubclass(model, HealthMonitor):
                 raise loadbalancer.HealthMonitorNotFound(monitor_id=id)
     return r
    def create(self, context, vip):
        """
        Create a VIP.
        """
        v = vip['vip']
        tenant_id = self._get_tenant_id_for_create(context, v)

        project = self._project_read(project_id=tenant_id)

        if v['pool_id']:
            try:
                pool = self._api.loadbalancer_pool_read(id=v['pool_id'])
            except NoIdError:
                raise loadbalancer.PoolNotFound(pool_id=v['pool_id'])
            project_id = pool.parent_uuid
            if str(uuid.UUID(tenant_id)) != project_id:
                raise n_exc.NotAuthorized()
            protocol = pool.get_loadbalancer_pool_properties().get_protocol()
            if protocol != v['protocol']:
                raise loadbalancer.ProtocolMismatch(vip_proto=v['protocol'],
                                                    pool_proto=protocol)
            if pool.get_virtual_ip_back_refs():
                raise loadbalancer.VipExists(pool_id=v['pool_id'])
        else:
            pool = None

        obj_uuid = uuidutils.generate_uuid()
        name = self._get_resource_name('virtual-ip', project, v['name'],
                                       obj_uuid)
        id_perms = IdPermsType(enable=True, description=v['description'])
        vip = VirtualIp(name,
                        project,
                        id_perms=id_perms,
                        display_name=v['name'])
        vip.uuid = obj_uuid

        if pool:
            vip.set_loadbalancer_pool(pool)

        vmi, vip_address = self._create_virtual_interface(
            project, obj_uuid, v['subnet_id'], v.get('address'))
        vip.set_virtual_machine_interface(vmi)

        props = self.make_properties(v)
        props.set_address(vip_address)
        vip.set_virtual_ip_properties(props)

        self._api.virtual_ip_create(vip)
        return self.make_dict(vip)
    def update_object(self, vip_db, id, v):
        if 'pool_id' in v and self._get_vip_pool_id(vip_db) != v['pool_id']:
            try:
                pool = self._api.loadbalancer_pool_read(id=v['pool_id'])
            except NoIdError:
                raise loadbalancer.PoolNotFound(pool_id=v['pool_id'])
            if vip_db.parent_uuid != pool.parent_uuid:
                raise n_exc.NotAuthorized()
            # TODO: check that the pool has no vip configured
            # TODO: check that the protocol matches
            # TODO: check that the pool is in valid state
            # TODO: check that the provider is the same.
            vip_db.set_localbalancer_pool(pool)
            return True

        return False
    def create(self, context, vip):
        """
        Create a VIP.
        """
        v = vip['vip']
        tenant_id = self._get_tenant_id_for_create(context, v)

        project = self._project_read(project_id=tenant_id)

        if v['pool_id']:
            try:
                pool = self._api.loadbalancer_pool_read(id=v['pool_id'])
            except NoIdError:
                raise loadbalancer.PoolNotFound(pool_id=v['pool_id'])
            project_id = pool.parent_uuid
            if tenant_id != project_id:
                raise n_exc.NotAuthorized()
            # TODO: check that the pool has no vip configured
            # if pool.protocol != v['protocol']:
            #     raise loadbalancer.ProtocolMismatch(
            #         vip_proto=v['protocol'], pool_proto=pool.protocol)
        else:
            pool = None

        uuid = uuidutils.generate_uuid()
        name = self._get_resource_name('virtual-ip', project, v['name'], uuid)
        props = self.make_properties(v)
        id_perms = IdPermsType(uuid=uuid,
                               enable=True,
                               description=v['description'])
        vip = VirtualIp(name,
                        project,
                        virtual_ip_properties=props,
                        id_perms=id_perms,
                        display_name=v['name'])
        vip.uuid = uuid

        if pool:
            vip.set_loadbalancer_pool(pool)

        vmi = self._create_virtual_interface(project, uuid, v['subnet_id'],
                                             v.get('address'))
        vip.set_virtual_machine_interface(vmi)

        self._api.virtual_ip_create(vip)
        return self.make_dict(vip)
    def update_object(self, member_db, id, pool_id, m):
        try:
            pool = self._api.loadbalancer_pool_read(id=pool_id)
        except NoIdError:
            raise loadbalancer.PoolNotFound(pool_id=pool_id)

        db_props = member_db.get_loadbalancer_member_properties()
        members = pool.get_loadbalancer_members()
        for member in members or []:
            member_obj = self._api.loadbalancer_member_read(id=member['uuid'])
            props = member_obj.get_loadbalancer_member_properties()
            if ((props.get_address() == db_props.get_address()) and
                (props.get_protocol_port() == db_props.get_protocol_port())):
                raise loadbalancer.MemberExists(address=props.get_address(),
                                                port=props.get_protocol_port(),
                                                pool=pool_id)

        return True
Example #11
0
    def update_object(self, member_db, id, m):
        if 'pool_id' in m and self._get_member_pool_id(
                member_db) != m['pool_id']:
            try:
                pool = self._api.loadbalancer_pool_read(id=m['pool_id'])
            except NoIdError:
                raise loadbalancer.PoolNotFound(pool_id=m['pool_id'])

            db_props = member_db.get_loadbalancer_member_properties()
            members = pool.get_loadbalancer_members()
            for member in members or []:
                member_obj = self._api.loadbalancer_member_read(
                    id=member['uuid'])
                props = member_obj.get_loadbalancer_member_properties()
                if ((props.get_address() == db_props.get_address())
                        and (props.get_protocol_port()
                             == db_props.get_protocol_port())):
                    raise loadbalancer.MemberExists(
                        address=props.get_address(),
                        port=props.get_protocol_port(),
                        pool=m['pool_id'])

            # delete member from old pool
            props = member_db.get_loadbalancer_member_properties()
            obj_uuid = member_db.uuid
            self._api.loadbalancer_member_delete(id=member_db.uuid)

            # create member for the new pool with same uuid and props
            id_perms = IdPermsType(enable=True)
            member_obj = LoadbalancerMember(
                obj_uuid,
                pool,
                loadbalancer_member_properties=props,
                id_perms=id_perms)
            member_obj.uuid = obj_uuid
            self._api.loadbalancer_member_create(member_obj)

            return True

        return False
Example #12
0
 def get_exception_notfound(self, id=None):
     return loadbalancer.PoolNotFound(pool_id=id)