Skip to content

Commit

Permalink
Moved GenerateSnapshotRequest to a helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
mazin-s committed Nov 13, 2023
1 parent 11580f1 commit df01872
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
21 changes: 9 additions & 12 deletions ndb_api/time_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ import (

// Takes a snapshot for a time machine
// Returns the task info summary response for the operation TODO
func TakeSnapshotForTM(ctx context.Context, ndbClient *ndb_client.NDBClient, tmName string) (task TaskInfoSummaryResponse, err error) {
func TakeSnapshotForTM(
ctx context.Context,
ndbClient *ndb_client.NDBClient,
tmName string,
snapshotName string,
expiryDateTimezone string,
ExpireInDays string) (snapshotRequest SnapshotRequest, err error) {

log := ctrllog.FromContext(ctx)
log.Info("Entered ndb_api.TakeSnapshotForTM")
if ndbClient == nil {
Expand All @@ -42,17 +49,7 @@ func TakeSnapshotForTM(ctx context.Context, ndbClient *ndb_client.NDBClient, tmN
return
}
takeSnapshotPath := fmt.Sprintf("tms/%s/snapshots", tmName)
requestBody := &SnapshotRequest{
Name: "snapshot2",
SnapshotLcmConfig: SnapshotLcmConfig{
SnapshotLCMConfigDetailed: SnapshotLcmConfigDetailed{
ExpiryDetails: ExpiryDetails{
ExpiryDateTimezone: "Asia/Calcutta",
ExpireInDays: "10",
},
},
},
}
requestBody := GenerateSnapshotRequest(snapshotName, expiryDateTimezone, ExpireInDays)

res, err := ndbClient.Post(takeSnapshotPath, requestBody)
if err != nil || res == nil || res.StatusCode != http.StatusOK {
Expand Down
15 changes: 15 additions & 0 deletions ndb_api/time_machine_helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ndb_api

func GenerateSnapshotRequest(name string, expiryDateTimezone string, ExpireInDays string) *SnapshotRequest {
return &SnapshotRequest{
Name: name,
SnapshotLcmConfig: SnapshotLcmConfig{
SnapshotLCMConfigDetailed: SnapshotLcmConfigDetailed{
ExpiryDetails: ExpiryDetails{
ExpiryDateTimezone: expiryDateTimezone,
ExpireInDays: ExpireInDays,
},
},
},
}
}

0 comments on commit df01872

Please sign in to comment.