POST 動詞を使用して、flask-restplus を使用して VM でアクションを実行したいのですが、本体がない場合は常に 400 になります。
VM_ACTION_FIELDS = {
'vmActionId': fields.Integer(required=True, description='The vmActionId of the VmAction'),
'vmId': fields.Integer(required=True, description='The vmId of the VmAction'),
'status': fields.String(required=True, description='The status of the VmAction',
enum=['NEW', 'REQUESTED', 'IN_PROGRESS', 'ERROR', 'COMPLETED']),
'actionType': fields.String(required=True, description='The actionType of the VmAction',
enum=['STOP', 'RESTART']),
'createdAt': fields.DateTime(required=True,
description='The createdAt datetime of the VmAction'),
'completedAt': fields.DateTime(required=True,
description='The completedAt datetime of the VmAction'),
}
VM_ACTION_MODEL = api.model('VmAction', VM_ACTION_FIELDS)
[snip]
@vms_ns.route('/<int:vmId>/stop', endpoint='vmStop')
class VmStopView(Resource):
"""
Stop a VM
"""
@api.marshal_with(VM_ACTION_MODEL, code=202)
@api.doc(id='stopVm', description='Stop a Vm')
def post(self, vmId):
# do stuff
return vmAction, 202
結果は 400 { "メッセージ": "ブラウザ (またはプロキシ) が、このサーバーが理解できない要求を送信しました。" }
post から get に変更するだけで問題なく動作します。しかし、これには POST 動詞を使用したいと本当に思っています。これは、カスタムの非 CRUD アクションに従う必要がある標準的な動詞だからです。フラスコレストプラスで自分を隅に追いやったことがありますか?
注: 本体を必要とする操作の場合、正常に機能します。空の本体で 400 エラーが発生する唯一の本体のないフラスコ-レストプラス ポスト操作。