You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

48 lines
1.2 KiB

// Package vcontrol is used to control vmware and virtualbox VMs.
package vcontrol
import (
"fmt"
"github.com/erikh/vcontrol/context"
"github.com/erikh/vcontrol/providers/vmware"
)
var potentialProviders = []context.Provider{
&vmware.Provider{},
}
// Init returns an initialized Context for using the library functions to
// control vmware and virtualbox.
func Init(environment []string) (*context.Context, error) {
ctx := &context.Context{Providers: []context.Provider{}, Environment: environment}
for _, prov := range potentialProviders {
if err := prov.Available(ctx); err != nil {
continue
}
if err := prov.Init(ctx); err != nil {
return nil, fmt.Errorf("Could not init available provider: %v", err)
}
ctx.Providers = append(ctx.Providers, prov)
}
return ctx, nil
}
// InitWithProviders is the same as Init() but with a pre-supplied list of providers.
func InitWithProviders(providers []context.Provider, environment []string) (*context.Context, error) {
ctx := &context.Context{Providers: providers, Environment: environment}
for _, provider := range providers {
if err := provider.Available(ctx); err != nil {
return nil, err
}
if err := provider.Init(ctx); err != nil {
return nil, err
}
}
return ctx, nil
}