github.phpd.cn/hashicorp/packer@v1.3.2/fix/fixer_parallels_deprecations.go (about) 1 package fix 2 3 import ( 4 "github.com/mitchellh/mapstructure" 5 ) 6 7 // FixerParallelsDeprecations removes "parallels_tools_host_path" from a 8 // template in a Parallels builder and changes "guest_os_distribution" to 9 // "guest_os_type", possibly overwriting any existing "guest_os_type" 10 type FixerParallelsDeprecations struct{} 11 12 func (FixerParallelsDeprecations) Fix(input map[string]interface{}) (map[string]interface{}, error) { 13 // The type we'll decode into; we only care about builders 14 type template struct { 15 Builders []map[string]interface{} 16 } 17 18 // Decode the input into our structure, if we can 19 var tpl template 20 if err := mapstructure.Decode(input, &tpl); err != nil { 21 return nil, err 22 } 23 24 for _, builder := range tpl.Builders { 25 builderTypeRaw, ok := builder["type"] 26 if !ok { 27 continue 28 } 29 30 builderType, ok := builderTypeRaw.(string) 31 if !ok { 32 continue 33 } 34 35 if builderType != "parallels-iso" && builderType != "parallels-pvm" { 36 continue 37 } 38 39 _, ok = builder["parallels_tools_host_path"] 40 if ok { 41 delete(builder, "parallels_tools_host_path") 42 } 43 44 guestOsDistribution, ok := builder["guest_os_distribution"] 45 46 if ok { 47 builder["guest_os_type"] = guestOsDistribution 48 delete(builder, "guest_os_distribution") 49 } 50 } 51 52 input["builders"] = tpl.Builders 53 return input, nil 54 } 55 56 func (FixerParallelsDeprecations) Synopsis() string { 57 return `Removes deprecated "parallels_tools_host_path" from Parallels builders 58 and changes "guest_os_distribution" to "guest_os_type".` 59 }