diff --git a/backends/backends.go b/backends/backends.go index c93ffcae18..5357fc161b 100644 --- a/backends/backends.go +++ b/backends/backends.go @@ -25,5 +25,5 @@ func New() *libswarm.Client { backends.Bind("shipyard", Shipyard()) backends.Bind("ec2", Ec2()) backends.Bind("tutum", Tutum()) - return libswarm.Obj(backends) + return libswarm.AsClient(backends) } diff --git a/backends/dockerclient_test.go b/backends/dockerclient_test.go index 7c88310c07..ac9394b754 100644 --- a/backends/dockerclient_test.go +++ b/backends/dockerclient_test.go @@ -247,7 +247,7 @@ func instance(t *testing.T, server *stubServer) *libswarm.Client { } backend := DockerClient() - instance, err := libswarm.Obj(backend).Spawn(url) + instance, err := libswarm.AsClient(backend).Spawn(url) if err != nil { t.Fatal(err) } diff --git a/backends/dockerserver.go b/backends/dockerserver.go index 4005f0b3e8..3b9ae39912 100644 --- a/backends/dockerserver.go +++ b/backends/dockerserver.go @@ -109,13 +109,13 @@ type containerJson struct { } func getContainerJson(out libswarm.Sender, containerID string) (containerJson, error) { - o := libswarm.Obj(out) + o := libswarm.AsClient(out) _, containerOut, err := o.Attach(containerID) if err != nil { return containerJson{}, err } - container := libswarm.Obj(containerOut) + container := libswarm.AsClient(containerOut) responseJson, err := container.Get() if err != nil { return containerJson{}, err @@ -142,7 +142,7 @@ func getContainersJSON(out libswarm.Sender, version version.Version, w http.Resp return err } - o := libswarm.Obj(out) + o := libswarm.AsClient(out) names, err := o.Ls() if err != nil { return err @@ -225,7 +225,7 @@ func postContainersCreate(out libswarm.Sender, version version.Version, w http.R return err } - container, err := libswarm.Obj(out).Spawn(string(body)) + container, err := libswarm.AsClient(out).Spawn(string(body)) if err != nil { return err } @@ -250,8 +250,8 @@ func postContainersStart(out libswarm.Sender, version version.Version, w http.Re // TODO: r.Body name := vars["name"] - _, containerOut, err := libswarm.Obj(out).Attach(name) - container := libswarm.Obj(containerOut) + _, containerOut, err := libswarm.AsClient(out).Attach(name) + container := libswarm.AsClient(containerOut) if err != nil { return err } @@ -269,8 +269,8 @@ func postContainersStop(out libswarm.Sender, version version.Version, w http.Res } name := vars["name"] - _, containerOut, err := libswarm.Obj(out).Attach(name) - container := libswarm.Obj(containerOut) + _, containerOut, err := libswarm.AsClient(out).Attach(name) + container := libswarm.AsClient(containerOut) if err != nil { return err } @@ -325,11 +325,11 @@ func postContainersAttach(out libswarm.Sender, version version.Version, w http.R errStream := dockerutils.NewStdWriter(outStream, dockerutils.Stderr) outStream = dockerutils.NewStdWriter(outStream, dockerutils.Stdout) - _, containerOut, err := libswarm.Obj(out).Attach(vars["name"]) + _, containerOut, err := libswarm.AsClient(out).Attach(vars["name"]) if err != nil { return err } - container := libswarm.Obj(containerOut) + container := libswarm.AsClient(containerOut) containerR, _, err := container.Attach("") var tasks sync.WaitGroup diff --git a/backends/ec2.go b/backends/ec2.go index 5f24c2aa98..af9ece3535 100644 --- a/backends/ec2.go +++ b/backends/ec2.go @@ -281,7 +281,7 @@ func (c *ec2Client) initDockerClientInstance(instance *ec2.Instance) error { URLHost: "localhost", }) - dockerBackend := libswarm.Obj(dockerClient) + dockerBackend := libswarm.AsClient(dockerClient) url := fmt.Sprintf("tcp://localhost:%s", c.config.sshLocalPort) dockerInstance, err := dockerBackend.Spawn(url) c.dockerInstance = dockerInstance diff --git a/backends/exec.go b/backends/exec.go index f81d9e4f4a..1335406219 100644 --- a/backends/exec.go +++ b/backends/exec.go @@ -46,7 +46,7 @@ func Exec() libswarm.Sender { if _, err := msg.Ret.Send(&libswarm.Message{Verb: libswarm.Ack, Ret: inW}); err != nil { return err } - out := libswarm.Obj(msg.Ret) + out := libswarm.AsClient(msg.Ret) go func() { defer stdin.Close() for { @@ -84,7 +84,7 @@ func Exec() libswarm.Sender { go func() { defer cmd.tasks.Done() if err := cmd.Cmd.Wait(); err != nil { - libswarm.Obj(msg.Ret).Log("%s exited status=%v", cmd.Cmd.Path, err) + libswarm.AsClient(msg.Ret).Log("%s exited status=%v", cmd.Cmd.Path, err) } }() msg.Ret.Send(&libswarm.Message{Verb: libswarm.Ack}) diff --git a/backends/fakeclient.go b/backends/fakeclient.go index 56a9ed2a8a..0f357ab62e 100644 --- a/backends/fakeclient.go +++ b/backends/fakeclient.go @@ -15,7 +15,7 @@ func FakeClient() libswarm.Sender { instance := utils.Task(func(in libswarm.Receiver, out libswarm.Sender) { fmt.Printf("fake client!\n") defer fmt.Printf("end of fake client!\n") - o := libswarm.Obj(out) + o := libswarm.AsClient(out) o.Log("fake client starting") defer o.Log("fake client terminating") for { diff --git a/backends/orchard.go b/backends/orchard.go index 3e3d45c26c..cb15af29b5 100644 --- a/backends/orchard.go +++ b/backends/orchard.go @@ -40,7 +40,7 @@ func Orchard() libswarm.Sender { URLHost: host.IPAddress, TLSClientConfig: tlsConfig, }) - forwardBackend := libswarm.Obj(backend) + forwardBackend := libswarm.AsClient(backend) forwardInstance, err := forwardBackend.Spawn(url) if err != nil { return nil, err diff --git a/backends/simulator.go b/backends/simulator.go index 0a59388783..d992ae40b4 100644 --- a/backends/simulator.go +++ b/backends/simulator.go @@ -10,11 +10,11 @@ func Simulator() libswarm.Sender { s.OnVerb(libswarm.Spawn, libswarm.Handler(func(ctx *libswarm.Message) error { containers := ctx.Args instance := utils.Task(func(in libswarm.Receiver, out libswarm.Sender) { - libswarm.Obj(out).Log("[simulator] starting\n") + libswarm.AsClient(out).Log("[simulator] starting\n") s := libswarm.NewServer() s.OnVerb(libswarm.Ls, libswarm.Handler(func(msg *libswarm.Message) error { - libswarm.Obj(out).Log("[simulator] generating fake list of objects...\n") - libswarm.Obj(msg.Ret).Set(containers...) + libswarm.AsClient(out).Log("[simulator] generating fake list of objects...\n") + libswarm.AsClient(msg.Ret).Set(containers...) return nil })) libswarm.Copy(s, in) diff --git a/client.go b/client.go index 375a43e0a7..518c42dccf 100644 --- a/client.go +++ b/client.go @@ -12,7 +12,7 @@ type Client struct { Sender } -func Obj(dst Sender) *Client { +func AsClient(dst Sender) *Client { return &Client{dst} } diff --git a/utils/tree.go b/utils/tree.go index a9a1d3de17..169d1de846 100644 --- a/utils/tree.go +++ b/utils/tree.go @@ -25,7 +25,7 @@ func NewTree() *Tree { msg.Ret.Send(&libswarm.Message{Verb: libswarm.Ack, Ret: child}) return nil } - libswarm.Obj(msg.Ret).Error("not found") + libswarm.AsClient(msg.Ret).Error("not found") return nil })) t.OnVerb(libswarm.Ls, libswarm.Handler(func(msg *libswarm.Message) error { @@ -34,7 +34,7 @@ func NewTree() *Tree { names = append(names, name) } sort.Strings(names) - libswarm.Obj(msg.Ret).Set(names...) + libswarm.AsClient(msg.Ret).Set(names...) return nil })) return t