github.com/rothwerx/packer@v0.9.0/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  	endpoint string
    13  }
    14  
    15  // ArtifactServer wraps a packer.Artifact implementation and makes it
    16  // exportable as part of a Golang RPC server.
    17  type ArtifactServer struct {
    18  	artifact packer.Artifact
    19  }
    20  
    21  func (a *artifact) BuilderId() (result string) {
    22  	a.client.Call(a.endpoint+".BuilderId", new(interface{}), &result)
    23  	return
    24  }
    25  
    26  func (a *artifact) Files() (result []string) {
    27  	a.client.Call(a.endpoint+".Files", new(interface{}), &result)
    28  	return
    29  }
    30  
    31  func (a *artifact) Id() (result string) {
    32  	a.client.Call(a.endpoint+".Id", new(interface{}), &result)
    33  	return
    34  }
    35  
    36  func (a *artifact) String() (result string) {
    37  	a.client.Call(a.endpoint+".String", new(interface{}), &result)
    38  	return
    39  }
    40  
    41  func (a *artifact) State(name string) (result interface{}) {
    42  	a.client.Call(a.endpoint+".State", name, &result)
    43  	return
    44  }
    45  
    46  func (a *artifact) Destroy() error {
    47  	var result error
    48  	if err := a.client.Call(a.endpoint+".Destroy", new(interface{}), &result); err != nil {
    49  		return err
    50  	}
    51  
    52  	return result
    53  }
    54  
    55  func (s *ArtifactServer) BuilderId(args *interface{}, reply *string) error {
    56  	*reply = s.artifact.BuilderId()
    57  	return nil
    58  }
    59  
    60  func (s *ArtifactServer) Files(args *interface{}, reply *[]string) error {
    61  	*reply = s.artifact.Files()
    62  	return nil
    63  }
    64  
    65  func (s *ArtifactServer) Id(args *interface{}, reply *string) error {
    66  	*reply = s.artifact.Id()
    67  	return nil
    68  }
    69  
    70  func (s *ArtifactServer) String(args *interface{}, reply *string) error {
    71  	*reply = s.artifact.String()
    72  	return nil
    73  }
    74  
    75  func (s *ArtifactServer) State(name string, reply *interface{}) error {
    76  	*reply = s.artifact.State(name)
    77  	return nil
    78  }
    79  
    80  func (s *ArtifactServer) Destroy(args *interface{}, reply *error) error {
    81  	err := s.artifact.Destroy()
    82  	if err != nil {
    83  		err = NewBasicError(err)
    84  	}
    85  
    86  	*reply = err
    87  	return nil
    88  }