/
hyperv.go
67 lines (52 loc) · 1.67 KB
/
hyperv.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//go:build hyperv || !onlyprovider
package hyperv
import (
"errors"
"github.com/nanovms/ops/lepton"
"github.com/nanovms/ops/types"
"github.com/nanovms/ops/wsl"
)
// ProviderName of the cloud platform provider
const ProviderName = "hyper-v"
// Provider to interact with Hyper-V cloud infrastructure
type Provider struct{}
// NewProvider Hyper-V
func NewProvider() *Provider {
return &Provider{}
}
// Initialize checks conditions to use hyper-v
func (p *Provider) Initialize(c *types.ProviderConfig) error {
if available, _, _ := IsPowershellAvailable(); !available {
return errors.New("powershell not available")
}
isAdmin, err := isCurrentUserAnAdministrator()
if err != nil {
return err
} else if !isAdmin {
return errors.New("this feature is only supported on terminals with elevated privileges")
}
if !wsl.IsWSL() {
return errors.New("Hyper-v is only supported on WSL")
}
return nil
}
// CreateVolume is a stub
func (p *Provider) CreateVolume(ctx *lepton.Context, name, data, provider string) (lepton.NanosVolume, error) {
return lepton.NanosVolume{}, errors.New("Unsupported")
}
// GetAllVolumes is a stub
func (p *Provider) GetAllVolumes(ctx *lepton.Context) (*[]lepton.NanosVolume, error) {
return nil, errors.New("Unsupported")
}
// DeleteVolume is a stub
func (p *Provider) DeleteVolume(ctx *lepton.Context, name string) error {
return errors.New("Unsupported")
}
// AttachVolume is a stub
func (p *Provider) AttachVolume(ctx *lepton.Context, image, name string, attachID int) error {
return errors.New("Unsupported")
}
// DetachVolume is a stub
func (p *Provider) DetachVolume(ctx *lepton.Context, image, name string) error {
return errors.New("Unsupported")
}