summaryrefslogtreecommitdiff
path: root/iotronic/db/sqlalchemy/api.py
diff options
context:
space:
mode:
Diffstat (limited to 'iotronic/db/sqlalchemy/api.py')
-rw-r--r--iotronic/db/sqlalchemy/api.py81
1 files changed, 81 insertions, 0 deletions
diff --git a/iotronic/db/sqlalchemy/api.py b/iotronic/db/sqlalchemy/api.py
index 50132ca..275f674 100644
--- a/iotronic/db/sqlalchemy/api.py
+++ b/iotronic/db/sqlalchemy/api.py
@@ -761,3 +761,84 @@ class Connection(api.Connection):
761 761
762 ref.update(values) 762 ref.update(values)
763 return ref 763 return ref
764
765 # EXPOSED SERVICE api
766
767 def get_exposed_service_by_board_uuid(self, board_uuid):
768 query = model_query(
769 models.ExposedService).filter_by(
770 board_uuid=board_uuid)
771 try:
772 return query.one()
773 except NoResultFound:
774 raise exception.ExposedServiceNotFound()
775
776 def create_exposed_service(self, values):
777 # ensure defaults are present for new services
778 if 'uuid' not in values:
779 values['uuid'] = uuidutils.generate_uuid()
780 exp_serv = models.ExposedService()
781 exp_serv.update(values)
782 try:
783 exp_serv.save()
784 except db_exc.DBDuplicateEntry:
785 raise exception.ServiceAlreadyExposed(uuid=values['uuid'])
786 return exp_serv
787
788 def update_exposed_service(self, service_exposed_id, values):
789
790 if 'uuid' in values:
791 msg = _("Cannot overwrite UUID for an existing Service.")
792 raise exception.InvalidParameterValue(err=msg)
793 try:
794 return self._do_update_exposed_service(
795 service_exposed_id, values)
796
797 except db_exc.DBDuplicateEntry as e:
798 if 'name' in e.columns:
799 raise exception.DuplicateName(name=values['name'])
800 elif 'uuid' in e.columns:
801 raise exception.ServiceAlreadyExists(uuid=values['uuid'])
802 else:
803 raise e
804
805 def get_exposed_service_by_uuids(self, board_uuid, service_uuid):
806 query = model_query(
807 models.ExposedService).filter_by(
808 board_uuid=board_uuid).filter_by(
809 service_uuid=service_uuid)
810 try:
811 return query.one()
812 except NoResultFound:
813 raise exception.ExposedServiceNotFound(uuid=service_uuid)
814
815 def destroy_exposed_service(self, exposed_service_id):
816
817 session = get_session()
818 with session.begin():
819 query = model_query(models.ExposedService, session=session)
820 query = add_identity_filter(query, exposed_service_id)
821 try:
822 query.delete()
823
824 except NoResultFound:
825 raise exception.ExposedServiceNotFound()
826
827 def get_exposed_service_list(self, board_uuid):
828 query = model_query(
829 models.ExposedService).filter_by(
830 board_uuid=board_uuid)
831 return query.all()
832
833 def _do_update_exposed_service(self, service_id, values):
834 session = get_session()
835 with session.begin():
836 query = model_query(models.ExposedService, session=session)
837 query = add_identity_filter(query, service_id)
838 try:
839 ref = query.with_lockmode('update').one()
840 except NoResultFound:
841 raise exception.ServiceNotFoundNotFound(uuid=service_id)
842
843 ref.update(values)
844 return ref