mirror of https://github.com/hashicorp/packer
Extract vSphere driver into separate package (#35)
parent
ae3a1d6f24
commit
efe2c3c8b3
@ -0,0 +1,26 @@
|
||||
package driver
|
||||
|
||||
import (
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
func (d *Driver) NewHost(ref *types.ManagedObjectReference) *object.HostSystem {
|
||||
return object.NewHostSystem(d.client.Client, *ref)
|
||||
}
|
||||
|
||||
func (d *Driver) HostInfo(host *object.HostSystem, params ...string) (*mo.HostSystem, error){
|
||||
var p []string
|
||||
if len(params) == 0 {
|
||||
p = []string{"*"}
|
||||
} else {
|
||||
p = params
|
||||
}
|
||||
var hostInfo mo.HostSystem
|
||||
err := host.Properties(d.ctx, host.Reference(), p, &hostInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &hostInfo, nil
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package driver
|
||||
|
||||
import (
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
func (d *Driver) NewResourcePool(ref *types.ManagedObjectReference) *object.ResourcePool {
|
||||
return object.NewResourcePool(d.client.Client, *ref)
|
||||
}
|
||||
|
||||
func (d *Driver) ResourcePoolInfo(host *object.ResourcePool, params ...string) (*mo.ResourcePool, error){
|
||||
var p []string
|
||||
if len(params) == 0 {
|
||||
p = []string{"*"}
|
||||
} else {
|
||||
p = params
|
||||
}
|
||||
var poolInfo mo.ResourcePool
|
||||
err := host.Properties(d.ctx, host.Reference(), p, &poolInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &poolInfo, nil
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package driver
|
||||
|
||||
import (
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
)
|
||||
|
||||
func (d *Driver) FindVM(name string) (*object.VirtualMachine, error) {
|
||||
return d.finder.VirtualMachine(d.ctx, name)
|
||||
}
|
||||
|
||||
func (d *Driver) VMInfo(vm *object.VirtualMachine, params ...string) (*mo.VirtualMachine, error){
|
||||
var p []string
|
||||
if len(params) == 0 {
|
||||
p = []string{"*"}
|
||||
} else {
|
||||
p = params
|
||||
}
|
||||
var vmInfo mo.VirtualMachine
|
||||
err := vm.Properties(d.ctx, vm.Reference(), p, &vmInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &vmInfo, nil
|
||||
}
|
||||
Loading…
Reference in new issue