from load.projects.cloud.loadtesting.server.api.common.utils import generate_cloud_id
from load.projects.cloud.loadtesting.db.tables import AmmoTable


def create_ammo(db, name, folder_id, storage=None):
    ammo = AmmoTable()
    ammo.folder_id = folder_id
    ammo.id = generate_cloud_id()
    ammo.s3_name = name
    if storage is not None:
        ammo.storage_id = storage.id
        ammo.storage = storage
    db.ammo.add(ammo)
    return ammo
