From eb0de68365cc45c2503205a416e1672b3849fddb Mon Sep 17 00:00:00 2001 From: Kwon Date: Sun, 28 Jun 2026 16:49:53 +0900 Subject: [PATCH] feat: wire TakeExternalSnapshot to Core endpoint - Fix TakeSnapshotResponse to match Core response shape (uuid, snapKey) - Add CoreClient.TakeExternalSnapshot with 12m timeout for snapshot+upload - Fill in TakeSnapshot TODO: presigned PUT URL -> Core -> RustFS upload --- client/model/snapshot.go | 3 ++- client/vm.go | 14 ++++++++++++++ service/external_snap.go | 13 +++++++++---- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/client/model/snapshot.go b/client/model/snapshot.go index 123e024..e907181 100644 --- a/client/model/snapshot.go +++ b/client/model/snapshot.go @@ -10,5 +10,6 @@ type TakeSnapshotRequest struct { } type TakeSnapshotResponse struct { - Message string `json:"message,omitempty"` + UUID string `json:"uuid"` + SnapKey string `json:"snapKey"` } diff --git a/client/vm.go b/client/vm.go index 923f6fb..9821ab3 100644 --- a/client/vm.go +++ b/client/vm.go @@ -183,3 +183,17 @@ func (c *CoreClient) ForceShutdownVM(ctx context.Context, req model.ForceShutdow } return response, nil } + +// TakeExternalSnapshot asks Core to take a snapshot and upload it to RustFS via the given presigned PUT URL. +// Uses a dedicated HTTP client with a 12-minute timeout because snapshot creation + upload can take several minutes. +func (c *CoreClient) TakeExternalSnapshot(ctx context.Context, req model.TakeSnapshotRequest) (model.TakeSnapshotResponse, error) { + snapClient := &CoreClient{ + baseURL: c.baseURL, + client: &http.Client{Timeout: 12 * time.Minute}, + } + var response model.TakeSnapshotResponse + if err := snapClient.doRequest(ctx, http.MethodPost, "/TakeExternalSnapshot", req, &response); err != nil { + return model.TakeSnapshotResponse{}, err + } + return response, nil +} diff --git a/service/external_snap.go b/service/external_snap.go index e4da6a5..98cd9ae 100644 --- a/service/external_snap.go +++ b/service/external_snap.go @@ -6,6 +6,7 @@ import ( "time" "github.com/easy-cloud-Knet/KWS_Control/client" + "github.com/easy-cloud-Knet/KWS_Control/client/model" vms "github.com/easy-cloud-Knet/KWS_Control/structure" ) @@ -52,9 +53,13 @@ func TakeSnapshot(uuid vms.UUID, snapName string, ctx *vms.ControlContext) error return fmt.Errorf("TakeSnapshot %s: failed to generate presigned URL: %w", uuid, err) } - // TODO: coreClient.TakeSnapshot(context.Background(), model.TakeSnapshotRequest{ - // UUID: uuid, SnapKey: snapName, PresignedURL: presignedURL, - // }) - _ = presignedURL + coreClient := client.NewCoreClient(core) + if _, err := coreClient.TakeExternalSnapshot(context.Background(), model.TakeSnapshotRequest{ + UUID: uuid, + SnapKey: snapName, + PresignedURL: presignedURL, + }); err != nil { + return fmt.Errorf("TakeSnapshot %s: core failed: %w", uuid, err) + } return nil }