Revision 52343ac8 snf-astakos-app/astakos/im/views.py
b/snf-astakos-app/astakos/im/views.py | ||
---|---|---|
1044 | 1044 |
else: |
1045 | 1045 |
form = PickResourceForm() |
1046 | 1046 |
q = AstakosGroupQuota.objects.none() |
1047 |
|
|
1048 |
data ={ |
|
1049 |
'resources':[{ |
|
1050 |
'name': 'vm', |
|
1051 |
'description': 'Number Of Vms', |
|
1052 |
'unit':'', |
|
1053 |
'maxValue':'100', |
|
1054 |
'currValue':'50' |
|
1055 |
},{ |
|
1056 |
'name': 'ram', |
|
1057 |
'description':'Total Ram Usage', |
|
1058 |
'unit':'GB', |
|
1059 |
'maxValue':'4', |
|
1060 |
'currValue':'1' |
|
1061 |
},{ |
|
1062 |
'name': 'storage', |
|
1063 |
'description':'Total Disk Space Used', |
|
1064 |
'unit':'GB', |
|
1065 |
'maxValue':'200', |
|
1066 |
'currValue':'180' |
|
1067 |
},{ |
|
1068 |
'name': 'disk', |
|
1069 |
'description':'Disks Used', |
|
1070 |
'unit':'GB', |
|
1071 |
'maxValue':'16', |
|
1072 |
'currValue':'16' |
|
1073 |
},{ |
|
1074 |
'name': 'network', |
|
1075 |
'description':'Private Networks Used', |
|
1076 |
'unit':'', |
|
1077 |
'maxValue':'2', |
|
1078 |
'currValue':'1' |
|
1079 |
},{ |
|
1080 |
'name': 'bandwidth', |
|
1081 |
'description':'Bandwidth Monitoring Device', |
|
1082 |
'unit':'Gbps', |
|
1083 |
'maxValue':'200', |
|
1084 |
'currValue':'50' |
|
1085 |
}] |
|
1086 |
} |
|
1087 |
|
|
1088 |
def with_class(entry): |
|
1089 |
entry['load_class'] = 'red' |
|
1090 |
max_value = float(entry['maxValue']) |
|
1091 |
curr_value = float(entry['currValue']) |
|
1092 |
entry['ratio'] = (curr_value/max_value)*100 |
|
1093 |
if entry['ratio'] < 66: |
|
1094 |
entry['load_class']='yellow' |
|
1095 |
if entry['ratio'] < 33: |
|
1096 |
entry['load_class']='green' |
|
1097 |
|
|
1098 |
return entry |
|
1099 |
|
|
1100 |
def pluralize(entry): |
|
1101 |
if entry['unit'] == '': |
|
1102 |
entry['plural'] = entry['name']+'s' |
|
1103 |
else: |
|
1104 |
entry['plural'] = entry['name'] |
|
1105 |
|
|
1106 |
return entry |
|
1107 |
|
|
1108 |
data['resources'] = map(with_class, data['resources']) |
|
1109 |
data['resources'] = map(pluralize, data['resources']) |
|
1110 |
|
|
1047 | 1111 |
return object_list(request, q, |
1048 | 1112 |
template_name='im/astakosuserquota_list.html', |
1049 |
extra_context={'form': form}) |
|
1113 |
extra_context={'form': form, 'data':data})
|
|
1050 | 1114 |
|
1051 | 1115 |
|
1052 | 1116 |
def group_create_list(request): |
... | ... | |
1062 | 1126 |
|
1063 | 1127 |
today = datetime.today() |
1064 | 1128 |
month_last_day= calendar.monthrange(today.year, today.month)[1] |
1065 |
|
|
1129 |
data['resources'] = map(with_class,data['resources']) |
|
1066 | 1130 |
start = request.POST.get('datefrom', None) |
1067 | 1131 |
if start: |
1068 | 1132 |
today = datetime.fromtimestamp(int(start)) |
... | ... | |
1150 | 1214 |
form=form, |
1151 | 1215 |
timeline_header=timeline_header, |
1152 | 1216 |
timeline_body=timeline_body) |
1153 |
return data |
|
1217 |
return data |
Also available in: Unified diff