github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/cmd/roachprod/vm/flagstub/flagstub.go (about) 1 // Copyright 2018 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package flagstub 12 13 import ( 14 "time" 15 16 "github.com/cockroachdb/cockroach/pkg/cmd/roachprod/vm" 17 "github.com/cockroachdb/errors" 18 ) 19 20 // New wraps a delegate vm.Provider to only return its name and 21 // flags. This allows roachprod to provide a consistent tooling 22 // experience. Operations that can be reasonably stubbed out are 23 // implemented as no-op or no-value. All other operations will 24 // return the provided error. 25 func New(delegate vm.Provider, unimplemented string) vm.Provider { 26 return &provider{delegate: delegate, unimplemented: unimplemented} 27 } 28 29 type provider struct { 30 delegate vm.Provider 31 unimplemented string 32 } 33 34 // CleanSSH implements vm.Provider and is a no-op. 35 func (p *provider) CleanSSH() error { 36 return nil 37 } 38 39 // ConfigSSH implements vm.Provider and is a no-op. 40 func (p *provider) ConfigSSH() error { 41 return nil 42 } 43 44 // Create implements vm.Provider and returns Unimplemented. 45 func (p *provider) Create(names []string, opts vm.CreateOpts) error { 46 return errors.Newf("%s", p.unimplemented) 47 } 48 49 // Delete implements vm.Provider and returns Unimplemented. 50 func (p *provider) Delete(vms vm.List) error { 51 return errors.Newf("%s", p.unimplemented) 52 } 53 54 // Extend implements vm.Provider and returns Unimplemented. 55 func (p *provider) Extend(vms vm.List, lifetime time.Duration) error { 56 return errors.Newf("%s", p.unimplemented) 57 } 58 59 // FindActiveAccount implements vm.Provider and returns an empty account. 60 func (p *provider) FindActiveAccount() (string, error) { 61 return "", nil 62 } 63 64 // Flags implements vm.Provider and returns the delegate's name. 65 func (p *provider) Flags() vm.ProviderFlags { 66 return p.delegate.Flags() 67 } 68 69 // List implements vm.Provider and returns an empty list. 70 func (p *provider) List() (vm.List, error) { 71 return nil, nil 72 } 73 74 // Name implements vm.Provider and returns the delegate's name. 75 func (p *provider) Name() string { 76 return p.delegate.Name() 77 } 78 79 // Active is part of the vm.Provider interface. 80 func (p *provider) Active() bool { 81 return false 82 }