@@ -21,11 +21,9 @@ import (
21
21
22
22
"github.com/gophercloud/gophercloud"
23
23
"github.com/gophercloud/gophercloud/openstack"
24
- "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes"
25
24
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces"
26
25
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones"
27
26
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
28
- "github.com/gophercloud/gophercloud/openstack/imageservice/v2/images"
29
27
"github.com/gophercloud/utils/openstack/compute/v2/flavors"
30
28
31
29
"sigs.k8s.io/cluster-api-provider-openstack/pkg/metrics"
@@ -52,8 +50,6 @@ type ServerExt struct {
52
50
type ComputeClient interface {
53
51
ListAvailabilityZones () ([]availabilityzones.AvailabilityZone , error )
54
52
55
- ListImages (listOpts images.ListOptsBuilder ) ([]images.Image , error )
56
-
57
53
GetFlavorIDFromName (flavor string ) (string , error )
58
54
CreateServer (createOpts servers.CreateOptsBuilder ) (* ServerExt , error )
59
55
DeleteServer (serverID string ) error
@@ -62,18 +58,9 @@ type ComputeClient interface {
62
58
63
59
ListAttachedInterfaces (serverID string ) ([]attachinterfaces.Interface , error )
64
60
DeleteAttachedInterface (serverID , portID string ) error
65
-
66
- ListVolumes (opts volumes.ListOptsBuilder ) ([]volumes.Volume , error )
67
- CreateVolume (opts volumes.CreateOptsBuilder ) (* volumes.Volume , error )
68
- DeleteVolume (volumeID string , opts volumes.DeleteOptsBuilder ) error
69
- GetVolume (volumeID string ) (* volumes.Volume , error )
70
61
}
71
62
72
- type computeClient struct {
73
- compute * gophercloud.ServiceClient
74
- images * gophercloud.ServiceClient
75
- volume * gophercloud.ServiceClient
76
- }
63
+ type computeClient struct { client * gophercloud.ServiceClient }
77
64
78
65
// NewComputeClient returns a new compute client.
79
66
func NewComputeClient (scope * scope.Scope ) (ComputeClient , error ) {
@@ -85,122 +72,111 @@ func NewComputeClient(scope *scope.Scope) (ComputeClient, error) {
85
72
}
86
73
compute .Microversion = NovaMinimumMicroversion
87
74
88
- images , err := openstack .NewImageServiceV2 (scope .ProviderClient , gophercloud.EndpointOpts {
89
- Region : scope .ProviderClientOpts .RegionName ,
90
- })
91
- if err != nil {
92
- return nil , fmt .Errorf ("failed to create image service client: %v" , err )
93
- }
94
-
95
- volume , err := openstack .NewBlockStorageV3 (scope .ProviderClient , gophercloud.EndpointOpts {
96
- Region : scope .ProviderClientOpts .RegionName ,
97
- })
98
- if err != nil {
99
- return nil , fmt .Errorf ("failed to create volume service client: %v" , err )
100
- }
101
-
102
- return & computeClient {compute , images , volume }, nil
75
+ return & computeClient {compute }, nil
103
76
}
104
77
105
- func (s computeClient ) ListAvailabilityZones () ([]availabilityzones.AvailabilityZone , error ) {
78
+ func (c computeClient ) ListAvailabilityZones () ([]availabilityzones.AvailabilityZone , error ) {
106
79
mc := metrics .NewMetricPrometheusContext ("availability_zone" , "list" )
107
- allPages , err := availabilityzones .List (s . compute ).AllPages ()
80
+ allPages , err := availabilityzones .List (c . client ).AllPages ()
108
81
if mc .ObserveRequest (err ) != nil {
109
82
return nil , err
110
83
}
111
84
return availabilityzones .ExtractAvailabilityZones (allPages )
112
85
}
113
86
114
- func (s computeClient ) ListImages (listOpts images.ListOptsBuilder ) ([]images.Image , error ) {
115
- mc := metrics .NewMetricPrometheusContext ("image" , "list" )
116
- pages , err := images .List (s .images , listOpts ).AllPages ()
117
- if mc .ObserveRequest (err ) != nil {
118
- return nil , err
119
- }
120
- return images .ExtractImages (pages )
121
- }
122
-
123
- func (s computeClient ) GetFlavorIDFromName (flavor string ) (string , error ) {
87
+ func (c computeClient ) GetFlavorIDFromName (flavor string ) (string , error ) {
124
88
mc := metrics .NewMetricPrometheusContext ("flavor" , "get" )
125
- flavorID , err := flavors .IDFromName (s . compute , flavor )
89
+ flavorID , err := flavors .IDFromName (c . client , flavor )
126
90
return flavorID , mc .ObserveRequest (err )
127
91
}
128
92
129
- func (s computeClient ) CreateServer (createOpts servers.CreateOptsBuilder ) (* ServerExt , error ) {
93
+ func (c computeClient ) CreateServer (createOpts servers.CreateOptsBuilder ) (* ServerExt , error ) {
130
94
var server ServerExt
131
95
mc := metrics .NewMetricPrometheusContext ("server" , "create" )
132
- err := servers .Create (s . compute , createOpts ).ExtractInto (& server )
96
+ err := servers .Create (c . client , createOpts ).ExtractInto (& server )
133
97
if mc .ObserveRequest (err ) != nil {
134
98
return nil , err
135
99
}
136
100
return & server , nil
137
101
}
138
102
139
- func (s computeClient ) DeleteServer (serverID string ) error {
103
+ func (c computeClient ) DeleteServer (serverID string ) error {
140
104
mc := metrics .NewMetricPrometheusContext ("server" , "delete" )
141
- err := servers .Delete (s . compute , serverID ).ExtractErr ()
105
+ err := servers .Delete (c . client , serverID ).ExtractErr ()
142
106
return mc .ObserveRequestIgnoreNotFound (err )
143
107
}
144
108
145
- func (s computeClient ) GetServer (serverID string ) (* ServerExt , error ) {
109
+ func (c computeClient ) GetServer (serverID string ) (* ServerExt , error ) {
146
110
var server ServerExt
147
111
mc := metrics .NewMetricPrometheusContext ("server" , "get" )
148
- err := servers .Get (s . compute , serverID ).ExtractInto (& server )
112
+ err := servers .Get (c . client , serverID ).ExtractInto (& server )
149
113
if mc .ObserveRequestIgnoreNotFound (err ) != nil {
150
114
return nil , err
151
115
}
152
116
return & server , nil
153
117
}
154
118
155
- func (s computeClient ) ListServers (listOpts servers.ListOptsBuilder ) ([]ServerExt , error ) {
119
+ func (c computeClient ) ListServers (listOpts servers.ListOptsBuilder ) ([]ServerExt , error ) {
156
120
var serverList []ServerExt
157
121
mc := metrics .NewMetricPrometheusContext ("server" , "list" )
158
- allPages , err := servers .List (s . compute , listOpts ).AllPages ()
122
+ allPages , err := servers .List (c . client , listOpts ).AllPages ()
159
123
if mc .ObserveRequest (err ) != nil {
160
124
return nil , err
161
125
}
162
126
err = servers .ExtractServersInto (allPages , & serverList )
163
127
return serverList , err
164
128
}
165
129
166
- func (s computeClient ) ListAttachedInterfaces (serverID string ) ([]attachinterfaces.Interface , error ) {
130
+ func (c computeClient ) ListAttachedInterfaces (serverID string ) ([]attachinterfaces.Interface , error ) {
167
131
mc := metrics .NewMetricPrometheusContext ("server_os_interface" , "list" )
168
- interfaces , err := attachinterfaces .List (s . compute , serverID ).AllPages ()
132
+ interfaces , err := attachinterfaces .List (c . client , serverID ).AllPages ()
169
133
if mc .ObserveRequest (err ) != nil {
170
134
return nil , err
171
135
}
172
136
return attachinterfaces .ExtractInterfaces (interfaces )
173
137
}
174
138
175
- func (s computeClient ) DeleteAttachedInterface (serverID , portID string ) error {
139
+ func (c computeClient ) DeleteAttachedInterface (serverID , portID string ) error {
176
140
mc := metrics .NewMetricPrometheusContext ("server_os_interface" , "delete" )
177
- err := attachinterfaces .Delete (s . compute , serverID , portID ).ExtractErr ()
141
+ err := attachinterfaces .Delete (c . client , serverID , portID ).ExtractErr ()
178
142
return mc .ObserveRequestIgnoreNotFoundorConflict (err )
179
143
}
180
144
181
- func (s computeClient ) ListVolumes (opts volumes.ListOptsBuilder ) ([]volumes.Volume , error ) {
182
- mc := metrics .NewMetricPrometheusContext ("volume" , "list" )
183
- pages , err := volumes .List (s .volume , opts ).AllPages ()
184
- if mc .ObserveRequest (err ) != nil {
185
- return nil , err
186
- }
187
- return volumes .ExtractVolumes (pages )
145
+ type computeErrorClient struct { error }
146
+
147
+ // NewComputeErrorClient returns a ComputeClient in which every method returns the given error.
148
+ func NewComputeErrorClient (e error ) ComputeClient {
149
+ return computeErrorClient {e }
188
150
}
189
151
190
- func (s computeClient ) CreateVolume (opts volumes.CreateOptsBuilder ) (* volumes.Volume , error ) {
191
- mc := metrics .NewMetricPrometheusContext ("volume" , "create" )
192
- volume , err := volumes .Create (s .volume , opts ).Extract ()
193
- return volume , mc .ObserveRequest (err )
152
+ func (e computeErrorClient ) ListAvailabilityZones () ([]availabilityzones.AvailabilityZone , error ) {
153
+ return nil , e .error
194
154
}
195
155
196
- func (s computeClient ) DeleteVolume (volumeID string , opts volumes.DeleteOptsBuilder ) error {
197
- mc := metrics .NewMetricPrometheusContext ("volume" , "delete" )
198
- err := volumes .Delete (s .volume , volumeID , opts ).ExtractErr ()
199
- return mc .ObserveRequestIgnoreNotFound (err )
156
+ func (e computeErrorClient ) GetFlavorIDFromName (flavor string ) (string , error ) {
157
+ return "" , e .error
158
+ }
159
+
160
+ func (e computeErrorClient ) CreateServer (createOpts servers.CreateOptsBuilder ) (* ServerExt , error ) {
161
+ return nil , e .error
162
+ }
163
+
164
+ func (e computeErrorClient ) DeleteServer (serverID string ) error {
165
+ return e .error
166
+ }
167
+
168
+ func (e computeErrorClient ) GetServer (serverID string ) (* ServerExt , error ) {
169
+ return nil , e .error
170
+ }
171
+
172
+ func (e computeErrorClient ) ListServers (listOpts servers.ListOptsBuilder ) ([]ServerExt , error ) {
173
+ return nil , e .error
174
+ }
175
+
176
+ func (e computeErrorClient ) ListAttachedInterfaces (serverID string ) ([]attachinterfaces.Interface , error ) {
177
+ return nil , e .error
200
178
}
201
179
202
- func (s computeClient ) GetVolume (volumeID string ) (* volumes.Volume , error ) {
203
- mc := metrics .NewMetricPrometheusContext ("volume" , "get" )
204
- volume , err := volumes .Get (s .volume , volumeID ).Extract ()
205
- return volume , mc .ObserveRequestIgnoreNotFound (err )
180
+ func (e computeErrorClient ) DeleteAttachedInterface (serverID , portID string ) error {
181
+ return e .error
206
182
}
0 commit comments