66 lines
1.5 KiB
Go
66 lines
1.5 KiB
Go
package esx
|
|
|
|
import (
|
|
"fmt"
|
|
"path"
|
|
)
|
|
|
|
var DefaultSlugs = map[string]Slug{
|
|
"ubuntu-lunar-1gb-1cpu": {
|
|
Image: "ubuntu-lunar",
|
|
CpuCount: 1,
|
|
MemoryMB: 1024,
|
|
DiskSizeGB: 16,
|
|
},
|
|
}
|
|
|
|
var DefaultHostProperties = HostProperties{
|
|
SlugSource: "/vmfs/volumes/datastore1/slugs",
|
|
DefaultDatastore: "datastore1",
|
|
DefaultNetwork: "LAN",
|
|
Slugs: DefaultSlugs,
|
|
}
|
|
|
|
type Slug struct {
|
|
Id string
|
|
Image string
|
|
Description string
|
|
CpuCount uint
|
|
MemoryMB uint
|
|
DiskSizeGB uint
|
|
Cost uint
|
|
}
|
|
|
|
type HostProperties struct {
|
|
Slugs map[string]Slug
|
|
SlugSource string
|
|
DefaultDatastore string
|
|
DefaultNetwork string
|
|
}
|
|
|
|
func (hp *HostProperties) GetSlug(name string) (*Slug, error) {
|
|
if slug, ok := hp.Slugs[name]; ok {
|
|
return &slug, nil
|
|
}
|
|
return nil, fmt.Errorf("not found")
|
|
}
|
|
|
|
func (hp *HostProperties) GetPathToSlug(slug Slug) string {
|
|
slugFilename := fmt.Sprintf("%s.cloudimg.amd64.vmdk", slug.Image)
|
|
return path.Join(hp.SlugSource, slugFilename)
|
|
}
|
|
|
|
func (hp *HostProperties) GetPathToVM(name string) string {
|
|
return path.Join("/vmfs/volumes/", hp.DefaultDatastore, name)
|
|
}
|
|
|
|
func (hp *HostProperties) GetPathToVMDisk(name string) string {
|
|
diskName := fmt.Sprintf("%s.vmdk", name)
|
|
return path.Join("/vmfs/volumes/", hp.DefaultDatastore, name, diskName)
|
|
}
|
|
|
|
func (hp *HostProperties) GetPathToVMConfig(name string) string {
|
|
configName := fmt.Sprintf("%s.vmx", name)
|
|
return path.Join("/vmfs/volumes/", hp.DefaultDatastore, name, configName)
|
|
}
|