]> git.eshelyaron.com Git - emacs.git/commitdiff
Add new Tramp method "toolbox"
authorMichael Albinus <michael.albinus@gmx.de>
Sat, 7 Jan 2023 11:14:26 +0000 (12:14 +0100)
committerMichael Albinus <michael.albinus@gmx.de>
Sat, 7 Jan 2023 11:14:26 +0000 (12:14 +0100)
* doc/misc/tramp.texi (Inline methods): Add toolbox.

* etc/NEWS: Add new Tramp method "toolbox".

* lisp/net/tramp-container.el (tramp-toolbox-program): New defcustom.
(tramp-toolbox-method): New defconst.
(tramp-toolbox--completion-function): New defun.  Set it for "toolbox".
(tramp-methods) <toolbox>: Add.
(tramp-default-host-alist): Add rule for "toolbox".

doc/misc/tramp.texi
etc/NEWS
lisp/net/tramp-container.el

index a2c292dd5ad184223aafbac42cab087d28844f03..7f66dc9e849f26feb16a48e119a2c765405eb356 100644 (file)
@@ -927,6 +927,17 @@ pod is used.
 
 This method does not support user names.
 
+@item @option{toolbox}
+@cindex method @option{toolbox}
+@cindex @option{toolbox} method
+
+Integration of Toolbox system containers.  The host name may be either
+a container's name or ID, as returned by @samp{toolbox list -c}.
+Without a host name, the default Toolbox container for the host will
+be used.
+
+This method does not support user names.
+
 @end table
 
 
index a2924201267450d635b66fbe1dbcfaa1b8a15974..690e9c3faa9016e219170094d6f1cab2bcf3ed99 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -114,6 +114,12 @@ docstring, or a comment, or (re)indents the surrounding defun if
 point is not in a comment or a string.  It is by default bound to
 'M-q' in 'prog-mode' and all its descendants.
 
+** Tramp
+
++++
+*** New connection method "toolbox".
+This allow accessing system containers provided by Toolbox.
+
 \f
 * New Modes and Packages in Emacs 30.1
 
index 6cdd6c654ead0f7099961aa6cc004367ef8706e2..1dd29190f10a5c5cf3998b3b69c43081c6c0a5e7 100644 (file)
@@ -41,6 +41,7 @@
 ;;     CONTAINER     is the container to connect to
 ;;
 ;;
+;;
 ;; Open file in a Kubernetes container:
 ;;
 ;;     C-x C-f /kubernetes:POD:/path/to/file
 ;; namespace, use this command to change it:
 ;;
 ;; "kubectl config set-context --current --namespace=<name>"
+;;
+;;
+;;
+;; Open a file on an existing toolbox container via Toolbox:
+;;
+;;     C-x C-f /toolbox:CONTAINER:/path/to/file
+;;
+;; Where:
+;;     CONTAINER     is the container to connect to (optional)
+;;
+;; If the container is not running, it is started.  If no container is
+;; specified, the default Toolbox container is used.
 
 ;;; Code:
 
   :type '(choice (const "kubectl")
                  (string)))
 
+;;;###tramp-autoload
+(defcustom tramp-toolbox-program "toolbox"
+  "Name of the Toolbox client program."
+  :group 'tramp
+  :version "30.1"
+  :type '(choice (const "toolbox")
+                 (string)))
+
 ;;;###tramp-autoload
 (defconst tramp-docker-method "docker"
   "Tramp method name to use to connect to Docker containers.")
 (defconst tramp-kubernetes-method "kubernetes"
   "Tramp method name to use to connect to Kubernetes containers.")
 
+;;;###tramp-autoload
+(defconst tramp-toolbox-method "toolbox"
+  "Tramp method name to use to connect to Toolbox containers.")
+
 ;;;###tramp-autoload
 (defun tramp-docker--completion-function (&rest _args)
   "List Docker-like containers available for connection.
@@ -150,6 +175,27 @@ see its function help for a description of the format."
                 "jsonpath='{.contexts[?(@.name == \"%s\")]}'" current-context)))
          (buffer-string))))))
 
+;;;###tramp-autoload
+(defun tramp-toolbox--completion-function (&rest _args)
+  "List Toolbox containers available for connection.
+
+This function is used by `tramp-set-completion-function', please
+see its function help for a description of the format."
+  (when-let ((default-directory tramp-compat-temporary-file-directory)
+            (raw-list (shell-command-to-string
+                       (concat tramp-toolbox-program " list -c")))
+            ;; Ignore header line.
+             (lines (cdr (split-string raw-list "\n" 'omit)))
+             (names (mapcar
+                    (lambda (line)
+                       (when (string-match
+                             (rx bol (1+ (not space))
+                                 (1+ space) (group (1+ (not space))) space)
+                             line)
+                        (match-string 1 line)))
+                     lines)))
+    (mapcar (lambda (m) (list nil m)) (delq nil names))))
+
 ;;;###tramp-autoload
 (defvar tramp-default-remote-shell) ;; Silence byte compiler.
 
@@ -167,6 +213,7 @@ see its function help for a description of the format."
                 (tramp-remote-shell ,tramp-default-remote-shell)
                 (tramp-remote-shell-login ("-l"))
                 (tramp-remote-shell-args ("-i" "-c"))))
+
  (add-to-list 'tramp-methods
               `(,tramp-podman-method
                 (tramp-login-program ,tramp-podman-program)
@@ -179,6 +226,7 @@ see its function help for a description of the format."
                 (tramp-remote-shell ,tramp-default-remote-shell)
                 (tramp-remote-shell-login ("-l"))
                 (tramp-remote-shell-args ("-i" "-c"))))
+
  (add-to-list 'tramp-methods
               `(,tramp-kubernetes-method
                 (tramp-login-program ,tramp-kubernetes-program)
@@ -193,6 +241,19 @@ see its function help for a description of the format."
                 (tramp-remote-shell-login ("-l"))
                 (tramp-remote-shell-args ("-i" "-c"))))
 
+ (add-to-list 'tramp-methods
+             `(,tramp-toolbox-method
+               (tramp-login-program ,tramp-toolbox-program)
+               (tramp-login-args (("run")
+                                  ("-c" "%h")
+                                  ("%l")))
+               (tramp-direct-async (,tramp-default-remote-shell "-c"))
+               (tramp-remote-shell ,tramp-default-remote-shell)
+               (tramp-remote-shell-login ("-l"))
+               (tramp-remote-shell-args ("-c"))))
+
+ (add-to-list 'tramp-default-host-alist `(,tramp-toolbox-method nil ""))
+
  (tramp-set-completion-function
   tramp-docker-method
   '((tramp-docker--completion-function "")))
@@ -203,7 +264,11 @@ see its function help for a description of the format."
 
  (tramp-set-completion-function
   tramp-kubernetes-method
-  '((tramp-kubernetes--completion-function ""))))
+  '((tramp-kubernetes--completion-function "")))
+
+ (tramp-set-completion-function
+  tramp-toolbox-method
+  '((tramp-toolbox--completion-function ""))))
 
 (add-hook 'tramp-unload-hook
          (lambda ()