~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/govmomi/object/resource_pool.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (c) 2014 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
        "github.com/juju/govmomi/vim25"
 
21
        "github.com/juju/govmomi/vim25/methods"
 
22
        "github.com/juju/govmomi/vim25/types"
 
23
        "golang.org/x/net/context"
 
24
)
 
25
 
 
26
type ResourcePool struct {
 
27
        Common
 
28
 
 
29
        InventoryPath string
 
30
}
 
31
 
 
32
func NewResourcePool(c *vim25.Client, ref types.ManagedObjectReference) *ResourcePool {
 
33
        return &ResourcePool{
 
34
                Common: NewCommon(c, ref),
 
35
        }
 
36
}
 
37
 
 
38
func (p ResourcePool) ImportVApp(ctx context.Context, spec types.BaseImportSpec, folder *Folder, host *HostSystem) (*HttpNfcLease, error) {
 
39
        req := types.ImportVApp{
 
40
                This: p.Reference(),
 
41
                Spec: spec,
 
42
        }
 
43
 
 
44
        if folder != nil {
 
45
                ref := folder.Reference()
 
46
                req.Folder = &ref
 
47
        }
 
48
 
 
49
        if host != nil {
 
50
                ref := host.Reference()
 
51
                req.Host = &ref
 
52
        }
 
53
 
 
54
        res, err := methods.ImportVApp(ctx, p.c, &req)
 
55
        if err != nil {
 
56
                return nil, err
 
57
        }
 
58
 
 
59
        return NewHttpNfcLease(p.c, res.Returnval), nil
 
60
}
 
61
 
 
62
func (p ResourcePool) Create(ctx context.Context, name string, spec types.ResourceConfigSpec) (*ResourcePool, error) {
 
63
        req := types.CreateResourcePool{
 
64
                This: p.Reference(),
 
65
                Name: name,
 
66
                Spec: spec,
 
67
        }
 
68
 
 
69
        res, err := methods.CreateResourcePool(ctx, p.c, &req)
 
70
        if err != nil {
 
71
                return nil, err
 
72
        }
 
73
 
 
74
        return NewResourcePool(p.c, res.Returnval), nil
 
75
}
 
76
 
 
77
func (p ResourcePool) UpdateConfig(ctx context.Context, name string, config *types.ResourceConfigSpec) error {
 
78
        req := types.UpdateConfig{
 
79
                This:   p.Reference(),
 
80
                Name:   name,
 
81
                Config: config,
 
82
        }
 
83
 
 
84
        if config != nil && config.Entity == nil {
 
85
                ref := p.Reference()
 
86
 
 
87
                // Create copy of config so changes won't leak back to the caller
 
88
                newConfig := *config
 
89
                newConfig.Entity = &ref
 
90
                req.Config = &newConfig
 
91
        }
 
92
 
 
93
        _, err := methods.UpdateConfig(ctx, p.c, &req)
 
94
        return err
 
95
}
 
96
 
 
97
func (p ResourcePool) DestroyChildren(ctx context.Context) error {
 
98
        req := types.DestroyChildren{
 
99
                This: p.Reference(),
 
100
        }
 
101
 
 
102
        _, err := methods.DestroyChildren(ctx, p.c, &req)
 
103
        return err
 
104
}
 
105
 
 
106
func (p ResourcePool) Destroy(ctx context.Context) (*Task, error) {
 
107
        req := types.Destroy_Task{
 
108
                This: p.Reference(),
 
109
        }
 
110
 
 
111
        res, err := methods.Destroy_Task(ctx, p.c, &req)
 
112
        if err != nil {
 
113
                return nil, err
 
114
        }
 
115
 
 
116
        return NewTask(p.c, res.Returnval), nil
 
117
}