Skip to content

Instantly share code, notes, and snippets.

@andrewyager
Last active July 28, 2020 13:31
Show Gist options
  • Save andrewyager/1038616eb7f2ed7fc73e306a007d18a5 to your computer and use it in GitHub Desktop.
Save andrewyager/1038616eb7f2ed7fc73e306a007d18a5 to your computer and use it in GitHub Desktop.
Nova Password retrieval using openstack config.yaml configuration files
#!/usr/bin/env python3
"""
Nova Password retrieval for OpenStack
This utility allows you to retrieve a password (using the method made available by
openstack-novaclient) for a Virtual machine from your CLI.
openstack client (python-openstackclient) does not currently include the
`get password` option that is present in the `openstack-novaclient` utility.
The openstack-novaclient does not include the ability to use openstack clouds as a
configuration source. This little script allows you to retrieve an instance password
(useful for windows instances) without using horizon and using the same cloud.yaml
config files you use with your normal openstack implementation.
Installation:
* Make sure you have installed os_client_config, openstackclient and novaclient
* Copy this gist into your executable path (e.g. /usr/local/bin) and call
it something that means something to you (such as nova-password).
Usage:
* `nova-password -c openstack -s test-windows -k ~/.ssh/os` will give you
the password for the VM named test-windows decrypted using your 'os' key.
* `nova-password -c openstack` will give you a list of all encrypted passwords
for the instance project defined in your openstack config
* `nova-password -c openstack -k ~/.ssh/os` will decrypt the password for all
vm's within the openstack tenant using the key called 'os'
"""
# Include standard modules
import os_client_config
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--cloud", "-c", help="OpenStack Cloud Name", required=True)
parser.add_argument("--server", "-s", help="Server Instance")
parser.add_argument("--key", "-k", help="RSA Key used for decryption")
args = parser.parse_args()
cloud = args.cloud
server_name = args.server
key = args.key
nova = os_client_config.make_client("compute", cloud=cloud)
if server_name:
servers = nova.servers.list(search_opts={"name": server_name})
else:
servers = nova.servers.list()
for server in servers:
if server_name is None:
print(server.name + " " + server.get_password(key))
else:
print(server.get_password(key))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment