From: rohitagarwalla Date: Wed, 24 Aug 2011 20:36:38 +0000 (-0700) Subject: putting in db support for creds and qos X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=b5fd8f8075302b3aa56a47d98b56e922022fd803;p=openstack-build%2Fneutron-build.git putting in db support for creds and qos --- diff --git a/quantum/plugins/cisco/common/cisco_exceptions.py b/quantum/plugins/cisco/common/cisco_exceptions.py index d257f5ee1..0ef83528c 100644 --- a/quantum/plugins/cisco/common/cisco_exceptions.py +++ b/quantum/plugins/cisco/common/cisco_exceptions.py @@ -100,11 +100,26 @@ class QoSLevelInvalidDelete(exceptions.QuantumException): "for tenant %(tenant_id)s since association exists") +class QosNameAlreadyExists(exceptions.QuantumException): + message = _("QoS level with name %(qos_name)s already exists " \ + "for tenant %(tenant_id)s") + + class CredentialNotFound(exceptions.QuantumException): message = _("Credential %(credential_id)s could not be found " \ "for tenant %(tenant_id)s") +class CredentialNameNotFound(exceptions.QuantumException): + message = _("Credential %(credential_name)s could not be found " \ + "for tenant %(tenant_id)s") + + +class CredentialAlreadyExists(exceptions.QuantumException): + message = _("Credential %(credential_id)s already exists " \ + "for tenant %(tenant_id)s") + + class NexusPortBindingNotFound(exceptions.QuantumException): """NexusPort Binding is not present""" message = _("Nexus Port Binding %(port_id) is not present") diff --git a/quantum/plugins/cisco/db/l2network_db.py b/quantum/plugins/cisco/db/l2network_db.py index 6196fe17e..4626fcd0d 100644 --- a/quantum/plugins/cisco/db/l2network_db.py +++ b/quantum/plugins/cisco/db/l2network_db.py @@ -24,8 +24,8 @@ from quantum.plugins.cisco.common import cisco_exceptions as c_exc import l2network_models import logging as LOG import quantum.plugins.cisco.db.api as db -from quantum.plugins.cisco.db import nexus_db as ndb -from quantum.plugins.cisco.db import ucs_db as udb +import quantum.plugins.cisco.db.nexus_db as ndb +import quantum.plugins.cisco.db.ucs_db as udb def initialize(): @@ -132,6 +132,19 @@ def reserve_vlanid(): raise c_exc.VlanIDNotAvailable() +def get_all_vlanids_used(): + """Gets all the vlanids used""" + LOG.debug("get_all_vlanids() called") + session = db.get_session() + try: + vlanids = session.query(l2network_models.VlanID).\ + filter_by(vlan_used=True).\ + all() + return vlanids + except exc.NoResultFound: + return [] + + def get_all_vlan_bindings(): """Lists all the vlan to network associations""" LOG.debug("get_all_vlan_bindings() called") @@ -369,3 +382,162 @@ def update_pp_binding(tenantid, ppid, newtenantid=None, newportid=None, except exc.NoResultFound: raise c_exc.PortProfileNotFound(tenant_id=tenantid, portprofile_id=ppid) + + +def get_all_qoss(tenant_id): + """Lists all the qos to tenant associations""" + LOG.debug("get_all_qoss() called") + session = db.get_session() + try: + qoss = session.query(l2network_models.QoS).\ + filter_by(tenant_id=tenant_id).\ + all() + return qoss + except exc.NoResultFound: + return [] + + +def get_qos(tenant_id, qos_id): + """Lists the qos given a tenant_id and qos_id""" + LOG.debug("get_qos() called") + session = db.get_session() + try: + qos = session.query(l2network_models.QoS).\ + filter_by(tenant_id=tenant_id).\ + filter_by(uuid=qos_id).\ + one() + return qos + except exc.NoResultFound: + raise c_exc.QoSNotFound(qos_id=qos_id, + tenant_id=tenant_id) + + +def add_qos(tenant_id, qos_name, qos_desc): + """Adds a qos to tenant association""" + LOG.debug("add_qos() called") + session = db.get_session() + try: + qos = session.query(l2network_models.QoS).\ + filter_by(tenant_id=tenant_id).\ + filter_by(name=qos_name).\ + one() + raise c_exc.QosNameAlreadyExists(qos_name=qos_name, + tenant_id=tenant_id) + except exc.NoResultFound: + qos = l2network_models.QoS(tenant_id, qos_name, qos_desc) + session.add(qos) + session.flush() + return qos + + +def remove_qos(tenant_id, qos_id): + """Removes a qos to tenant association""" + session = db.get_session() + try: + qos = session.query(l2network_models.QoS).\ + filter_by(tenant_id=tenant_id).\ + filter_by(uuid=qos_id).\ + one() + session.delete(qos) + session.flush() + return qos + except exc.NoResultFound: + pass + + +def update_qos(tenant_id, qos_id, new_qos_name=None): + """Updates a qos to tenant association""" + session = db.get_session() + try: + qos = session.query(l2network_models.QoS).\ + filter_by(tenant_id=tenant_id).\ + filter_by(uuid=qos_id).\ + one() + if new_qos_name: + qos["name"] = new_qos_name + session.merge(qos) + session.flush() + return qos + except exc.NoResultFound: + raise c_exc.QoSNotFound(qos_id=qos_id, + tenant_id=tenant_id) + + +def get_all_credentials(tenant_id): + """Lists all the creds for a tenant""" + session = db.get_session() + try: + creds = session.query(l2network_models.Credential).\ + filter_by(tenant_id=tenant_id).\ + all() + return creds + except exc.NoResultFound: + return [] + + +def get_credential(tenant_id, credential_name): + """Lists the creds for given a cred_id and tenant_id""" + session = db.get_session() + try: + cred = session.query(l2network_models.Credential).\ + filter_by(tenant_id=tenant_id).\ + filter_by(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() + try: + cred = session.query(l2network_models.Credential).\ + filter_by(tenant_id=tenant_id).\ + filter_by(name=credential_name).\ + one() + raise c_exc.CredentialAlreadyExists(credential_name=credential_name, + tenant_id=tenant_id) + except exc.NoResultFound: + cred = l2network_models.Credential(tenant_id, + credential_name, user_name, password) + session.add(cred) + session.flush() + return cred + + +def remove_credential(tenant_id, credential_name): + """Removes a credential from a tenant""" + session = db.get_session() + try: + cred = session.query(l2network_models.Credential).\ + filter_by(tenant_id=tenant_id).\ + filter_by(name=credential_name).\ + one() + session.delete(cred) + session.flush() + return cred + except exc.NoResultFound: + pass + + +def update_credential(tenant_id, credential_name, + new_user_name=None, new_password=None): + """Updates a credential for a tenant""" + session = db.get_session() + try: + cred = session.query(l2network_models.Credential).\ + filter_by(tenant_id=tenant_id).\ + filter_by(name=credential_name).\ + one() + if new_user_name: + cred["user_name"] = new_user_name + if new_password: + cred["password"] = new_password + session.merge(cred) + session.flush() + return cred + except exc.NoResultFound: + raise c_exc.CredentialNameNotFound(credential_name=credential_name, + tenant_id=tenant_id) diff --git a/quantum/plugins/cisco/db/l2network_models.py b/quantum/plugins/cisco/db/l2network_models.py index 52039ff61..bcfdd7768 100644 --- a/quantum/plugins/cisco/db/l2network_models.py +++ b/quantum/plugins/cisco/db/l2network_models.py @@ -145,3 +145,45 @@ class PortProfileBinding(BASE, L2NetworkBase): def __repr__(self): return "" % \ (self.tenant_id, self.port_id, self.portprofile_id, self.default) + + +class QoS(BASE, L2NetworkBase): + """Represents QoS for a tenant""" + __tablename__ = 'QoS' + + uuid = Column(String(255), primary_key=True) + tenant_id = Column(String(255)) + name = Column(String(255)) + desc = Column(String(255)) + + def __init__(self, tenant_id, qos_name, qos_desc): + self.uuid = uuid.uuid4() + self.tenant_id = tenant_id + self.name = qos_name + self.desc = qos_desc + + def __repr__(self): + return "" % \ + (self.tenant_id, self.name, self.desc) + + +class Credential(BASE, L2NetworkBase): + """Represents credentials for a tenant""" + __tablename__ = 'QoS' + + uuid = Column(String(255)) + tenant_id = Column(String(255), primary_key=True) + name = Column(String(255), primary_key=True) + user_name = Column(String(255)) + password = Column(String(255)) + + def __init__(self, tenant_id, name, user_name, password): + self.uuid = uuid.uuid4() + self.tenant_id = tenant_id + self.name = name + self.user_name = user_name + self.password = password + + def __repr__(self): + return "" % \ + (self.tenant_id, self.name, self.user_name, self.password)