github.com/vmware/govmomi@v0.43.0/govc/host/account/account.go (about) 1 /* 2 Copyright (c) 2016 VMware, Inc. All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package account 18 19 import ( 20 "context" 21 "flag" 22 23 "github.com/vmware/govmomi/govc/flags" 24 "github.com/vmware/govmomi/object" 25 "github.com/vmware/govmomi/vim25/types" 26 ) 27 28 type AccountFlag struct { 29 *flags.ClientFlag 30 *flags.DatacenterFlag 31 *flags.HostSystemFlag 32 33 types.HostAccountSpec 34 } 35 36 func newAccountFlag(ctx context.Context) (*AccountFlag, context.Context) { 37 f := &AccountFlag{} 38 f.ClientFlag, ctx = flags.NewClientFlag(ctx) 39 f.DatacenterFlag, ctx = flags.NewDatacenterFlag(ctx) 40 f.HostSystemFlag, ctx = flags.NewHostSystemFlag(ctx) 41 return f, ctx 42 } 43 44 func (f *AccountFlag) Register(ctx context.Context, fs *flag.FlagSet) { 45 f.ClientFlag.Register(ctx, fs) 46 f.DatacenterFlag.Register(ctx, fs) 47 f.HostSystemFlag.Register(ctx, fs) 48 49 fs.StringVar(&f.Id, "id", "", "The ID of the specified account") 50 fs.StringVar(&f.Password, "password", "", "The password for the specified account id") 51 fs.StringVar(&f.Description, "description", "", "The description of the specified account") 52 } 53 54 func (f *AccountFlag) Process(ctx context.Context) error { 55 if err := f.ClientFlag.Process(ctx); err != nil { 56 return err 57 } 58 if err := f.DatacenterFlag.Process(ctx); err != nil { 59 return err 60 } 61 if err := f.HostSystemFlag.Process(ctx); err != nil { 62 return err 63 } 64 return nil 65 } 66 67 func (f *AccountFlag) HostAccountManager(ctx context.Context) (*object.HostAccountManager, error) { 68 h, err := f.HostSystem() 69 if err != nil { 70 return nil, err 71 } 72 73 return h.ConfigManager().AccountManager(ctx) 74 }