Alessandro Pilotti 8 лет назад
Родитель
Сommit
e6aaecec6d

+ 18 - 0
coriolis/api/v1/endpoints.py

@@ -54,6 +54,24 @@ class EndpointController(api_wsgi.Controller):
             req.environ['coriolis.context'], name, endpoint_type, description,
             connection_info))
 
+    def _validate_update_body(self, body):
+        try:
+            endpoint = body["endpoint"]
+            return {k: endpoint[k] for k in endpoint.keys() &
+                    {"name", "description", "connection_info"}}
+        except Exception as ex:
+            LOG.exception(ex)
+            if hasattr(ex, "message"):
+                msg = ex.message
+            else:
+                msg = str(ex)
+            raise exception.InvalidInput(msg)
+
+    def update(self, req, id, body):
+        updated_values = self._validate_update_body(body)
+        return endpoint_view.single(req, self._endpoint_api.update(
+            req.environ['coriolis.context'], id, updated_values))
+
     def delete(self, req, id):
         try:
             self._endpoint_api.delete(req.environ['coriolis.context'], id)

+ 6 - 0
coriolis/conductor/rpc/client.py

@@ -19,6 +19,12 @@ class ConductorClient(object):
             ctxt, 'create_endpoint', name=name, endpoint_type=endpoint_type,
             description=description, connection_info=connection_info)
 
+    def update_endpoint(self, ctxt, endpoint_id, updated_values):
+        return self._client.call(
+            ctxt, 'update_endpoint',
+            endpoint_id=endpoint_id,
+            updated_values=updated_values)
+
     def get_endpoints(self, ctxt):
         return self._client.call(
             ctxt, 'get_endpoints')

+ 5 - 0
coriolis/conductor/rpc/server.py

@@ -86,6 +86,11 @@ class ConductorServerEndpoint(object):
         LOG.info("Endpoint created: %s", endpoint.id)
         return self.get_endpoint(ctxt, endpoint.id)
 
+    def update_endpoint(self, ctxt, endpoint_id, updated_values):
+        db_api.update_endpoint(ctxt, endpoint_id, updated_values)
+        LOG.info("Endpoint updated: %s", endpoint_id)
+        return self.get_endpoint(ctxt, endpoint_id)
+
     def get_endpoints(self, ctxt):
         return db_api.get_endpoints(ctxt)
 

+ 8 - 0
coriolis/db/api.py

@@ -80,6 +80,14 @@ def add_endpoint(context, endpoint):
     context.session.add(endpoint)
 
 
+@enginefacade.writer
+def update_endpoint(context, endpoint_id, updated_values):
+    endpoint = get_endpoint(context, endpoint_id)
+    for n in ["name", "description", "connection_info"]:
+        if n in updated_values:
+            setattr(endpoint, n, updated_values[n])
+
+
 @enginefacade.writer
 def delete_endpoint(context, endpoint_id):
     count = _soft_delete_aware_query(context, models.Endpoint).filter_by(

+ 4 - 0
coriolis/endpoints/api.py

@@ -13,6 +13,10 @@ class API(object):
         return self._rpc_client.create_endpoint(
             ctxt, name, endpoint_type, description, connection_info)
 
+    def update(self, ctxt, endpoint_id, properties):
+        return self._rpc_client.update_endpoint(
+            ctxt, endpoint_id, properties)
+
     def delete(self, ctxt, endpoint_id):
         self._rpc_client.delete_endpoint(ctxt, endpoint_id)