Browse Source

Support function update

Change-Id: Ib184236b28a4aa3684970654f2788c9e3677f822
changes/83/476483/2
Lingxian Kong 4 years ago
parent
commit
13f1e6f41e
  1. 28
      qinling/api/controllers/v1/function.py
  2. 4
      qinling/api/controllers/v1/resources.py
  3. 12
      qinling/db/sqlalchemy/api.py

28
qinling/api/controllers/v1/function.py

@ -39,6 +39,7 @@ CONF = cfg.CONF
POST_REQUIRED = set(['name', 'code'])
CODE_SOURCE = set(['package', 'swift', 'image'])
UPDATE_ALLOWED = set(['name', 'description', 'entry'])
class FunctionsController(rest.RestController):
@ -182,3 +183,30 @@ class FunctionsController(rest.RestController):
# This will also delete function service mapping as well.
db_api.delete_function(id)
@rest_utils.wrap_wsme_controller_exception
@wsme_pecan.wsexpose(
resources.Function,
types.uuid,
body=resources.Function
)
def put(self, id, func):
"""Update function.
Currently, we only support update name, description, entry.
"""
values = {}
for key in UPDATE_ALLOWED:
if key in func.to_dict():
values.update({key: func.to_dict().get(key)})
LOG.info('Update function [id=%s, values=%s]' % (id, values))
with db_api.transaction():
func_db = db_api.update_function(id, values)
if 'entry' in values:
# Update entry will delete allocated resources in orchestrator.
db_api.delete_function_service_mapping(id)
self.engine_client.delete_function(id)
return resources.Function.from_dict(func_db.to_dict())

4
qinling/api/controllers/v1/resources.py

@ -166,10 +166,10 @@ class Function(Resource):
description = wtypes.text
memory_size = int
timeout = int
runtime_id = types.uuid
runtime_id = wsme.wsattr(types.uuid, readonly=True)
code = types.jsontype
entry = wtypes.text
count = int
count = wsme.wsattr(int, readonly=True)
created_at = wtypes.text
updated_at = wtypes.text

12
qinling/db/sqlalchemy/api.py

@ -213,8 +213,11 @@ def create_function(values, session=None):
@db_base.session_aware()
def update_function(id, values):
pass
def update_function(id, values, session=None):
function = get_function(id)
function.update(values.copy())
return function
@db_base.session_aware()
@ -336,6 +339,9 @@ def get_function_service_mappings(session=None, **kwargs):
@db_base.session_aware()
def delete_function_service_mapping(id, session=None):
mapping = get_function_service_mapping(id)
try:
mapping = get_function_service_mapping(id)
except exc.DBEntityNotFoundError:
return
session.delete(mapping)
Loading…
Cancel
Save