Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ with identical semantics upstream.
| `cinder/db` | `GetSnapshotCount` | `SnapshotCount` |
| `cinder/db` | `GetAllVolumes` | `VolumeGetAllWithAttachments` |
| `glance/db` | `GetAllImages` | `ImageGetAll` |
| `designate/db` | `ListZonesAndRecordsets` (zone details) | `ZoneGetAll` |
| `designate/db` | `ListZonesAndRecordsets` (per-zone counts) | `RecordsetCountByZone` |
| `designate/db` | `ListZonesAndRecordsets` (recordset details) | `RecordsetGetAllWithStatus` |
| `heat/db` | `GetStackMetrics` | `StackGetAll` |
| `ironic/db` | `GetNodeMetrics` | `GetNodeList` |
| `keystone/db` | `GetProjectMetrics` | `ListProjects` |
Expand Down Expand Up @@ -62,6 +65,7 @@ with identical semantics upstream.
- [Nova API database](https://github.com/openstack/nova/tree/master/nova/db/api) and [objects](https://github.com/openstack/nova/tree/master/nova/objects): flavor, aggregate, and quota data.
- [Cinder DB API](https://github.com/openstack/cinder/blob/master/cinder/db/api.py): `volume_get`, `volume_get_all`, `volume_type_get_all`, `service_get_all`.
- [Glance DB API](https://github.com/openstack/glance/blob/master/glance/db/sqlalchemy/api.py): `image_get`, `image_get_all`.
- [Designate storage](https://github.com/openstack/designate/blob/master/designate/storage/sqlalchemy/__init__.py): `find_zones`, `find_recordsets`, `count_recordsets`. The library also follows [Designate's UUID conversion](https://github.com/openstack/designate/blob/master/designate/storage/sqlalchemy/types.py) and [recordset status precedence](https://github.com/openstack/designate/blob/master/designate/objects/recordset.py).
- [Ironic DB API](https://github.com/openstack/ironic/blob/master/ironic/db/api.py) and [Magnum DB API](https://github.com/openstack/magnum/blob/master/magnum/db/api.py): `get_node_list`, `get_cluster_list`.
- [Heat DB API](https://github.com/openstack/heat/blob/master/heat/db/api.py): `stack_get_all`.
- [Manila DB API](https://github.com/openstack/manila/blob/master/manila/db/api.py): share operations; the instance join is an explicit extension.
Expand All @@ -77,6 +81,7 @@ with identical semantics upstream.
- Current exporter queries retain their existing deleted/hidden/status predicates; they are not full upstream administrative listings.
- Errors are Go/database errors; absent single resources return `sql.ErrNoRows` rather than Python service-specific exceptions.
- Aggregate queries such as `QuotaGetAllWithUsage`, `GetResourceProviderInventories`, and `GetResourceCountsByProject` are explicitly library extensions.
- Designate returns canonical zone and recordset UUIDs and excludes soft-deleted zones. `RecordsetCountByZone` includes zero-count zones and can run without reading individual records. `RecordsetGetAllWithStatus` uses the child precedence `ERROR`, `PENDING`, `ACTIVE`, `DELETED` and returns `ACTIVE` for an empty recordset. Recordsets with a NULL `zone_id` have no visible zone and are omitted.
- No cross-cell routing or historic schema negotiation is performed. Nova archive access is explicitly selected with `InstanceFilters.Archive`.

## Resource lifecycle and metadata reads
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ repository objects. Placement queries live under `placement/objects`.
| `nova/db/api` | `FlavorGetAll`, `AggregateGetAll`, quota projections |
| `cinder/db` | `ServiceGetAll`, `QuotaGetProjectLimits`, `QuotaUsageGetAll` |
| `glance/db` | `ImageGetAll` |
| `designate/db` | `ZoneGetAll`, `RecordsetCountByZone`, `RecordsetGetAllWithStatus` |
| `keystone/db` | `ListProjects`, `ListDomains`, `ListUsers` |
| `heat/db` | `StackGetAll` |
| `ironic/db` | `GetNodeList` |
Expand Down
31 changes: 31 additions & 0 deletions designate/db/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions designate/db/designate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package designate

import (
"context"

"github.com/google/uuid"
)

type (
ZoneGetAllRow = zoneGetAllRow
RecordsetCountByZoneRow = recordsetCountByZoneRow
RecordsetGetAllWithStatusRow = recordsetGetAllWithStatusRow
)

// ZoneGetAll returns non-deleted zones with API-format UUIDs.
func (q *Queries) ZoneGetAll(ctx context.Context) ([]ZoneGetAllRow, error) {
rows, err := q.zoneGetAll(ctx)
for i := range rows {
rows[i].ID = formatUUID(rows[i].ID)
}
return rows, err
}

// RecordsetCountByZone returns counts for non-deleted zones, including empty zones.
func (q *Queries) RecordsetCountByZone(ctx context.Context) ([]RecordsetCountByZoneRow, error) {
rows, err := q.recordsetCountByZone(ctx)
for i := range rows {
rows[i].ZoneID = formatUUID(rows[i].ZoneID)
}
return rows, err
}

// RecordsetGetAllWithStatus returns recordsets in non-deleted zones.
// Status follows Designate's child record precedence and defaults to ACTIVE.
func (q *Queries) RecordsetGetAllWithStatus(ctx context.Context) ([]RecordsetGetAllWithStatusRow, error) {
rows, err := q.recordsetGetAllWithStatus(ctx)
for i := range rows {
rows[i].ID = formatUUID(rows[i].ID)
rows[i].ZoneID = formatUUID(rows[i].ZoneID)
}
return rows, err
}

// Designate stores compact UUIDs and returns canonical UUIDs through its API.
func formatUUID(value string) string {
id, err := uuid.Parse(value)
if err != nil {
return value
}
return id.String()
}
31 changes: 31 additions & 0 deletions designate/db/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions designate/db/queries.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
-- name: zoneGetAll :many
SELECT id, name, tenant_id, status, type
FROM zones
WHERE deleted = '0';

-- name: recordsetCountByZone :many
SELECT
z.id AS zone_id,
z.name AS zone_name,
z.tenant_id,
COUNT(rs.id) AS recordset_count
FROM zones z
LEFT JOIN recordsets rs ON rs.zone_id = z.id
WHERE z.deleted = '0'
GROUP BY z.id, z.name, z.tenant_id;

-- name: recordsetGetAllWithStatus :many
SELECT
rs.id,
rs.name,
rs.type,
z.id AS zone_id,
z.name AS zone_name,
CASE rs_status.severity
WHEN 1 THEN 'ERROR'
WHEN 2 THEN 'PENDING'
WHEN 3 THEN 'ACTIVE'
WHEN 4 THEN 'DELETED'
ELSE 'ACTIVE'
END AS status
FROM recordsets rs
JOIN zones z ON z.id = rs.zone_id
LEFT JOIN (
SELECT recordset_id,
MIN(CASE status
WHEN 'ERROR' THEN 1
WHEN 'PENDING' THEN 2
WHEN 'ACTIVE' THEN 3
WHEN 'DELETED' THEN 4
END) AS severity
FROM records
GROUP BY recordset_id
) rs_status ON rs_status.recordset_id = rs.id
WHERE z.deleted = '0';
170 changes: 170 additions & 0 deletions designate/db/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.25.5
require (
github.com/DATA-DOG/go-sqlmock v1.5.2
github.com/go-sql-driver/mysql v1.9.3
github.com/google/uuid v1.6.0
github.com/stretchr/testify v1.11.1
github.com/testcontainers/testcontainers-go v0.40.0
github.com/testcontainers/testcontainers-go/modules/mariadb v0.40.0
Expand All @@ -31,7 +32,6 @@ require (
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.8 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
Expand Down
Loading