packer-cn/packer/rpc/artifact.go

79 lines
1.7 KiB
Go
Raw Normal View History

2013-05-22 01:10:21 -04:00
package rpc
import (
"github.com/mitchellh/packer/packer"
"net/rpc"
)
// An implementation of packer.Artifact where the artifact is actually
// available over an RPC connection.
type artifact struct {
client *rpc.Client
endpoint string
2013-05-22 01:10:21 -04:00
}
// ArtifactServer wraps a packer.Artifact implementation and makes it
// exportable as part of a Golang RPC server.
type ArtifactServer struct {
artifact packer.Artifact
}
func (a *artifact) BuilderId() (result string) {
a.client.Call(a.endpoint+".BuilderId", new(interface{}), &result)
2013-05-22 01:10:21 -04:00
return
}
func (a *artifact) Files() (result []string) {
a.client.Call(a.endpoint+".Files", new(interface{}), &result)
2013-05-22 01:10:21 -04:00
return
}
func (a *artifact) Id() (result string) {
a.client.Call(a.endpoint+".Id", new(interface{}), &result)
2013-05-22 01:10:21 -04:00
return
}
func (a *artifact) String() (result string) {
a.client.Call(a.endpoint+".String", new(interface{}), &result)
2013-05-22 01:10:21 -04:00
return
}
func (a *artifact) Destroy() error {
var result error
if err := a.client.Call(a.endpoint+".Destroy", new(interface{}), &result); err != nil {
return err
}
return result
}
2013-05-22 01:10:21 -04:00
func (s *ArtifactServer) BuilderId(args *interface{}, reply *string) error {
*reply = s.artifact.BuilderId()
return nil
}
func (s *ArtifactServer) Files(args *interface{}, reply *[]string) error {
*reply = s.artifact.Files()
return nil
}
func (s *ArtifactServer) Id(args *interface{}, reply *string) error {
*reply = s.artifact.Id()
return nil
}
func (s *ArtifactServer) String(args *interface{}, reply *string) error {
*reply = s.artifact.String()
return nil
}
func (s *ArtifactServer) Destroy(args *interface{}, reply *error) error {
err := s.artifact.Destroy()
if err != nil {
err = NewBasicError(err)
}
*reply = err
return nil
}