1/* 2Copyright (c) 2015 VMware, Inc. All Rights Reserved. 3 4Licensed under the Apache License, Version 2.0 (the "License"); 5you may not use this file except in compliance with the License. 6You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10Unless required by applicable law or agreed to in writing, software 11distributed under the License is distributed on an "AS IS" BASIS, 12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13See the License for the specific language governing permissions and 14limitations under the License. 15*/ 16 17package object 18 19import ( 20 "context" 21 22 "github.com/vmware/govmomi/vim25" 23 "github.com/vmware/govmomi/vim25/methods" 24 "github.com/vmware/govmomi/vim25/types" 25) 26 27type CustomizationSpecManager struct { 28 Common 29} 30 31func NewCustomizationSpecManager(c *vim25.Client) *CustomizationSpecManager { 32 cs := CustomizationSpecManager{ 33 Common: NewCommon(c, *c.ServiceContent.CustomizationSpecManager), 34 } 35 36 return &cs 37} 38 39func (cs CustomizationSpecManager) DoesCustomizationSpecExist(ctx context.Context, name string) (bool, error) { 40 req := types.DoesCustomizationSpecExist{ 41 This: cs.Reference(), 42 Name: name, 43 } 44 45 res, err := methods.DoesCustomizationSpecExist(ctx, cs.c, &req) 46 47 if err != nil { 48 return false, err 49 } 50 51 return res.Returnval, nil 52} 53 54func (cs CustomizationSpecManager) GetCustomizationSpec(ctx context.Context, name string) (*types.CustomizationSpecItem, error) { 55 req := types.GetCustomizationSpec{ 56 This: cs.Reference(), 57 Name: name, 58 } 59 60 res, err := methods.GetCustomizationSpec(ctx, cs.c, &req) 61 62 if err != nil { 63 return nil, err 64 } 65 66 return &res.Returnval, nil 67} 68 69func (cs CustomizationSpecManager) CreateCustomizationSpec(ctx context.Context, item types.CustomizationSpecItem) error { 70 req := types.CreateCustomizationSpec{ 71 This: cs.Reference(), 72 Item: item, 73 } 74 75 _, err := methods.CreateCustomizationSpec(ctx, cs.c, &req) 76 if err != nil { 77 return err 78 } 79 80 return nil 81} 82 83func (cs CustomizationSpecManager) OverwriteCustomizationSpec(ctx context.Context, item types.CustomizationSpecItem) error { 84 req := types.OverwriteCustomizationSpec{ 85 This: cs.Reference(), 86 Item: item, 87 } 88 89 _, err := methods.OverwriteCustomizationSpec(ctx, cs.c, &req) 90 if err != nil { 91 return err 92 } 93 94 return nil 95} 96 97func (cs CustomizationSpecManager) DeleteCustomizationSpec(ctx context.Context, name string) error { 98 req := types.DeleteCustomizationSpec{ 99 This: cs.Reference(), 100 Name: name, 101 } 102 103 _, err := methods.DeleteCustomizationSpec(ctx, cs.c, &req) 104 if err != nil { 105 return err 106 } 107 108 return nil 109} 110 111func (cs CustomizationSpecManager) DuplicateCustomizationSpec(ctx context.Context, name string, newName string) error { 112 req := types.DuplicateCustomizationSpec{ 113 This: cs.Reference(), 114 Name: name, 115 NewName: newName, 116 } 117 118 _, err := methods.DuplicateCustomizationSpec(ctx, cs.c, &req) 119 if err != nil { 120 return err 121 } 122 123 return nil 124} 125 126func (cs CustomizationSpecManager) RenameCustomizationSpec(ctx context.Context, name string, newName string) error { 127 req := types.RenameCustomizationSpec{ 128 This: cs.Reference(), 129 Name: name, 130 NewName: newName, 131 } 132 133 _, err := methods.RenameCustomizationSpec(ctx, cs.c, &req) 134 if err != nil { 135 return err 136 } 137 138 return nil 139} 140 141func (cs CustomizationSpecManager) CustomizationSpecItemToXml(ctx context.Context, item types.CustomizationSpecItem) (string, error) { 142 req := types.CustomizationSpecItemToXml{ 143 This: cs.Reference(), 144 Item: item, 145 } 146 147 res, err := methods.CustomizationSpecItemToXml(ctx, cs.c, &req) 148 if err != nil { 149 return "", err 150 } 151 152 return res.Returnval, nil 153} 154 155func (cs CustomizationSpecManager) XmlToCustomizationSpecItem(ctx context.Context, xml string) (*types.CustomizationSpecItem, error) { 156 req := types.XmlToCustomizationSpecItem{ 157 This: cs.Reference(), 158 SpecItemXml: xml, 159 } 160 161 res, err := methods.XmlToCustomizationSpecItem(ctx, cs.c, &req) 162 if err != nil { 163 return nil, err 164 } 165 return &res.Returnval, nil 166} 167