Skip to content

Commit

Permalink
Merge pull request #8 from sapcc/quota-bursting
Browse files Browse the repository at this point in the history
Quota bursting
  • Loading branch information
talal authored Jan 3, 2019
2 parents 91f6cab + e6fe803 commit 035cc77
Show file tree
Hide file tree
Showing 24 changed files with 424 additions and 315 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
language: go
sudo: false

go:
- 1.11
Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ install: FORCE all
install -m 0755 build/limesctl "$(DESTDIR)$(PREFIX)/bin/limesctl"

ifeq ($(GOOS),windows)
release: release/$(BINARY64)
release: FORCE release/$(BINARY64)
cd release && cp -f $(BINARY64) limesctl.exe && zip $(RELEASE64).zip limesctl.exe
cd release && rm -f limesctl.exe
else
release: release/$(BINARY64)
else
release: FORCE release/$(BINARY64)
cd release && cp -f $(BINARY64) limesctl && tar -czf $(RELEASE64).tgz limesctl
cd release && rm -f limesctl
endif

release-all: FORCE clean
release-all: FORCE clean
GOOS=darwin make release
GOOS=linux make release

Expand All @@ -53,7 +53,7 @@ GO_ALLPKGS := $(PKG) $(shell go list $(PKG)/pkg/...)
# which packages to test with `go test`?
GO_TESTPKGS := $(shell go list -f '{{if .TestGoFiles}}{{.ImportPath}}{{end}}' $(PKG)/pkg/...)
# which packages to measure coverage for?
GO_COVERPKGS := $(shell go list $(PKG)/pkg/... | grep -v plugins)
GO_COVERPKGS := $(shell go list $(PKG)/pkg/...)
# output files from `go test`
GO_COVERFILES := $(patsubst %,build/%.cover.out,$(subst /,_,$(GO_TESTPKGS)))

Expand All @@ -76,7 +76,7 @@ build/%.cover.out: FORCE
@echo '>> go test $*'
$(GO) test $(GO_BUILDFLAGS) -ldflags '$(GO_LDFLAGS)' -coverprofile=$@ -covermode=count -coverpkg=$(subst $(space),$(comma),$(GO_COVERPKGS)) $(subst _,/,$*)
build/cover.out: $(GO_COVERFILES)
pkg/test/util/gocovcat.go $(GO_COVERFILES) > $@
util/gocovcat/main.go $(GO_COVERFILES) > $@
build/cover.html: build/cover.out
$(GO) tool cover -html $< -o $@

Expand Down
29 changes: 11 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/alecthomas/kingpin"
"github.com/sapcc/limesctl/pkg/cli"
"github.com/sapcc/limesctl/pkg/errors"
)

