def do_destroy(args): """Destroy a droplet based on configuration""" config = Configuration() if not config.read_config(args.config_file): return False destroy(config) return True
def do_create(args): """Create a droplet based on configuration""" config = Configuration() if not config.read_config(args.config_file): return False create(config) return True
for action in actions: action.wait() print 'Action {} is {}'.format(action.type, action.status) # Now get and upate the DNS record -- assumes a single A record, which we # delete domains = manager.get_all_domains() for domain in domains: if domain.name == config.domain_name: records = domain.get_records() for record in records: if record.type == 'A': record.destroy() print 'Destroy of {} complete!'.format(config.domain_name) return True if __name__ == '__main__': # Use argparse, even though just getting on arg for now parser = argparse.ArgumentParser() parser.add_argument('config_file', help='configuration file to use') args = parser.parse_args() # Read config file config = Configuration() if not config.read_config(args.config_file): sys.exit(1) destroy(config)
# Main loop @atexit.register def cleanup(): debug_print("Closing devices and database...") device_handle.close() db_cursor.close() if __name__ == "__main__": if len(sys.argv) < 2: sys.exit("Not enough arguments. Usage: %s <configuration file>") random.seed() instance_conf.read_config(sys.argv[1]) # Open database db = MySQLdb.connect(host=instance_conf.db_host, port=instance_conf.db_port, db=instance_conf.db_database, user=instance_conf.db_username, passwd=instance_conf.db_password) db_cursor = db.cursor() # Open device for k, v in instance_conf.devices: device_arr[k] = (serial.Serial(k), ReadDeviceThread()) device_arr[k][1].set_device_handle(device_handle) device_arr[k][1].set_data_buffer(data_buffer) device_arr[k][1].set_data_buffer_lock(data_buffer_lock) device_arr[k][1].start() debug_print("Device running in thread: %s" % device_arr[k][1].getName())