-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
Signed-off-by: Kristián Feldsam <[email protected]>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ class DISK(XMLObject): | |
values = ['CLONE','READONLY','SAVE','SOURCE','TARGET' ] | ||
|
||
class TEMPLATE(XMLObject): | ||
values = [ 'CPU', 'MEMORY', 'NAME', 'RANK', 'REQUIREMENTS', 'VMID', 'VCPU', 'PACKEDMEMORY', 'MAXMEMORY' ] | ||
values = [ 'CPU', 'MEMORY', 'NAME', 'RANK', 'REQUIREMENTS', 'VMID', 'VCPU' ] | ||
This comment has been minimized.
Sorry, something went wrong. |
||
tuples = { 'GRAPHICS': GRAPHICS, 'OS': OS } | ||
tuples_lists = { 'DISK': DISK, 'NIC': NIC } | ||
numeric = [ 'CPU', 'MEMORY', 'VCPU' ] | ||
|
@@ -62,7 +62,7 @@ class VM(XMLObject): | |
STATE_FAILED=7 | ||
STATE_STR = {'0': 'init', '1': 'pending', '2': 'hold', '3': 'active', '4': 'stopped', '5': 'suspended', '6': 'done', '7': 'failed' } | ||
LCM_STATE_STR={'0':'init','1':'prologing','2':'booting','3':'running','4':'migrating','5':'saving (stop)','6':'saving (suspend)','7':'saving (migrate)', '8':'prologing (migration)', '9':'prologing (resume)', '10': 'epilog (stop)','11':'epilog', '12':'cancel','13':'failure','14':'delete','15':'unknown'} | ||
values = [ 'ID','UID','NAME','LAST_POLL','STATE','LCM_STATE','DEPLOY_ID','MEMORY','CPU','NET_TX','NET_RX', 'STIME','ETIME' ] | ||
values = [ 'ID','UID','NAME','LAST_POLL','STATE','LCM_STATE','DEPLOY_ID','MEMORY','CPU','NET_TX','NET_RX', 'STIME','ETIME', 'PACKEDMEMORY', 'MAXMEMORY', 'REALMEMORY' ] | ||
This comment has been minimized.
Sorry, something went wrong.
feldsam
Author
Owner
|
||
tuples = { 'TEMPLATE': TEMPLATE, 'HISTORY_RECORDS': HISTORY_RECORDS, 'USER_TEMPLATE': USER_TEMPLATE } | ||
numeric = [ 'ID', 'UID', 'STATE', 'LCM_STATE', 'STIME','ETIME' ] | ||
|
||
|
@@ -148,10 +148,10 @@ def get_vm_list(): | |
res = [] | ||
for vm in res_vm.VM: | ||
host = HostInfo(int(vm.HISTORY_RECORDS.HISTORY[0].HID), vm.HISTORY_RECORDS.HISTORY[0].HOSTNAME) | ||
new_vm = VirtualMachineInfo(int(vm.ID), host, vm.TEMPLATE.MEMORY * 1024, vm) | ||
new_vm = VirtualMachineInfo(int(vm.ID), host, vm.MAXMEMORY, vm) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
new_vm.user_id = vm.UID | ||
if vm.USER_TEMPLATE.MEM_TOTAL: | ||
new_vm.set_memory_values(int(vm.USER_TEMPLATE.MEM_TOTAL_REAL), | ||
new_vm.set_memory_values(int(vm.REALMEMORY), | ||
This comment has been minimized.
Sorry, something went wrong.
feldsam
Author
Owner
|
||
int(vm.USER_TEMPLATE.MEM_TOTAL), | ||
int(vm.USER_TEMPLATE.MEM_FREE)) | ||
if vm.USER_TEMPLATE.MIN_FREE_MEM: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,31 +103,32 @@ def monitor_vm(self, vm, all_vms): | |
""" | ||
Main function of the monitor | ||
""" | ||
vm_pct_free_memory = float(vm.free_memory)/float(vm.total_memory) * 100.0 | ||
mem_over_ratio = Config.MEM_OVER | ||
if vm.mem_over_ratio: | ||
mem_over_ratio = vm.mem_over_ratio | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
if vm.id not in self.mem_diff: | ||
self.mem_diff[vm.id] = vm.real_memory - vm.total_memory | ||
|
||
vm.total_memory += self.mem_diff[vm.id] | ||
vm_pct_free_memory = float(vm.free_memory)/float(vm.total_memory) * 100.0 | ||
vm_pct_free_memory_inc_over_ratio = vm_pct_free_memory * (1 + mem_over_ratio / 100.0); | ||
This comment has been minimized.
Sorry, something went wrong.
feldsam
Author
Owner
|
||
|
||
vmid_msg = "VMID " + str(vm.id) + ": " | ||
vm.host = self.get_host_info(vm.host.id) | ||
#logger.debug(vmid_msg + "VM is in Host: " + vm.host.name + ". PACKEDMEMORY = " + str(vm.host.raw.TEMPLATE.PACKEDMEMORY)) | ||
|
||
logger.info(vmid_msg + "Real Memory: " + str(vm.real_memory)) | ||
logger.info(vmid_msg + "Total Memory: " + str(vm.total_memory)) | ||
logger.info(vmid_msg + "Free Memory: %d" % vm.free_memory) | ||
|
||
mem_over_ratio = Config.MEM_OVER | ||
if vm.mem_over_ratio: | ||
mem_over_ratio = vm.mem_over_ratio | ||
|
||
if vm_pct_free_memory < (mem_over_ratio - Config.MEM_MARGIN) or vm_pct_free_memory > (mem_over_ratio + Config.MEM_MARGIN): | ||
if vm_pct_free_memory_inc_over_ratio < (mem_over_ratio - Config.MEM_MARGIN) or vm_pct_free_memory_inc_over_ratio > (mem_over_ratio + Config.MEM_MARGIN): | ||
This comment has been minimized.
Sorry, something went wrong.
feldsam
Author
Owner
|
||
now = time.time() | ||
|
||
logger.debug(vmid_msg + "VM %s has %.2f of free memory, change the memory size" % (vm.id, vm_pct_free_memory)) | ||
if vm.id in self.last_set_mem: | ||
logger.debug(vmid_msg + "Last memory change was %s secs ago." % (now - self.last_set_mem[vm.id])) | ||
else: | ||
self.original_mem[vm.id] = vm.total_memory | ||
self.original_mem[vm.id] = vm.allocated_memory | ||
This comment has been minimized.
Sorry, something went wrong. |
||
logger.debug(vmid_msg + "The memory of this VM has been never modified. Store the initial memory : " + str(self.original_mem[vm.id])) | ||
self.last_set_mem[vm.id] = now | ||
|
||
|
@@ -158,11 +159,18 @@ def monitor_vm(self, vm, all_vms): | |
multiplier = 1.0 + (mem_over_ratio/100.0) | ||
logger.debug(vmid_msg + "The used memory %d is multiplied by %.2f" % (int(mem_usada), multiplier)) | ||
new_mem = int(mem_usada * multiplier) | ||
|
||
# Check for minimum memory | ||
if new_mem < Config.MEM_MIN: | ||
new_mem = Config.MEM_MIN | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
# add diff to new_mem value | ||
new_mem += self.mem_diff[vm.id] | ||
This comment has been minimized.
Sorry, something went wrong.
feldsam
Author
Owner
|
||
|
||
# We never set more memory that the initial amount | ||
if new_mem > self.original_mem[vm.id]: | ||
new_mem = self.original_mem[vm.id] | ||
elif new_mem < Config.MEM_MIN: | ||
new_mem = Config.MEM_MIN | ||
|
||
if abs(int(vm.total_memory)-new_mem) < Config.MEM_DIFF_TO_CHANGE: | ||
logger.debug(vmid_msg + "Not changing the memory. Too small difference.") | ||
else: | ||
|
@@ -319,7 +327,7 @@ def change_memory(vm_id, vm_host, new_mem): | |
""" | ||
chmem_cmd = Config.CHANGE_MEMORY_CMD.format(hostname = vm_host.name, vmid = str(vm_id), newmemory = str(new_mem)) | ||
|
||
logger.debug("Change the memory from " + str(vm_id) + " to " + str(new_mem)) | ||
logger.debug("Change the memory of VM: " + str(vm_id) + " to " + str(new_mem)) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
logger.debug("Executing: " + chmem_cmd) | ||
if not Config.ONLY_TEST: | ||
success, out = runcommand(chmem_cmd, shell=True) | ||
|
This values doesn't exists in VM TEMPLATE, they are in monitoring info