2013-05-04 02:55:08 -04:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
"net/rpc"
|
|
|
|
)
|
|
|
|
|
2013-05-22 01:10:21 -04:00
|
|
|
// Registers the appropriate endpoint on an RPC server to serve an
|
|
|
|
// Artifact.
|
|
|
|
func RegisterArtifact(s *rpc.Server, a packer.Artifact) {
|
|
|
|
s.RegisterName("Artifact", &ArtifactServer{a})
|
|
|
|
}
|
|
|
|
|
2013-05-05 20:38:50 -04:00
|
|
|
// Registers the appropriate endpoint on an RPC server to serve a
|
|
|
|
// Packer Build.
|
|
|
|
func RegisterBuild(s *rpc.Server, b packer.Build) {
|
|
|
|
s.RegisterName("Build", &BuildServer{b})
|
2013-05-04 02:55:08 -04:00
|
|
|
}
|
|
|
|
|
2013-05-05 20:38:50 -04:00
|
|
|
// Registers the appropriate endpoint on an RPC server to serve a
|
|
|
|
// Packer Builder.
|
|
|
|
func RegisterBuilder(s *rpc.Server, b packer.Builder) {
|
|
|
|
s.RegisterName("Builder", &BuilderServer{b})
|
2013-05-04 16:47:11 -04:00
|
|
|
}
|
|
|
|
|
2013-05-05 20:38:50 -04:00
|
|
|
// Registers the appropriate endpoint on an RPC server to serve a
|
|
|
|
// Packer Command.
|
|
|
|
func RegisterCommand(s *rpc.Server, c packer.Command) {
|
2013-05-08 16:42:25 -04:00
|
|
|
s.RegisterName("Command", &CommandServer{c})
|
2013-05-04 18:33:36 -04:00
|
|
|
}
|
|
|
|
|
2013-05-12 17:47:55 -04:00
|
|
|
// Registers the appropriate endpoint on an RPC server to serve a
|
|
|
|
// Packer Communicator.
|
|
|
|
func RegisterCommunicator(s *rpc.Server, c packer.Communicator) {
|
|
|
|
s.RegisterName("Communicator", &CommunicatorServer{c})
|
|
|
|
}
|
|
|
|
|
2013-05-05 20:38:50 -04:00
|
|
|
// Registers the appropriate endpoint on an RPC server to serve a
|
|
|
|
// Packer Environment
|
|
|
|
func RegisterEnvironment(s *rpc.Server, e packer.Environment) {
|
|
|
|
s.RegisterName("Environment", &EnvironmentServer{e})
|
2013-05-04 18:33:36 -04:00
|
|
|
}
|
|
|
|
|
2013-05-11 12:51:49 -04:00
|
|
|
// Registers the appropriate endpoint on an RPC server to serve a
|
|
|
|
// Hook.
|
|
|
|
func RegisterHook(s *rpc.Server, hook packer.Hook) {
|
|
|
|
s.RegisterName("Hook", &HookServer{hook})
|
|
|
|
}
|
|
|
|
|
2013-05-22 18:35:52 -04:00
|
|
|
// Registers the appropriate endpoint on an RPC server to serve a packer.Provisioner
|
|
|
|
func RegisterProvisioner(s *rpc.Server, p packer.Provisioner) {
|
|
|
|
s.RegisterName("Provisioner", &ProvisionerServer{p})
|
|
|
|
}
|
|
|
|
|
2013-05-05 20:38:50 -04:00
|
|
|
// Registers the appropriate endpoint on an RPC server to serve a
|
|
|
|
// Packer UI
|
|
|
|
func RegisterUi(s *rpc.Server, ui packer.Ui) {
|
|
|
|
s.RegisterName("Ui", &UiServer{ui})
|
2013-05-04 18:33:36 -04:00
|
|
|
}
|
|
|
|
|
2013-05-05 20:38:50 -04:00
|
|
|
func serveSingleConn(s *rpc.Server) string {
|
|
|
|
l := netListenerInRange(portRangeMin, portRangeMax)
|
2013-05-04 02:55:08 -04:00
|
|
|
|
2013-05-05 20:38:50 -04:00
|
|
|
// Accept a single connection in a goroutine and then exit
|
|
|
|
go func() {
|
|
|
|
defer l.Close()
|
|
|
|
conn, err := l.Accept()
|
|
|
|
if err != nil {
|
|
|
|
return
|
2013-05-04 02:55:08 -04:00
|
|
|
}
|
|
|
|
|
2013-05-05 20:38:50 -04:00
|
|
|
s.ServeConn(conn)
|
|
|
|
}()
|
|
|
|
|
|
|
|
return l.Addr().String()
|
2013-05-04 02:55:08 -04:00
|
|
|
}
|