Support function update
Change-Id: Ib184236b28a4aa3684970654f2788c9e3677f822
This commit is contained in:
parent
5587f947f6
commit
13f1e6f41e
|
@ -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())
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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…
Reference in New Issue