-
Notifications
You must be signed in to change notification settings - Fork 197
/
base.go
57 lines (49 loc) · 1.52 KB
/
base.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
package vsphere
import (
"fmt"
"github.com/openshift/assisted-service/internal/common"
"github.com/openshift/assisted-service/internal/provider"
"github.com/openshift/assisted-service/models"
"github.com/sirupsen/logrus"
)
type vsphereProvider struct {
Log logrus.FieldLogger
}
// NewVsphereProvider creates a new vSphere provider.
func NewVsphereProvider(log logrus.FieldLogger) provider.Provider {
return &vsphereProvider{
Log: log,
}
}
// Name returns the name of the provider
func (p *vsphereProvider) Name() models.PlatformType {
return models.PlatformTypeVsphere
}
func (p *vsphereProvider) IsHostSupported(host *models.Host) (bool, error) {
// during the discovery there is a short time that host didn't return its inventory to the service
if host.Inventory == "" {
return false, nil
}
hostInventory, err := common.UnmarshalInventory(host.Inventory)
if err != nil {
return false, fmt.Errorf("error marshaling host to inventory, error %w", err)
}
return hostInventory.SystemVendor.Manufacturer == VmwareManufacturer, nil
}
func (p *vsphereProvider) AreHostsSupported(hosts []*models.Host) (bool, error) {
for _, h := range hosts {
supported, err := p.IsHostSupported(h)
if err != nil {
return false, fmt.Errorf("error while checking if host is supported, error is: %w", err)
}
if !supported {
return false, nil
}
}
return true, nil
}
func (p *vsphereProvider) IsProviderForPlatform(platform *models.Platform) bool {
return platform != nil &&
platform.Type != nil &&
*platform.Type == p.Name()
}