github.com/amanya/packer@v0.12.1-0.20161117214323-902ac5ab2eb6/command/plugin.go (about)

     1  //
     2  // This file is automatically generated by scripts/generate-plugins.go -- Do not edit!
     3  //
     4  
     5  package command
     6  
     7  import (
     8  	"fmt"
     9  	"log"
    10  	"regexp"
    11  	"strings"
    12  
    13  	"github.com/mitchellh/packer/packer"
    14  	"github.com/mitchellh/packer/packer/plugin"
    15  
    16  	amazonchrootbuilder "github.com/mitchellh/packer/builder/amazon/chroot"
    17  	amazonebsbuilder "github.com/mitchellh/packer/builder/amazon/ebs"
    18  	amazonebsvolumebuilder "github.com/mitchellh/packer/builder/amazon/ebsvolume"
    19  	amazoninstancebuilder "github.com/mitchellh/packer/builder/amazon/instance"
    20  	azurearmbuilder "github.com/mitchellh/packer/builder/azure/arm"
    21  	cloudstackbuilder "github.com/mitchellh/packer/builder/cloudstack"
    22  	digitaloceanbuilder "github.com/mitchellh/packer/builder/digitalocean"
    23  	dockerbuilder "github.com/mitchellh/packer/builder/docker"
    24  	filebuilder "github.com/mitchellh/packer/builder/file"
    25  	googlecomputebuilder "github.com/mitchellh/packer/builder/googlecompute"
    26  	nullbuilder "github.com/mitchellh/packer/builder/null"
    27  	openstackbuilder "github.com/mitchellh/packer/builder/openstack"
    28  	parallelsisobuilder "github.com/mitchellh/packer/builder/parallels/iso"
    29  	parallelspvmbuilder "github.com/mitchellh/packer/builder/parallels/pvm"
    30  	profitbricksbuilder "github.com/mitchellh/packer/builder/profitbricks"
    31  	qemubuilder "github.com/mitchellh/packer/builder/qemu"
    32  	virtualboxisobuilder "github.com/mitchellh/packer/builder/virtualbox/iso"
    33  	virtualboxovfbuilder "github.com/mitchellh/packer/builder/virtualbox/ovf"
    34  	vmwareisobuilder "github.com/mitchellh/packer/builder/vmware/iso"
    35  	vmwarevmxbuilder "github.com/mitchellh/packer/builder/vmware/vmx"
    36  	amazonimportpostprocessor "github.com/mitchellh/packer/post-processor/amazon-import"
    37  	artificepostprocessor "github.com/mitchellh/packer/post-processor/artifice"
    38  	atlaspostprocessor "github.com/mitchellh/packer/post-processor/atlas"
    39  	checksumpostprocessor "github.com/mitchellh/packer/post-processor/checksum"
    40  	compresspostprocessor "github.com/mitchellh/packer/post-processor/compress"
    41  	dockerimportpostprocessor "github.com/mitchellh/packer/post-processor/docker-import"
    42  	dockerpushpostprocessor "github.com/mitchellh/packer/post-processor/docker-push"
    43  	dockersavepostprocessor "github.com/mitchellh/packer/post-processor/docker-save"
    44  	dockertagpostprocessor "github.com/mitchellh/packer/post-processor/docker-tag"
    45  	googlecomputeexportpostprocessor "github.com/mitchellh/packer/post-processor/googlecompute-export"
    46  	manifestpostprocessor "github.com/mitchellh/packer/post-processor/manifest"
    47  	shelllocalpostprocessor "github.com/mitchellh/packer/post-processor/shell-local"
    48  	vagrantpostprocessor "github.com/mitchellh/packer/post-processor/vagrant"
    49  	vagrantcloudpostprocessor "github.com/mitchellh/packer/post-processor/vagrant-cloud"
    50  	vspherepostprocessor "github.com/mitchellh/packer/post-processor/vsphere"
    51  	ansibleprovisioner "github.com/mitchellh/packer/provisioner/ansible"
    52  	ansiblelocalprovisioner "github.com/mitchellh/packer/provisioner/ansible-local"
    53  	chefclientprovisioner "github.com/mitchellh/packer/provisioner/chef-client"
    54  	chefsoloprovisioner "github.com/mitchellh/packer/provisioner/chef-solo"
    55  	fileprovisioner "github.com/mitchellh/packer/provisioner/file"
    56  	powershellprovisioner "github.com/mitchellh/packer/provisioner/powershell"
    57  	puppetmasterlessprovisioner "github.com/mitchellh/packer/provisioner/puppet-masterless"
    58  	puppetserverprovisioner "github.com/mitchellh/packer/provisioner/puppet-server"
    59  	saltmasterlessprovisioner "github.com/mitchellh/packer/provisioner/salt-masterless"
    60  	shellprovisioner "github.com/mitchellh/packer/provisioner/shell"
    61  	shelllocalprovisioner "github.com/mitchellh/packer/provisioner/shell-local"
    62  	windowsrestartprovisioner "github.com/mitchellh/packer/provisioner/windows-restart"
    63  	windowsshellprovisioner "github.com/mitchellh/packer/provisioner/windows-shell"
    64  )
    65  
    66  type PluginCommand struct {
    67  	Meta
    68  }
    69  
    70  var Builders = map[string]packer.Builder{
    71  	"amazon-chroot":    new(amazonchrootbuilder.Builder),
    72  	"amazon-ebs":       new(amazonebsbuilder.Builder),
    73  	"amazon-ebsvolume": new(amazonebsvolumebuilder.Builder),
    74  	"amazon-instance":  new(amazoninstancebuilder.Builder),
    75  	"azure-arm":        new(azurearmbuilder.Builder),
    76  	"cloudstack":       new(cloudstackbuilder.Builder),
    77  	"digitalocean":     new(digitaloceanbuilder.Builder),
    78  	"docker":           new(dockerbuilder.Builder),
    79  	"file":             new(filebuilder.Builder),
    80  	"googlecompute":    new(googlecomputebuilder.Builder),
    81  	"null":             new(nullbuilder.Builder),
    82  	"openstack":        new(openstackbuilder.Builder),
    83  	"parallels-iso":    new(parallelsisobuilder.Builder),
    84  	"parallels-pvm":    new(parallelspvmbuilder.Builder),
    85  	"profitbricks":     new(profitbricksbuilder.Builder),
    86  	"qemu":             new(qemubuilder.Builder),
    87  	"virtualbox-iso":   new(virtualboxisobuilder.Builder),
    88  	"virtualbox-ovf":   new(virtualboxovfbuilder.Builder),
    89  	"vmware-iso":       new(vmwareisobuilder.Builder),
    90  	"vmware-vmx":       new(vmwarevmxbuilder.Builder),
    91  }
    92  
    93  var Provisioners = map[string]packer.Provisioner{
    94  	"ansible":           new(ansibleprovisioner.Provisioner),
    95  	"ansible-local":     new(ansiblelocalprovisioner.Provisioner),
    96  	"chef-client":       new(chefclientprovisioner.Provisioner),
    97  	"chef-solo":         new(chefsoloprovisioner.Provisioner),
    98  	"file":              new(fileprovisioner.Provisioner),
    99  	"powershell":        new(powershellprovisioner.Provisioner),
   100  	"puppet-masterless": new(puppetmasterlessprovisioner.Provisioner),
   101  	"puppet-server":     new(puppetserverprovisioner.Provisioner),
   102  	"salt-masterless":   new(saltmasterlessprovisioner.Provisioner),
   103  	"shell":             new(shellprovisioner.Provisioner),
   104  	"shell-local":       new(shelllocalprovisioner.Provisioner),
   105  	"windows-restart":   new(windowsrestartprovisioner.Provisioner),
   106  	"windows-shell":     new(windowsshellprovisioner.Provisioner),
   107  }
   108  
   109  var PostProcessors = map[string]packer.PostProcessor{
   110  	"amazon-import":        new(amazonimportpostprocessor.PostProcessor),
   111  	"artifice":             new(artificepostprocessor.PostProcessor),
   112  	"atlas":                new(atlaspostprocessor.PostProcessor),
   113  	"checksum":             new(checksumpostprocessor.PostProcessor),
   114  	"compress":             new(compresspostprocessor.PostProcessor),
   115  	"docker-import":        new(dockerimportpostprocessor.PostProcessor),
   116  	"docker-push":          new(dockerpushpostprocessor.PostProcessor),
   117  	"docker-save":          new(dockersavepostprocessor.PostProcessor),
   118  	"docker-tag":           new(dockertagpostprocessor.PostProcessor),
   119  	"googlecompute-export": new(googlecomputeexportpostprocessor.PostProcessor),
   120  	"manifest":             new(manifestpostprocessor.PostProcessor),
   121  	"shell-local":          new(shelllocalpostprocessor.PostProcessor),
   122  	"vagrant":              new(vagrantpostprocessor.PostProcessor),
   123  	"vagrant-cloud":        new(vagrantcloudpostprocessor.PostProcessor),
   124  	"vsphere":              new(vspherepostprocessor.PostProcessor),
   125  }
   126  
   127  var pluginRegexp = regexp.MustCompile("packer-(builder|post-processor|provisioner)-(.+)")
   128  
   129  func (c *PluginCommand) Run(args []string) int {
   130  	// This is an internal call (users should not call this directly) so we're
   131  	// not going to do much input validation. If there's a problem we'll often
   132  	// just crash. Error handling should be added to facilitate debugging.
   133  	log.Printf("args: %#v", args)
   134  	if len(args) != 1 {
   135  		c.Ui.Error("Wrong number of args")
   136  		return 1
   137  	}
   138  
   139  	// Plugin will match something like "packer-builder-amazon-ebs"
   140  	parts := pluginRegexp.FindStringSubmatch(args[0])
   141  	if len(parts) != 3 {
   142  		c.Ui.Error(fmt.Sprintf("Error parsing plugin argument [DEBUG]: %#v", parts))
   143  		return 1
   144  	}
   145  	pluginType := parts[1] // capture group 1 (builder|post-processor|provisioner)
   146  	pluginName := parts[2] // capture group 2 (.+)
   147  
   148  	server, err := plugin.Server()
   149  	if err != nil {
   150  		c.Ui.Error(fmt.Sprintf("Error starting plugin server: %s", err))
   151  		return 1
   152  	}
   153  
   154  	switch pluginType {
   155  	case "builder":
   156  		builder, found := Builders[pluginName]
   157  		if !found {
   158  			c.Ui.Error(fmt.Sprintf("Could not load builder: %s", pluginName))
   159  			return 1
   160  		}
   161  		server.RegisterBuilder(builder)
   162  	case "provisioner":
   163  		provisioner, found := Provisioners[pluginName]
   164  		if !found {
   165  			c.Ui.Error(fmt.Sprintf("Could not load provisioner: %s", pluginName))
   166  			return 1
   167  		}
   168  		server.RegisterProvisioner(provisioner)
   169  	case "post-processor":
   170  		postProcessor, found := PostProcessors[pluginName]
   171  		if !found {
   172  			c.Ui.Error(fmt.Sprintf("Could not load post-processor: %s", pluginName))
   173  			return 1
   174  		}
   175  		server.RegisterPostProcessor(postProcessor)
   176  	}
   177  
   178  	server.Serve()
   179  
   180  	return 0
   181  }
   182  
   183  func (*PluginCommand) Help() string {
   184  	helpText := `
   185  Usage: packer plugin PLUGIN
   186  
   187    Runs an internally-compiled version of a plugin from the packer binary.
   188  
   189    NOTE: this is an internal command and you should not call it yourself.
   190  `
   191  
   192  	return strings.TrimSpace(helpText)
   193  }
   194  
   195  func (c *PluginCommand) Synopsis() string {
   196  	return "internal plugin command"
   197  }