github.com/vmware/govmomi@v0.37.1/object/customization_spec_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 CustomizationSpecManager struct {
    29  	Common
    30  }
    31  
    32  func NewCustomizationSpecManager(c *vim25.Client) *CustomizationSpecManager {
    33  	cs := CustomizationSpecManager{
    34  		Common: NewCommon(c, *c.ServiceContent.CustomizationSpecManager),
    35  	}
    36  
    37  	return &cs
    38  }
    39  
    40  func (cs CustomizationSpecManager) Info(ctx context.Context) ([]types.CustomizationSpecInfo, error) {
    41  	var m mo.CustomizationSpecManager
    42  	err := cs.Properties(ctx, cs.Reference(), []string{"info"}, &m)
    43  	return m.Info, err
    44  }
    45  
    46  func (cs CustomizationSpecManager) DoesCustomizationSpecExist(ctx context.Context, name string) (bool, error) {
    47  	req := types.DoesCustomizationSpecExist{
    48  		This: cs.Reference(),
    49  		Name: name,
    50  	}
    51  
    52  	res, err := methods.DoesCustomizationSpecExist(ctx, cs.c, &req)
    53  
    54  	if err != nil {
    55  		return false, err
    56  	}
    57  
    58  	return res.Returnval, nil
    59  }
    60  
    61  func (cs CustomizationSpecManager) GetCustomizationSpec(ctx context.Context, name string) (*types.CustomizationSpecItem, error) {
    62  	req := types.GetCustomizationSpec{
    63  		This: cs.Reference(),
    64  		Name: name,
    65  	}
    66  
    67  	res, err := methods.GetCustomizationSpec(ctx, cs.c, &req)
    68  
    69  	if err != nil {
    70  		return nil, err
    71  	}
    72  
    73  	return &res.Returnval, nil
    74  }
    75  
    76  func (cs CustomizationSpecManager) CreateCustomizationSpec(ctx context.Context, item types.CustomizationSpecItem) error {
    77  	req := types.CreateCustomizationSpec{
    78  		This: cs.Reference(),
    79  		Item: item,
    80  	}
    81  
    82  	_, err := methods.CreateCustomizationSpec(ctx, cs.c, &req)
    83  	if err != nil {
    84  		return err
    85  	}
    86  
    87  	return nil
    88  }
    89  
    90  func (cs CustomizationSpecManager) OverwriteCustomizationSpec(ctx context.Context, item types.CustomizationSpecItem) error {
    91  	req := types.OverwriteCustomizationSpec{
    92  		This: cs.Reference(),
    93  		Item: item,
    94  	}
    95  
    96  	_, err := methods.OverwriteCustomizationSpec(ctx, cs.c, &req)
    97  	if err != nil {
    98  		return err
    99  	}
   100  
   101  	return nil
   102  }
   103  
   104  func (cs CustomizationSpecManager) DeleteCustomizationSpec(ctx context.Context, name string) error {
   105  	req := types.DeleteCustomizationSpec{
   106  		This: cs.Reference(),
   107  		Name: name,
   108  	}
   109  
   110  	_, err := methods.DeleteCustomizationSpec(ctx, cs.c, &req)
   111  	if err != nil {
   112  		return err
   113  	}
   114  
   115  	return nil
   116  }
   117  
   118  func (cs CustomizationSpecManager) DuplicateCustomizationSpec(ctx context.Context, name string, newName string) error {
   119  	req := types.DuplicateCustomizationSpec{
   120  		This:    cs.Reference(),
   121  		Name:    name,
   122  		NewName: newName,
   123  	}
   124  
   125  	_, err := methods.DuplicateCustomizationSpec(ctx, cs.c, &req)
   126  	if err != nil {
   127  		return err
   128  	}
   129  
   130  	return nil
   131  }
   132  
   133  func (cs CustomizationSpecManager) RenameCustomizationSpec(ctx context.Context, name string, newName string) error {
   134  	req := types.RenameCustomizationSpec{
   135  		This:    cs.Reference(),
   136  		Name:    name,
   137  		NewName: newName,
   138  	}
   139  
   140  	_, err := methods.RenameCustomizationSpec(ctx, cs.c, &req)
   141  	if err != nil {
   142  		return err
   143  	}
   144  
   145  	return nil
   146  }
   147  
   148  func (cs CustomizationSpecManager) CustomizationSpecItemToXml(ctx context.Context, item types.CustomizationSpecItem) (string, error) {
   149  	req := types.CustomizationSpecItemToXml{
   150  		This: cs.Reference(),
   151  		Item: item,
   152  	}
   153  
   154  	res, err := methods.CustomizationSpecItemToXml(ctx, cs.c, &req)
   155  	if err != nil {
   156  		return "", err
   157  	}
   158  
   159  	return res.Returnval, nil
   160  }
   161  
   162  func (cs CustomizationSpecManager) XmlToCustomizationSpecItem(ctx context.Context, xml string) (*types.CustomizationSpecItem, error) {
   163  	req := types.XmlToCustomizationSpecItem{
   164  		This:        cs.Reference(),
   165  		SpecItemXml: xml,
   166  	}
   167  
   168  	res, err := methods.XmlToCustomizationSpecItem(ctx, cs.c, &req)
   169  	if err != nil {
   170  		return nil, err
   171  	}
   172  	return &res.Returnval, nil
   173  }