github.phpd.cn/hashicorp/packer@v1.3.2/packer/rpc/artifact.go (about)

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