Persist Floating IP UUIDs for direct Neutron operations
This commit is contained in:
1 parent
89ac4d5bcd
commit
94124747ce
24 files changed
+918
-116
No files matched your search
@@ -12,6 +12,7 @@ type DiagnosticHold struct {
|
||||
Address string `json:"address"`
|
||||
ValidatorID string `json:"validator_id"`
|
||||
FIPID string `json:"fip_id"`
|
||||
PortID string `json:"-"`
|
||||
Note string `json:"note"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
@@ -20,10 +21,14 @@ type DiagnosticHold struct {
|
||||
// the hold, in one transaction. ErrNotFound: no such validator; ErrBusy: the
|
||||
// validator is not idle; ErrConflict: the address or validator is already held.
|
||||
func (d *DB) ClaimDiagnostic(ctx context.Context, validatorID, address, fipID, note string) error {
|
||||
return d.claimDiagnostic(ctx, validatorID, address, fipID, note, nil)
|
||||
return d.ClaimDiagnosticAtPort(ctx, validatorID, "", address, fipID, note)
|
||||
}
|
||||
|
||||
func (d *DB) claimDiagnostic(ctx context.Context, validatorID, address, fipID, note string, item *DiagnosticOperationItem) error {
|
||||
func (d *DB) ClaimDiagnosticAtPort(ctx context.Context, validatorID, portID, address, fipID, note string) error {
|
||||
return d.claimDiagnostic(ctx, validatorID, portID, address, fipID, note, nil)
|
||||
}
|
||||
|
||||
func (d *DB) claimDiagnostic(ctx context.Context, validatorID, expectedPort, address, fipID, note string, item *DiagnosticOperationItem) error {
|
||||
tx, err := d.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -49,10 +54,6 @@ func (d *DB) claimDiagnostic(ctx context.Context, validatorID, address, fipID, n
|
||||
if held {
|
||||
return fmt.Errorf("address %q or validator %q is already held: %w", address, validatorID, ErrConflict)
|
||||
}
|
||||
var expectedPort string
|
||||
if item != nil {
|
||||
expectedPort = item.PortID
|
||||
}
|
||||
res, err := tx.ExecContext(ctx, `
|
||||
UPDATE validators SET state=?, updated_at=?
|
||||
WHERE validator_id=? AND state=? AND current_ip_id IS NULL AND (?='' OR os_port_id=?)
|
||||
@@ -81,9 +82,9 @@ func (d *DB) claimDiagnostic(ctx context.Context, validatorID, address, fipID, n
|
||||
}
|
||||
}
|
||||
if _, err := tx.ExecContext(ctx, `
|
||||
INSERT INTO diagnostic_holds (address, validator_id, fip_id, note, created_at, pending_item_id)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
`, address, validatorID, fipID, note, now, pendingID); err != nil {
|
||||
INSERT INTO diagnostic_holds (address, validator_id, fip_id, note, created_at, pending_item_id, port_id)
|
||||
VALUES (?, ?, ?, ?, ?, ?, (SELECT os_port_id FROM validators WHERE validator_id=?))
|
||||
`, address, validatorID, fipID, note, now, pendingID, validatorID); err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.Commit()
|
||||
@@ -120,7 +121,7 @@ func resetDiagnosticValidator(ctx context.Context, tx *sql.Tx, validatorID strin
|
||||
return err
|
||||
}
|
||||
|
||||
const holdSelect = `SELECT address, validator_id, fip_id, note, created_at FROM diagnostic_holds`
|
||||
const holdSelect = `SELECT address, validator_id, fip_id, note, created_at, port_id FROM diagnostic_holds`
|
||||
|
||||
func (d *DB) HasDiagnosticHold(ctx context.Context, address string) (bool, error) {
|
||||
var exists bool
|
||||
@@ -131,7 +132,7 @@ func (d *DB) HasDiagnosticHold(ctx context.Context, address string) (bool, error
|
||||
func scanHold(row rowScanner) (*DiagnosticHold, error) {
|
||||
var h DiagnosticHold
|
||||
var created string
|
||||
if err := row.Scan(&h.Address, &h.ValidatorID, &h.FIPID, &h.Note, &created); err != nil {
|
||||
if err := row.Scan(&h.Address, &h.ValidatorID, &h.FIPID, &h.Note, &created, &h.PortID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var err error
|
||||
|
||||
Reference in new issue
Block a user