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 {
|
2013-12-09 18:44:00 -05:00
|
|
|
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) {
|
2013-12-09 18:44:00 -05:00
|
|
|
a.client.Call(a.endpoint+".BuilderId", new(interface{}), &result)
|
2013-05-22 01:10:21 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *artifact) Files() (result []string) {
|
2013-12-09 18:44:00 -05:00
|
|
|
a.client.Call(a.endpoint+".Files", new(interface{}), &result)
|
2013-05-22 01:10:21 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *artifact) Id() (result string) {
|
2013-12-09 18:44:00 -05:00
|
|
|
a.client.Call(a.endpoint+".Id", new(interface{}), &result)
|
2013-05-22 01:10:21 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *artifact) String() (result string) {
|
2013-12-09 18:44:00 -05:00
|
|
|
a.client.Call(a.endpoint+".String", new(interface{}), &result)
|
2013-05-22 01:10:21 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-01-19 13:32:44 -05:00
|
|
|
func (a *artifact) State(name string) (result interface{}) {
|
|
|
|
a.client.Call(a.endpoint+".State", name, &result)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2013-06-18 19:01:14 -04:00
|
|
|
func (a *artifact) Destroy() error {
|
|
|
|
var result error
|
2013-12-09 18:44:00 -05:00
|
|
|
if err := a.client.Call(a.endpoint+".Destroy", new(interface{}), &result); err != nil {
|
2013-06-18 19:01:14 -04:00
|
|
|
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
|
|
|
|
}
|
2013-06-18 19:01:14 -04:00
|
|
|
|
2014-01-19 13:32:44 -05:00
|
|
|
func (s *ArtifactServer) State(name string, reply *interface{}) error {
|
|
|
|
*reply = s.artifact.State(name)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2013-06-18 19:01:14 -04:00
|
|
|
func (s *ArtifactServer) Destroy(args *interface{}, reply *error) error {
|
|
|
|
err := s.artifact.Destroy()
|
|
|
|
if err != nil {
|
|
|
|
err = NewBasicError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
*reply = err
|
|
|
|
return nil
|
|
|
|
}
|