forked from Cloud-Foundations/Dominator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
impl.go
62 lines (58 loc) · 1.46 KB
/
impl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package client
import (
"fmt"
"io"
"github.com/Cloud-Foundations/Dominator/lib/errors"
"github.com/Cloud-Foundations/Dominator/lib/srpc"
proto "github.com/Cloud-Foundations/Dominator/proto/imaginator"
)
func buildImage(client *srpc.Client, request proto.BuildImageRequest,
response *proto.BuildImageResponse, logWriter io.Writer) error {
conn, err := client.Call("Imaginator.BuildImage")
if err != nil {
return err
}
defer conn.Close()
if err := conn.Encode(request); err != nil {
return err
}
if err := conn.Flush(); err != nil {
return err
}
str, err := conn.ReadString('\n')
if err != nil {
return err
}
if str != "\n" {
return errors.New(str[:len(str)-1])
}
for {
var reply proto.BuildImageResponse
if err := conn.Decode(&reply); err != nil {
return fmt.Errorf("error reading reply: %s", err)
}
if err := errors.New(reply.ErrorString); err != nil {
return err
}
logWriter.Write(reply.BuildLog)
reply.BuildLog = nil
if reply.Image != nil || reply.ImageName != "" {
*response = reply
return nil
}
}
}
func getDirectedGraph(client *srpc.Client,
request proto.GetDirectedGraphRequest) (
proto.GetDirectedGraphResult, error) {
var zero proto.GetDirectedGraphResult
var reply proto.GetDirectedGraphResponse
err := client.RequestReply("Imaginator.GetDirectedGraph", request, &reply)
if err != nil {
return zero, err
}
if reply.Error != "" {
return zero, errors.New(reply.Error)
}
return reply.GetDirectedGraphResult, nil
}