Skip to content

Commit

Permalink
remove custom gophercloud fork
Browse files Browse the repository at this point in the history
The one place where we needed it needs to be replaced by a custom type
anyway because of the upcoming "hardware_state" field.
  • Loading branch information
majewsky committed Jun 1, 2023
1 parent 8888888 commit d321f8e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,3 @@ require (
golang.org/x/text v0.9.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
)

replace github.com/gophercloud/gophercloud v1.4.0 => github.com/sapcc/gophercloud v0.0.0-20230525104810-f3053bcf30d8
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
github.com/gophercloud/gophercloud v0.20.0/go.mod h1:wRtmUelyIIv3CSSDI47aUwbs075O6i+LY+pXsKCBsb4=
github.com/gophercloud/gophercloud v1.0.0/go.mod h1:Q8fZtyi5zZxPS/j9aj3sSxtvj41AdQMDwyo1myduD5c=
github.com/gophercloud/gophercloud v1.3.0/go.mod h1:aAVqcocTSXh2vYFZ1JTvx4EQmfgzxRcNupUfxZbBNDM=
github.com/gophercloud/gophercloud v1.4.0 h1:RqEu43vaX0lb0LanZr5BylK5ICVxjpFFoc0sxivyuHU=
github.com/gophercloud/gophercloud v1.4.0/go.mod h1:aAVqcocTSXh2vYFZ1JTvx4EQmfgzxRcNupUfxZbBNDM=
github.com/gophercloud/utils v0.0.0-20220927104426-4113af8d2663/go.mod h1:qOGlfG6OIJ193/c3Xt/XjOfHataNZdQcVgiu93LxBUM=
github.com/gophercloud/utils v0.0.0-20230523080330-de873b9cf00d h1:6Gvua77nKyAiZQpu0N3AsamGu1L6Mlnhp3tAtDcqwvc=
github.com/gophercloud/utils v0.0.0-20230523080330-de873b9cf00d/go.mod h1:VSalo4adEk+3sNkmVJLnhHoOyOYYS8sTWLG4mv5BKto=
Expand Down Expand Up @@ -145,8 +147,6 @@ github.com/sapcc/go-api-declarations v1.5.1 h1:K0dn7gy9uvBRn3qBUHOYli4J3eJCRrTBI
github.com/sapcc/go-api-declarations v1.5.1/go.mod h1:3OCDo75YJwpytM/I0SjwcZJf1ZNu89KeAZ55kdOTSqE=
github.com/sapcc/go-bits v0.0.0-20230601094646-819288b07996 h1:ZtVsCacJEl120F1Kk37EKTRmbMyEaSmZHHq5rxEnKNU=
github.com/sapcc/go-bits v0.0.0-20230601094646-819288b07996/go.mod h1:oLyIE5wiTzAli9diwAHGY/Jr6fsRsMugHI3JUbCfeoo=
github.com/sapcc/gophercloud v0.0.0-20230525104810-f3053bcf30d8 h1:1cWpZx9GPj+QJP8oan5gqdJje4MqBR+iCGk8qBVJuC4=
github.com/sapcc/gophercloud v0.0.0-20230525104810-f3053bcf30d8/go.mod h1:aAVqcocTSXh2vYFZ1JTvx4EQmfgzxRcNupUfxZbBNDM=
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
Expand Down
30 changes: 28 additions & 2 deletions internal/plugins/capacity_manila.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/gophercloud/gophercloud/openstack"
"github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/schedulerstats"
"github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/services"
"github.com/gophercloud/gophercloud/pagination"
"github.com/prometheus/client_golang/prometheus"
"github.com/sapcc/go-bits/logg"

Expand Down Expand Up @@ -145,13 +146,13 @@ type capacityForShareType struct {

func (p *capacityManilaPlugin) scrapeForShareType(shareType ManilaShareTypeSpec, azForServiceHost map[string]string) (capacityForShareType, error) {
//list all pools for the Manila share types corresponding to this virtual share type
var allPools []schedulerstats.Pool
var allPools []manilaPool
for _, stName := range getAllManilaShareTypes(shareType) {
allPages, err := schedulerstats.ListDetail(p.ManilaV2, schedulerstats.ListDetailOpts{ShareType: stName}).AllPages()
if err != nil {
return capacityForShareType{}, err
}
pools, err := schedulerstats.ExtractPools(allPages)
pools, err := manilaExtractPools(allPages)
if err != nil {
return capacityForShareType{}, err
}
Expand Down Expand Up @@ -248,3 +249,28 @@ func getShareCapacity(capGB, capBalance float64) uint64 {
func getSnapshotCapacity(capGB, capBalance float64) uint64 {
return uint64(capBalance / (capBalance + 1) * capGB)
}

////////////////////////////////////////////////////////////////////////////////
// We need a custom type for Pool.Capabilities to support CCloud-specific fields.

// manilaPool is a custom extension of the type `schedulerstats.Pool`.
type manilaPool struct {
Name string `json:"name"`
Host string `json:"host"`
Capabilities struct {
//standard fields
TotalCapacityGB float64 `json:"total_capacity_gb"`
AllocatedCapacityGB float64 `json:"allocated_capacity_gb"`
//CCloud extension fields
//TODO: hardware_state (coming soon)
} `json:"capabilities,omitempty"`
}

// manilaExtractPools is `schedulerstats.ExtractPools()`, but using our custom pool type.
func manilaExtractPools(p pagination.Page) ([]manilaPool, error) {
var s struct {
Pools []manilaPool `json:"pools"`
}
err := (p.(schedulerstats.PoolPage)).ExtractInto(&s)
return s.Pools, err
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ github.com/golang-migrate/migrate/v4/source/go_bindata
# github.com/golang/protobuf v1.5.3
## explicit; go 1.9
github.com/golang/protobuf/proto
# github.com/gophercloud/gophercloud v1.4.0 => github.com/sapcc/gophercloud v0.0.0-20230525104810-f3053bcf30d8
# github.com/gophercloud/gophercloud v1.4.0
## explicit; go 1.14
github.com/gophercloud/gophercloud
github.com/gophercloud/gophercloud/openstack
Expand Down

0 comments on commit d321f8e

Please sign in to comment.