github.com/openshift/installer@v1.4.17/pkg/asset/installconfig/baremetal/host.go (about) 1 package baremetal 2 3 import ( 4 "github.com/AlecAivazis/survey/v2" 5 6 "github.com/openshift/installer/pkg/types/baremetal" 7 "github.com/openshift/installer/pkg/validate" 8 ) 9 10 // Host prompts the user for hardware details about a baremetal host. 11 func Host() (*baremetal.Host, error) { 12 var host baremetal.Host 13 14 if err := survey.Ask([]*survey.Question{ 15 { 16 Prompt: &survey.Input{ 17 Message: "Name", 18 }, 19 Validate: survey.ComposeValidators(survey.Required), 20 }, 21 }, &host.Name); err != nil { 22 return nil, err 23 } 24 25 if err := survey.Ask([]*survey.Question{ 26 { 27 Prompt: &survey.Input{ 28 Message: "BMC Address", 29 Help: "The address for the BMC, e.g. ipmi://192.168.0.1", 30 }, 31 Validate: survey.ComposeValidators(survey.Required, uriValidator), 32 }, 33 }, &host.BMC.Address); err != nil { 34 return nil, err 35 } 36 37 if err := survey.Ask([]*survey.Question{ 38 { 39 Prompt: &survey.Input{ 40 Message: "BMC Username", 41 }, 42 Validate: survey.ComposeValidators(survey.Required), 43 }, 44 }, &host.BMC.Username); err != nil { 45 return nil, err 46 } 47 48 if err := survey.Ask([]*survey.Question{ 49 { 50 Prompt: &survey.Password{ 51 Message: "BMC Password", 52 }, 53 Validate: survey.ComposeValidators(survey.Required), 54 }, 55 }, &host.BMC.Password); err != nil { 56 return nil, err 57 } 58 59 if err := survey.Ask([]*survey.Question{ 60 { 61 Prompt: &survey.Input{ 62 Message: "Boot MAC Address", 63 }, 64 Validate: survey.ComposeValidators(survey.Required, macValidator), 65 }, 66 }, &host.BootMACAddress); err != nil { 67 return nil, err 68 } 69 70 return &host, nil 71 } 72 73 // uriValidator validates if the answer provided in prompt is a valid 74 // url and has non-empty scheme. 75 func uriValidator(ans interface{}) error { 76 return validate.URI(ans.(string)) 77 } 78 79 // macValidator validates if the answer provided is a valid mac address 80 func macValidator(ans interface{}) error { 81 return validate.MAC(ans.(string)) 82 }