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

     1  package rpc
     2  
     3  import (
     4  	"github.com/mitchellh/packer/packer"
     5  	"net/rpc"
     6  )
     7  
     8  // An implementation of packer.Artifact where the artifact is actually
     9  // available over an RPC connection.
    10  type artifact struct {
    11  	client *rpc.Client
    12  }
    13  
    14  // ArtifactServer wraps a packer.Artifact implementation and makes it
    15  // exportable as part of a Golang RPC server.
    16  type ArtifactServer struct {
    17  	artifact packer.Artifact
    18  }
    19  
    20  func Artifact(client *rpc.Client) *artifact {
    21  	return &artifact{client}
    22  }
    23  
    24  func (a *artifact) BuilderId() (result string) {
    25  	a.client.Call("Artifact.BuilderId", new(interface{}), &result)
    26  	return
    27  }
    28  
    29  func (a *artifact) Files() (result []string) {
    30  	a.client.Call("Artifact.Files", new(interface{}), &result)
    31  	return
    32  }
    33  
    34  func (a *artifact) Id() (result string) {
    35  	a.client.Call("Artifact.Id", new(interface{}), &result)
    36  	return
    37  }
    38  
    39  func (a *artifact) String() (result string) {
    40  	a.client.Call("Artifact.String", new(interface{}), &result)
    41  	return
    42  }
    43  
    44  func (a *artifact) Destroy() error {
    45  	var result error
    46  	if err := a.client.Call("Artifact.Destroy", new(interface{}), &result); err != nil {
    47  		return err
    48  	}
    49  
    50  	return result
    51  }
    52  
    53  func (s *ArtifactServer) BuilderId(args *interface{}, reply *string) error {
    54  	*reply = s.artifact.BuilderId()
    55  	return nil
    56  }
    57  
    58  func (s *ArtifactServer) Files(args *interface{}, reply *[]string) error {
    59  	*reply = s.artifact.Files()
    60  	return nil
    61  }
    62  
    63  func (s *ArtifactServer) Id(args *interface{}, reply *string) error {
    64  	*reply = s.artifact.Id()
    65  	return nil
    66  }
    67  
    68  func (s *ArtifactServer) String(args *interface{}, reply *string) error {
    69  	*reply = s.artifact.String()
    70  	return nil
    71  }
    72  
    73  func (s *ArtifactServer) Destroy(args *interface{}, reply *error) error {
    74  	err := s.artifact.Destroy()
    75  	if err != nil {
    76  		err = NewBasicError(err)
    77  	}
    78  
    79  	*reply = err
    80  	return nil
    81  }