-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5cde85
commit 53ce856
Showing
7 changed files
with
192 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package cmd | ||
|
||
import ( | ||
"cli/cmd/exec" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// execCmd represents the base command for executing commands in a pod | ||
var execCmd = &cobra.Command{ | ||
Use: "exec", | ||
Short: "Execute commands in a pod", | ||
Long: `Execute a local file remotely in a pod.`, | ||
} | ||
|
||
func init() { | ||
execCmd.AddCommand(exec.RemotePythonCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package exec | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var RemotePythonCmd = &cobra.Command{ | ||
Use: "python [file]", | ||
Short: "Runs a remote Python shell", | ||
Long: `Runs a remote Python shell with a local script file.`, | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
podID, _ := cmd.Flags().GetString("pod_id") | ||
file := args[0] | ||
|
||
// Default to the session pod if no pod_id is provided | ||
// if podID == "" { | ||
// var err error | ||
// podID, err = api.GetSessionPod() | ||
// if err != nil { | ||
// fmt.Fprintf(os.Stderr, "Error retrieving session pod: %v\n", err) | ||
// return | ||
// } | ||
// } | ||
|
||
fmt.Println("Running remote Python shell...") | ||
if err := PythonOverSSH(podID, file); err != nil { | ||
fmt.Fprintf(os.Stderr, "Error executing Python over SSH: %v\n", err) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
RemotePythonCmd.Flags().String("pod_id", "", "The ID of the pod to run the command on.") | ||
RemotePythonCmd.MarkFlagRequired("file") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package exec | ||
|
||
import ( | ||
"cli/cmd/project" | ||
"fmt" | ||
) | ||
|
||
func PythonOverSSH(podID string, file string) error { | ||
sshConn, err := project.PodSSHConnection(podID) | ||
if err != nil { | ||
return fmt.Errorf("getting SSH connection: %w", err) | ||
} | ||
|
||
// Copy the file to the pod using Rsync | ||
if err := sshConn.Rsync(file, "/tmp/"+file, false); err != nil { | ||
return fmt.Errorf("copying file to pod: %w", err) | ||
} | ||
|
||
// Run the file on the pod | ||
if err := sshConn.RunCommand("python3.11 /tmp/" + file); err != nil { | ||
return fmt.Errorf("running Python command: %w", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.