#!/usr/bin/python import lxd_common as lc t0 = lc.time() DOMAIN = lc.sys.argv[1] HOST = lc.sys.argv[2] VM_ID = lc.sys.argv[3] client = lc.Client() container = client.containers.get(DOMAIN) lc.log_function(lc.separator) dicc = lc.xml_start(container.config['user.xml']) # CONTAINER_SHUTDOWN signal = lc.sys.argv[4].split("/")[-1] if signal == "cancel": container.stop(force=True, wait=True) elif signal == "shutdown": container.stop(wait=True) else: lc.log_function("Unknown kill VM signal given", 'e') lc.sys.exit(1) lc.container_wipe(container, dicc) lc.clock(t0)
lc.log_function('INFO', 40 * "#") # INITIALIZE_CONTAINER init = {'name': VM_NAME, 'source': {'type': 'none'}} try: container = client.containers.create(init, wait=True) except LXDAPIException as lxdapie: # probably this container already exists lc.log_function('INFO', 'container: ' + VM_NAME + ' ' + str(lxdapie)) container = client.containers.get(VM_NAME) # BOOT_CONTAINER apply_profile(profile, container) try: container.start(wait=True) container.config['user.xml'] # validate config except LXDAPIException as lxdapie: if container.status == 'Running': container.stop(wait=True) DISK_TYPE = profile['DISK_TYPE'] DISK_TARGET = profile['DISK_TARGET'] num_hdds = profile['num_hdds'] lc.container_wipe(num_hdds, container, DISK_TARGET, DISK_TYPE) lc.log_function('ERROR', 'container: ' + str(lxdapie)) lc.sys.exit(1) lc.vnc_start(VM_ID, profile['dicc']) lc.clock(t0, VM_ID) print VM_NAME