def get_image(driver, cloud_name, platform='amd'): util.message("getting default image", "info") provider, xxx, region, default_ssh_key, cloud_keys = cloud.read( cloud_name, True) sql = "SELECT image_id, image_type FROM images \n" + \ " WHERE provider = %s AND region = %s AND platform = %s AND is_default = 1" data = cloud.exec_sql(sql, [provider, region, platform]) if data == None or data == []: util.message("Image not known for " + str(cloud_name) + \ ", " + str(region) + ", " + str(platform) + ")", "error") return (None, None) image_id = str(data[0]) image_type = str(data[1]) if provider == 'aws': images = driver.list_images(ex_image_ids=image_id.split()) else: images = driver.list_images() for i in images: if i.id == image_id: util.message("image_id - " + image_type + " : " + image_id, "info") return (i, image_type) util.message("Cannot Locate image '" + str(image_id) + "'", "error") return (None, None)
def create(name, service): sql = "INSERT INTO clusters \n" + \ " (name, service, created_utc, updated_utc) \n" + \ "VALUES (%s, %s, %s, %s)" now = util.sysdate() rc = cloud.exec_sql(sql, [name, service, now, now]) return (rc)
def read(key_name): sql = "SELECT username, pem_file, \n" + \ " created_utc, updated_utc \n" + \ " FROM keys WHERE name = %s" data = cloud.exec_sql(sql, [key_name]) return (str(data[0]), str(data[1]))
def update(name, username, pem_file): if not os.path.isfile(pem_file): util.message("WARNING: pem_file not found", "info") sql = "UPDATE keys SET username = %s, pem_file = %s, updated_utc = %s \n" + \ " WHERE name = %s" rc = cloud.exec_sql(sql, [username, pem_file, util.sysdate(), name]) return (rc)
def upsert(cloud_name, machine_id, describe): sql = "SELECT count(*) FROM nodes WHERE machine_id = %s" data = cloud.exec_sql(sql, [machine_id]) kount = data[0] now = util.sysdate() if kount == 0: sql = "INSERT INTO nodes (cloud, machine_id, \n" + \ " describe, created_utc, updated_utc) \n" + \ "VAlUES (%s, %s, %s, %s, %s)" cloud.exec_sql(sql, [cloud_name, machine_id, str(describe), now, now]) else: sql = "UPDATE nodes SET cloud = %s, describe = %s, \n" + \ " updated_utc = %s WHERE machine_id = %s" cloud.exec_sql(sql, [cloud_name, str(describe), now, machine_id]) return
def insert(name, username, pem_file): now = util.sysdate() if not os.path.isfile(pem_file): util.message("WARNING: pem_file not found", "info") sql = "INSERT INTO keys (name, username, pem_file, \n" + \ " created_utc, updated_utc) VALUES (%s, %s, %s, %s, %s)" rc = cloud.exec_sql(sql, [name, username, pem_file, now, now]) return (rc)
def get_size(provider, flavor): sql = "SELECT size FROM flavors WHERE provider = %s AND flavor = %s" data = cloud.exec_sql(sql, [provider, flavor]) size = flavor if data == None or data == []: pass else: size = str(data[0]) util.message( "translating flavor " + str(flavor) + " to size " + str(size), "info") return (size)
def delete(name): sql = "DELETE FROM keys WHERE name = %s" rc = cloud.exec_sql(sql, [name]) return (rc)
def delete(machine_id): sql = "DELETE FROM nodes WHERE machine_id = %s" cloud.exec_sql(sql, [machine_id]) return
def delete(name): sql = "DELETE FROM clusters WHERE name = %s" cloud.exec_sql(sql, [name]) return
def update(name): sql = "UPDATE clusters SET updated_utc = %s WHERE name = %s" cloud.exec_sql(sql, [util.sysdate(), name]) return