diff --git a/integration/client.go b/integration/client.go index a842d1fc..879ca4b0 100644 --- a/integration/client.go +++ b/integration/client.go @@ -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( diff --git a/integration/hyper_test.go b/integration/hyper_test.go index 295b6058..617c2ebd 100644 --- a/integration/hyper_test.go +++ b/integration/hyper_test.go @@ -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) diff --git a/serverrpc/container.go b/serverrpc/container.go index dbf9b612..729b88b1 100644 --- a/serverrpc/container.go +++ b/serverrpc/container.go @@ -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 +} diff --git a/types/types.pb.go b/types/types.pb.go index 59f58aa0..b7a7746b 100644 --- a/types/types.pb.go +++ b/types/types.pb.go @@ -89,6 +89,8 @@ It has these top-level messages: AttachMessage ContainerCreateRequest ContainerCreateResponse + ContainerRenameRequest + ContainerRenameResponse AuthConfig ImagePullRequest ImagePullResponse @@ -1529,6 +1531,22 @@ func (m *ContainerCreateResponse) Reset() { *m = ContainerCreateResponse func (m *ContainerCreateResponse) String() string { return proto.CompactTextString(m) } func (*ContainerCreateResponse) ProtoMessage() {} +type ContainerRenameRequest struct { + OldContainerName string `protobuf:"bytes,1,opt,name=oldContainerName,proto3" json:"oldContainerName,omitempty"` + NewContainerName string `protobuf:"bytes,2,opt,name=newContainerName,proto3" json:"newContainerName,omitempty"` +} + +func (m *ContainerRenameRequest) Reset() { *m = ContainerRenameRequest{} } +func (m *ContainerRenameRequest) String() string { return proto.CompactTextString(m) } +func (*ContainerRenameRequest) ProtoMessage() {} + +type ContainerRenameResponse struct { +} + +func (m *ContainerRenameResponse) Reset() { *m = ContainerRenameResponse{} } +func (m *ContainerRenameResponse) String() string { return proto.CompactTextString(m) } +func (*ContainerRenameResponse) ProtoMessage() {} + type AuthConfig struct { Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"` Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` @@ -1942,6 +1960,8 @@ func init() { proto.RegisterType((*AttachMessage)(nil), "types.AttachMessage") proto.RegisterType((*ContainerCreateRequest)(nil), "types.ContainerCreateRequest") proto.RegisterType((*ContainerCreateResponse)(nil), "types.ContainerCreateResponse") + proto.RegisterType((*ContainerRenameRequest)(nil), "types.ContainerRenameRequest") + proto.RegisterType((*ContainerRenameResponse)(nil), "types.ContainerRenameResponse") proto.RegisterType((*AuthConfig)(nil), "types.AuthConfig") proto.RegisterType((*ImagePullRequest)(nil), "types.ImagePullRequest") proto.RegisterType((*ImagePullResponse)(nil), "types.ImagePullResponse") @@ -2021,7 +2041,8 @@ type PublicAPIClient interface { ContainerLogs(ctx context.Context, in *ContainerLogsRequest, opts ...grpc.CallOption) (PublicAPI_ContainerLogsClient, error) // ContainerCreate creates a container in specified pod ContainerCreate(ctx context.Context, in *ContainerCreateRequest, opts ...grpc.CallOption) (*ContainerCreateResponse, error) - // TODO: ContainerRename renames a container + // ContainerRename renames a container + ContainerRename(ctx context.Context, in *ContainerRenameRequest, opts ...grpc.CallOption) (*ContainerRenameResponse, error) // 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 @@ -2280,6 +2301,15 @@ func (c *publicAPIClient) ContainerCreate(ctx context.Context, in *ContainerCrea return out, nil } +func (c *publicAPIClient) ContainerRename(ctx context.Context, in *ContainerRenameRequest, opts ...grpc.CallOption) (*ContainerRenameResponse, error) { + out := new(ContainerRenameResponse) + err := grpc.Invoke(ctx, "/types.PublicAPI/ContainerRename", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *publicAPIClient) ContainerStop(ctx context.Context, in *ContainerStopRequest, opts ...grpc.CallOption) (*ContainerStopResponse, error) { out := new(ContainerStopResponse) err := grpc.Invoke(ctx, "/types.PublicAPI/ContainerStop", in, out, c.cc, opts...) @@ -2537,7 +2567,8 @@ type PublicAPIServer interface { ContainerLogs(*ContainerLogsRequest, PublicAPI_ContainerLogsServer) error // ContainerCreate creates a container in specified pod ContainerCreate(context.Context, *ContainerCreateRequest) (*ContainerCreateResponse, error) - // TODO: ContainerRename renames a container + // ContainerRename renames a container + ContainerRename(context.Context, *ContainerRenameRequest) (*ContainerRenameResponse, error) // 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 @@ -2827,6 +2858,18 @@ func _PublicAPI_ContainerCreate_Handler(srv interface{}, ctx context.Context, de return out, nil } +func _PublicAPI_ContainerRename_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { + in := new(ContainerRenameRequest) + if err := dec(in); err != nil { + return nil, err + } + out, err := srv.(PublicAPIServer).ContainerRename(ctx, in) + if err != nil { + return nil, err + } + return out, nil +} + func _PublicAPI_ContainerStop_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { in := new(ContainerStopRequest) if err := dec(in); err != nil { @@ -3113,6 +3156,10 @@ var _PublicAPI_serviceDesc = grpc.ServiceDesc{ MethodName: "ContainerCreate", Handler: _PublicAPI_ContainerCreate_Handler, }, + { + MethodName: "ContainerRename", + Handler: _PublicAPI_ContainerRename_Handler, + }, { MethodName: "ContainerStop", Handler: _PublicAPI_ContainerStop_Handler, diff --git a/types/types.proto b/types/types.proto index 37624295..25b6e934 100644 --- a/types/types.proto +++ b/types/types.proto @@ -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; @@ -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