-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackit_client.go
More file actions
105 lines (95 loc) · 4.72 KB
/
stackit_client.go
File metadata and controls
105 lines (95 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package provider
import (
"context"
)
// StackitClient is an interface for interacting with STACKIT IAAS API
// This allows us to mock the client in unit tests
//
// Architecture: Single-tenant design
// - Each client instance is bound to one STACKIT project via serviceAccountKey
// - The serviceAccountKey is provided once during client creation (NewStackitClient)
// - The SDK automatically handles JWT token generation and refresh
//
// Note: region parameter is required by STACKIT SDK v1.0.0+
// It must be extracted from the Secret (e.g., "eu01-1", "eu01-2")
// nolint:dupl // the duplicates are mock functions
type StackitClient interface {
// CreateServer creates a new server in STACKIT
CreateServer(ctx context.Context, projectID, region string, req *CreateServerRequest) (*Server, error)
// GetServer retrieves a server by ID from STACKIT
GetServer(ctx context.Context, projectID, region, serverID string) (*Server, error)
// DeleteServer deletes a server by ID from STACKIT
DeleteServer(ctx context.Context, projectID, region, serverID string) error
// ListServers lists all servers in a project
ListServers(ctx context.Context, projectID, region string, labelSelector map[string]string) ([]*Server, error)
// GetNICsForServer retrieves a network interfaces for a given server
GetNICsForServer(ctx context.Context, projectID, region, serverID string) ([]*NIC, error)
// ListNics list all nics for a network
ListNICs(ctx context.Context, projectID, region, networkID string) ([]*NIC, error)
// DeleteNIC delete a given nic by ID
DeleteNIC(ctx context.Context, projectID, region, networkID, nicID string) error
// UpdateNIC updates a network interface
UpdateNIC(ctx context.Context, projectID, region, networkID, nicID string, allowedAddresses []string) (*NIC, error)
}
// CreateServerRequest represents the request to create a server
type CreateServerRequest struct {
Name string `json:"name"`
MachineType string `json:"machineType"`
ImageID string `json:"imageId,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Networking *ServerNetworkingRequest `json:"networking"` // Required in v2 API, no omitempty
SecurityGroups []string `json:"securityGroups,omitempty"`
UserData string `json:"userData,omitempty"`
BootVolume *BootVolumeRequest `json:"bootVolume,omitempty"`
Volumes []string `json:"volumes,omitempty"`
KeypairName string `json:"keypairName,omitempty"`
AvailabilityZone string `json:"availabilityZone,omitempty"`
AffinityGroup string `json:"affinityGroup,omitempty"`
ServiceAccountMails []string `json:"serviceAccountMails,omitempty"`
Agent *AgentRequest `json:"agent,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
// ServerNetworkingRequest represents the networking configuration for a server
//
// Union type - use one of the following (mutually exclusive):
// - NetworkID: Auto-create a NIC in the specified network (takes precedence)
// - NICIDs: Attach pre-existing NICs to the server
//
// If both are specified, NetworkID takes precedence and NICIDs is ignored.
type ServerNetworkingRequest struct {
NetworkID string `json:"networkId,omitempty"`
NICIDs []string `json:"nicIds,omitempty"`
}
// BootVolumeRequest represents the boot volume configuration for a server
type BootVolumeRequest struct {
DeleteOnTermination *bool `json:"deleteOnTermination,omitempty"`
PerformanceClass string `json:"performanceClass,omitempty"`
Size int `json:"size,omitempty"`
Source *BootVolumeSourceRequest `json:"source,omitempty"`
}
// BootVolumeSourceRequest represents the source for creating a boot volume
type BootVolumeSourceRequest struct {
Type string `json:"type"`
ID string `json:"id"`
}
// AgentRequest represents the STACKIT agent configuration for a server
type AgentRequest struct {
Provisioned *bool `json:"provisioned,omitempty"`
}
// Server represents a STACKIT server response
type Server struct {
ID string `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
Labels map[string]string `json:"labels,omitempty"`
}
// NIC represents a STACKIT network interface
type NIC struct {
ID string
NetworkID string
AllowedAddresses []string
Name string
}