2015-09-18 03:27:50 -04:00
|
|
|
package fix
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/mitchellh/mapstructure"
|
|
|
|
)
|
|
|
|
|
|
|
|
// FixerParallelsDeprecations removes "parallels_tools_host_path" from a
|
|
|
|
// template in a Parallels builder and changes "guest_os_distribution" to
|
|
|
|
// "guest_os_type", possibly overwriting any existing "guest_os_type"
|
|
|
|
type FixerParallelsDeprecations struct{}
|
|
|
|
|
2020-10-09 20:01:55 -04:00
|
|
|
func (FixerParallelsDeprecations) DeprecatedOptions() map[string][]string {
|
|
|
|
return map[string][]string{
|
|
|
|
"packer.parallels": []string{"parallels_tools_host_path", "guest_os_distribution"},
|
|
|
|
}
|
2020-05-28 17:37:29 -04:00
|
|
|
}
|
|
|
|
|
2015-09-18 03:27:50 -04:00
|
|
|
func (FixerParallelsDeprecations) Fix(input map[string]interface{}) (map[string]interface{}, error) {
|
|
|
|
// The type we'll decode into; we only care about builders
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, builder := range tpl.Builders {
|
|
|
|
builderTypeRaw, ok := builder["type"]
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
builderType, ok := builderTypeRaw.(string)
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if builderType != "parallels-iso" && builderType != "parallels-pvm" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
_, ok = builder["parallels_tools_host_path"]
|
|
|
|
if ok {
|
|
|
|
delete(builder, "parallels_tools_host_path")
|
|
|
|
}
|
|
|
|
|
|
|
|
guestOsDistribution, ok := builder["guest_os_distribution"]
|
|
|
|
|
|
|
|
if ok {
|
|
|
|
builder["guest_os_type"] = guestOsDistribution
|
|
|
|
delete(builder, "guest_os_distribution")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
input["builders"] = tpl.Builders
|
|
|
|
return input, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (FixerParallelsDeprecations) Synopsis() string {
|
2019-07-24 12:18:07 -04:00
|
|
|
return `Removes deprecated "parallels_tools_host_path" from Parallels builders and changes "guest_os_distribution" to "guest_os_type".`
|
2015-09-18 03:27:50 -04:00
|
|
|
}
|