+
+
+class DeploymentManagerSqlAlchemyRepository(DeploymentManagerRepository):
+ def __init__(self, session):
+ super().__init__()
+ self.session = session
+
+ def _add(self, deployment_manager: ocloud.DeploymentManager):
+ self.session.add(deployment_manager)
+
+ def _get(self, deployment_manager_id) -> ocloud.DeploymentManager:
+ return self.session.query(ocloud.DeploymentManager).filter_by(
+ deploymentManagerId=deployment_manager_id).first()
+
+ def _list(self, *args, **kwargs) -> Tuple[int,
+ List[ocloud.DeploymentManager]]:
+ size = kwargs.pop('limit') if 'limit' in kwargs else None
+ offset = kwargs.pop('start') if 'start' in kwargs else 0
+
+ result = self.session.query(ocloud.DeploymentManager).filter(
+ *args).order_by('deploymentManagerId')
+ count = result.count()
+ if size is not None and size != -1:
+ return (count, result.limit(size).offset(offset))
+ return (count, result)
+
+ def _update(self, deployment_manager: ocloud.DeploymentManager):
+ self.session.add(deployment_manager)
+
+
+class SubscriptionSqlAlchemyRepository(SubscriptionRepository):
+ def __init__(self, session):
+ super().__init__()
+ self.session = session
+
+ def _add(self, subscription: subscription_obj.Subscription):
+ self.session.add(subscription)
+
+ def _get(self, subscription_id) -> subscription_obj.Subscription:
+ return self.session.query(subscription_obj.Subscription).filter_by(
+ subscriptionId=subscription_id).first()
+
+ def _list(self, *args, **kwargs) -> \
+ Tuple[int, List[subscription_obj.Subscription]]:
+ size = kwargs.pop('limit') if 'limit' in kwargs else None
+ offset = kwargs.pop('start') if 'start' in kwargs else 0
+
+ result = self.session.query(subscription_obj.Subscription).filter(
+ *args).order_by('subscriptionId')
+ count = result.count()
+ if size is not None and size != -1:
+ return (count, result.limit(size).offset(offset))
+ return (count, result)
+
+ def _update(self, subscription: subscription_obj.Subscription):
+ self.session.add(subscription)
+
+ def _delete(self, subscription_id):
+ self.session.query(subscription_obj.Subscription).filter_by(
+ subscriptionId=subscription_id).delete()