github.com/vmware/govmomi@v0.43.0/object/extension_manager.go (about) 1 /* 2 Copyright (c) 2015 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 object 18 19 import ( 20 "context" 21 22 "github.com/vmware/govmomi/vim25" 23 "github.com/vmware/govmomi/vim25/methods" 24 "github.com/vmware/govmomi/vim25/mo" 25 "github.com/vmware/govmomi/vim25/types" 26 ) 27 28 type ExtensionManager struct { 29 Common 30 } 31 32 // GetExtensionManager wraps NewExtensionManager, returning ErrNotSupported 33 // when the client is not connected to a vCenter instance. 34 func GetExtensionManager(c *vim25.Client) (*ExtensionManager, error) { 35 if c.ServiceContent.ExtensionManager == nil { 36 return nil, ErrNotSupported 37 } 38 return NewExtensionManager(c), nil 39 } 40 41 func NewExtensionManager(c *vim25.Client) *ExtensionManager { 42 o := ExtensionManager{ 43 Common: NewCommon(c, *c.ServiceContent.ExtensionManager), 44 } 45 46 return &o 47 } 48 49 func (m ExtensionManager) List(ctx context.Context) ([]types.Extension, error) { 50 var em mo.ExtensionManager 51 52 err := m.Properties(ctx, m.Reference(), []string{"extensionList"}, &em) 53 if err != nil { 54 return nil, err 55 } 56 57 return em.ExtensionList, nil 58 } 59 60 func (m ExtensionManager) Find(ctx context.Context, key string) (*types.Extension, error) { 61 req := types.FindExtension{ 62 This: m.Reference(), 63 ExtensionKey: key, 64 } 65 66 res, err := methods.FindExtension(ctx, m.c, &req) 67 if err != nil { 68 return nil, err 69 } 70 71 return res.Returnval, nil 72 } 73 74 func (m ExtensionManager) Register(ctx context.Context, extension types.Extension) error { 75 req := types.RegisterExtension{ 76 This: m.Reference(), 77 Extension: extension, 78 } 79 80 _, err := methods.RegisterExtension(ctx, m.c, &req) 81 return err 82 } 83 84 func (m ExtensionManager) SetCertificate(ctx context.Context, key string, certificatePem string) error { 85 req := types.SetExtensionCertificate{ 86 This: m.Reference(), 87 ExtensionKey: key, 88 CertificatePem: certificatePem, 89 } 90 91 _, err := methods.SetExtensionCertificate(ctx, m.c, &req) 92 return err 93 } 94 95 func (m ExtensionManager) Unregister(ctx context.Context, key string) error { 96 req := types.UnregisterExtension{ 97 This: m.Reference(), 98 ExtensionKey: key, 99 } 100 101 _, err := methods.UnregisterExtension(ctx, m.c, &req) 102 return err 103 } 104 105 func (m ExtensionManager) Update(ctx context.Context, extension types.Extension) error { 106 req := types.UpdateExtension{ 107 This: m.Reference(), 108 Extension: extension, 109 } 110 111 _, err := methods.UpdateExtension(ctx, m.c, &req) 112 return err 113 }