Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] Compute #420

Draft
wants to merge 76 commits into
base: devel
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
05b1ec4
[Comp] Batch Replace
Aloento Sep 6, 2022
e5869ec
Merge branch 'devel' into compute
Aloento Sep 7, 2022
f19aa9a
aggregates
Aloento Sep 7, 2022
64d8330
attachinterfaces
Aloento Sep 7, 2022
a62d594
availabilityzones
Aloento Sep 7, 2022
0a31910
bootfromvolume
Aloento Sep 7, 2022
bf1c10c
defsecrules
Aloento Sep 7, 2022
4baebc3
floatingips
Aloento Sep 7, 2022
f3635ce
hypervisors
Aloento Sep 7, 2022
67e77a1
migrate
Aloento Sep 7, 2022
7b14638
quotasets
Aloento Sep 7, 2022
96b0127
secgroups
Aloento Sep 7, 2022
b505ec5
servergroups
Aloento Sep 7, 2022
125babe
usage
Aloento Sep 7, 2022
9ef0bbf
volumeattach
Aloento Sep 7, 2022
88e6d7b
a
Aloento Sep 7, 2022
1dc3f23
b
Aloento Sep 7, 2022
970755f
h
Aloento Sep 7, 2022
6687e49
l
Aloento Sep 7, 2022
c603d2e
q
Aloento Sep 7, 2022
b1e346c
r
Aloento Sep 7, 2022
8b7113c
t
Aloento Sep 7, 2022
52659e9
v
Aloento Sep 7, 2022
bc9a611
(raw.Body,
Aloento Sep 7, 2022
0ab5686
aggregates
Aloento Sep 7, 2022
70e1a28
aggregates
Aloento Sep 7, 2022
1df8595
attachinterfaces
Aloento Sep 9, 2022
fbe186c
availabilityzones
Aloento Sep 9, 2022
2b7fb6c
bootfromvolume
Aloento Sep 9, 2022
53b5fb1
defsecrules
Aloento Sep 9, 2022
d1ef375
diskconfig
Aloento Sep 9, 2022
3e5452e
evacuate
Aloento Sep 9, 2022
cf00e10
floatingips
Aloento Sep 9, 2022
25e4311
hypervisors
Aloento Sep 9, 2022
71a00f3
keypairs
Aloento Sep 9, 2022
5d1834c
limits
Aloento Sep 9, 2022
dc310c8
lockunlock
Aloento Sep 9, 2022
932e10e
migrate
Aloento Sep 9, 2022
c37a9c0
networks
Aloento Sep 9, 2022
fb78fc6
pauseunpause
Aloento Sep 9, 2022
2dcd90e
quotasets
Aloento Sep 9, 2022
384e039
rescueunrescue
Aloento Sep 9, 2022
478abaf
resetstate
Aloento Sep 9, 2022
74bbd91
schedulerhints
Aloento Sep 9, 2022
336de5e
suspendresume
Aloento Sep 9, 2022
9bdb7ec
secgroups
Aloento Sep 12, 2022
bfdd6c0
servergroups
Aloento Sep 12, 2022
60105ae
services
Aloento Sep 12, 2022
0cc8904
startstop
Aloento Sep 12, 2022
170a24f
tags
Aloento Sep 12, 2022
13f89d7
tenantnetworks
Aloento Sep 12, 2022
d02c8ca
usage
Aloento Sep 12, 2022
2c3bf2b
volumeattach
Aloento Sep 12, 2022
113e792
exp
Aloento Sep 12, 2022
9983fa4
flavors
Aloento Sep 12, 2022
dd51ebe
images
Aloento Sep 12, 2022
22da84f
servers 1
Aloento Sep 13, 2022
e1b7167
servers 2
Aloento Sep 13, 2022
0486029
servers 3
Aloento Sep 13, 2022
db95af7
servers 4
Aloento Sep 13, 2022
546efed
fix
Aloento Sep 13, 2022
d267a49
fix
Aloento Sep 13, 2022
d3c77b9
fix
Aloento Sep 13, 2022
a5cdc05
fix
Aloento Sep 13, 2022
721e07d
fix
Aloento Sep 13, 2022
09dc96b
fix
Aloento Sep 14, 2022
1fb25b5
fix
Aloento Sep 14, 2022
42c65c7
fix
Aloento Sep 14, 2022
18a3e5b
fix
Aloento Sep 14, 2022
ca31625
Merge branch 'devel' into compute
Aloento Oct 13, 2022
5a6d348
update
Aloento Oct 13, 2022
fe6ad34
fix
Aloento Oct 13, 2022
23b1867
Merge branch 'devel' into compute
Aloento Oct 24, 2022
3fb5377
fix
Aloento Oct 24, 2022
793edad
fix
Aloento Oct 24, 2022
b9f83fc
Merge branch 'devel' into compute
anton-sidelnikov Dec 13, 2022
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
4 changes: 2 additions & 2 deletions acceptance/openstack/cce/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func CreateKeypair(t *testing.T) string {
opts := keypairs.CreateOpts{
Name: tools.RandomString("cce-nodes-", 4),
}
_, err = keypairs.Create(client, opts).Extract()
_, err = keypairs.Create(client, opts)
th.AssertNoErr(t, err)
return opts.Name
}
Expand All @@ -135,5 +135,5 @@ func DeleteKeypair(t *testing.T, kp string) {
client, err := clients.NewComputeV2Client()
th.AssertNoErr(t, err)

th.AssertNoErr(t, keypairs.Delete(client, kp).ExtractErr())
th.AssertNoErr(t, keypairs.Delete(client, kp))
}
8 changes: 3 additions & 5 deletions acceptance/openstack/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ func DefaultSecurityGroup(t *testing.T) string {
client, err := clients.NewComputeV2Client()
th.AssertNoErr(t, err)

securityGroupPages, err := secgroups.List(client).AllPages()
th.AssertNoErr(t, err)
securityGroups, err := secgroups.ExtractSecurityGroups(securityGroupPages)
securityGroups, err := secgroups.List(client)
th.AssertNoErr(t, err)
var sgId string
for _, val := range securityGroups {
Expand All @@ -54,11 +52,11 @@ func CreateSecurityGroup(t *testing.T) string {
client, err := clients.NewComputeV2Client()
th.AssertNoErr(t, err)

createSGOpts := secgroups.CreateOpts{
createSGOpts := secgroups.GroupOpts{
Name: tools.RandomString("acc-sg-", 3),
Description: "security group for acceptance testing",
}
secGroup, err := secgroups.Create(client, createSGOpts).Extract()
secGroup, err := secgroups.Create(client, createSGOpts)
th.AssertNoErr(t, err)

t.Logf("Security group %s was created", secGroup.ID)
Expand Down
14 changes: 7 additions & 7 deletions acceptance/openstack/compute/v2/servers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,29 @@ func TestServerLifecycle(t *testing.T) {
},
}

ecs, err := servers.Create(client, createOpts).Extract()
ecs, err := servers.Create(client, createOpts)
th.AssertNoErr(t, err)

err = servers.WaitForStatus(client, ecs.ID, "ACTIVE", 1200)
th.AssertNoErr(t, err)
t.Logf("Created ECSv2: %s", ecs.ID)

ecs, err = servers.Get(client, ecs.ID).Extract()
ecs, err = servers.Get(client, ecs.ID)
th.AssertNoErr(t, err)
th.AssertEquals(t, ecsName, ecs.Name)

nicInfo, err := servers.GetNICs(client, ecs.ID).Extract()
nicInfo, err := servers.GetNICs(client, ecs.ID)
th.AssertNoErr(t, err)
tools.PrintResource(t, nicInfo)

defer func() {
t.Logf("Attempting to delete ECSv2: %s", ecs.ID)

_, err := servers.Delete(client, ecs.ID).ExtractJobResponse()
err := servers.Delete(client, ecs.ID)
th.AssertNoErr(t, err)

err = golangsdk.WaitFor(1200, func() (bool, error) {
_, err := servers.Get(client, ecs.ID).Extract()
_, err := servers.Get(client, ecs.ID)
if err != nil {
if _, ok := err.(golangsdk.ErrDefault400); ok {
time.Sleep(10 * time.Second)
Expand All @@ -112,13 +112,13 @@ func TestServerLifecycle(t *testing.T) {
Name: ecsName,
}

_, err = servers.Update(client, ecs.ID, updateOpts).Extract()
_, err = servers.Update(client, ecs.ID, updateOpts)
th.AssertNoErr(t, err)

t.Logf("ECSv2 successfully updated: %s", ecs.ID)
th.AssertNoErr(t, err)

newECS, err := servers.Get(client, ecs.ID).Extract()
newECS, err := servers.Get(client, ecs.ID)
th.AssertNoErr(t, err)
th.AssertEquals(t, ecsName, newECS.Name)
}
8 changes: 4 additions & 4 deletions acceptance/openstack/csbs/v1/policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func createComputeInstance(t *testing.T, subnetID string) *servers.Server {
},
}

server, err := servers.Create(client, opts).Extract()
server, err := servers.Create(client, opts)
th.AssertNoErr(t, err)
err = waitForComputeInstanceAvailable(client, 600, server.ID)
th.AssertNoErr(t, err)
Expand All @@ -221,15 +221,15 @@ func deleteComputeInstance(t *testing.T, instanceId string) {
client, err := clients.NewComputeV2Client()
th.AssertNoErr(t, err)

err = servers.Delete(client, instanceId).ExtractErr()
err = servers.Delete(client, instanceId)
th.AssertNoErr(t, err)
err = waitForComputeInstanceDelete(client, 600, instanceId)
th.AssertNoErr(t, err)
}

func waitForComputeInstanceAvailable(client *golangsdk.ServiceClient, secs int, instanceId string) error {
return golangsdk.WaitFor(secs, func() (bool, error) {
server, err := servers.Get(client, instanceId).Extract()
server, err := servers.Get(client, instanceId)
if err != nil {
return false, err
}
Expand All @@ -242,7 +242,7 @@ func waitForComputeInstanceAvailable(client *golangsdk.ServiceClient, secs int,

func waitForComputeInstanceDelete(client *golangsdk.ServiceClient, secs int, instanceId string) error {
return golangsdk.WaitFor(secs, func() (bool, error) {
server, err := servers.Get(client, instanceId).Extract()
server, err := servers.Get(client, instanceId)
if err != nil {
if _, ok := err.(golangsdk.ErrDefault404); ok {
return true, nil
Expand Down
19 changes: 0 additions & 19 deletions internal/build/backward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/compute/v2/servers"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/dns/v2/zones"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/objectstorage/v1/accounts"
"github.com/stretchr/testify/require"
Expand All @@ -18,24 +17,6 @@ import (
//
// Those tests can be used as an example of replacing deprecated methods.

func TestCompareQueryOpts(t *testing.T) {
listOpts := &servers.ListOpts{
ChangesSince: "2012-06-12",
Image: "some-random-image",
Flavor: "top-flavor",
Limit: 64,
AllTenants: true,
}

expected, err := listOpts.ToServerListQuery()
require.NoError(t, err)

actual, err := QueryString(listOpts)
require.NoError(t, err)

require.EqualValues(t, expected, actual.String()) // inside ToServerListQuery `.String()` for URL is called
}

func TestCompareHeaderOpts(t *testing.T) {
headerOpts := &accounts.UpdateOpts{
ContentType: "application/lolson",
Expand Down
26 changes: 26 additions & 0 deletions openstack/compute/v2/extensions/aggregates/add_host.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package aggregates

import (
"strconv"

"github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
)

type AddHostOpts struct {
// The name of the host.
Host string `json:"host" required:"true"`
}

// AddHost makes a request against the API to add host to a specific aggregate.
func AddHost(client *golangsdk.ServiceClient, aggregateID int, opts AddHostOpts) (*Aggregate, error) {
b, err := build.RequestBody(opts, "add_host")
if err != nil {
return nil, err
}

raw, err := client.Post(client.ServiceURL("os-aggregates", strconv.Itoa(aggregateID), "action"), b, nil, &golangsdk.RequestOpts{
OkCodes: []int{200},
})
return extra(err, raw)
}
29 changes: 29 additions & 0 deletions openstack/compute/v2/extensions/aggregates/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package aggregates

import (
"github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
)

type CreateOpts struct {
// The name of the host aggregate.
Name string `json:"name" required:"true"`
// The availability zone of the host aggregate.
// You should use a custom availability zone rather than
// the default returned by the os-availability-zone API.
// The availability zone must not include ‘:’ in its name.
AvailabilityZone string `json:"availability_zone,omitempty"`
}

// Create makes a request against the API to create an aggregate.
func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*Aggregate, error) {
b, err := build.RequestBody(opts, "aggregate")
if err != nil {
return nil, err
}

raw, err := client.Post(client.ServiceURL("os-aggregates"), b, nil, &golangsdk.RequestOpts{
OkCodes: []int{200},
})
return extra(err, raw)
}
15 changes: 15 additions & 0 deletions openstack/compute/v2/extensions/aggregates/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package aggregates

import (
"strconv"

"github.com/opentelekomcloud/gophertelekomcloud"
)

// Delete makes a request against the API to delete an aggregate.
func Delete(client *golangsdk.ServiceClient, aggregateID int) (err error) {
_, err = client.Delete(client.ServiceURL("os-aggregates", strconv.Itoa(aggregateID)), &golangsdk.RequestOpts{
OkCodes: []int{200},
})
return
}
15 changes: 15 additions & 0 deletions openstack/compute/v2/extensions/aggregates/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package aggregates

import (
"strconv"

"github.com/opentelekomcloud/gophertelekomcloud"
)

// Get makes a request against the API to get details for a specific aggregate.
func Get(client *golangsdk.ServiceClient, aggregateID int) (*Aggregate, error) {
raw, err := client.Get(client.ServiceURL("os-aggregates", strconv.Itoa(aggregateID)), nil, &golangsdk.RequestOpts{
OkCodes: []int{200},
})
return extra(err, raw)
}
18 changes: 18 additions & 0 deletions openstack/compute/v2/extensions/aggregates/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package aggregates

import (
"github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
)

// List makes a request against the API to list aggregates.
func List(client *golangsdk.ServiceClient) ([]Aggregate, error) {
raw, err := client.Get(client.ServiceURL("os-aggregates"), nil, nil)
if err != nil {
return nil, err
}

var res []Aggregate
err = extract.IntoSlicePtr(raw.Body, &res, "aggregates")
return res, err
}
26 changes: 26 additions & 0 deletions openstack/compute/v2/extensions/aggregates/remove_host.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package aggregates

import (
"strconv"

"github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
)

type RemoveHostOpts struct {
// The name of the host.
Host string `json:"host" required:"true"`
}

// RemoveHost makes a request against the API to remove host from a specific aggregate.
func RemoveHost(client *golangsdk.ServiceClient, aggregateID int, opts RemoveHostOpts) (*Aggregate, error) {
b, err := build.RequestBody(opts, "remove_host")
if err != nil {
return nil, err
}

raw, err := client.Post(client.ServiceURL("os-aggregates", strconv.Itoa(aggregateID), "action"), b, nil, &golangsdk.RequestOpts{
OkCodes: []int{200},
})
return extra(err, raw)
}
Loading