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