Return an explicit error when a NIO type is not supported by a VM.

This commit is contained in:
Jeremy
2015-04-27 14:19:17 -06:00
parent d5ae4750e9
commit b6a935aeb8
11 changed files with 188 additions and 380 deletions

View File

@ -15,11 +15,12 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from aiohttp.web import HTTPConflict
from ...web.route import Route
from ...schemas.nio import NIO_SCHEMA
from ...schemas.qemu import QEMU_CREATE_SCHEMA
from ...schemas.qemu import QEMU_UPDATE_SCHEMA
from ...schemas.qemu import QEMU_OBJECT_SCHEMA
from ...schemas.qemu import QEMU_NIO_SCHEMA
from ...schemas.qemu import QEMU_BINARY_LIST_SCHEMA
from ...modules.qemu import Qemu
@ -239,12 +240,15 @@ class QEMUHandler:
404: "Instance doesn't exist"
},
description="Add a NIO to a Qemu VM instance",
input=QEMU_NIO_SCHEMA,
output=QEMU_NIO_SCHEMA)
input=NIO_SCHEMA,
output=NIO_SCHEMA)
def create_nio(request, response):
qemu_manager = Qemu.instance()
vm = qemu_manager.get_vm(request.match_info["vm_id"], project_id=request.match_info["project_id"])
nio_type = request.json["type"]
if nio_type != "nio_udp":
raise HTTPConflict(text="NIO of type {} is not supported".format(nio_type))
nio = qemu_manager.create_nio(vm.qemu_path, request.json)
yield from vm.adapter_add_nio_binding(int(request.match_info["adapter_number"]), nio)
response.set_status(201)