Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions integration/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,21 @@ func (c *HyperClient) CreateContainer(podID string, spec *types.UserContainer) (
return resp.ContainerID, nil
}

// RenameContainer renames a container
func (c *HyperClient) RenameContainer(oldName string, newName string) error {
req := types.ContainerRenameRequest{
OldContainerName: oldName,
NewContainerName: newName,
}
_, err := c.client.ContainerRename(c.ctx, &req)

if err != nil {
return err
}

return nil
}

// RemovePod removes a pod by podID
func (c *HyperClient) RemovePod(podID string) error {
_, err := c.client.PodRemove(
Expand Down
31 changes: 31 additions & 0 deletions integration/hyper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,37 @@ func (s *TestSuite) TestCreateContainer(c *C) {
c.Assert(err, IsNil)
}

func (s *TestSuite) TestRenameContainer(c *C) {
err := s.client.PullImage("busybox", "latest", nil)
c.Assert(err, IsNil)

spec := types.UserPod{}
pod, err := s.client.CreatePod(&spec)
c.Assert(err, IsNil)
c.Logf("Pod created: %s", pod)

container, err := s.client.CreateContainer(pod, &types.UserContainer{
Image: "busybox",
})
c.Assert(err, IsNil)
c.Logf("Container created: %s", container)

info, err := s.client.GetContainerInfo(container)
c.Assert(err, IsNil)

oldName := info.Container.Name[1:]
newName := "busybox0123456789"
err = s.client.RenameContainer(oldName, newName)
c.Assert(err, IsNil)

info, err = s.client.GetContainerInfo(container)
c.Assert(err, IsNil)
c.Assert(info.Container.Name[1:], Equals, newName)

err = s.client.RemovePod(pod)
c.Assert(err, IsNil)
}

func (s *TestSuite) TestPullImage(c *C) {
err := s.client.PullImage("alpine", "latest", nil)
c.Assert(err, IsNil)
Expand Down
13 changes: 13 additions & 0 deletions serverrpc/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,16 @@ func (s *ServerRPC) ContainerStop(c context.Context, req *types.ContainerStopReq

return &types.ContainerStopResponse{}, nil
}

// ContainerRename rename a container
func (s *ServerRPC) ContainerRename(c context.Context, req *types.ContainerRenameRequest) (*types.ContainerRenameResponse, error) {
glog.V(3).Infof("ContainerRename with request %v", req.String())

err := s.daemon.ContainerRename(req.OldContainerName, req.NewContainerName)
if err != nil {
glog.Errorf("ContainerRename error: %v", err)
return nil, err
}

return &types.ContainerRenameResponse{}, nil
}
51 changes: 49 additions & 2 deletions types/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion types/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,13 @@ message ContainerCreateResponse {
string containerID = 1;
}

message ContainerRenameRequest {
string oldContainerName = 1;
string newContainerName = 2;
}

message ContainerRenameResponse {}

message AuthConfig {
string username = 1;
string password = 2;
Expand Down Expand Up @@ -754,7 +761,8 @@ service PublicAPI {
rpc ContainerLogs(ContainerLogsRequest) returns (stream ContainerLogsResponse) {}
// ContainerCreate creates a container in specified pod
rpc ContainerCreate(ContainerCreateRequest) returns (ContainerCreateResponse) {}
// TODO: ContainerRename renames a container
// ContainerRename renames a container
rpc ContainerRename(ContainerRenameRequest) returns (ContainerRenameResponse) {}
// TODO: ContainerCommit commits the changes of the specified container
// TODO: ContainerSignal sends a singla to specified container
// TODO: ContainerLabels updates labels of the specified container
Expand Down