From 4f985d4f257e1231e4ff4a0cf3275aae355d0b6d Mon Sep 17 00:00:00 2001 From: Swann Perarnau Date: Mon, 2 Jul 2018 14:06:06 -0500 Subject: [PATCH] [fix] Use metadata to map instances to lease The lease id recently disappeared from the availability zone info in servers. It broke the configure part of an appliance, as we were using this info to create an ansible inventory for the stack. Unfortunately, after an exchange with Chameleon staff, it became clear that this "feature" wasn't intended. We now add metadata to our appliance template, allowing us to add the arbitrary info we need to the server info. This way we can filter as we want. This should make the script more future-proof. --- chameleon-appliances/bare-template.yaml | 5 +++++ chi-appliance.py | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/chameleon-appliances/bare-template.yaml b/chameleon-appliances/bare-template.yaml index 28c81a4..64c3d30 100644 --- a/chameleon-appliances/bare-template.yaml +++ b/chameleon-appliances/bare-template.yaml @@ -38,6 +38,10 @@ parameters: default: CC-CentOS7 constraints: - custom_constraint: glance.image + server_meta: + type: json + label: Server metadata + description: Metadata to add to the servers created resources: # floating IP for frontend instance_floating_ip: @@ -64,6 +68,7 @@ resources: networks: - network: sharednet1 scheduler_hints: { reservation: { get_param: reservation_id } } + metadata: { get_param: server_meta } outputs: first_instance_ip: description: The public IP address of the first instance. Login with the command 'ssh cc@first_instance_ip'. diff --git a/chi-appliance.py b/chi-appliance.py index 05fd83c..a70092e 100755 --- a/chi-appliance.py +++ b/chi-appliance.py @@ -50,6 +50,9 @@ def do_create(argv): extra_args.update(argv.extra) extra_args['reservation_id'] = reservation['id'] extra_args['node_count'] = reservation['max'] + # add metadata to the servers + lease_meta = {'lease_name': argv.lease, 'lease_id': leases[0]['id']} + extra_args['server_meta'] = json.dumps(lease_meta) template = os.path.abspath(argv.template) try: ret = shade_client.create_stack(argv.name, template_file=template, @@ -131,8 +134,12 @@ def do_configure(argv): # appliance inventory, need to grab info about hostnames and private_ip of # all nodes remote_inventory = {'all': {'hosts': {}}} - server_list = shade_client.list_servers({'az': 'blazar_'+lease['id']}) + server_list = shade_client.list_servers() for s in server_list: + meta = s.get('metadata') + if not meta or meta.get('lease_id') != lease['id']: + continue + name = s['name'] for i in s['addresses']['sharednet1']: if i['OS-EXT-IPS:type'] == 'fixed': -- GitLab