Skip to content

Commit

Permalink
Merge pull request #107 from metal-stack/switch-sync-not-v1
Browse files Browse the repository at this point in the history
Switch sync was not decoupled from internal data.
  • Loading branch information
Gerrit91 authored Sep 23, 2020
2 parents 2a85998 + b54dedd commit 248d0da
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 28 deletions.
31 changes: 27 additions & 4 deletions cmd/metal-api/internal/service/v1/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,39 @@ type SwitchResponse struct {
Nics SwitchNics `json:"nics" description:"the list of network interfaces on the switch"`
Partition PartitionResponse `json:"partition" description:"the partition in which this switch is located"`
Connections []SwitchConnection `json:"connections" description:"a connection between a switch port and a machine"`
LastSync *metal.SwitchSync `json:"last_sync" description:"last successful synchronization to the switch"`
LastSyncError *metal.SwitchSync `json:"last_sync_error" description:"last synchronization to the switch that was erroneous"`
LastSync *SwitchSync `json:"last_sync" description:"last successful synchronization to the switch" optional:"true"`
LastSyncError *SwitchSync `json:"last_sync_error" description:"last synchronization to the switch that was erroneous" optional:"true"`
Timestamps
}

type SwitchSync struct {
Time time.Time `json:"time" description:"point in time when the last switch sync happened"`
Duration time.Duration `json:"duration" description:"the duration that lat switch sync took"`
Error *string `json:"error" description:"shows the error occurred during the sync" optional:"true"`
}

func NewSwitchResponse(s *metal.Switch, p *metal.Partition, nics SwitchNics, cons []SwitchConnection) *SwitchResponse {
if s == nil {
return nil
}

var lastSync *SwitchSync
if s.LastSync != nil {
lastSync = &SwitchSync{
Time: s.LastSync.Time,
Duration: s.LastSync.Duration,
Error: s.LastSync.Error,
}
}
var lastSyncError *SwitchSync
if s.LastSyncError != nil {
lastSyncError = &SwitchSync{
Time: s.LastSyncError.Time,
Duration: s.LastSyncError.Duration,
Error: s.LastSyncError.Error,
}
}

return &SwitchResponse{
Common: Common{
Identifiable: Identifiable{
Expand All @@ -99,8 +122,8 @@ func NewSwitchResponse(s *metal.Switch, p *metal.Partition, nics SwitchNics, con
Nics: nics,
Partition: *NewPartitionResponse(p),
Connections: cons,
LastSync: s.LastSync,
LastSyncError: s.LastSyncError,
LastSync: lastSync,
LastSyncError: lastSyncError,
Timestamps: Timestamps{
Created: s.Created,
Changed: s.Changed,
Expand Down
48 changes: 24 additions & 24 deletions spec/metal-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,6 @@
"statuscode"
]
},
"metal.SwitchSync": {
"properties": {
"duration": {
"format": "integer",
"type": "integer"
},
"error": {
"type": "string"
},
"time": {
"format": "date-time",
"type": "string"
}
},
"required": [
"duration",
"error",
"time"
]
},
"rest.status": {
"properties": {
"message": {
Expand Down Expand Up @@ -2897,11 +2877,11 @@
"uniqueItems": true
},
"last_sync": {
"$ref": "#/definitions/metal.SwitchSync",
"$ref": "#/definitions/v1.SwitchSync",
"description": "last successful synchronization to the switch"
},
"last_sync_error": {
"$ref": "#/definitions/metal.SwitchSync",
"$ref": "#/definitions/v1.SwitchSync",
"description": "last synchronization to the switch that was erroneous"
},
"mode": {
Expand Down Expand Up @@ -2931,13 +2911,33 @@
"required": [
"connections",
"id",
"last_sync",
"last_sync_error",
"nics",
"partition",
"rack_id"
]
},
"v1.SwitchSync": {
"properties": {
"duration": {
"description": "the duration that lat switch sync took",
"format": "integer",
"type": "integer"
},
"error": {
"description": "shows the error occurred during the sync",
"type": "string"
},
"time": {
"description": "point in time when the last switch sync happened",
"format": "date-time",
"type": "string"
}
},
"required": [
"duration",
"time"
]
},
"v1.SwitchUpdateRequest": {
"properties": {
"description": {
Expand Down

0 comments on commit 248d0da

Please sign in to comment.