#!/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)
#!/usr/bin/python import lxd_common as lc t0 = lc.time() client = lc.Client() VM_ID = lc.sys.argv[1] container = client.containers.get('one-' + VM_ID) # READ_XML dicc = lc.xml_start(container.config['user.xml']) DISK_TYPE = lc.xml_query_list('DISK/TYPE', dicc) CONTEXT_DISK_ID = lc.xml_query_item('CONTEXT/DISK_ID', dicc) DISK_TARGET = lc.xml_query_list('DISK/TARGET', dicc) # no need to read unless num_hdds > 1 # CONTAINER_SHUTDOWN if len(lc.sys.argv) == 3: container.stop(force=True, wait=True) else: container.stop(wait=True) # CLEANING num_hdds = len(DISK_TYPE) lc.container_wipe(num_hdds, container, DISK_TARGET, CONTEXT_DISK_ID, DISK_TYPE) lc.clock(t0, VM_ID)
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
lc.log_function(lc.separator) # INITIALIZE_CONTAINER # xml is passed by opennebula as argument ex. deployment.0 profile = create_profile(lc.sys.argv[1]) VM_NAME = 'one-' + profile['VM_ID'] init = {'name': VM_NAME, 'source': {'type': 'none'}} try: container = client.containers.create(init, wait=True) except lc.LXDAPIException as lxdapie: # probably this container already exists container = client.containers.get(VM_NAME) if container.status == 'Running': lc.log_function("A container with the same ID is already running", 'e') lc.sys.exit(1) apply_profile(profile, container) # BOOT_CONTAINER try: container.start(wait=True) except lc.LXDAPIException as lxdapie: if container.status == 'Running': container.stop(wait=True) lc.container_wipe(container, profile) lc.log_function(lxdapie, 'e') lc.sys.exit(1) lc.vnc_start(profile['VM_ID'], profile['VNC_PORT'], profile['VNC_PASSWD']) lc.clock(t0) print VM_NAME