-
Notifications
You must be signed in to change notification settings - Fork 0
/
platform.go
87 lines (76 loc) · 2.17 KB
/
platform.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package installconfig
import (
"fmt"
"sort"
"github.com/pkg/errors"
survey "gopkg.in/AlecAivazis/survey.v1"
"github.com/openshift/installer/pkg/asset"
awsconfig "github.com/openshift/installer/pkg/asset/installconfig/aws"
libvirtconfig "github.com/openshift/installer/pkg/asset/installconfig/libvirt"
openstackconfig "github.com/openshift/installer/pkg/asset/installconfig/openstack"
"github.com/openshift/installer/pkg/types"
"github.com/openshift/installer/pkg/types/aws"
"github.com/openshift/installer/pkg/types/libvirt"
"github.com/openshift/installer/pkg/types/none"
"github.com/openshift/installer/pkg/types/openstack"
)
// Platform is an asset that queries the user for the platform on which to install
// the cluster.
type platform types.Platform
var _ asset.Asset = (*platform)(nil)
// Dependencies returns no dependencies.
func (a *platform) Dependencies() []asset.Asset {
return []asset.Asset{}
}
// Generate queries for input from the user.
func (a *platform) Generate(asset.Parents) error {
platform, err := a.queryUserForPlatform()
if err != nil {
return err
}
switch platform {
case aws.Name:
a.AWS, err = awsconfig.Platform()
if err != nil {
return err
}
case libvirt.Name:
a.Libvirt, err = libvirtconfig.Platform()
if err != nil {
return err
}
case none.Name:
a.None = &none.Platform{}
case openstack.Name:
a.OpenStack, err = openstackconfig.Platform()
if err != nil {
return err
}
default:
return fmt.Errorf("unknown platform type %q", platform)
}
return nil
}
// Name returns the human-friendly name of the asset.
func (a *platform) Name() string {
return "Platform"
}
func (a *platform) queryUserForPlatform() (platform string, err error) {
err = survey.Ask([]*survey.Question{
{
Prompt: &survey.Select{
Message: "Platform",
Options: types.PlatformNames,
},
Validate: survey.ComposeValidators(survey.Required, func(ans interface{}) error {
choice := ans.(string)
i := sort.SearchStrings(types.PlatformNames, choice)
if i == len(types.PlatformNames) || types.PlatformNames[i] != choice {
return errors.Errorf("invalid platform %q", choice)
}
return nil
}),
},
}, &platform)
return
}