customization_spec_manager.go 3.9 KB

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