packer-cn/packer/rpc/server.go

89 lines
2.6 KiB
Go
Raw Normal View History

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) {
registerComponent(s, "Artifact", &ArtifactServer{a}, false)
2013-05-22 01:10:21 -04:00
}
// Registers the appropriate endpoint on an RPC server to serve a
// Packer Build.
func RegisterBuild(s *rpc.Server, b packer.Build) {
registerComponent(s, "Build", &BuildServer{b}, false)
}
// Registers the appropriate endpoint on an RPC server to serve a
// Packer Builder.
func RegisterBuilder(s *rpc.Server, b packer.Builder) {
2013-12-10 15:14:08 -05:00
registerComponent(s, "Builder", &BuilderServer{builder: b}, false)
2013-05-04 16:47:11 -04:00
}
2013-06-09 22:25:48 -04:00
// Registers the appropriate endpoint on an RPC server to serve a
// Packer Cache.
func RegisterCache(s *rpc.Server, c packer.Cache) {
registerComponent(s, "Cache", &CacheServer{c}, false)
2013-06-09 22:25:48 -04:00
}
// Registers the appropriate endpoint on an RPC server to serve a
// Packer Command.
func RegisterCommand(s *rpc.Server, c packer.Command) {
2013-12-10 15:02:01 -05:00
registerComponent(s, "Command", &CommandServer{command: c}, false)
}
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) {
2013-12-10 14:43:02 -05:00
registerComponent(s, "Communicator", &CommunicatorServer{c: c}, false)
2013-05-12 17:47:55 -04:00
}
// Registers the appropriate endpoint on an RPC server to serve a
// Packer Environment
func RegisterEnvironment(s *rpc.Server, e packer.Environment) {
registerComponent(s, "Environment", &EnvironmentServer{e}, false)
}
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, h packer.Hook) {
2013-12-10 14:50:30 -05:00
registerComponent(s, "Hook", &HookServer{hook: h}, false)
2013-05-11 12:51:49 -04:00
}
2013-06-18 16:44:57 -04:00
// Registers the appropriate endpoing on an RPC server to serve a
// PostProcessor.
func RegisterPostProcessor(s *rpc.Server, p packer.PostProcessor) {
registerComponent(s, "PostProcessor", &PostProcessorServer{p: p}, false)
2013-06-18 16:44:57 -04:00
}
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) {
2013-12-10 14:56:15 -05:00
registerComponent(s, "Provisioner", &ProvisionerServer{p: p}, false)
2013-05-22 18:35:52 -04:00
}
// Registers the appropriate endpoint on an RPC server to serve a
// Packer UI
func RegisterUi(s *rpc.Server, ui packer.Ui) {
registerComponent(s, "Ui", &UiServer{ui}, false)
}
func serveSingleConn(s *rpc.Server) string {
l := netListenerInRange(portRangeMin, portRangeMax)
// Accept a single connection in a goroutine and then exit
go func() {
defer l.Close()
conn, err := l.Accept()
if err != nil {
2013-06-03 18:30:09 -04:00
panic(err)
}
s.ServeConn(conn)
}()
return l.Addr().String()
}