def create_root_drive(name, path_to_key, image_description=None, region='us-west-2', orig_image_id="ami-5189a661", install_kwargs={}, verbose=True, auto_terminate=True): ''' Creates the root drive for AstroCompute instances. Parameters ---------- name : str Name of the image. Note that the time will be appended to the name. path_to_key : str Path to the key to link to the VM. Note this key must be attached to you AWS account. image_description : str, optional Description of the created image. region : str, optional Region to create image. orig_image_id must be correct for the region. orig_image_id : str, optional Image ID to base the new image on. This defaults to ubuntu 14.04. Note the ami changes with the chosen region. install_kwargs : dict, optional Passed to install_packages. verbose : bool, optional Enables output of the process. auto_terminate : bool, optional When enabled, terminates the instance after the image has been created. ''' key_name = path_to_key.split("/")[-1].rstrip(".pem") name += "_"+timestring() instance = launch(key_name, region=region, image_id=orig_image_id) if verbose: print("Instance status: " + str(instance.state)) try: install_packages(instance, path_to_key, verbose=verbose, **install_kwargs) except Exception, e: warnings.warn("Something went wrong. Terminating instance.") instance.terminate() raise e
queue.write(mess) print("Launching instance") # Launch an instance with the worker script user_data = WORKER_SCRIPT \ % {"USER": "******", "QUEUE_NAME": proc_name, "REGION": region, "KEY": key, "SECRET": secret, "RESP_QUEUE_NAME": proc_name + "_response", "CUSTOM_LINES": ''} inst = launch(key_name=None, region=region, image_id="ami-b7fc75d7", user_data=user_data) # sleep 1 min t0 = time() while time() < t0 + 60: update = inst.update() print update if update in [u"stopping", u"stopped"]: print("Instance shutting down.") break sleep(5) else: print("Reached time limit. Terminating after 1 min.") inst.terminate()
mess = queue.new_message(body=json.dumps(mess)) queue.write(mess) print("Launching instance") # Launch an instance with the worker script user_data = WORKER_SCRIPT \ % {"USER": "******", "QUEUE_NAME": proc_name, "REGION": region, "KEY": key, "SECRET": secret, "RESP_QUEUE_NAME": proc_name + "_response", "CUSTOM_LINES": ''} inst = launch(key_name=None, region=region, image_id="ami-54869e35", user_data=user_data) # sleep 1 min t0 = time() while time() < t0 + 60: update = inst.update() print update if update in [u"stopping", u"stopped"]: print("Instance shutting down.") break sleep(5) else: print("Reached time limit. Terminating after 1 min.") inst.terminate()