github.com/vmware/govmomi@v0.51.0/object/customization_spec_manager.go (about)

     1  // © Broadcom. All Rights Reserved.
     2  // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package object
     6  
     7  import (
     8  	"context"
     9  
    10  	"github.com/vmware/govmomi/vim25"
    11  	"github.com/vmware/govmomi/vim25/methods"
    12  	"github.com/vmware/govmomi/vim25/mo"
    13  	"github.com/vmware/govmomi/vim25/types"
    14  )
    15  
    16  type CustomizationSpecManager struct {
    17  	Common
    18  }
    19  
    20  func NewCustomizationSpecManager(c *vim25.Client) *CustomizationSpecManager {
    21  	cs := CustomizationSpecManager{
    22  		Common: NewCommon(c, *c.ServiceContent.CustomizationSpecManager),
    23  	}
    24  
    25  	return &cs
    26  }
    27  
    28  func (cs CustomizationSpecManager) Info(ctx context.Context) ([]types.CustomizationSpecInfo, error) {
    29  	var m mo.CustomizationSpecManager
    30  	err := cs.Properties(ctx, cs.Reference(), []string{"info"}, &m)
    31  	return m.Info, err
    32  }
    33  
    34  func (cs CustomizationSpecManager) DoesCustomizationSpecExist(ctx context.Context, name string) (bool, error) {
    35  	req := types.DoesCustomizationSpecExist{
    36  		This: cs.Reference(),
    37  		Name: name,
    38  	}
    39  
    40  	res, err := methods.DoesCustomizationSpecExist(ctx, cs.c, &req)
    41  
    42  	if err != nil {
    43  		return false, err
    44  	}
    45  
    46  	return res.Returnval, nil
    47  }
    48  
    49  func (cs CustomizationSpecManager) GetCustomizationSpec(ctx context.Context, name string) (*types.CustomizationSpecItem, error) {
    50  	req := types.GetCustomizationSpec{
    51  		This: cs.Reference(),
    52  		Name: name,
    53  	}
    54  
    55  	res, err := methods.GetCustomizationSpec(ctx, cs.c, &req)
    56  
    57  	if err != nil {
    58  		return nil, err
    59  	}
    60  
    61  	return &res.Returnval, nil
    62  }
    63  
    64  func (cs CustomizationSpecManager) CreateCustomizationSpec(ctx context.Context, item types.CustomizationSpecItem) error {
    65  	req := types.CreateCustomizationSpec{
    66  		This: cs.Reference(),
    67  		Item: item,
    68  	}
    69  
    70  	_, err := methods.CreateCustomizationSpec(ctx, cs.c, &req)
    71  	if err != nil {
    72  		return err
    73  	}
    74  
    75  	return nil
    76  }
    77  
    78  func (cs CustomizationSpecManager) OverwriteCustomizationSpec(ctx context.Context, item types.CustomizationSpecItem) error {
    79  	req := types.OverwriteCustomizationSpec{
    80  		This: cs.Reference(),
    81  		Item: item,
    82  	}
    83  
    84  	_, err := methods.OverwriteCustomizationSpec(ctx, cs.c, &req)
    85  	if err != nil {
    86  		return err
    87  	}
    88  
    89  	return nil
    90  }
    91  
    92  func (cs CustomizationSpecManager) DeleteCustomizationSpec(ctx context.Context, name string) error {
    93  	req := types.DeleteCustomizationSpec{
    94  		This: cs.Reference(),
    95  		Name: name,
    96  	}
    97  
    98  	_, err := methods.DeleteCustomizationSpec(ctx, cs.c, &req)
    99  	if err != nil {
   100  		return err
   101  	}
   102  
   103  	return nil
   104  }
   105  
   106  func (cs CustomizationSpecManager) DuplicateCustomizationSpec(ctx context.Context, name string, newName string) error {
   107  	req := types.DuplicateCustomizationSpec{
   108  		This:    cs.Reference(),
   109  		Name:    name,
   110  		NewName: newName,
   111  	}
   112  
   113  	_, err := methods.DuplicateCustomizationSpec(ctx, cs.c, &req)
   114  	if err != nil {
   115  		return err
   116  	}
   117  
   118  	return nil
   119  }
   120  
   121  func (cs CustomizationSpecManager) RenameCustomizationSpec(ctx context.Context, name string, newName string) error {
   122  	req := types.RenameCustomizationSpec{
   123  		This:    cs.Reference(),
   124  		Name:    name,
   125  		NewName: newName,
   126  	}
   127  
   128  	_, err := methods.RenameCustomizationSpec(ctx, cs.c, &req)
   129  	if err != nil {
   130  		return err
   131  	}
   132  
   133  	return nil
   134  }
   135  
   136  func (cs CustomizationSpecManager) CustomizationSpecItemToXml(ctx context.Context, item types.CustomizationSpecItem) (string, error) {
   137  	req := types.CustomizationSpecItemToXml{
   138  		This: cs.Reference(),
   139  		Item: item,
   140  	}
   141  
   142  	res, err := methods.CustomizationSpecItemToXml(ctx, cs.c, &req)
   143  	if err != nil {
   144  		return "", err
   145  	}
   146  
   147  	return res.Returnval, nil
   148  }
   149  
   150  func (cs CustomizationSpecManager) XmlToCustomizationSpecItem(ctx context.Context, xml string) (*types.CustomizationSpecItem, error) {
   151  	req := types.XmlToCustomizationSpecItem{
   152  		This:        cs.Reference(),
   153  		SpecItemXml: xml,
   154  	}
   155  
   156  	res, err := methods.XmlToCustomizationSpecItem(ctx, cs.c, &req)
   157  	if err != nil {
   158  		return nil, err
   159  	}
   160  	return &res.Returnval, nil
   161  }