Browse Source

Playing around with some new interfaces to creating vms.

Signed-off-by: Erik Hollensbe <github@hollensbe.org>
master
Erik Hollensbe 6 years ago
parent
commit
a71a320dbe
  1. 2
      context/provider.go
  2. 2
      providers/vmware/shared_folder.go
  3. 33
      providers/vmware/vm.go

2
context/provider.go

@ -6,6 +6,6 @@ import "github.com/erikh/vcontrol/types"
type Provider interface {
Init(*Context) error // Init initializes the provider.
Available(*Context) error // Available returns if the provider can be used on this host.
SetVMS([]types.VM) error // SetVMS sets the VMs being managed by this provider
NewVM(types.VM) error // NewVM creates a new VM and adds it to the VM list.
Name() string // Name is the name of this provider.
}

2
providers/vmware/shared_folder.go

@ -15,7 +15,7 @@ type SharedFolder struct {
Present bool
}
// NewSharedFolder constructs a shared folder for .
// NewSharedFolder constructs a shared folder for VWware.
func NewSharedFolder(hostPath, guestPath string, readable, writable, present bool) *SharedFolder {
return &SharedFolder{
hostPath: hostPath,

33
providers/vmware/vm.go

@ -1,6 +1,10 @@
package vmware
import "github.com/erikh/vcontrol/types"
import (
"fmt"
"github.com/erikh/vcontrol/types"
)
// VM represents a VM.
type VM struct {
@ -8,6 +12,29 @@ type VM struct {
name string
}
// NewVM creates a new VM and adds it to the VM list.
func (vp *Provider) NewVM(vm types.VM) error {
if _, ok := vm.(*VM); !ok {
return fmt.Errorf("Invalid VM for VMWare provider")
}
vp.vms = append(vp.vms, vm)
return nil
}
// NewVMFromVMX adds a VM from a pre-defined VMX file.
func (vp *Provider) NewVMFromVMX(filename string) error {
vmx, err := vp.NewVMXFromFile(filename)
if err != nil {
return fmt.Errorf("Reading VMX file: %v", err)
}
vp.vms = append(vp.vms, &VM{config: vmx})
return nil
}
// Up starts the VMs, if any are required. It returns an error if it does not
// succeed.
func (vm *VM) Up() error { return nil }
@ -18,7 +45,9 @@ func (vm *VM) Down() error { return nil }
// Configure configures the VMs every time it is called. It returns an error if
// it does not succeed.
func (vm *VM) Configure() error { return nil }
func (vm *VM) Configure() error {
return nil
}
// Config returns the VMConfig for this VM.
func (vm *VM) Config() types.VMConfig {

Loading…
Cancel
Save