2013-11-02 04:43:57 -04:00
|
|
|
package fix
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/mitchellh/mapstructure"
|
|
|
|
)
|
|
|
|
|
|
|
|
// FixerVirtualBoxGAAttach changes the "guest_additions_attach" of a template
|
|
|
|
// to "guest_additions_mode".
|
|
|
|
type FixerVirtualBoxGAAttach struct{}
|
|
|
|
|
2020-10-09 20:01:55 -04:00
|
|
|
func (FixerVirtualBoxGAAttach) DeprecatedOptions() map[string][]string {
|
|
|
|
return map[string][]string{
|
|
|
|
"mitchellh.virtualbox": []string{"guest_additions_attach"},
|
|
|
|
}
|
2020-05-28 17:37:29 -04:00
|
|
|
}
|
|
|
|
|
2013-11-02 04:43:57 -04:00
|
|
|
func (FixerVirtualBoxGAAttach) 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 != "virtualbox" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
gaAttachRaw, ok := builder["guest_additions_attach"]
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
gaAttach, ok := gaAttachRaw.(bool)
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
gaMode := "upload"
|
|
|
|
if gaAttach {
|
|
|
|
gaMode = "attach"
|
|
|
|
}
|
|
|
|
|
|
|
|
delete(builder, "guest_additions_attach")
|
|
|
|
builder["guest_additions_mode"] = gaMode
|
|
|
|
}
|
|
|
|
|
|
|
|
input["builders"] = tpl.Builders
|
|
|
|
return input, nil
|
|
|
|
}
|
2013-11-02 04:49:00 -04:00
|
|
|
|
|
|
|
func (FixerVirtualBoxGAAttach) Synopsis() string {
|
|
|
|
return `Updates VirtualBox builders using "guest_additions_attach" to use "guest_additions_mode"`
|
|
|
|
}
|