From: rohitagarwalla Date: Wed, 24 Aug 2011 23:05:03 +0000 (-0700) Subject: helper function to get creds based on name X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=8b50cb07f6d67518a0495776ee50e645e271c88f;p=openstack-build%2Fneutron-build.git helper function to get creds based on name --- diff --git a/quantum/plugins/cisco/common/cisco_exceptions.py b/quantum/plugins/cisco/common/cisco_exceptions.py index 02f4078da..5e9eb77da 100644 --- a/quantum/plugins/cisco/common/cisco_exceptions.py +++ b/quantum/plugins/cisco/common/cisco_exceptions.py @@ -114,6 +114,12 @@ class CredentialNotFound(exceptions.QuantumException): "for tenant %(tenant_id)s") +class CredentialNameNotFound(exceptions.QuantumException): + """Credential Name could not be found""" + message = _("Credential %(credential_name)s could not be found " \ + "for tenant %(tenant_id)s") + + class CredentialAlreadyExists(exceptions.QuantumException): """Credential ID already exists""" message = _("Credential %(credential_id)s already exists " \ diff --git a/quantum/plugins/cisco/db/l2network_db.py b/quantum/plugins/cisco/db/l2network_db.py index b97ce5efa..81557264a 100644 --- a/quantum/plugins/cisco/db/l2network_db.py +++ b/quantum/plugins/cisco/db/l2network_db.py @@ -408,7 +408,7 @@ def get_qos(tenant_id, qos_id): one() return qos except exc.NoResultFound: - raise c_exc.QoSNotFound(qos_id=qos_id, + raise c_exc.QosNotFound(qos_id=qos_id, tenant_id=tenant_id) @@ -459,7 +459,7 @@ def update_qos(tenant_id, qos_id, new_qos_name=None): session.flush() return qos except exc.NoResultFound: - raise c_exc.QoSNotFound(qos_id=qos_id, + raise c_exc.QosNotFound(qos_id=qos_id, tenant_id=tenant_id) @@ -489,6 +489,20 @@ def get_credential(tenant_id, credential_id): tenant_id=tenant_id) +def get_credential_name(tenant_id, credential_name): + """Lists the creds for given a cred_name and tenant_id""" + session = db.get_session() + try: + cred = session.query(l2network_models.Credential).\ + filter_by(tenant_id=tenant_id).\ + filter_by(credential_name=credential_name).\ + one() + return cred + except exc.NoResultFound: + raise c_exc.CredentialNameNotFound(credential_name=credential_name, + tenant_id=tenant_id) + + def add_credential(tenant_id, credential_name, user_name, password): """Adds a qos to tenant association""" session = db.get_session()