github.com/jerryclinesmith/packer@v0.3.7/packer/rpc/server.go (about)

     1  package rpc
     2  
     3  import (
     4  	"github.com/mitchellh/packer/packer"
     5  	"net/rpc"
     6  )
     7  
     8  // Registers the appropriate endpoint on an RPC server to serve an
     9  // Artifact.
    10  func RegisterArtifact(s *rpc.Server, a packer.Artifact) {
    11  	s.RegisterName("Artifact", &ArtifactServer{a})
    12  }
    13  
    14  // Registers the appropriate endpoint on an RPC server to serve a
    15  // Packer Build.
    16  func RegisterBuild(s *rpc.Server, b packer.Build) {
    17  	s.RegisterName("Build", &BuildServer{b})
    18  }
    19  
    20  // Registers the appropriate endpoint on an RPC server to serve a
    21  // Packer Builder.
    22  func RegisterBuilder(s *rpc.Server, b packer.Builder) {
    23  	s.RegisterName("Builder", &BuilderServer{b})
    24  }
    25  
    26  // Registers the appropriate endpoint on an RPC server to serve a
    27  // Packer Cache.
    28  func RegisterCache(s *rpc.Server, c packer.Cache) {
    29  	s.RegisterName("Cache", &CacheServer{c})
    30  }
    31  
    32  // Registers the appropriate endpoint on an RPC server to serve a
    33  // Packer Command.
    34  func RegisterCommand(s *rpc.Server, c packer.Command) {
    35  	s.RegisterName("Command", &CommandServer{c})
    36  }
    37  
    38  // Registers the appropriate endpoint on an RPC server to serve a
    39  // Packer Communicator.
    40  func RegisterCommunicator(s *rpc.Server, c packer.Communicator) {
    41  	s.RegisterName("Communicator", &CommunicatorServer{c})
    42  }
    43  
    44  // Registers the appropriate endpoint on an RPC server to serve a
    45  // Packer Environment
    46  func RegisterEnvironment(s *rpc.Server, e packer.Environment) {
    47  	s.RegisterName("Environment", &EnvironmentServer{e})
    48  }
    49  
    50  // Registers the appropriate endpoint on an RPC server to serve a
    51  // Hook.
    52  func RegisterHook(s *rpc.Server, hook packer.Hook) {
    53  	s.RegisterName("Hook", &HookServer{hook})
    54  }
    55  
    56  // Registers the appropriate endpoing on an RPC server to serve a
    57  // PostProcessor.
    58  func RegisterPostProcessor(s *rpc.Server, p packer.PostProcessor) {
    59  	s.RegisterName("PostProcessor", &PostProcessorServer{p})
    60  }
    61  
    62  // Registers the appropriate endpoint on an RPC server to serve a packer.Provisioner
    63  func RegisterProvisioner(s *rpc.Server, p packer.Provisioner) {
    64  	s.RegisterName("Provisioner", &ProvisionerServer{p})
    65  }
    66  
    67  // Registers the appropriate endpoint on an RPC server to serve a
    68  // Packer UI
    69  func RegisterUi(s *rpc.Server, ui packer.Ui) {
    70  	s.RegisterName("Ui", &UiServer{ui})
    71  }
    72  
    73  func serveSingleConn(s *rpc.Server) string {
    74  	l := netListenerInRange(portRangeMin, portRangeMax)
    75  
    76  	// Accept a single connection in a goroutine and then exit
    77  	go func() {
    78  		defer l.Close()
    79  		conn, err := l.Accept()
    80  		if err != nil {
    81  			panic(err)
    82  		}
    83  
    84  		s.ServeConn(conn)
    85  	}()
    86  
    87  	return l.Addr().String()
    88  }