github.com/openshift/installer@v1.4.17/pkg/tfvars/baremetal/baremetal.go (about) 1 // Package baremetal contains bare metal specific Terraform-variable logic. 2 package baremetal 3 4 import ( 5 "encoding/json" 6 7 "github.com/pkg/errors" 8 9 "github.com/openshift/installer/pkg/rhcos/cache" 10 ) 11 12 // Config represents the baremetal platform parts of install config needed for bootstrapping. 13 type Config struct { 14 LibvirtURI string `json:"libvirt_uri,omitempty"` 15 BootstrapOSImage string `json:"bootstrap_os_image,omitempty"` 16 Bridges []map[string]string `json:"bridges"` 17 } 18 19 type imageDownloadFunc func(baseURL, applicationName string) (string, error) 20 21 var ( 22 imageDownloader imageDownloadFunc 23 ) 24 25 func init() { 26 imageDownloader = cache.DownloadImageFile 27 } 28 29 // TFVars generates bare metal specific Terraform variables. 30 func TFVars(libvirtURI string, bootstrapOSImage, externalBridge, externalMAC, provisioningBridge, provisioningMAC string) ([]byte, error) { 31 bootstrapOSImage, err := imageDownloader(bootstrapOSImage, cache.InstallerApplicationName) 32 if err != nil { 33 return nil, errors.Wrap(err, "failed to use cached bootstrap libvirt image") 34 } 35 36 var bridges []map[string]string 37 38 bridges = append(bridges, 39 map[string]string{ 40 "name": externalBridge, 41 "mac": externalMAC, 42 }) 43 44 if provisioningBridge != "" { 45 bridges = append( 46 bridges, 47 map[string]string{ 48 "name": provisioningBridge, 49 "mac": provisioningMAC, 50 }) 51 } 52 53 cfg := &Config{ 54 LibvirtURI: libvirtURI, 55 BootstrapOSImage: bootstrapOSImage, 56 Bridges: bridges, 57 } 58 59 return json.MarshalIndent(cfg, "", " ") 60 }