Advertisement
Guest User

Untitled

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