Update LowerCaseCharField to subclass proper CharField
[ganeti_webmgr.git] / ganeti_web / logs.py
blobd8071620e1e3644db6d02f5c924c2278513cfa9a
1 # Copyright (C) 2010 Oregon State University et al.
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
16 # USA.
18 from object_log.models import LogAction
21 def build_vm_cache(user, object1, object2, object3, data):
22 """
23 object1: VirtualMachine
24 object2: Job
25 """
27 data = {}
28 if object1 is not None:
29 data['cluster_slug'] = object1.cluster.slug
30 data['hostname'] = object1.hostname
31 if hasattr(object1, 'newname'):
32 data['newname'] = object1.newname
33 if object2 is not None:
34 data['job_id'] = object2.job_id
35 return data
38 def build_node_cache(user, object1, object2, object3, data):
39 data = {}
40 if object1 is not None:
41 data['cluster_slug'] = object1.cluster.slug
42 data['hostname'] = object1.hostname
43 if object2 is not None:
44 data['job_id'] = object2.job_id
45 return data
48 def build_cluster_cache(user, object1, object2, object3, data):
49 data = {}
50 if object1 is not None:
51 data['cluster_slug'] = object1.slug
52 data['hostname'] = object1.hostname
53 if object2 is not None:
54 data['job_id'] = object2.job_id
55 return data
58 def build_op_cache(user, object1, object2, object3, data):
59 data = {
60 'object_str': str(object1)
62 if object2:
63 data['affected_user'] = str(object2)
64 data['affected_user_class'] = object2.__class__.__name__
65 return data
68 def register_log_actions():
69 # Register LogActions used within the Ganeti App
70 LogAction.objects.register('VM_REBOOT', 'ganeti/object_log/vm_reboot.html',
71 build_vm_cache)
72 LogAction.objects.register('VM_START', 'ganeti/object_log/vm_start.html',
73 build_vm_cache)
74 LogAction.objects.register('VM_STOP', 'ganeti/object_log/vm_stop.html',
75 build_vm_cache)
76 LogAction.objects.register('VM_MIGRATE',
77 'ganeti/object_log/vm_migrate.html',
78 build_vm_cache)
79 LogAction.objects.register('VM_REPLACE_DISKS',
80 'ganeti/object_log/vm_replace_disks.html',
81 build_vm_cache)
82 LogAction.objects.register('VM_REINSTALL',
83 'ganeti/object_log/vm_reinstall.html',
84 build_vm_cache)
85 LogAction.objects.register('VM_MODIFY',
86 'ganeti/object_log/vm_modify.html',
87 build_vm_cache)
88 LogAction.objects.register('VM_RENAME',
89 'ganeti/object_log/vm_rename.html',
90 build_vm_cache)
91 LogAction.objects.register('VM_RECOVER',
92 'ganeti/object_log/vm_recover.html',
93 build_vm_cache)
95 LogAction.objects.register('CLUSTER_REDISTRIBUTE',
96 'ganeti/object_log/cluster_redistribute.html',
97 build_cluster_cache)
99 LogAction.objects.register('NODE_EVACUATE',
100 'ganeti/object_log/node_evacuate.html',
101 build_node_cache)
102 LogAction.objects.register('NODE_MIGRATE',
103 'ganeti/object_log/node_migrate.html',
104 build_node_cache)
105 LogAction.objects.register('NODE_ROLE_CHANGE',
106 'ganeti/object_log/node_role_change.html',
107 build_node_cache)
109 # add log actions for permission actions here
110 LogAction.objects.register('ADD_USER',
111 'ganeti/object_log/permissions/add_user.html',
112 build_op_cache)
113 LogAction.objects.register('REMOVE_USER',
114 'ganeti/object_log/permissions'
115 '/remove_user.html',
116 build_op_cache)
117 LogAction.objects.register('MODIFY_PERMS',
118 'ganeti/object_log/permissions'
119 '/modify_perms.html',
120 build_op_cache)