forked from uncloud/uncloud
meow
93dee1c9fc
1. User can now use image name instead of image uuid when creation vm. For Example, now user can create an alpine vm using the following command ```shell ucloud-cli vm create --vm-name myvm --cpu 2 --ram '2GB' \ --os-ssd '10GB' --image images:alpine ``` 2. Instead of directly running code, code is now placed under a function main and is called using the following code ```python if __name__ == "__main__": main() ``` 3. Multiprocess (Process) is used instead of threading (Thread) to update heart beat of host. 4. IP Address of vm is included in vm's status which is retrieved by the following command ```shell ucloud-cli vm status --vm-name myvm ```
35 lines
920 B
Python
Executable file
35 lines
920 B
Python
Executable file
import logging
|
|
|
|
from etcd3_wrapper import Etcd3Wrapper
|
|
from ucloud_common.vm import VmPool
|
|
from ucloud_common.host import HostPool
|
|
from ucloud_common.request import RequestPool
|
|
from decouple import config
|
|
|
|
WITHOUT_CEPH = config("WITHOUT_CEPH", False, cast=bool)
|
|
|
|
logging.basicConfig(
|
|
level=logging.DEBUG,
|
|
filename="log.txt",
|
|
filemode="a",
|
|
format="%(asctime)s: %(levelname)s - %(message)s",
|
|
datefmt="%d-%b-%y %H:%M:%S",
|
|
)
|
|
|
|
etcd_wrapper_args = ()
|
|
etcd_wrapper_kwargs = {"host": config("ETCD_URL")}
|
|
|
|
etcd_client = Etcd3Wrapper(*etcd_wrapper_args, **etcd_wrapper_kwargs)
|
|
|
|
HOST_PREFIX = config("HOST_PREFIX")
|
|
VM_PREFIX = config("VM_PREFIX")
|
|
REQUEST_PREFIX = config("REQUEST_PREFIX")
|
|
VM_DIR = config("VM_DIR")
|
|
IMAGE_DIR = config("IMAGE_DIR")
|
|
|
|
|
|
host_pool = HostPool(etcd_client, HOST_PREFIX)
|
|
vm_pool = VmPool(etcd_client, VM_PREFIX)
|
|
request_pool = RequestPool(etcd_client, REQUEST_PREFIX)
|
|
|
|
running_vms = []
|