customization_spec_manager.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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/mo"
  19. "github.com/vmware/govmomi/vim25/types"
  20. )
  21. type CustomizationSpecManager struct {
  22. Common
  23. }
  24. func NewCustomizationSpecManager(c *vim25.Client) *CustomizationSpecManager {
  25. cs := CustomizationSpecManager{
  26. Common: NewCommon(c, *c.ServiceContent.CustomizationSpecManager),
  27. }
  28. return &cs
  29. }
  30. func (cs CustomizationSpecManager) Info(ctx context.Context) ([]types.CustomizationSpecInfo, error) {
  31. var m mo.CustomizationSpecManager
  32. err := cs.Properties(ctx, cs.Reference(), []string{"info"}, &m)
  33. return m.Info, err
  34. }
  35. func (cs CustomizationSpecManager) DoesCustomizationSpecExist(ctx context.Context, name string) (bool, error) {
  36. req := types.DoesCustomizationSpecExist{
  37. This: cs.Reference(),
  38. Name: name,
  39. }
  40. res, err := methods.DoesCustomizationSpecExist(ctx, cs.c, &req)
  41. if err != nil {
  42. return false, err
  43. }
  44. return res.Returnval, nil
  45. }
  46. func (cs CustomizationSpecManager) GetCustomizationSpec(ctx context.Context, name string) (*types.CustomizationSpecItem, error) {
  47. req := types.GetCustomizationSpec{
  48. This: cs.Reference(),
  49. Name: name,
  50. }
  51. res, err := methods.GetCustomizationSpec(ctx, cs.c, &req)
  52. if err != nil {
  53. return nil, err
  54. }
  55. return &res.Returnval, nil
  56. }
  57. func (cs CustomizationSpecManager) CreateCustomizationSpec(ctx context.Context, item types.CustomizationSpecItem) error {
  58. req := types.CreateCustomizationSpec{
  59. This: cs.Reference(),
  60. Item: item,
  61. }
  62. _, err := methods.CreateCustomizationSpec(ctx, cs.c, &req)
  63. if err != nil {
  64. return err
  65. }
  66. return nil
  67. }
  68. func (cs CustomizationSpecManager) OverwriteCustomizationSpec(ctx context.Context, item types.CustomizationSpecItem) error {
  69. req := types.OverwriteCustomizationSpec{
  70. This: cs.Reference(),
  71. Item: item,
  72. }
  73. _, err := methods.OverwriteCustomizationSpec(ctx, cs.c, &req)
  74. if err != nil {
  75. return err
  76. }
  77. return nil
  78. }
  79. func (cs CustomizationSpecManager) DeleteCustomizationSpec(ctx context.Context, name string) error {
  80. req := types.DeleteCustomizationSpec{
  81. This: cs.Reference(),
  82. Name: name,
  83. }
  84. _, err := methods.DeleteCustomizationSpec(ctx, cs.c, &req)
  85. if err != nil {
  86. return err
  87. }
  88. return nil
  89. }
  90. func (cs CustomizationSpecManager) DuplicateCustomizationSpec(ctx context.Context, name string, newName string) error {
  91. req := types.DuplicateCustomizationSpec{
  92. This: cs.Reference(),
  93. Name: name,
  94. NewName: newName,
  95. }
  96. _, err := methods.DuplicateCustomizationSpec(ctx, cs.c, &req)
  97. if err != nil {
  98. return err
  99. }
  100. return nil
  101. }
  102. func (cs CustomizationSpecManager) RenameCustomizationSpec(ctx context.Context, name string, newName string) error {
  103. req := types.RenameCustomizationSpec{
  104. This: cs.Reference(),
  105. Name: name,
  106. NewName: newName,
  107. }
  108. _, err := methods.RenameCustomizationSpec(ctx, cs.c, &req)
  109. if err != nil {
  110. return err
  111. }
  112. return nil
  113. }
  114. func (cs CustomizationSpecManager) CustomizationSpecItemToXml(ctx context.Context, item types.CustomizationSpecItem) (string, error) {
  115. req := types.CustomizationSpecItemToXml{
  116. This: cs.Reference(),
  117. Item: item,
  118. }
  119. res, err := methods.CustomizationSpecItemToXml(ctx, cs.c, &req)
  120. if err != nil {
  121. return "", err
  122. }
  123. return res.Returnval, nil
  124. }
  125. func (cs CustomizationSpecManager) XmlToCustomizationSpecItem(ctx context.Context, xml string) (*types.CustomizationSpecItem, error) {
  126. req := types.XmlToCustomizationSpecItem{
  127. This: cs.Reference(),
  128. SpecItemXml: xml,
  129. }
  130. res, err := methods.XmlToCustomizationSpecItem(ctx, cs.c, &req)
  131. if err != nil {
  132. return nil, err
  133. }
  134. return &res.Returnval, nil
  135. }