var (
Expand All @@ -48,7 +49,7 @@ var (
osUserDomainName = app.Flag("os-user-domain-name", "User's domain name.").PlaceHolder("OS_USER_DOMAIN_NAME").String()
osProjectID = app.Flag("os-project-id", "Project ID to scope to.").PlaceHolder("OS_PROJECT_ID").String()
osProjectName = app.Flag("os-project-name", "Project name to scope to.").PlaceHolder("OS_PROJECT_NAME").String()
osProjectDomainID = app.Flag("os-project-domain-ID", "Domain ID containing project to scope to.").PlaceHolder("OS_PROJECT_DOMAIN_ID").String()
osProjectDomainID = app.Flag("os-project-domain-id", "Domain ID containing project to scope to.").PlaceHolder("OS_PROJECT_DOMAIN_ID").String()
osProjectDomainName = app.Flag("os-project-domain-name", "Domain name containing project to scope to.").PlaceHolder("OS_PROJECT_DOMAIN_NAME").String()

area = app.Flag("area", "Resource area.").String()
Expand Down Expand Up @@ -149,7 +150,7 @@ func main() {
// If the ID is not provided then the capacities get interpreted
// as the ID and the error shown is not relevant to the context
if strings.Contains(*clusterSetID, "=") {
kingpin.Fatalf("required argument 'cluster-id' not provided, try --help")
errors.Handle(errors.New("required argument 'cluster-id' not provided, try --help"))
}
c := &cli.Cluster{ID: *clusterSetID}
cli.RunSetTask(c, clusterSetCaps)
Expand All @@ -170,7 +171,7 @@ func main() {
if *domainCluster == "" {
var err error
d, err = cli.FindDomain(*domainShowID)
fatalIfErr(err)
errors.Handle(err)
} else {
d = &cli.Domain{ID: *domainShowID}
}
Expand All @@ -182,13 +183,13 @@ func main() {

case domainSetCmd.FullCommand():
if strings.Contains(*domainSetID, "=") {
kingpin.Fatalf("required argument 'domain-id' not provided, try --help")
errors.Handle(errors.New("required argument 'domain-id' not provided, try --help"))
}
var d *cli.Domain
if *domainCluster == "" {
var err error
d, err = cli.FindDomain(*domainSetID)
fatalIfErr(err)
errors.Handle(err)
} else {
d = &cli.Domain{ID: *domainSetID}
}
Expand All @@ -204,7 +205,7 @@ func main() {
} else {
d, err = cli.FindDomainInCluster(*projectListDomain, *projectCluster)
}
fatalIfErr(err)
errors.Handle(err)

p := &cli.Project{
DomainID: d.ID,
Expand All @@ -223,7 +224,7 @@ func main() {
} else {
p, err = cli.FindProjectInCluster(*projectShowID, *projectShowDomain, *projectCluster)
}
fatalIfErr(err)
errors.Handle(err)

p.Filter = filter
p.Filter.Cluster = *projectCluster
Expand All @@ -232,7 +233,7 @@ func main() {

case projectSetCmd.FullCommand():
if strings.Contains(*projectSetID, "=") {
kingpin.Fatalf("required argument 'project-id' not provided, try --help")
errors.Handle(errors.New("required argument 'project-id' not provided, try --help"))
}
var p *cli.Project
var err error
Expand All @@ -241,7 +242,7 @@ func main() {
} else {
p, err = cli.FindProjectInCluster(*projectSetID, *projectSetDomain, *projectCluster)
}
fatalIfErr(err)
errors.Handle(err)

p.Filter.Cluster = *projectCluster
cli.RunSetTask(p, projectSetQuotas)
Expand All @@ -254,7 +255,7 @@ func main() {
} else {
p, err = cli.FindProjectInCluster(*projectSyncID, *projectSyncDomain, *projectCluster)
}
fatalIfErr(err)
errors.Handle(err)

p.Filter.Cluster = *projectCluster
cli.RunSyncTask(p)
Expand All @@ -268,11 +269,3 @@ func setEnvUnlessEmpty(env, val string) {

os.Setenv(env, val)
}

func fatalIfErr(err error) {
if err == nil {
return
}

kingpin.Fatalf(err.Error())
}
17 changes: 4 additions & 13 deletions pkg/cli/misc.go → pkg/cli/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,24 @@
package cli

import (
"github.com/alecthomas/kingpin"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack"
"github.com/gophercloud/utils/openstack/clientconfig"
"github.com/sapcc/gophercloud-limes/resources"
"github.com/sapcc/limesctl/pkg/errors"
)

// getServiceClients authenticates against OpenStack and returns respective ServiceClients
// for Keystone and Limes.
func getServiceClients() (identityV3, limesV1 *gophercloud.ServiceClient) {
provider, err := clientconfig.AuthenticatedClient(nil)
handleError("can not connect to OpenStack", err)
errors.Handle(err, "can not connect to OpenStack")

identityClient, err := openstack.NewIdentityV3(provider, gophercloud.EndpointOpts{})
handleError("could not initialize identity client", err)
errors.Handle(err, "could not initialize identity client")

limesClient, err := resources.NewLimesV1(provider, gophercloud.EndpointOpts{})
handleError("could not initialize Limes client", err)
errors.Handle(err, "could not initialize Limes client")

return identityClient, limesClient
}

// handleError is a convenient wrapper around kingpin.Fatalf.
func handleError(str string, err error) {
if err == nil {
return
}

kingpin.Fatalf("%v: %v", str, err)
}
4 changes: 2 additions & 2 deletions pkg/cli/fixtures/cluster-get-filtered.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"cluster id";"area";"service";"category";"resource";"capacity";"domains quota";"usage";"unit";"comment";"scraped at (UTC)"
"west";"shared";"shared";"";"capacity";10;3;"1.5";"PiB";"hand-counted";"1970-01-01T00:00:22Z"
"cluster id";"area";"service";"category";"resource";"capacity";"domains quota";"usage";"burst usage";"unit";"comment";"scraped at (UTC)"
"west";"shared";"shared";"";"capacity";10240;3072;1536;2;"TiB";"hand-counted";"1970-01-01T00:00:22Z"
3 changes: 2 additions & 1 deletion pkg/cli/fixtures/cluster-get-filtered.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"capacity": 10485760,
"comment": "hand-counted",
"domains_quota": 3145728,
"usage": 1572864
"usage": 1572864,
"burst_usage": 2048
}
],
"max_scraped_at": 66,
Expand Down
6 changes: 3 additions & 3 deletions pkg/cli/fixtures/cluster-list-filtered.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"cluster id";"area";"service";"category";"resource";"capacity";"domains quota";"usage";"unit";"comment";"scraped at (UTC)"
"east";"shared";"shared";"";"capacity";185;50;8;"B";"hand-counted";"1970-01-01T00:01:28Z"
"west";"shared";"shared";"";"capacity";185;50;8;"B";"hand-counted";"1970-01-01T00:00:22Z"
"cluster id";"area";"service";"category";"resource";"capacity";"domains quota";"usage";"burst usage";"unit";"comment";"scraped at (UTC)"
"east";"shared";"shared";"";"capacity";185;50;8;0;"B";"hand-counted";"1970-01-01T00:01:28Z"
"west";"shared";"shared";"";"capacity";185;50;8;0;"B";"hand-counted";"1970-01-01T00:00:22Z"
2 changes: 1 addition & 1 deletion pkg/cli/fixtures/domain-get-filtered.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"domain name";"service";"resource";"quota";"projects quota";"usage";"unit"
"germany";"shared";"capacity";"28732.49";9659;500;"TiB"
"germany";"shared";"capacity";"29422070.31";"9890820.31";512000;"GiB"
3 changes: 2 additions & 1 deletion pkg/cli/fixtures/domain-get-filtered.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"quota": 30128200000,
"projects_quota": 10128200000,
"usage": 524288000,
"backend_quota": 110
"backend_quota": 110,
"burst_usage": 100000
}
],
"max_scraped_at": 44,
Expand Down
6 changes: 3 additions & 3 deletions pkg/cli/fixtures/domain-list-filtered.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"domain id";"domain name";"area";"service";"category";"resource";"quota";"projects quota";"usage";"unit";"scraped at (UTC)"
"uuid-for-france";"france";"shared";"shared";"";"things";0;10;2;"";"1970-01-01T00:01:06Z"
"uuid-for-germany";"germany";"shared";"shared";"";"things";30;20;4;"";"1970-01-01T00:00:22Z"
"domain id";"domain name";"area";"service";"category";"resource";"quota";"projects quota";"usage";"burst usage";"unit";"scraped at (UTC)"
"uuid-for-france";"france";"shared";"shared";"";"things";0;10;2;0;"";"1970-01-01T00:01:06Z"
"uuid-for-germany";"germany";"shared";"shared";"";"things";30;20;4;0;"";"1970-01-01T00:00:22Z"
2 changes: 1 addition & 1 deletion pkg/cli/fixtures/project-get-filtered.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"domain name";"project name";"service";"resource";"quota";"usage";"unit"
"germany";"dresden";"shared";"capacity";15;"2.73";"TiB"
"germany";"dresden";"shared";"capacity";15728640;"15728651.56";"MiB"
9 changes: 7 additions & 2 deletions pkg/cli/fixtures/project-get-filtered.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"project": {
"bursting": {
"enabled": true,
"multiplier": 0.1
},
"id": "uuid-for-dresden",
"name": "dresden",
"parent_id": "uuid-for-germany",
Expand All @@ -12,8 +16,9 @@
"name": "capacity",
"unit": "B",
"quota": 16492674416640,
"usage": 3004120411540,
"backend_quota": 16492674416640
"usage": 16492686537852,
"backend_quota": 18141941858304,
"burst_usage": 12121212
}
],
"scraped_at": 44
Expand Down
6 changes: 3 additions & 3 deletions pkg/cli/fixtures/project-list-filtered.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"domain id";"domain name";"project id";"project name";"area";"service";"category";"resource";"quota";"usage";"unit";"scraped at (UTC)"
"uuid-for-germany";"germany";"uuid-for-berlin";"berlin";"shared";"shared";"";"things";10;2;"";"1970-01-01T00:00:22Z"
"uuid-for-germany";"germany";"uuid-for-dresden";"dresden";"shared";"shared";"";"things";10;2;"";"1970-01-01T00:00:44Z"
"domain id";"domain name";"project id";"project name";"area";"service";"category";"resource";"quota";"burst quota";"usage";"burst usage";"unit";"scraped at (UTC)"
"uuid-for-germany";"germany";"uuid-for-berlin";"berlin";"shared";"shared";"";"things";10;0;2;0;"";"1970-01-01T00:00:22Z"
"uuid-for-germany";"germany";"uuid-for-dresden";"dresden";"shared";"shared";"";"things";10;0;2;0;"";"1970-01-01T00:00:44Z"
7 changes: 4 additions & 3 deletions pkg/cli/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/sapcc/gophercloud-limes/resources/v1/clusters"
"github.com/sapcc/gophercloud-limes/resources/v1/domains"
"github.com/sapcc/gophercloud-limes/resources/v1/projects"
"github.com/sapcc/limesctl/pkg/errors"
)

// get retrieves information about a single cluster.
Expand All @@ -34,7 +35,7 @@ func (c *Cluster) get() {
Service: c.Filter.Service,
Resource: c.Filter.Resource,
})
handleError("could not get cluster", c.Result.Err)
errors.Handle(c.Result.Err, "could not get cluster")
}

// get retrieves information about a single domain.
Expand All @@ -47,7 +48,7 @@ func (d *Domain) get() {
Service: d.Filter.Service,
Resource: d.Filter.Resource,
})
handleError("could not get domain", d.Result.Err)
errors.Handle(d.Result.Err, "could not get domain")
}

// get retrieves information about a single project within a specific domain.
Expand All @@ -60,5 +61,5 @@ func (p *Project) get() {
Service: p.Filter.Service,
Resource: p.Filter.Resource,
})
handleError("could not get project", p.Result.Err)
errors.Handle(p.Result.Err, "could not get project")
}
Loading

0 comments on commit 035cc77

Please sign in to comment.