Commit 8d3ae2c2 authored by Swann Perarnau's avatar Swann Perarnau

[feature] add basic ansible appliance management

This is not ideal. Ansible has tons of issues when we launch it from
there, and the configuration become tedious.

It might be easier to deploy ansible on the frontend and rerun
everything inside, or to create a python script that deals with ansible
directly.
parent fddad11c
**/secure.yaml
*.retry
......@@ -38,3 +38,20 @@ required*
> ./chi-lease.py create
> ./chi-lease.py show
> ./chi-lease.py delete
# Appliance Management
Once a lease is active, you can manage an appliance on it using ansible. First,
output the required extra variables for ansible.
> ./chi-lease.py ansible-extra-vars <lease_name> <stack_name> <template_file> <chameleon_key> <image> > myextravars
Then call the ansible playbooks.
> ansible-playbook -e @myextravars --connection=local stack-create.yaml
Use can then ssh onto the front node and run your experiments.
To destroy the stack, before deleting the lease:
> ansible-playbook -e @myextravars --connection=local stack-delete.yaml
......@@ -9,6 +9,13 @@ import os
import os_client_config
from blazarclient import client as blazar_client
import keystoneauth1
import shade
def get_cloud_config(cloud=None):
"""Retrieve the config in clouds.yaml."""
config = os_client_config.OpenStackConfig()
return config.get_one(cloud)
def get_client(cloud=None):
......@@ -94,6 +101,27 @@ def do_list(argv):
print("No leases.")
def do_ansible_extra_vars(argv):
"""Output a JSON dict with parameters for ansible config."""
cloud = get_cloud_config(argv.cloud)
client = get_client(argv.cloud)
lease_list = client.lease.list()
leases = [l for l in lease_list if l['name'] == argv.lease]
lease = leases.pop()
if leases:
print("WARNING: more than one lease with that name, using the first.")
reservation = lease['reservations'][0]
extra_vars = {'cloud_name': cloud.name,
'stack_name': argv.stack,
'template_file': os.path.abspath(argv.template),
'key_name': argv.key,
'reservation_id': reservation['id'],
'node_count': reservation['min'],
'image': argv.image
}
print(json.dumps(extra_vars, indent=4))
def main():
parser = argparse.ArgumentParser(description='Chameleon Lease Helper')
parser.add_argument('--cloud', default=os.environ.get('OS_CLOUD'),
......@@ -126,6 +154,15 @@ def main():
parser_list = subparsers.add_parser("list", help="List all leases")
parser_list.set_defaults(func=do_list)
parser_extra = subparsers.add_parser("ansible-extra-vars",
help="generate extra-vars file")
parser_extra.add_argument("lease", help="Lease name")
parser_extra.add_argument("stack", help="Stack name")
parser_extra.add_argument("template", help="appliance template")
parser_extra.add_argument("key", help="User key name")
parser_extra.add_argument("image", help="Image name")
parser_extra.set_defaults(func=do_ansible_extra_vars)
args = parser.parse_args()
if args.debug:
logger = logging.getLogger('keystoneauth')
......
# ansible
---
- hosts: localhost
tasks:
- name: make stack available
os_stack:
name: "{{ stack_name }}"
state: present
cloud: "{{ cloud_name }}"
template: "{{ template_file }}"
parameters:
key_name: "{{ key_name }}"
reservation_id: "{{ reservation_id }}"
node_count: "{{ node_count }}"
image: "{{ image }}"
# ansible
---
- hosts: localhost
tasks:
- name: make stack unavailable
os_stack:
name: "{{ stack_name }}"
state: absent
cloud: "{{ cloud_name }}"
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