mirror of
https://github.com/Oxalide/vsphere-influxdb-go.git
synced 2023-10-10 11:36:51 +00:00
add vendoring with go dep
This commit is contained in:
98
vendor/github.com/vmware/govmomi/govc/pool/change.go
generated
vendored
Normal file
98
vendor/github.com/vmware/govmomi/govc/pool/change.go
generated
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
Copyright (c) 2015 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package pool
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type change struct {
|
||||
*flags.DatacenterFlag
|
||||
*ResourceConfigSpecFlag
|
||||
|
||||
name string
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("pool.change", &change{})
|
||||
}
|
||||
|
||||
func (cmd *change) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.DatacenterFlag, ctx = flags.NewDatacenterFlag(ctx)
|
||||
cmd.DatacenterFlag.Register(ctx, f)
|
||||
cmd.ResourceConfigSpecFlag = NewResourceConfigSpecFlag()
|
||||
cmd.ResourceConfigSpecFlag.Register(ctx, f)
|
||||
|
||||
f.StringVar(&cmd.name, "name", "", "Resource pool name")
|
||||
}
|
||||
|
||||
func (cmd *change) Process(ctx context.Context) error {
|
||||
if err := cmd.DatacenterFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cmd.ResourceConfigSpecFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *change) Usage() string {
|
||||
return "POOL..."
|
||||
}
|
||||
|
||||
func (cmd *change) Description() string {
|
||||
return "Change the configuration of one or more resource POOLs.\n" + poolNameHelp
|
||||
}
|
||||
|
||||
func (cmd *change) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
if f.NArg() == 0 {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
finder, err := cmd.Finder()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cmd.SetAllocation(func(a types.BaseResourceAllocationInfo) {
|
||||
ra := a.GetResourceAllocationInfo()
|
||||
if ra.Shares.Level == "" {
|
||||
ra.Shares = nil
|
||||
}
|
||||
})
|
||||
|
||||
for _, arg := range f.Args() {
|
||||
pools, err := finder.ResourcePoolListAll(ctx, arg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, pool := range pools {
|
||||
err := pool.UpdateConfig(ctx, cmd.name, &cmd.ResourceConfigSpec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
101
vendor/github.com/vmware/govmomi/govc/pool/create.go
generated
vendored
Normal file
101
vendor/github.com/vmware/govmomi/govc/pool/create.go
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
Copyright (c) 2015 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package pool
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"path"
|
||||
|
||||
"github.com/vmware/govmomi/find"
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type create struct {
|
||||
*flags.DatacenterFlag
|
||||
*ResourceConfigSpecFlag
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("pool.create", &create{})
|
||||
}
|
||||
|
||||
func (cmd *create) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.DatacenterFlag, ctx = flags.NewDatacenterFlag(ctx)
|
||||
cmd.DatacenterFlag.Register(ctx, f)
|
||||
|
||||
cmd.ResourceConfigSpecFlag = NewResourceConfigSpecFlag()
|
||||
cmd.ResourceConfigSpecFlag.SetAllocation(func(a types.BaseResourceAllocationInfo) {
|
||||
ra := a.GetResourceAllocationInfo()
|
||||
ra.Shares.Level = types.SharesLevelNormal
|
||||
ra.ExpandableReservation = types.NewBool(true)
|
||||
})
|
||||
cmd.ResourceConfigSpecFlag.Register(ctx, f)
|
||||
}
|
||||
|
||||
func (cmd *create) Process(ctx context.Context) error {
|
||||
if err := cmd.DatacenterFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cmd.ResourceConfigSpecFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *create) Usage() string {
|
||||
return "POOL..."
|
||||
}
|
||||
|
||||
func (cmd *create) Description() string {
|
||||
return "Create one or more resource POOLs.\n" + poolCreateHelp
|
||||
}
|
||||
|
||||
func (cmd *create) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
if f.NArg() == 0 {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
finder, err := cmd.Finder()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, arg := range f.Args() {
|
||||
dir := path.Dir(arg)
|
||||
base := path.Base(arg)
|
||||
parents, err := finder.ResourcePoolList(ctx, dir)
|
||||
if err != nil {
|
||||
if _, ok := err.(*find.NotFoundError); ok {
|
||||
return fmt.Errorf("cannot create resource pool '%s': parent not found", base)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
for _, parent := range parents {
|
||||
_, err = parent.Create(ctx, base, cmd.ResourceConfigSpec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
101
vendor/github.com/vmware/govmomi/govc/pool/destroy.go
generated
vendored
Normal file
101
vendor/github.com/vmware/govmomi/govc/pool/destroy.go
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
Copyright (c) 2015 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package pool
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
|
||||
"github.com/vmware/govmomi/find"
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
)
|
||||
|
||||
type destroy struct {
|
||||
*flags.DatacenterFlag
|
||||
|
||||
children bool
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("pool.destroy", &destroy{})
|
||||
}
|
||||
|
||||
func (cmd *destroy) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.DatacenterFlag, ctx = flags.NewDatacenterFlag(ctx)
|
||||
cmd.DatacenterFlag.Register(ctx, f)
|
||||
|
||||
f.BoolVar(&cmd.children, "children", false, "Remove all children pools")
|
||||
}
|
||||
|
||||
func (cmd *destroy) Process(ctx context.Context) error {
|
||||
if err := cmd.DatacenterFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *destroy) Usage() string {
|
||||
return "POOL..."
|
||||
}
|
||||
|
||||
func (cmd *destroy) Description() string {
|
||||
return "Destroy one or more resource POOLs.\n" + poolNameHelp
|
||||
}
|
||||
|
||||
func (cmd *destroy) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
if f.NArg() == 0 {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
finder, err := cmd.Finder()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, arg := range f.Args() {
|
||||
pools, err := finder.ResourcePoolList(ctx, arg)
|
||||
if err != nil {
|
||||
if _, ok := err.(*find.NotFoundError); ok {
|
||||
// Ignore if pool cannot be found
|
||||
continue
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
for _, pool := range pools {
|
||||
if cmd.children {
|
||||
err = pool.DestroyChildren(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
task, err := pool.Destroy(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = task.Wait(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
50
vendor/github.com/vmware/govmomi/govc/pool/help.go
generated
vendored
Normal file
50
vendor/github.com/vmware/govmomi/govc/pool/help.go
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
Copyright (c) 2015 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package pool
|
||||
|
||||
var poolNameHelp = `
|
||||
POOL may be an absolute or relative path to a resource pool or a (clustered)
|
||||
compute host. If it resolves to a compute host, the associated root resource
|
||||
pool is returned. If a relative path is specified, it is resolved with respect
|
||||
to the current datacenter's "host" folder (i.e. /ha-datacenter/host).
|
||||
|
||||
Paths to nested resource pools must traverse through the root resource pool of
|
||||
the selected compute host, i.e. "compute-host/Resources/nested-pool".
|
||||
|
||||
The same globbing rules that apply to the "ls" command apply here. For example,
|
||||
POOL may be specified as "*/Resources/*" to expand to all resource pools that
|
||||
are nested one level under the root resource pool, on all (clustered) compute
|
||||
hosts in the current datacenter.`
|
||||
|
||||
var poolCreateHelp = `
|
||||
POOL may be an absolute or relative path to a resource pool. The parent of the
|
||||
specified POOL must be an existing resource pool. If a relative path is
|
||||
specified, it is resolved with respect to the current datacenter's "host"
|
||||
folder (i.e. /ha-datacenter/host). The basename of the specified POOL is used
|
||||
as the name for the new resource pool.
|
||||
|
||||
The same globbing rules that apply to the "ls" command apply here. For example,
|
||||
the path to the parent resource pool in POOL may be specified as "*/Resources"
|
||||
to expand to the root resource pools on all (clustered) compute hosts in the
|
||||
current datacenter.
|
||||
|
||||
For example:
|
||||
*/Resources/test Create resource pool "test" on all (clustered)
|
||||
compute hosts in the current datacenter.
|
||||
somehost/Resources/*/nested Create resource pool "nested" in every
|
||||
resource pool that is a direct descendant of
|
||||
the root resource pool on "somehost".`
|
212
vendor/github.com/vmware/govmomi/govc/pool/info.go
generated
vendored
Normal file
212
vendor/github.com/vmware/govmomi/govc/pool/info.go
generated
vendored
Normal file
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
Copyright (c) 2015-2016 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package pool
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/vmware/govmomi/find"
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/property"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type info struct {
|
||||
*flags.DatacenterFlag
|
||||
*flags.OutputFlag
|
||||
|
||||
pools bool
|
||||
apps bool
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("pool.info", &info{})
|
||||
}
|
||||
|
||||
func (cmd *info) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.DatacenterFlag, ctx = flags.NewDatacenterFlag(ctx)
|
||||
cmd.DatacenterFlag.Register(ctx, f)
|
||||
cmd.OutputFlag, ctx = flags.NewOutputFlag(ctx)
|
||||
cmd.OutputFlag.Register(ctx, f)
|
||||
|
||||
f.BoolVar(&cmd.pools, "p", true, "List resource pools")
|
||||
f.BoolVar(&cmd.apps, "a", false, "List virtual app resource pools")
|
||||
}
|
||||
|
||||
func (cmd *info) Process(ctx context.Context) error {
|
||||
if err := cmd.DatacenterFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cmd.OutputFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *info) Usage() string {
|
||||
return "POOL..."
|
||||
}
|
||||
|
||||
func (cmd *info) Description() string {
|
||||
return "Retrieve information about one or more resource POOLs.\n" + poolNameHelp
|
||||
}
|
||||
|
||||
func (cmd *info) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
if f.NArg() == 0 {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
c, err := cmd.Client()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
finder, err := cmd.Finder()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var res infoResult
|
||||
var props []string
|
||||
|
||||
if cmd.OutputFlag.JSON {
|
||||
props = nil
|
||||
} else {
|
||||
props = []string{
|
||||
"name",
|
||||
"config.cpuAllocation",
|
||||
"config.memoryAllocation",
|
||||
"runtime.cpu",
|
||||
"runtime.memory",
|
||||
}
|
||||
}
|
||||
|
||||
var vapps []*object.VirtualApp
|
||||
|
||||
for _, arg := range f.Args() {
|
||||
if cmd.pools {
|
||||
objects, err := finder.ResourcePoolList(ctx, arg)
|
||||
if err != nil {
|
||||
if _, ok := err.(*find.NotFoundError); !ok {
|
||||
return err
|
||||
}
|
||||
}
|
||||
res.objects = append(res.objects, objects...)
|
||||
}
|
||||
|
||||
if cmd.apps {
|
||||
apps, err := finder.VirtualAppList(ctx, arg)
|
||||
if err != nil {
|
||||
if _, ok := err.(*find.NotFoundError); !ok {
|
||||
return err
|
||||
}
|
||||
}
|
||||
vapps = append(vapps, apps...)
|
||||
}
|
||||
}
|
||||
|
||||
if len(res.objects) != 0 {
|
||||
refs := make([]types.ManagedObjectReference, 0, len(res.objects))
|
||||
for _, o := range res.objects {
|
||||
refs = append(refs, o.Reference())
|
||||
}
|
||||
|
||||
pc := property.DefaultCollector(c)
|
||||
err = pc.Retrieve(ctx, refs, props, &res.ResourcePools)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if len(vapps) != 0 {
|
||||
var apps []mo.VirtualApp
|
||||
refs := make([]types.ManagedObjectReference, 0, len(vapps))
|
||||
for _, o := range vapps {
|
||||
refs = append(refs, o.Reference())
|
||||
p := object.NewResourcePool(c, o.Reference())
|
||||
p.InventoryPath = o.InventoryPath
|
||||
res.objects = append(res.objects, p)
|
||||
}
|
||||
|
||||
pc := property.DefaultCollector(c)
|
||||
err = pc.Retrieve(ctx, refs, props, &apps)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, app := range apps {
|
||||
res.ResourcePools = append(res.ResourcePools, app.ResourcePool)
|
||||
}
|
||||
}
|
||||
|
||||
return cmd.WriteResult(&res)
|
||||
}
|
||||
|
||||
type infoResult struct {
|
||||
ResourcePools []mo.ResourcePool
|
||||
objects []*object.ResourcePool
|
||||
}
|
||||
|
||||
func (r *infoResult) Write(w io.Writer) error {
|
||||
// Maintain order via r.objects as Property collector does not always return results in order.
|
||||
objects := make(map[types.ManagedObjectReference]mo.ResourcePool, len(r.ResourcePools))
|
||||
for _, o := range r.ResourcePools {
|
||||
objects[o.Reference()] = o
|
||||
}
|
||||
|
||||
tw := tabwriter.NewWriter(w, 2, 0, 2, ' ', 0)
|
||||
|
||||
for _, o := range r.objects {
|
||||
pool := objects[o.Reference()]
|
||||
fmt.Fprintf(tw, "Name:\t%s\n", pool.Name)
|
||||
fmt.Fprintf(tw, " Path:\t%s\n", o.InventoryPath)
|
||||
|
||||
writeInfo(tw, "CPU", "MHz", &pool.Runtime.Cpu, pool.Config.CpuAllocation)
|
||||
pool.Runtime.Memory.MaxUsage >>= 20
|
||||
pool.Runtime.Memory.OverallUsage >>= 20
|
||||
writeInfo(tw, "Mem", "MB", &pool.Runtime.Memory, pool.Config.MemoryAllocation)
|
||||
}
|
||||
|
||||
return tw.Flush()
|
||||
}
|
||||
|
||||
func writeInfo(w io.Writer, name string, units string, ru *types.ResourcePoolResourceUsage, b types.BaseResourceAllocationInfo) {
|
||||
ra := b.GetResourceAllocationInfo()
|
||||
usage := 100.0 * float64(ru.OverallUsage) / float64(ru.MaxUsage)
|
||||
shares := ""
|
||||
limit := "unlimited"
|
||||
|
||||
if ra.Shares.Level == types.SharesLevelCustom {
|
||||
shares = fmt.Sprintf(" (%d)", ra.Shares.Shares)
|
||||
}
|
||||
|
||||
if ra.Limit != -1 {
|
||||
limit = fmt.Sprintf("%d%s", ra.Limit, units)
|
||||
}
|
||||
|
||||
fmt.Fprintf(w, " %s Usage:\t%d%s (%0.1f%%)\n", name, ru.OverallUsage, units, usage)
|
||||
fmt.Fprintf(w, " %s Shares:\t%s%s\n", name, ra.Shares.Level, shares)
|
||||
fmt.Fprintf(w, " %s Reservation:\t%d%s (expandable=%v)\n", name, ra.Reservation, units, *ra.ExpandableReservation)
|
||||
fmt.Fprintf(w, " %s Limit:\t%s\n", name, limit)
|
||||
}
|
97
vendor/github.com/vmware/govmomi/govc/pool/resource_config_spec.go
generated
vendored
Normal file
97
vendor/github.com/vmware/govmomi/govc/pool/resource_config_spec.go
generated
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
Copyright (c) 2015 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package pool
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type sharesInfo types.SharesInfo
|
||||
|
||||
func (s *sharesInfo) String() string {
|
||||
return string(s.Level)
|
||||
}
|
||||
|
||||
func (s *sharesInfo) Set(val string) error {
|
||||
switch val {
|
||||
case string(types.SharesLevelNormal), string(types.SharesLevelLow), string(types.SharesLevelHigh):
|
||||
s.Level = types.SharesLevel(val)
|
||||
default:
|
||||
n, err := strconv.Atoi(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s.Level = types.SharesLevelCustom
|
||||
s.Shares = int32(n)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewResourceConfigSpecFlag() *ResourceConfigSpecFlag {
|
||||
f := new(ResourceConfigSpecFlag)
|
||||
f.MemoryAllocation = new(types.ResourceAllocationInfo)
|
||||
f.CpuAllocation = new(types.ResourceAllocationInfo)
|
||||
|
||||
f.SetAllocation(func(a types.BaseResourceAllocationInfo) {
|
||||
a.GetResourceAllocationInfo().Shares = new(types.SharesInfo)
|
||||
})
|
||||
return f
|
||||
}
|
||||
|
||||
type ResourceConfigSpecFlag struct {
|
||||
types.ResourceConfigSpec
|
||||
}
|
||||
|
||||
func (s *ResourceConfigSpecFlag) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
opts := []struct {
|
||||
name string
|
||||
units string
|
||||
types.BaseResourceAllocationInfo
|
||||
}{
|
||||
{"CPU", "MHz", s.CpuAllocation},
|
||||
{"Memory", "MB", s.MemoryAllocation},
|
||||
}
|
||||
|
||||
for _, opt := range opts {
|
||||
prefix := strings.ToLower(opt.name)[:3]
|
||||
ra := opt.GetResourceAllocationInfo()
|
||||
shares := (*sharesInfo)(ra.Shares)
|
||||
|
||||
f.Int64Var(&ra.Limit, prefix+".limit", 0, opt.name+" limit in "+opt.units)
|
||||
f.Int64Var(&ra.Reservation, prefix+".reservation", 0, opt.name+" reservation in "+opt.units)
|
||||
f.Var(flags.NewOptionalBool(&ra.ExpandableReservation), prefix+".expandable", opt.name+" expandable reservation")
|
||||
f.Var(shares, prefix+".shares", opt.name+" shares level or number")
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ResourceConfigSpecFlag) Process(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *ResourceConfigSpecFlag) SetAllocation(f func(types.BaseResourceAllocationInfo)) {
|
||||
for _, a := range []types.BaseResourceAllocationInfo{s.CpuAllocation, s.MemoryAllocation} {
|
||||
f(a)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user