Commit f39cc43d authored by Swann Perarnau's avatar Swann Perarnau
Browse files

[feature] Add general helper script

Add a script to help with general configuration issues.
parent 2f654ad9
......@@ -33,6 +33,22 @@ specified as the `--region` option for all operations in a specific site. If
you don't want to repeat this option everytime, set the `OS_REGION_NAME`
environment variable.
# General Help
The `` script contains a few commands to help you figure out if
your configuration is working properly, or access specific information about a
> ./ list-clouds
> ./ list-keys
In general the scripts included in this repo are here to simplify access to the
openstack tools. But if you need to do something more complex, you can always
rely on the openstack GUI or CLI directly. The `pipenv` setup will give you
access to the `openstack` command in particular. You can have this tool use the
same `clouds.yaml` configuration by using the `--os-cloud` and `--os-region`
# Lease Management
Chameleon requires that a lease is created before we can boot nodes. You can
#!/usr/bin/env python
import argparse
import json
import logging
import os
import os_client_config
from blazarclient import client as blazar_client
import shade
def get_cloud_config(region=None):
"""Retrieve the config in clouds.yaml."""
config = os_client_config.OpenStackConfig()
return config.get_one('chameleon', region_name=region)
def get_shade_client(region=None):
cloud = get_cloud_config(region)
return shade.OpenStackCloud(cloud_config=cloud)
def get_blazar_client(region=None):
"""Retrieve a client to blazar based on clouds.yaml config."""
cloud_config = get_cloud_config(region)
session = cloud_config.get_session()
# blazar acces
return blazar_client.Client(1, session=session, service_type='reservation')
def do_listclouds(argv):
"""List available clouds."""
config = os_client_config.OpenStackConfig()
clouds = config.get_all()
if not clouds:
print("No cloud in the clouds.yaml definition.")
for cloud in clouds:
print(json.dumps(cloud.config, indent=4))
def do_listkeys(argv):
"""List keys in a cloud."""
shade_client = get_shade_client(argv.region)
ret = shade_client.list_keypairs()
if ret:
for k in ret:
print(json.dumps(k, indent=4))
print("No keypair found.")
def main():
parser = argparse.ArgumentParser(description='Chameleon General Helper')
parser.add_argument('--region', default=os.environ.get('OS_REGION_NAME'),
help='Region name (in clouds.yaml)')
parser.add_argument('--debug', help="Print debugging output",
subparsers = parser.add_subparsers(title='Commands', dest='command')
subparsers.required = True
# create a lease
parser_listclouds = subparsers.add_parser("list-clouds",
help="List available clouds")
parser_listkeys = subparsers.add_parser("list-keys",
help="List available keypairs")
args = parser.parse_args()
if args.debug:
logger = logging.getLogger('keystoneauth')
if __name__ == '__main__':
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment