Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit b2a245c

Browse files
authored
Merge pull request #400 from YaoZengzeng/rename-gRPC
add container rename grpc api
2 parents c640f35 + 7cc7869 commit b2a245c

File tree

5 files changed

+117
-3
lines changed

5 files changed

+117
-3
lines changed

integration/client.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,21 @@ func (c *HyperClient) CreateContainer(podID string, spec *types.UserContainer) (
249249
return resp.ContainerID, nil
250250
}
251251

252+
// RenameContainer renames a container
253+
func (c *HyperClient) RenameContainer(oldName string, newName string) error {
254+
req := types.ContainerRenameRequest{
255+
OldContainerName: oldName,
256+
NewContainerName: newName,
257+
}
258+
_, err := c.client.ContainerRename(c.ctx, &req)
259+
260+
if err != nil {
261+
return err
262+
}
263+
264+
return nil
265+
}
266+
252267
// RemovePod removes a pod by podID
253268
func (c *HyperClient) RemovePod(podID string) error {
254269
_, err := c.client.PodRemove(

integration/hyper_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,37 @@ func (s *TestSuite) TestCreateContainer(c *C) {
210210
c.Assert(err, IsNil)
211211
}
212212

213+
func (s *TestSuite) TestRenameContainer(c *C) {
214+
err := s.client.PullImage("busybox", "latest", nil)
215+
c.Assert(err, IsNil)
216+
217+
spec := types.UserPod{}
218+
pod, err := s.client.CreatePod(&spec)
219+
c.Assert(err, IsNil)
220+
c.Logf("Pod created: %s", pod)
221+
222+
container, err := s.client.CreateContainer(pod, &types.UserContainer{
223+
Image: "busybox",
224+
})
225+
c.Assert(err, IsNil)
226+
c.Logf("Container created: %s", container)
227+
228+
info, err := s.client.GetContainerInfo(container)
229+
c.Assert(err, IsNil)
230+
231+
oldName := info.Container.Name[1:]
232+
newName := "busybox0123456789"
233+
err = s.client.RenameContainer(oldName, newName)
234+
c.Assert(err, IsNil)
235+
236+
info, err = s.client.GetContainerInfo(container)
237+
c.Assert(err, IsNil)
238+
c.Assert(info.Container.Name[1:], Equals, newName)
239+
240+
err = s.client.RemovePod(pod)
241+
c.Assert(err, IsNil)
242+
}
243+
213244
func (s *TestSuite) TestPullImage(c *C) {
214245
err := s.client.PullImage("alpine", "latest", nil)
215246
c.Assert(err, IsNil)

serverrpc/container.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,16 @@ func (s *ServerRPC) ContainerStop(c context.Context, req *types.ContainerStopReq
3333

3434
return &types.ContainerStopResponse{}, nil
3535
}
36+
37+
// ContainerRename rename a container
38+
func (s *ServerRPC) ContainerRename(c context.Context, req *types.ContainerRenameRequest) (*types.ContainerRenameResponse, error) {
39+
glog.V(3).Infof("ContainerRename with request %v", req.String())
40+
41+
err := s.daemon.ContainerRename(req.OldContainerName, req.NewContainerName)
42+
if err != nil {
43+
glog.Errorf("ContainerRename error: %v", err)
44+
return nil, err
45+
}
46+
47+
return &types.ContainerRenameResponse{}, nil
48+
}

types/types.pb.go

Lines changed: 49 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

types/types.proto

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,13 @@ message ContainerCreateResponse {
576576
string containerID = 1;
577577
}
578578

579+
message ContainerRenameRequest {
580+
string oldContainerName = 1;
581+
string newContainerName = 2;
582+
}
583+
584+
message ContainerRenameResponse {}
585+
579586
message AuthConfig {
580587
string username = 1;
581588
string password = 2;
@@ -760,7 +767,8 @@ service PublicAPI {
760767
rpc ContainerLogs(ContainerLogsRequest) returns (stream ContainerLogsResponse) {}
761768
// ContainerCreate creates a container in specified pod
762769
rpc ContainerCreate(ContainerCreateRequest) returns (ContainerCreateResponse) {}
763-
// TODO: ContainerRename renames a container
770+
// ContainerRename renames a container
771+
rpc ContainerRename(ContainerRenameRequest) returns (ContainerRenameResponse) {}
764772
// TODO: ContainerCommit commits the changes of the specified container
765773
// TODO: ContainerSignal sends a singla to specified container
766774
// TODO: ContainerLabels updates labels of the specified container

0 commit comments

Comments
 (0)