Skip to content

Commit

Permalink
compose: Add cloud API --wait to start command
Browse files Browse the repository at this point in the history
Related: RHEL-60123
  • Loading branch information
bcl committed Feb 3, 2025
1 parent eacfa0e commit 1a4a012
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions cmd/composer-cli/compose/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,23 @@ func start(cmd *cobra.Command, args []string) error {

uuid, err = root.Cloud.StartComposeUpload(blueprint, args[1], args[2], uploadOptions, nil, size)
}

if err != nil {
return root.ExecutionError(cmd, "starting cloud API compose: %s", err)
}
fmt.Printf("Compose %s added to the queue\n", uuid)

if wait {
fmt.Printf("Waiting %v for compose to finish\n", timeout)
aborted, status, err := root.Cloud.ComposeWait(uuid, timeout, interval)
if err != nil {
return root.ExecutionError(cmd, "%s", err)
}
if aborted {
return root.ExecutionError(cmd, "timeout after %v", timeout)
}

fmt.Printf("%s %s\n", uuid, status.Status)
}
} else {
// 2 args is saved locally, 4 is uploaded to the specified service
if len(args) == 2 {
Expand All @@ -123,28 +136,23 @@ func start(cmd *cobra.Command, args []string) error {
return root.ExecutionErrors(cmd, resp.Errors)
}
}
fmt.Printf("Compose %s added to the queue\n", uuid)

}
fmt.Printf("Compose %s added to the queue\n", uuid)
if wait {
fmt.Printf("Waiting %v for compose to finish\n", timeout)
aborted, info, resp, err := root.Client.ComposeWait(uuid, timeout, interval)
if err != nil {
return root.ExecutionError(cmd, "Wait: %s", err)
}
if resp != nil {
return root.ExecutionErrors(cmd, resp.Errors)
}
if aborted {
return root.ExecutionError(cmd, "Wait: timeout after %v", timeout)
}

// TODO Make this work with cloud API
if wait {
fmt.Printf("Waiting %v for compose to finish\n", timeout)
aborted, info, resp, err := root.Client.ComposeWait(uuid, timeout, interval)
if err != nil {
return root.ExecutionError(cmd, "Wait Error: %s", err)
fmt.Printf("%s %s\n", info.ID, info.QueueStatus)
}
if resp != nil {
return root.ExecutionErrors(cmd, resp.Errors)
}
if aborted {
return root.ExecutionError(cmd, "Wait Error: timeout after %v", timeout)
}

fmt.Printf("%s %s\n",
info.ID,
info.QueueStatus,
)
}

return nil
Expand Down

0 comments on commit 1a4a012

Please sign in to comment.