-
Notifications
You must be signed in to change notification settings - Fork 8
/
testing_tools.py
54 lines (37 loc) · 1.63 KB
/
testing_tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from django.http import HttpResponse, HttpResponseRedirect
from datetime import datetime
from vdi.models import Instance, Application
from opus.lib import log
log = log.get_logger('vdi')
from cost_tools import convert_to_date_time
from app_cluster_tools import AppCluster
def get_nodesInCluster(request, app_pk, date_time):
instances = AppCluster(app_pk).nodes
date_time = convert_to_date_time(date_time)
num_nodes = 0
for instance in instances:
if instance.state == 5:
if instance.startUpDateTime < date_time and instance.shutdownDateTime > date_time:
num_nodes += 1
else:
if instance.startUpDateTime < date_time:
num_nodes += 1
return HttpResponse(num_nodes)
def get_provisioningEventsInDateRange(request, app_pk, start_date, end_date):
instances = AppCluster(app_pk).nodes
num_events = 0
starting_dateTime = convert_to_date_time(start_date)
ending_dateTime = convert_to_date_time(end_date)
for instance in instances:
if instance.startUpDateTime > starting_dateTime and instance.startUpDateTime < ending_dateTime:
num_events += 1
return HttpResponse(num_events)
def get_deprovisioningEventsInDateRange(request, app_pk, start_date, end_date):
instances = AppCluster(app_pk).deleted
num_events = 0
starting_dateTime = convert_to_date_time(start_date)
ending_dateTime = convert_to_date_time(end_date)
for instance in instances:
if instance.shutdownDateTime > starting_dateTime and instance.shutdownDateTime < ending_dateTime:
num_events += 1
return HttpResponse(num_events)