github.com/vmware/govmomi@v0.43.0/object/virtual_app.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/types" 25 ) 26 27 type VirtualApp struct { 28 *ResourcePool 29 } 30 31 func NewVirtualApp(c *vim25.Client, ref types.ManagedObjectReference) *VirtualApp { 32 return &VirtualApp{ 33 ResourcePool: NewResourcePool(c, ref), 34 } 35 } 36 37 func (p VirtualApp) CreateChildVM(ctx context.Context, config types.VirtualMachineConfigSpec, host *HostSystem) (*Task, error) { 38 req := types.CreateChildVM_Task{ 39 This: p.Reference(), 40 Config: config, 41 } 42 43 if host != nil { 44 ref := host.Reference() 45 req.Host = &ref 46 } 47 48 res, err := methods.CreateChildVM_Task(ctx, p.c, &req) 49 if err != nil { 50 return nil, err 51 } 52 53 return NewTask(p.c, res.Returnval), nil 54 } 55 56 func (p VirtualApp) UpdateConfig(ctx context.Context, spec types.VAppConfigSpec) error { 57 req := types.UpdateVAppConfig{ 58 This: p.Reference(), 59 Spec: spec, 60 } 61 62 _, err := methods.UpdateVAppConfig(ctx, p.c, &req) 63 return err 64 } 65 66 func (p VirtualApp) PowerOn(ctx context.Context) (*Task, error) { 67 req := types.PowerOnVApp_Task{ 68 This: p.Reference(), 69 } 70 71 res, err := methods.PowerOnVApp_Task(ctx, p.c, &req) 72 if err != nil { 73 return nil, err 74 } 75 76 return NewTask(p.c, res.Returnval), nil 77 } 78 79 func (p VirtualApp) PowerOff(ctx context.Context, force bool) (*Task, error) { 80 req := types.PowerOffVApp_Task{ 81 This: p.Reference(), 82 Force: force, 83 } 84 85 res, err := methods.PowerOffVApp_Task(ctx, p.c, &req) 86 if err != nil { 87 return nil, err 88 } 89 90 return NewTask(p.c, res.Returnval), nil 91 92 } 93 94 func (p VirtualApp) Suspend(ctx context.Context) (*Task, error) { 95 req := types.SuspendVApp_Task{ 96 This: p.Reference(), 97 } 98 99 res, err := methods.SuspendVApp_Task(ctx, p.c, &req) 100 if err != nil { 101 return nil, err 102 } 103 104 return NewTask(p.c, res.Returnval), nil 105 } 106 107 func (p VirtualApp) Clone(ctx context.Context, name string, target types.ManagedObjectReference, spec types.VAppCloneSpec) (*Task, error) { 108 req := types.CloneVApp_Task{ 109 This: p.Reference(), 110 Name: name, 111 Target: target, 112 Spec: spec, 113 } 114 115 res, err := methods.CloneVApp_Task(ctx, p.c, &req) 116 if err != nil { 117 return nil, err 118 } 119 120 return NewTask(p.c, res.Returnval), nil 121 }