New Features + Refactoring
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
```
This commit is contained in:
parent
da77ac65eb
commit
93dee1c9fc
13 changed files with 354 additions and 233 deletions
|
|
@ -18,6 +18,8 @@ import json
|
|||
import os
|
||||
import bitmath
|
||||
|
||||
import helper
|
||||
|
||||
from ucloud_common.host import HostPool, HostStatus
|
||||
from ucloud_common.vm import VmPool, VMStatus
|
||||
|
||||
|
|
@ -207,22 +209,24 @@ class CreateVMSchema(OTPSchema):
|
|||
# Fields
|
||||
self.specs = Field("specs", dict, data.get("specs", KeyError))
|
||||
self.vm_name = Field("vm_name", str, data.get("vm_name", KeyError))
|
||||
self.image_uuid = Field("image_uuid", str, data.get("image_uuid", KeyError))
|
||||
self.image = Field("image", str, data.get("image", KeyError))
|
||||
|
||||
# Validation
|
||||
self.image_uuid.validation = self.image_uuid_validation
|
||||
self.image.validation = self.image_validation
|
||||
self.vm_name.validation = self.vm_name_validation
|
||||
self.specs.validation = self.specs_validation
|
||||
|
||||
fields = [self.vm_name, self.image_uuid, self.specs]
|
||||
fields = [self.vm_name, self.image, self.specs]
|
||||
|
||||
super().__init__(data=data, fields=fields)
|
||||
|
||||
def image_uuid_validation(self):
|
||||
images = client.get_prefix(IMAGE_PREFIX)
|
||||
|
||||
if self.image_uuid.value not in [i.key.split("/")[-1] for i in images]:
|
||||
self.add_error("Image UUID not valid")
|
||||
def image_validation(self):
|
||||
try:
|
||||
image_uuid = helper.resolve_image_name(self.image.value, client)
|
||||
except Exception as e:
|
||||
self.add_error(str(e))
|
||||
else:
|
||||
self.image_uuid = image_uuid
|
||||
|
||||
def vm_name_validation(self):
|
||||
if resolve_vm_name(name=self.vm_name.value, owner=self.name.value):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue