Merge into master
This commit is contained in:
parent
9aeb05987b
commit
4a3c81852a
12 changed files with 18 additions and 364 deletions
11
main.py
Normal file → Executable file
11
main.py
Normal file → Executable file
|
|
@ -8,8 +8,8 @@ import subprocess
|
|||
from flask import Flask, request
|
||||
from flask_restful import Resource, Api
|
||||
from uuid import uuid4
|
||||
from etcd3_wrapper import Etcd3Wrapper
|
||||
from os.path import join
|
||||
from config import etcd_client as client
|
||||
|
||||
from ucloud_common.vm import VmPool, VMStatus
|
||||
from ucloud_common.host import HostPool
|
||||
|
|
@ -22,7 +22,6 @@ from schemas import (CreateVMSchema, VMStatusSchema,
|
|||
app = Flask(__name__)
|
||||
api = Api(app)
|
||||
|
||||
client = Etcd3Wrapper()
|
||||
vm_pool = VmPool(client, "/v1/vm")
|
||||
host_pool = HostPool(client, "/v1/host")
|
||||
request_pool = RequestPool(client, "/v1/request")
|
||||
|
|
@ -35,6 +34,7 @@ class CreateVM(Resource):
|
|||
validator = CreateVMSchema(data)
|
||||
if validator.is_valid():
|
||||
# Create VM Entry under /v1/vm/
|
||||
# TODO: !!!Generate Mac Address on creation of VM
|
||||
vm_uuid = uuid4().hex
|
||||
vm_key = f"/v1/vm/{vm_uuid}"
|
||||
vm_entry = {
|
||||
|
|
@ -43,7 +43,8 @@ class CreateVM(Resource):
|
|||
"hostname": "",
|
||||
"status": "",
|
||||
"image_uuid": data["image_uuid"],
|
||||
"log": []
|
||||
"log": [],
|
||||
"storage_attachment": []
|
||||
}
|
||||
client.put(vm_key, vm_entry, value_in_json=True)
|
||||
|
||||
|
|
@ -228,8 +229,8 @@ class CreateHost(Resource):
|
|||
client.put(host_key, host_entry, value_in_json=True)
|
||||
|
||||
return {"message": "Host Created"}, 200
|
||||
else:
|
||||
return validator.get_errors(), 400
|
||||
|
||||
return validator.get_errors(), 400
|
||||
|
||||
|
||||
class ListHost(Resource):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue