github.com/kaixiang/packer@v0.5.2-0.20140114230416-1f5786b0d7f1/command/fix/fixer_virtualbox_gaattach.go (about)

     1  package fix
     2  
     3  import (
     4  	"github.com/mitchellh/mapstructure"
     5  )
     6  
     7  // FixerVirtualBoxGAAttach changes the "guest_additions_attach" of a template
     8  // to "guest_additions_mode".
     9  type FixerVirtualBoxGAAttach struct{}
    10  
    11  func (FixerVirtualBoxGAAttach) Fix(input map[string]interface{}) (map[string]interface{}, error) {
    12  	// The type we'll decode into; we only care about builders
    13  	type template struct {
    14  		Builders []map[string]interface{}
    15  	}
    16  
    17  	// Decode the input into our structure, if we can
    18  	var tpl template
    19  	if err := mapstructure.Decode(input, &tpl); err != nil {
    20  		return nil, err
    21  	}
    22  
    23  	for _, builder := range tpl.Builders {
    24  		builderTypeRaw, ok := builder["type"]
    25  		if !ok {
    26  			continue
    27  		}
    28  
    29  		builderType, ok := builderTypeRaw.(string)
    30  		if !ok {
    31  			continue
    32  		}
    33  
    34  		if builderType != "virtualbox" {
    35  			continue
    36  		}
    37  
    38  		gaAttachRaw, ok := builder["guest_additions_attach"]
    39  		if !ok {
    40  			continue
    41  		}
    42  
    43  		gaAttach, ok := gaAttachRaw.(bool)
    44  		if !ok {
    45  			continue
    46  		}
    47  
    48  		gaMode := "upload"
    49  		if gaAttach {
    50  			gaMode = "attach"
    51  		}
    52  
    53  		delete(builder, "guest_additions_attach")
    54  		builder["guest_additions_mode"] = gaMode
    55  	}
    56  
    57  	input["builders"] = tpl.Builders
    58  	return input, nil
    59  }
    60  
    61  func (FixerVirtualBoxGAAttach) Synopsis() string {
    62  	return `Updates VirtualBox builders using "guest_additions_attach" to use "guest_additions_mode"`
    63  }