| package actions |
| |
| import ( |
| "context" |
| _ "embed" |
| "time" |
| |
| "cos.googlesource.com/cos/tools.git/src/pkg/utils" |
| "cos.googlesource.com/cos/tools.git/src/pkg/kernel" |
| "github.com/spf13/cobra" |
| ) |
| |
| func unlockGCPInstance(ctx context.Context, args []string) error { |
| ctx, cancel := context.WithTimeout(ctx, 2 * time.Minute) |
| defer cancel() |
| |
| opts := utils.RetryOptions { |
| Attempts: 5, |
| Delay: 10 * time.Second, |
| ShouldRetry: ShouldRetryGcloudComputeSsh, |
| } |
| |
| return utils.Retry(ctx, func(ctx context.Context) error { |
| return kernel.UnlockGCPInstance(ctx, args) |
| }, opts) |
| } |
| |
| var unlockCmd = &cobra.Command{ |
| Use: "unlock", |
| Short: "Unlocks a local or remote GCP instance to allow development", |
| Long: `Executes a bash script to set up either a local instance or remote GCP instance for |
| development. If no arguments are given, then the script is run to unlock the local instance. If |
| arguments are given, then the arguments are passed into gcloud compute ssh to be executed on`, |
| RunE: func(cmd *cobra.Command, args []string) error { |
| if len(args) == 0 { |
| return kernel.UnlockLocalInstance() |
| } else { |
| return unlockGCPInstance(cmd.Context(), args) |
| } |
| }, |
| } |
| |
| func init() { |
| rootCmd.AddCommand(unlockCmd) |
| } |