Remove ucloud_common and put its files under ucloud.common subpackage.
Remove individual config.py used by every component and put them into single config.py ucloud/config.py Use /etc/ucloud/ucloud.conf for Environment Variables Refactoring and a lot of it Make ucloud repo a package and different components of ucloud a subpackage for avoiding code duplication. Improved logging.
This commit is contained in:
parent
1d2b980c74
commit
6fa77bce4d
51 changed files with 890 additions and 567 deletions
|
|
@ -1,21 +1,15 @@
|
|||
import bitmath
|
||||
|
||||
from collections import Counter
|
||||
from functools import reduce
|
||||
|
||||
from ucloud_common.vm import VmPool, VMStatus
|
||||
from ucloud_common.host import HostPool, HostStatus
|
||||
from ucloud_common.request import RequestEntry, RequestPool, RequestType
|
||||
import bitmath
|
||||
|
||||
from decouple import config
|
||||
from config import etcd_client as client
|
||||
|
||||
vm_pool = VmPool(client, config("VM_PREFIX"))
|
||||
host_pool = HostPool(client, config("HOST_PREFIX"))
|
||||
request_pool = RequestPool(client, config("REQUEST_PREFIX"))
|
||||
from common.host import HostStatus
|
||||
from common.request import RequestEntry, RequestType
|
||||
from common.vm import VMStatus
|
||||
from config import vm_pool, host_pool, request_pool, env_vars
|
||||
|
||||
|
||||
def accumulated_specs(vms_specs):
|
||||
def accumulated_specs(vms_specs):
|
||||
if not vms_specs:
|
||||
return {}
|
||||
return reduce((lambda x, y: Counter(x) + Counter(y)), vms_specs)
|
||||
|
|
@ -23,7 +17,7 @@ def accumulated_specs(vms_specs):
|
|||
|
||||
def remaining_resources(host_specs, vms_specs):
|
||||
# Return remaining resources host_specs - vms
|
||||
|
||||
|
||||
_vms_specs = Counter(vms_specs)
|
||||
_remaining = Counter(host_specs)
|
||||
|
||||
|
|
@ -69,7 +63,7 @@ def get_suitable_host(vm_specs, hosts=None):
|
|||
# Find out remaining resources after
|
||||
# host_specs - already running vm_specs
|
||||
remaining = remaining_resources(host.specs, running_vms_accumulated_specs)
|
||||
|
||||
|
||||
# Find out remaining - new_vm_specs
|
||||
remaining = remaining_resources(remaining, vm_specs)
|
||||
|
||||
|
|
@ -111,7 +105,8 @@ def assign_host(vm):
|
|||
|
||||
r = RequestEntry.from_scratch(type=RequestType.StartVM,
|
||||
uuid=vm.uuid,
|
||||
hostname=vm.hostname)
|
||||
hostname=vm.hostname,
|
||||
request_prefix=env_vars.get("REQUEST_PREFIX"))
|
||||
request_pool.put(r)
|
||||
|
||||
vm.log.append("VM scheduled for starting")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue