Esempio n. 1
0
def add_credential(tenant_id, credential_name, user_name, password):
    """Adds a qos to tenant association."""
    session = db.get_session()
    try:
        cred = (session.query(network_models_v2.Credential).filter_by(
            tenant_id=tenant_id).filter_by(
                credential_name=credential_name).one())
        raise c_exc.CredentialAlreadyExists(credential_name=credential_name,
                                            tenant_id=tenant_id)
    except exc.NoResultFound:
        cred = network_models_v2.Credential(tenant_id, credential_name,
                                            user_name, password)
        session.add(cred)
        session.flush()
        return cred
Esempio n. 2
0
def add_credential(credential_name, user_name, password, type):
    """Create a credential."""
    session = db.get_session()
    try:
        cred = (session.query(network_models_v2.Credential).filter_by(
            credential_name=credential_name).one())
        raise c_exc.CredentialAlreadyExists(credential_name=credential_name)
    except exc.NoResultFound:
        cred = network_models_v2.Credential(
            credential_id=uuidutils.generate_uuid(),
            credential_name=credential_name,
            user_name=user_name,
            password=password,
            type=type)
        session.add(cred)
        session.flush()
        return cred