Skip to content
Merged
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
59 changes: 25 additions & 34 deletions internal/scheduling/nova/nova_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"log/slog"
"net/http"

Expand Down Expand Up @@ -157,31 +156,28 @@ func (api *novaClient) GetServerMigrations(ctx context.Context, id string) ([]mi
var nextURL = &initialURL
var migrations []migration
for nextURL != nil {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, *nextURL, http.NoBody)
if err != nil {
return nil, err
}
req.Header.Set("X-Auth-Token", api.sc.Token())
req.Header.Set("X-OpenStack-Nova-API-Version", api.sc.Microversion)
resp, err := api.sc.HTTPClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
}
var list struct {
Migrations []migration `json:"migrations"`
Links []struct {
Rel string `json:"rel"`
Href string `json:"href"`
} `json:"migrations_links"`
}
err = json.NewDecoder(resp.Body).Decode(&list)
resp, err := api.sc.Get(ctx, *nextURL, &list, &gophercloud.RequestOpts{
OkCodes: []int{http.StatusOK},
MoreHeaders: map[string]string{
"X-OpenStack-Nova-API-Version": api.sc.Microversion,
},
})
if err != nil {
if resp != nil {
resp.Body.Close()
}
return nil, err
}
if resp != nil {
resp.Body.Close()
}
nextURL = nil
for _, link := range list.Links {
if link.Rel == "next" {
Expand All @@ -206,23 +202,6 @@ func (api *novaClient) ListProjectServers(ctx context.Context, projectID string)
var result []ServerDetail

for nextURL != nil {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, *nextURL, http.NoBody)
if err != nil {
return nil, err
}
req.Header.Set("X-Auth-Token", api.sc.Token())
req.Header.Set("X-OpenStack-Nova-API-Version", api.sc.Microversion)

resp, err := api.sc.HTTPClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
}

// Response structure with nested flavor, metadata, tags, image, and volumes
var list struct {
Servers []struct {
Expand Down Expand Up @@ -255,9 +234,21 @@ func (api *novaClient) ListProjectServers(ctx context.Context, projectID string)
} `json:"servers_links"`
}

if err := json.NewDecoder(resp.Body).Decode(&list); err != nil {
resp, err := api.sc.Get(ctx, *nextURL, &list, &gophercloud.RequestOpts{
OkCodes: []int{http.StatusOK},
MoreHeaders: map[string]string{
"X-OpenStack-Nova-API-Version": api.sc.Microversion,
},
})
if err != nil {
if resp != nil {
resp.Body.Close()
}
return nil, err
}
if resp != nil {
resp.Body.Close()
}

// Convert to ServerDetail
for _, s := range list.Servers {
Expand Down
Loading