Fixed a bug due to a change in the JSON output of OpenStack

I may have to screw with this more, as it isn't very robust.
This commit is contained in:
Howard Abrams 2022-03-14 09:48:24 -07:00
parent a8b5dc578a
commit 4687c8c398

View file

@ -398,18 +398,18 @@ We'll do the work of getting the /server list/ with this function:
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(defun ha-ssh-overcloud-cache-populate (cluster) (defun ha-ssh-overcloud-cache-populate (cluster)
(interactive (list (completing-read "Cluster: " '(devprod1 devprod501 devprod502)))) (interactive (list (completing-read "Cluster: " '(devprod1 devprod501 devprod502))))
(message "Calling the =openstack= command...this will take a while. Grab a coffee, eh?") (message "Calling the `openstack' command...this will take a while. Grab a coffee, eh?")
(let* ((command (format "openstack --os-cloud %s server list --no-name-lookup --insecure -f json" cluster)) (let* ((command (format "openstack --os-cloud %s server list --no-name-lookup --insecure -f json" cluster))
(json-data (shell-command-to-string command))) (json-data (shell-command-to-string command)))
(message "Call to openstack returned: %s" json-data) (message "Call to openstack returned: %s" json-data)
(setq ha-ssh-overcloud-cache-data (json-read-from-string json-data)) (setq ha-ssh-overcloud-cache-data (json-read-from-string json-data))
(let* ((hostnames (->> ha-ssh-overcloud-cache-data (cl-flet* ((ssh-tuple (entry) (cons (alist-get 'Name entry)
(--map (alist-get 'Name it)))) (aref (thread-last entry
(addresses (->> ha-ssh-overcloud-cache-data (alist-get 'Networks)
(--map (alist-get 'Networks it)) (alist-get 'cedev13))
(--map (replace-regexp-in-string ".*?=" "" it))))) 0))))
(setq ha-ssh-favorite-hostnames (append ha-ssh-favorite-hostnames (setq ha-ssh-favorite-hostnames
(-zip-pair hostnames addresses))))) (mapcar #'ssh-tuple ha-ssh-overcloud-cache-data))))
(message "Call to =openstack= complete. Found %d hosts." (length ha-ssh-overcloud-cache-data))) (message "Call to =openstack= complete. Found %d hosts." (length ha-ssh-overcloud-cache-data)))
#+END_SRC #+END_SRC