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