1/*
2Copyright (c) 2015 VMware, Inc. All Rights Reserved.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package object
18
19import (
20	"context"
21
22	"github.com/vmware/govmomi/vim25"
23	"github.com/vmware/govmomi/vim25/methods"
24	"github.com/vmware/govmomi/vim25/mo"
25	"github.com/vmware/govmomi/vim25/types"
26)
27
28type ClusterComputeResource struct {
29	ComputeResource
30}
31
32func NewClusterComputeResource(c *vim25.Client, ref types.ManagedObjectReference) *ClusterComputeResource {
33	return &ClusterComputeResource{
34		ComputeResource: *NewComputeResource(c, ref),
35	}
36}
37
38func (c ClusterComputeResource) Configuration(ctx context.Context) (*types.ClusterConfigInfoEx, error) {
39	var obj mo.ClusterComputeResource
40
41	err := c.Properties(ctx, c.Reference(), []string{"configurationEx"}, &obj)
42	if err != nil {
43		return nil, err
44	}
45
46	return obj.ConfigurationEx.(*types.ClusterConfigInfoEx), nil
47}
48
49func (c ClusterComputeResource) AddHost(ctx context.Context, spec types.HostConnectSpec, asConnected bool, license *string, resourcePool *types.ManagedObjectReference) (*Task, error) {
50	req := types.AddHost_Task{
51		This:        c.Reference(),
52		Spec:        spec,
53		AsConnected: asConnected,
54	}
55
56	if license != nil {
57		req.License = *license
58	}
59
60	if resourcePool != nil {
61		req.ResourcePool = resourcePool
62	}
63
64	res, err := methods.AddHost_Task(ctx, c.c, &req)
65	if err != nil {
66		return nil, err
67	}
68
69	return NewTask(c.c, res.Returnval), nil
70}
71