]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
helper function to get creds based on name
authorrohitagarwalla <roagarwa@cisco.com>
Wed, 24 Aug 2011 23:05:03 +0000 (16:05 -0700)
committerrohitagarwalla <roagarwa@cisco.com>
Wed, 24 Aug 2011 23:05:03 +0000 (16:05 -0700)
quantum/plugins/cisco/common/cisco_exceptions.py
quantum/plugins/cisco/db/l2network_db.py

index 02f4078daa1a80c9ff40229f9ca9d3836c6167f3..5e9eb77da6f120e95df21a1e1413e300230b572b 100644 (file)
@@ -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 " \
index b97ce5efaba4ba6a84379421c52d18e9855126aa..81557264abc51b8dc1bc49416de43391a53bc51f 100644 (file)
@@ -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()