Commit 726d06dc authored by Christos Stavrakakis's avatar Christos Stavrakakis

Rename 'cpu' and 'ram' resources

Rename CPU and RAM relative resources to avoid data migrations.
Specifically, the resources that are renamed are the following:

* cpu -> total_cpu
* ram -> total_ram
* active_cpu -> cpu
* active_ram -> ram
parent 4b23893e
......@@ -84,51 +84,51 @@ RESOURCES = {
'verbose_name': 'System Disk',
'group': 'compute'
},
'cyclades.ram': {
'cyclades.total_ram': {
'help_text': 'RAM used by VMs ',
'help_text_input_each': ('This is the total amount of RAM that '
'will be granted to each user of this '
'Project (on all VMs) '),
'is_abbreviation': True,
'report_desc': 'RAM',
'report_desc': 'Total RAM',
'placeholder': 'eg. 4GB',
'verbose_name': 'ram',
'verbose_name': 'Total ram',
'group': 'compute'
},
'cyclades.active_ram': {
'cyclades.ram': {
'help_text': 'RAM used by active VMs ',
'help_text_input_each': ('This is the total amount of RAM that '
'will be granted to each user of this '
'Project (on all active VMs) '),
'is_abbreviation': False,
'report_desc': 'Active RAM',
'report_desc': 'RAM',
'placeholder': 'eg. 4GB',
'verbose_name': 'Active RAM',
'verbose_name': 'RAM',
'group': 'compute'
},
'cyclades.cpu': {
'cyclades.total_cpu': {
'help_text': 'CPUs used by VMs ',
'help_text_input_each': ('This is the total number of CPUs that '
'will be granted to each user of this '
'Project (on all VMs) '),
'is_abbreviation': True,
'report_desc': 'CPUs',
'report_desc': 'Total CPUs',
'placeholder': 'eg. 1',
'verbose_name': 'cpu',
'verbose_name': 'Total cpu',
'group': 'compute'
},
'cyclades.active_cpu': {
'cyclades.cpu': {
'help_text': 'CPUs used by active VMs ',
'help_text_input_each': ('This is the total number of CPUs that '
'will be granted to each user of this '
'Project (on all active VMs) '),
'is_abbreviation': False,
'report_desc': 'Active CPUs',
'report_desc': 'CPUs',
'placeholder': 'eg. 1',
'verbose_name': 'Active CPU',
'verbose_name': 'CPU',
'group': 'compute'
},
......@@ -186,10 +186,10 @@ RESOURCES = {
'groups_order': ['storage', 'compute', 'network', 'accounts'],
'resources_order': ['pithos.diskspace',
'cyclades.disk',
'cyclades.total_cpu',
'cyclades.cpu',
'cyclades.active_cpu',
'cyclades.total_ram',
'cyclades.ram',
'cyclades.active_ram',
'cyclades.vm',
'cyclades.network.private',
'cyclades.floating_ip',
......
......@@ -512,10 +512,10 @@ form input[type="text"]:-ms-input-placeholder,
.stats .info p { color:#999; margin:0; }
.stats .info h3 { font-size:1.231em; color:#222222 }
.stats .vm .img-wrap { background-image:url(../images/vm-stats.png) }
.stats .ram .img-wrap { background-image:url(../images/ram-stats.png) }
.stats .active_ram .img-wrap { background-image:url(../images/ram-stats.png) }
.stats .cpu .img-wrap { background-image:url(../images/cpu-stats.png) }
.stats .active_cpu .img-wrap { background-image:url(../images/cpu-stats.png) }
.stats .total_ram .img-wrap { background-image:url(../images/ram-stats.png) }
.stats .ram .img-wrap { background-image:url(../images/ram-stats.png) }
.stats .total_cpu .img-wrap { background-image:url(../images/cpu-stats.png) }
.stats .cpu .img-wrap { background-image:url(../images/cpu-stats.png) }
.stats .network .img-wrap { background-image:url(../images/network-stats.png) }
.stats .disksize .img-wrap { background-image:url(../images/disk-stats.png) }
.stats .disk .img-wrap { background-image:url(../images/disk-stats.png) }
......
......@@ -77,28 +77,28 @@ cyclades_services = {
"service_type": "compute",
"service_origin": "cyclades_compute",
},
'cpu': {
"name": "cyclades.cpu",
'total_cpu': {
"name": "cyclades.total_cpu",
"desc": "Number of virtual machine processors",
"service_type": "compute",
"service_origin": "cyclades_compute",
},
'active_cpu': {
"name": "cyclades.active_cpu",
'cpu': {
"name": "cyclades.cpu",
"desc": "Number of virtual machine processors of running"
" servers",
"service_type": "compute",
"service_origin": "cyclades_compute",
},
'ram': {
"name": "cyclades.ram",
'total_ram': {
"name": "cyclades.total_ram",
"desc": "Virtual machine memory size",
"unit": "bytes",
"service_type": "compute",
"service_origin": "cyclades_compute",
},
'active_ram': {
"name": "cyclades.active_ram",
'ram': {
"name": "cyclades.ram",
"desc": "Virtual machine memory size of running servers",
"unit": "bytes",
"service_type": "compute",
......
......@@ -51,28 +51,28 @@ cyclades_services = {
"service_type": "compute",
"service_origin": "cyclades_compute",
},
'cpu': {
"name": "cyclades.cpu",
'total_cpu': {
"name": "cyclades.total_cpu",
"desc": "Number of virtual machine processors",
"service_type": "compute",
"service_origin": "cyclades_compute",
},
'active_cpu': {
"name": "cyclades.active_cpu",
'cpu': {
"name": "cyclades.cpu",
"desc": "Number of virtual machine processors of running"
" servers",
"service_type": "compute",
"service_origin": "cyclades_compute",
},
'ram': {
"name": "cyclades.ram",
'total_ram': {
"name": "cyclades.total_ram",
"desc": "Virtual machine memory size",
"unit": "bytes",
"service_type": "compute",
"service_origin": "cyclades_compute",
},
'active_ram': {
"name": "cyclades.active_ram",
'ram': {
"name": "cyclades.ram",
"desc": "Virtual machine memory size of running servers",
"unit": "bytes",
"service_type": "compute",
......
......@@ -46,11 +46,11 @@ log = logging.getLogger(__name__)
DEFAULT_SOURCE = 'system'
RESOURCES = [
"cyclades.vm",
"cyclades.total_cpu",
"cyclades.cpu",
"cyclades.active_cpu",
"cyclades.disk",
"cyclades.total_ram",
"cyclades.ram",
"cyclades.active_ram",
"cyclades.network.private",
"cyclades.floating_ip",
]
......@@ -280,11 +280,11 @@ def get_commission_info(resource, action, action_fields=None):
if isinstance(resource, VirtualMachine):
flavor = resource.flavor
resources = {"cyclades.vm": 1,
"cyclades.cpu": flavor.cpu,
"cyclades.total_cpu": flavor.cpu,
"cyclades.disk": 1073741824 * flavor.disk,
"cyclades.ram": 1048576 * flavor.ram}
online_resources = {"cyclades.active_cpu": flavor.cpu,
"cyclades.active_ram": 1048576 * flavor.ram}
"cyclades.total_ram": 1048576 * flavor.ram}
online_resources = {"cyclades.cpu": flavor.cpu,
"cyclades.ram": 1048576 * flavor.ram}
if action == "BUILD":
resources.update(online_resources)
return resources
......@@ -311,8 +311,8 @@ def get_commission_info(resource, action, action_fields=None):
beparams = action_fields.get("beparams")
cpu = beparams.get("vcpus", flavor.cpu)
ram = beparams.get("maxmem", flavor.ram)
return {"cyclades.cpu": cpu - flavor.cpu,
"cyclades.ram": 1048576 * (ram - flavor.ram)}
return {"cyclades.total_cpu": cpu - flavor.cpu,
"cyclades.total_ram": 1048576 * (ram - flavor.ram)}
else:
#["CONNECT", "DISCONNECT", "SET_FIREWALL_PROFILE"]:
return None
......
......@@ -56,11 +56,11 @@ class GetDBHoldingsTestCase(TestCase):
mfactory.VirtualMachineFactory(flavor=flavor, userid="user1",
operstate="BUILD")
user_holdings = {"user1": {"cyclades.vm": 1,
"cyclades.total_cpu": 24,
"cyclades.cpu": 24,
"cyclades.active_cpu": 24,
"cyclades.disk": 21474836480,
"cyclades.ram": 8589934592,
"cyclades.active_ram": 8589934592}}
"cyclades.total_ram": 8589934592,
"cyclades.ram": 8589934592}}
holdings = util.get_db_holdings(user="user1")
self.assertEqual(holdings, user_holdings)
holdings = util.get_db_holdings()
......@@ -70,19 +70,19 @@ class GetDBHoldingsTestCase(TestCase):
mfactory.VirtualMachineFactory(flavor=flavor, userid="user2",
operstate="STARTED")
user_holdings = {"user2": {"cyclades.vm": 1,
"cyclades.total_cpu": 24,
"cyclades.cpu": 24,
"cyclades.active_cpu": 24,
"cyclades.disk": 21474836480,
"cyclades.ram": 8589934592,
"cyclades.active_ram": 8589934592}}
"cyclades.total_ram": 8589934592,
"cyclades.ram": 8589934592}}
holdings = util.get_db_holdings(user="user2")
self.assertEqual(holdings, user_holdings)
mfactory.VirtualMachineFactory(flavor=flavor, userid="user3",
operstate="STOPPED")
user_holdings = {"user3": {"cyclades.vm": 1,
"cyclades.cpu": 24,
"cyclades.total_cpu": 24,
"cyclades.disk": 21474836480,
"cyclades.ram": 8589934592}}
"cyclades.total_ram": 8589934592}}
holdings = util.get_db_holdings(user="user3")
self.assertEqual(holdings, user_holdings)
......@@ -138,51 +138,51 @@ class GetCommissionInfoTest(TestCase):
#commission = quotas.get_commission_info(vm, "BUILD")
#self.assertEqual({"cyclades.vm": 1,
# "cyclades.cpu": 2,
# "cyclades.active_cpu": 2,
# "cyclades.cpu": 2,
# "cyclades.ram": 1048576 * 1024,
# "cyclades.ram": 1048576 * 1024,
# "cyclades.active_ram": 1048576 * 1024,
# "cyclades.disk": 1073741824 * 20}, commission)
vm.operstate = "STARTED"
vm.save()
commission = quotas.get_commission_info(vm, "STOP")
self.assertEqual({"cyclades.active_cpu": -2,
"cyclades.active_ram": 1048576 * -1024}, commission)
self.assertEqual({"cyclades.cpu": -2,
"cyclades.ram": 1048576 * -1024}, commission)
# Check None quotas if vm is already stopped
vm.operstate = "STOPPED"
vm.save()
commission = quotas.get_commission_info(vm, "STOP")
self.assertEqual(None, commission)
commission = quotas.get_commission_info(vm, "START")
self.assertEqual({"cyclades.active_cpu": 2,
"cyclades.active_ram": 1048576 * 1024}, commission)
self.assertEqual({"cyclades.cpu": 2,
"cyclades.ram": 1048576 * 1024}, commission)
vm.operstate = "STARTED"
vm.save()
commission = quotas.get_commission_info(vm, "DESTROY")
self.assertEqual({"cyclades.vm": -1,
"cyclades.total_cpu": -2,
"cyclades.cpu": -2,
"cyclades.active_cpu": -2,
"cyclades.total_ram": 1048576 * -1024,
"cyclades.ram": 1048576 * -1024,
"cyclades.active_ram": 1048576 * -1024,
"cyclades.disk": 1073741824 * -20}, commission)
vm.operstate = "STOPPED"
vm.save()
commission = quotas.get_commission_info(vm, "DESTROY")
self.assertEqual({"cyclades.vm": -1,
"cyclades.cpu": -2,
"cyclades.ram": 1048576 * -1024,
"cyclades.total_cpu": -2,
"cyclades.total_ram": 1048576 * -1024,
"cyclades.disk": 1073741824 * -20}, commission)
commission = quotas.get_commission_info(vm, "RESIZE")
self.assertEqual(None, commission)
commission = quotas.get_commission_info(vm, "RESIZE",
{"beparams": {"vcpus": 4,
"maxmem": 2048}})
self.assertEqual({"cyclades.cpu": 2,
"cyclades.ram": 1048576 * 1024}, commission)
self.assertEqual({"cyclades.total_cpu": 2,
"cyclades.total_ram": 1048576 * 1024}, commission)
vm.operstate = "STOPPED"
vm.save()
commission = quotas.get_commission_info(vm, "REBOOT")
self.assertEqual({"cyclades.active_cpu": 2,
"cyclades.active_ram": 1048576 * 1024}, commission)
self.assertEqual({"cyclades.cpu": 2,
"cyclades.ram": 1048576 * 1024}, commission)
vm.operstate = "STARTED"
vm.save()
commission = quotas.get_commission_info(vm, "REBOOT")
......
......@@ -51,29 +51,30 @@ def get_db_holdings(user=None):
floating_ips = floating_ips.filter(userid=user)
# Get resources related with VMs
vm_resources = vms.values("userid").annotate(num=Count("id"),
ram=Sum("flavor__ram"),
cpu=Sum("flavor__cpu"),
disk=Sum("flavor__disk"))
vm_resources = vms.values("userid")\
.annotate(num=Count("id"),
total_ram=Sum("flavor__ram"),
total_cpu=Sum("flavor__cpu"),
disk=Sum("flavor__disk"))
vm_active_resources = \
vms.values("userid")\
.filter(Q(operstate="STARTED") | Q(operstate="BUILD") |
Q(operstate="ERROR"))\
.annotate(active_ram=Sum("flavor__ram"),
active_cpu=Sum("flavor__cpu"))
.annotate(ram=Sum("flavor__ram"),
cpu=Sum("flavor__cpu"))
for vm_res in vm_resources.iterator():
user = vm_res['userid']
res = {"cyclades.vm": vm_res["num"],
"cyclades.cpu": vm_res["cpu"],
"cyclades.total_cpu": vm_res["total_cpu"],
"cyclades.disk": 1073741824 * vm_res["disk"],
"cyclades.ram": 1048576 * vm_res["ram"]}
"cyclades.total_ram": 1048576 * vm_res["total_ram"]}
holdings[user] = res
for vm_res in vm_active_resources.iterator():
user = vm_res['userid']
holdings[user]["cyclades.active_cpu"] = vm_res["active_cpu"]
holdings[user]["cyclades.active_ram"] = 1048576 * vm_res["active_ram"]
holdings[user]["cyclades.cpu"] = vm_res["cpu"]
holdings[user]["cyclades.ram"] = 1048576 * vm_res["ram"]
# Get resources related with networks
net_resources = networks.values("userid")\
......
......@@ -1260,10 +1260,10 @@ def import_services():
snf-manage resource-modify --limit 2 astakos.pending_app
snf-manage resource-modify --limit 4 cyclades.vm
snf-manage resource-modify --limit 40G cyclades.disk
snf-manage resource-modify --limit 16G cyclades.ram
snf-manage resource-modify --limit 8G cyclades.active_ram
snf-manage resource-modify --limit 32 cyclades.cpu
snf-manage resource-modify --limit 16 cyclades.active_cpu
snf-manage resource-modify --limit 16G cyclades.total_ram
snf-manage resource-modify --limit 8G cyclades.ram
snf-manage resource-modify --limit 32 cyclades.total_cpu
snf-manage resource-modify --limit 16 cyclades.cpu
snf-manage resource-modify --limit 4 cyclades.network.private
snf-manage resource-modify --limit 4 cyclades.floating_ip
"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment