Commit 4fd66b54 authored by Ioannis Tsafaras's avatar Ioannis Tsafaras
Browse files

Implement logic for image creation in service_vm_manager

parent 726bed16
......@@ -26,7 +26,7 @@ class Manager:
self.ansible_inventory.add_group(ansible_group)
all_group.add_child_group(ansible_group)
def run_playbook(self, playbook_file, tags=None):
def run_playbook(self, playbook_file, only_tags=None, skip_tags=None):
"""
Run the playbook_file using created inventory and tags specified
:return:
......@@ -35,7 +35,7 @@ class Manager:
playbook_cb = callbacks.PlaybookCallbacks(verbose=utils.VERBOSITY)
runner_cb = callbacks.PlaybookRunnerCallbacks(stats, verbose=utils.VERBOSITY)
pb = PlayBook(playbook=playbook_file, inventory=self.ansible_inventory, stats=stats,
callbacks=playbook_cb,
runner_callbacks=runner_cb, only_tags=tags)
callbacks=playbook_cb, runner_callbacks=runner_cb,
only_tags=only_tags, skip_tags=skip_tags)
playbook_result = pb.run()
return playbook_result
......@@ -36,13 +36,12 @@ def test_playbook_run_minimal_manager():
# Initialize the ansible manager and run a playbook
manager = MiniManager("test_host", "test_group", "/path/to/private/keys")
manager.run_playbook(playbook_file="/path/to/playbook.yml",
tags=["touch"])
only_tags=["touch"], skip_tags=["touch-2"])
# Check playbook was called with the correct arguements
pb.assert_called_with(stats='c', only_tags=['touch'],
callbacks='a',
pb.assert_called_with(only_tags=["touch"], skip_tags=["touch-2"],
stats='c', callbacks='a', runner_callbacks='b',
playbook='/path/to/playbook.yml',
runner_callbacks='b',
inventory=mock_ansible.inventory.Inventory.return_value)
......@@ -64,8 +63,7 @@ def test_playbook_run():
# Check that playbook was called with the correct argumenets
pb.asset_called_with(stats='c', only_tags=['touch'], skip_tags=["touch-2"], callbacks='a',
playbook='/path/to/playbook.yml', runner_callbacks='b',
inventory=manager.inventory
)
inventory=manager.inventory)
if __name__ == "__main__":
......
......@@ -44,6 +44,8 @@
- name: Create user fixture
template: src=users.yaml.j2 dest={{ repository_download_path}}/okeanos-LoD/webapp/backend/fixtures/users.yaml
tags: create-user
- name: Load user from fixtures
django_manage: command=loaddata app_path={{ repository_download_path }}/okeanos-LoD/webapp/ fixtures=users.yaml
tags: create-user
#!/bin/bash
# Log file path
LOGFILE="/root/ansible-vm-init.log"
log(){
message=$1
echo "$(date): $message" >> $LOGFILE
}
start(){
# Initialize VM with ansible
log "Initializing VM with ansible"
ansible-playbook -i "localhost," -c local /var/www/okeanos-LoD/webapp/ansible/playbooks/image-configure.yml --tags "image-configure" >> $LOGFILE 2>&1
retVal=$?
if [ $retVal -eq 0 ]
then
log "Ansible VM initialization successful"
rm /etc/init.d/ansible-vm-init
update-rc.d ansible-vm-init remove
else
log "Ansible VM initialization failed with return value $retVal"
fi
return 0
}
case "$1" in
start)
start
;;
*)
echo "Usage: $0 start"
esac
......@@ -37,7 +37,8 @@ class ServiceVMManager(object):
def service_vm_create(self, vm_name='Service VM',
vcpus=4, ram=4096, disk=40,
project_name='lambda.grnet.gr',
private_key_path=None, public_key_path=None):
private_key_path=None, public_key_path=None,
only_tags=None, skip_tags=None):
"""
Creates the service vm and installs the relevant s/w.
:return: ansible result
......@@ -54,7 +55,8 @@ class ServiceVMManager(object):
self._patch_auth_token_ansible()
ansible_manager = Manager(hostname, group, private_key_path)
ansible_result = ansible_manager.run_playbook(
playbook_file=os.path.join(ansible_path, 'playbooks', 'setup.yml'))
playbook_file=os.path.join(ansible_path, 'playbooks', 'setup.yml'),
only_tags=only_tags, skip_tags=skip_tags)
self._clean_up_token_ansible_patch()
return ansible_result
......@@ -122,7 +124,7 @@ if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Lambda service VM provisioning')
parser.add_argument('--action', type=str, dest='action', required=True,
choices=['create', 'start', 'stop', 'destroy'])
choices=['create', 'start', 'stop', 'destroy', 'image_creation'])
parser.add_argument('--auth_token', type=str, dest='auth_token', required=False)
parser.add_argument('--vm_id', type=int, dest='vm_id')
parser.add_argument('--vm_name', type=str, dest='vm_name', required=False,
......@@ -145,6 +147,13 @@ if __name__ == "__main__":
project_name=args.project_name,
private_key_path=args.private_key_path,
public_key_path=args.public_key_path)
elif args.action == 'image_creation':
sm.service_vm_create(vm_name=args.vm_name,
vcpus=args.vcpus, ram=args.ram, disk=args.disk,
project_name=args.project_name,
private_key_path=args.private_key_path,
public_key_path=args.public_key_path,
skip_tags=['image-configure', 'create-user'])
elif args.vm_id is None:
raise ValueError("VM id must be specified")
else:
......
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