Skip to content

Commit

Permalink
Merge pull request #9 from sapcc/fractional-quota-values
Browse files Browse the repository at this point in the history
allow fractional quota values in set subcommand
  • Loading branch information
talal authored Jan 7, 2019
2 parents 035cc77 + 8b1fa70 commit 403e0d3
Show file tree
Hide file tree
Showing 6 changed files with 355 additions and 153 deletions.
18 changes: 13 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# v1.2.1 (TBD)
# v1.3.0 (2019-01-07)

New features:
- Display quota bursting information when `--long` output flag is given.
- Allow fractional quota values for the `set` subcommand.

Changes:
- Optimize library dependencies. Binary size has been reduced by over 20%.

# v1.2.0 (2018-11-05)

New features:
- Users can manually overwrite the OpenStack environment variables by providing them as command-line flags.
- Users can manually overwrite the OpenStack environment variables by providing
them as command-line flags.

Changes:
- For the `--cluster` flag, the domain/project must be identified by ID. Specifiying a domain/project name will not work.
- For the `--cluster` flag, the domain/project must be identified by ID.
Specifiying a domain/project name will not work.

Bugfixes:
- `--cluster` flag now works as expected.
Expand All @@ -18,8 +24,10 @@ Bugfixes:
# v1.1.0 (2018-10-29)

New features:
- Human friendly values: users can give the `--human-readable` flag to get the different quota/usage values in a more human friendly unit. Only valid for
table/CSV output and can be combined with other output flags: `--names` or `--long`.
- Human friendly values: users can give the `--human-readable` flag to get the
different quota/usage values in a more human friendly unit. Only valid for
table/CSV output and can be combined with other output flags: `--names` or
`--long`.


# v1.0.0 (2018-10-24)
Expand Down
45 changes: 39 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var (

clusterSetCmd = clusterCmd.Command("set", "Change resource(s) quota for a cluster. Use 'current' to show information regarding the current cluster. Requires a cloud-admin token.")
clusterSetID = clusterSetCmd.Arg("cluster-id", "Cluster ID.").Required().String()
clusterSetCaps = cli.ParseQuotas(clusterSetCmd.Arg("capacities", "Capacities to change. Format: service/resource=value(unit):\"comment\"").Required())
clusterSetCaps = QuotaList(clusterSetCmd.Arg("capacities", "Capacities to change. Format: service/resource=value(unit):\"comment\"").Required())

domainListCmd = domainCmd.Command("list", "Query data for all the domains. Requires a cloud-admin token.")

Expand All @@ -77,7 +77,7 @@ var (

domainSetCmd = domainCmd.Command("set", "Change resource(s) quota for a domain. Requires a cloud-admin token.")
domainSetID = domainSetCmd.Arg("domain-id", "Domain ID (name/UUID).").Required().String()
domainSetQuotas = cli.ParseQuotas(domainSetCmd.Arg("quotas", "Quotas to change. Format: service/resource=value(unit)").Required())
domainSetQuotas = QuotaList(domainSetCmd.Arg("quotas", "Quotas to change. Format: service/resource=value(unit)").Required())

projectListCmd = projectCmd.Command("list", "Query data for all the projects in a domain. Requires a domain-admin token.")
projectListDomain = projectListCmd.Flag("domain", "Domain ID.").Short('d').Required().String()
Expand All @@ -89,7 +89,7 @@ var (
projectSetCmd = projectCmd.Command("set", "Change resource(s) quota for a project. Requires a domain-admin token.")
projectSetDomain = projectSetCmd.Flag("domain", "Domain ID.").Short('d').String()
projectSetID = projectSetCmd.Arg("project-id", "Project ID (name/UUID).").Required().String()
projectSetQuotas = cli.ParseQuotas(projectSetCmd.Arg("quotas", "Quotas to change. Format: service/resource=value(unit)").Required())
projectSetQuotas = QuotaList(projectSetCmd.Arg("quotas", "Quotas to change. Format: service/resource=value(unit)").Required())

projectSyncCmd = projectCmd.Command("sync", "Sync a project's quota and usage data from the backing services into Limes' local database. Requires a project-admin token.")
projectSyncDomain = projectSyncCmd.Flag("domain", "Domain ID.").Short('d').String()
Expand Down Expand Up @@ -152,8 +152,11 @@ func main() {
if strings.Contains(*clusterSetID, "=") {
errors.Handle(errors.New("required argument 'cluster-id' not provided, try --help"))
}

c := &cli.Cluster{ID: *clusterSetID}
cli.RunSetTask(c, clusterSetCaps)
q, err := cli.ParseRawQuotas(c, clusterSetCaps, false)
errors.Handle(err)
cli.RunSetTask(c, q)

case domainListCmd.FullCommand():
d := &cli.Domain{
Expand Down Expand Up @@ -195,7 +198,9 @@ func main() {
}

d.Filter.Cluster = *domainCluster
cli.RunSetTask(d, domainSetQuotas)
q, err := cli.ParseRawQuotas(d, domainSetQuotas, false)
errors.Handle(err)
cli.RunSetTask(d, q)

case projectListCmd.FullCommand():
var d *cli.Domain
Expand Down Expand Up @@ -245,7 +250,9 @@ func main() {
errors.Handle(err)

p.Filter.Cluster = *projectCluster
cli.RunSetTask(p, projectSetQuotas)
q, err := cli.ParseRawQuotas(p, projectSetQuotas, false)
errors.Handle(err)
cli.RunSetTask(p, q)

case projectSyncCmd.FullCommand():
var p *cli.Project
Expand All @@ -269,3 +276,29 @@ func setEnvUnlessEmpty(env, val string) {

os.Setenv(env, val)
}

type rawQuotas cli.RawQuotas

// Set implements the kingpin.Value interface.
func (rq *rawQuotas) Set(value string) error {
*rq = append(*rq, strings.TrimSpace(value))
return nil
}

// String implements the kingpin.Value interface.
func (rq *rawQuotas) String() string {
return ""
}

// IsCumulative allows consumption of remaining command line arguments.
func (rq *rawQuotas) IsCumulative() bool {
return true
}

// QuotaList appends the raw quota values given at the command line to the
// aggregate cli.RawQuotas list.
func QuotaList(s kingpin.Settings) (target *cli.RawQuotas) {
target = new(cli.RawQuotas)
s.SetValue((*rawQuotas)(target))
return
}
13 changes: 0 additions & 13 deletions pkg/cli/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ 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/limes"
"github.com/sapcc/limesctl/pkg/errors"
)

Expand Down Expand Up @@ -128,18 +127,6 @@ func RunListTask(t ListTask, outputFmt string) {
}
}

// Resource contains quota information about a single resource.
type Resource struct {
Name string
Value int64
Unit limes.Unit
Comment string
}

// Quotas is a map of service name to a list of resources. It contains the aggregate
// quota values used by the set methods to update a single cluster/domain/project.
type Quotas map[string][]Resource

// SetTask is the interface type that abstracts a put operation.
type SetTask interface {
set(*Quotas)
Expand Down
Loading

0 comments on commit 403e0d3

Please sign in to comment.