def add_remove_brick(volume, action):
    _db.table_cleanup_bricks(volume=volume)

    vol_data = volumes.get(volume)
    vol = vol_data[0]

    bricks = []
    for brick in vol['bricks']:
        bricks.append((vol['name'], brick))

    _db.bricks_add(bricks)
    _db.update_volume(vol['name'], "num_bricks", len(bricks))
def volume_create(volume):
    vol_data = volumes.get(volume)
    vol = vol_data[0]
    vols = (vol["uuid"],
            vol["name"],
            vol["type"],
            vol["status"],
            vol["num_bricks"],
            vol["transport"])
    _db.volumes_add([vols])
    bricks = []
    for brick in vol['bricks']:
        bricks.append((vol['name'], brick))

    _db.bricks_add(bricks)
def flush_and_regenerate(param=None):
    _db.table_cleanup_all()
    vols = []
    vols_data = volumes.get()

    for vol in vols_data:
        bricks = []
        vols.append((vol["uuid"],
                     vol["name"],
                     vol["type"],
                     vol["status"],
                     vol["num_bricks"],
                     vol["transport"]))

        for brick in vol['bricks']:
            bricks.append((vol['name'], brick))

    _db.volumes_add(vols)
    _db.bricks_add(bricks)