Skip to content

Commit f627e1c

Browse files
aschemanGerd Aschemann (EXT)
authored and
Gerd Aschemann (EXT)
committed
Start OpenStack instanceactions implementation
1 parent 92ca9c5 commit f627e1c

File tree

6 files changed

+377
-6
lines changed

6 files changed

+377
-6
lines changed

cloudmock/openstack/mockcompute/api.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"net/http/httptest"
2121
"sync"
2222

23+
"github.com/gophercloud/gophercloud/v2/openstack/compute/v2/instanceactions"
24+
2325
"github.com/gophercloud/gophercloud/v2"
2426

2527
"github.com/gophercloud/gophercloud/v2/openstack/compute/v2/flavors"
@@ -35,12 +37,13 @@ type MockClient struct {
3537
openstack.MockOpenstackServer
3638
mutex sync.Mutex
3739

38-
serverGroups map[string]servergroups.ServerGroup
39-
servers map[string]servers.Server
40-
keyPairs map[string]keypairs.KeyPair
41-
images map[string]images.Image
42-
flavors map[string]flavors.Flavor
43-
networkClient *gophercloud.ServiceClient
40+
serverGroups map[string]servergroups.ServerGroup
41+
servers map[string]servers.Server
42+
keyPairs map[string]keypairs.KeyPair
43+
images map[string]images.Image
44+
flavors map[string]flavors.Flavor
45+
instanceActions map[string]instanceactions.InstanceAction
46+
networkClient *gophercloud.ServiceClient
4447
}
4548

4649
// CreateClient will create a new mock networking client
@@ -52,6 +55,7 @@ func CreateClient(networkClient *gophercloud.ServiceClient) *MockClient {
5255
m.mockServers()
5356
m.mockKeyPairs()
5457
m.mockFlavors()
58+
m.mockInstanceActions()
5559
m.Server = httptest.NewServer(m.Mux)
5660
m.networkClient = networkClient
5761
return m
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package mockcompute
18+
19+
import (
20+
"encoding/json"
21+
"net/http"
22+
)
23+
24+
type instanceActionsResponse struct {
25+
InstanceActions []interface{} `json:"instanceActions"`
26+
}
27+
28+
func (m *MockClient) mockInstanceActions() {
29+
//re := regexp.MustCompile(`/servers/(.*?)/os-instance-actions/?`)
30+
31+
handler := func(w http.ResponseWriter, r *http.Request) {
32+
m.mutex.Lock()
33+
defer m.mutex.Unlock()
34+
35+
w.Header().Add("Content-Type", "application/json")
36+
37+
if r.Method != http.MethodGet {
38+
w.WriteHeader(http.StatusBadRequest)
39+
return
40+
}
41+
42+
resp := instanceActionsResponse{
43+
InstanceActions: make([]interface{}, 0),
44+
}
45+
respB, err := json.Marshal(resp)
46+
if err != nil {
47+
panic("failed to marshal response")
48+
}
49+
_, err = w.Write(respB)
50+
if err != nil {
51+
panic("failed to write body")
52+
}
53+
}
54+
m.Mux.HandleFunc("/servers/{server_id}/os-instance-actions/", handler)
55+
}

vendor/github.com/gophercloud/gophercloud/v2/openstack/compute/v2/instanceactions/doc.go

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/gophercloud/gophercloud/v2/openstack/compute/v2/instanceactions/request.go

Lines changed: 81 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/gophercloud/gophercloud/v2/openstack/compute/v2/instanceactions/results.go

Lines changed: 194 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)