Created
May 12, 2016 04:47
-
-
Save howardabrams/e7237b6bbd9e84bcc353bde13213576a to your computer and use it in GitHub Desktop.
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
(defun remote-shell-fav-hosts-get () | |
"My hook to the remote-shell processes in order to connect to | |
my OpenStack controller, and create a hashtable of host names as | |
the keys, and IP addresses as the values." | |
(interactive) | |
;; Run nova list command remotely on this host system, and put the | |
;; results in a temp buffer: | |
(let* ((undercloud-controller "10.98.1.145") | |
(default-directory (format "/ssh:%s:" undercloud-controller)) | |
(tmp-buffer "host-list")) | |
(shell-command "source ./openrc; nova --os-password 'oh-bugger' list" tmp-buffer) | |
(with-current-buffer tmp-buffer | |
;; Assuming we get here, let's invalidate the cache | |
(clrhash remote-shell-fav-hosts) | |
(puthash "undercloud-controller" undercloud-controller remote-shell-fav-hosts) | |
(goto-char (point-min)) | |
(while (re-search-forward (concat "^| " ;; Look for the UUID | |
"[0-9a-fA-F]\\{8\\}-" | |
"[0-9a-fA-F]\\{4\\}-" | |
"[0-9a-fA-F]\\{4\\}-" | |
"[0-9a-fA-F]\\{4\\}-" | |
"[0-9a-fA-F]\\{12\\} *| *") | |
nil t) | |
(let* ((name-s (point)) | |
(name-e (progn (re-search-forward " ") | |
(1- (match-end 0)))) | |
(name (buffer-substring-no-properties name-s name-e)) | |
(addr-s (progn (re-search-forward "cedev.*=") | |
(match-end 0))) | |
(addr-e (progn (re-search-forward " ") | |
(1- (match-end 0)))) | |
(addr (buffer-substring-no-properties addr-s addr-e))) | |
(puthash name addr remote-shell-fav-hosts)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment