packer-cn/fix/fixer_enhanced_networking.go

46 lines
1.2 KiB
Go

package fix
import (
"github.com/mitchellh/mapstructure"
)
// FixerEnhancedNetworking is a Fixer that replaces the "enhanced_networking" configuration key
// with the clearer "ena_support". This disambiguates ena_support from sriov_support.
type FixerEnhancedNetworking struct{}
func (FixerEnhancedNetworking) Fix(input map[string]interface{}) (map[string]interface{}, error) {
// Our template type we'll use for this fixer only
type template struct {
Builders []map[string]interface{}
}
// Decode the input into our structure, if we can
var tpl template
if err := mapstructure.Decode(input, &tpl); err != nil {
return nil, err
}
// Go through each builder and replace the enhanced_networking if we can
for _, builder := range tpl.Builders {
enhancedNetworkingRaw, ok := builder["enhanced_networking"]
if !ok {
continue
}
enhancedNetworkingString, ok := enhancedNetworkingRaw.(bool)
if !ok {
// TODO: error?
continue
}
delete(builder, "enhanced_networking")
builder["ena_support"] = enhancedNetworkingString
}
input["builders"] = tpl.Builders
return input, nil
}
func (FixerEnhancedNetworking) Synopsis() string {
return `Replaces "enhanced_networking" in builders with "ena_support"`
}