cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
vm.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 # @COPYRIGHT_begin
3 #
4 # Copyright [2010-2014] Institute of Nuclear Physics PAN, Krakow, Poland
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18 # @COPYRIGHT_end
19 
20 ##
21 # @package src.wi.urls.user.vm
22 #
23 # @author Krzysztof Danielowski
24 # @author Piotr W√≥jcik
25 # @date 26.11.2010
26 #
27 
28 from django.conf.urls import patterns, url, include
29 from django.utils.translation import ungettext, ugettext_lazy as _
30 
31 from wi.forms.vm import ChangeVMPasswordForm, EditVMForm, SetSshKeyForm, \
32  AssignChosenIPForm, CreateVMForm1, CreateVMForm2, CreateVMForm3, CreateVMForm4, \
33  MonitoringVMForm
34 from wi.utils.decorators import user_permission
35 from wi.utils.views import direct_to_template, simple_generic_id, \
36  form_generic_id, generic_multiple_id, generic_multiple_id_form
37 from wi.views.user.vm import CreateVMWizard
38 
39 
40 vm_patterns = patterns('wi.views.user.vm',
41  url(r'^$', user_permission(direct_to_template), {'template_name': 'vms/base.html'}, name='vms_vms'),
42 
43  url(r'^create_vm/$', CreateVMWizard.as_view([CreateVMForm1, CreateVMForm2, CreateVMForm3, CreateVMForm4]), name='vms_create_vm'),
44  url(r'^show_vm/$', user_permission(direct_to_template), {'template_name': 'vms/show_vm.html'}, name='vms_show_vm'),
45 
46  url(r'^vnc/(?P<vm_id>\d+)/$', 'vms_vnc', name='vms_vnc'),
47 
48  url(r'^ajax/vm_details/(?P<vm_id>\d+)/$', 'vms_ajax_vm_details', name='vms_ajax_vm_details'),
49  url(r'^ajax/get_table/$', 'vms_ajax_get_table', name='vms_ajax_get_table'),
50 
51  url(r'^ajax/ssh_key/$', user_permission(generic_multiple_id_form),
52  {'template_name': 'generic/form.html',
53  'success_msg': (lambda desc, count: ungettext('SSH key has been copied successfully to <b>%(desc)s</b>.', 'SSH key has been copied successfully to %(count)d virtual machines (<b>%(desc)s</b>).', count) % {'desc': desc, 'count': count}),
54  'ask_msg': (lambda desc, count: ungettext('Enter a public key to set for machine <b>%(desc)s</b>.', 'Enter a public key to set for %(count)d machines <b>%(desc)s</b>.', count) % {'desc': desc, 'count': count}),
55  'confirmation': _('Set key'),
56  'request_url': 'user/ctx/add_ssh_key/',
57  'form_class': SetSshKeyForm,
58  'request_url_both': {'keys': 'user/key/get_list/'},
59  'id_key': 'vm_ids'
60  },
61  name='vms_ajax_ssh_key'),
62  url(r'^ajax/reset_password/(?P<id1>\d+)/$', user_permission(form_generic_id),
63  {'template_name': 'generic/form.html',
64  'success_msg': (lambda desc, data: _('Password has been set to: (<b>%(password)s</b>) on machine: <b>%(desc)s</b>.') % {'password': data['password'], 'desc': desc}),
65  'ask_msg': (lambda desc: _('Reset machine <b>%(desc)s</b> password for selected user.') % {'desc': desc}),
66  'confirmation': _('Reset password'),
67  'request_url_post': 'user/ctx/reset_password/',
68  'form_class': ChangeVMPasswordForm,
69  'ajax_success_status': 7999, # for 'info' class of the popup
70  'id_key': 'vm_id'
71  },
72  name='vms_ajax_reset_password'),
73  url(r'^ajax/destroy/$', user_permission(generic_multiple_id),
74  {'template_name': 'generic/simple.html',
75  'success_msg': (lambda desc, count: ungettext('You have successfully destroyed virtual machine <b>%(desc)s</b>.', 'You have successfully destroyed %(count)d virtual machines (<b>%(desc)s</b>).', count) % {'desc': desc, 'count': count}),
76  'ask_msg': (lambda desc, count: ungettext('Do you want to destroy virtual machine <b>%(desc)s</b>?<br /><b>Note!</b> If you would like to use this machine later make sure to use the <b>Save and shutdown</b> option instead!<br /> We recommend to manually unmount any attached storage disks.',
77  'Do you want to destroy %(count)d virtual machines <b>%(desc)s</b>?<br /><b>Note!</b> If you would like to use this machine later make sure to use the <b>Save and shutdown</b> option instead!<br /> We recommend to manually unmount any attached storage disks.', count) % {'desc': desc, 'count': count}),
78  'request_url': 'user/vm/destroy/',
79  'id_key': 'vm_ids'
80  },
81  name='vms_ajax_destroy'),
82  url(r'^ajax/restart/$', user_permission(generic_multiple_id),
83  {'template_name': 'generic/simple.html',
84  'success_msg': (lambda desc, count: ungettext('You have successfully rebooted virtual machine <b>%(desc)s</b>.', 'You have successfully rebooted %(count)d virtual machines (<b>%(desc)s</b>).', count) % {'desc': desc, 'count': count}),
85  'ask_msg': (lambda desc, count: ungettext('Do you want to reset virtual machine <b>%(desc)s</b>?.<br /><b>Note!</b> Any unsaved data will be lost!', 'Do you want to reset %(count)d virtual machines <b>%(desc)s</b>?.<br /><b>Note!</b> Any unsaved data will be lost!', count) % {'desc': desc, 'count': count}),
86  'request_url': 'user/vm/reset/',
87  'id_key': 'vm_ids'
88  },
89  name='vms_ajax_restart'),
90 
91  url(r'^ajax/assign_chosen_ip/(?P<id1>\d+)/$', user_permission(form_generic_id),
92  {'template_name': 'vms/ajax/assign_ip.html',
93  'success_msg': (lambda desc, data: _('You have successfully assigned selected IP address.') % {'desc': desc}),
94  'ask_msg': (lambda desc: _('Select an IP address to assign:') % {'desc': desc}),
95  'confirmation': _('Assign selected IP'),
96  'request_url_post': 'user/public_ip/assign/',
97  'form_class': AssignChosenIPForm,
98  'request_url_both': {'ips': 'user/public_ip/get_list/'},
99  'id_key': 'lease_id'
100  },
101  name='vms_ajax_assign_chosen_ip'),
102 
103  url(r'^ajax/assign_ip/(?P<vm_id>\d+)/$', 'vms_ajax_assign_ip', name='vms_ajax_assign_ip'),
104 
105  url(r'^ajax/revoke_chosen_ip/(?P<id1>\d+)/$', user_permission(simple_generic_id),
106  {'template_name': 'generic/simple.html',
107  'success_msg': (lambda desc: _('You have successfully revoked IP address.') % {'desc': desc}),
108  'ask_msg': (lambda desc: _('Do you want to revoke IP address?') % {'desc': desc}),
109  'request_url': 'user/public_ip/unassign/',
110  'id_key': 'lease_id'
111  },
112  name='vms_ajax_revoke_chosen_ip'),
113 
114  url(r'^ajax/revoke_ip/(?P<vm_id>\d+)/$', 'vms_ajax_revoke_ip', name='vms_ajax_revoke_ip'),
115  url(r'^ajax/assign_disk/(?P<vm_id>\d+)/$', 'vms_ajax_assign_disk', name='vms_ajax_assign_disk'),
116  url(r'^ajax/revoke_disk/(?P<vm_id>\d+)/$', 'vms_ajax_revoke_disk', name='vms_ajax_revoke_disk'),
117 
118  url(r'^ajax/edit_vm/(?P<id1>\d+)/$', user_permission(form_generic_id),
119  {'template_name': 'generic/form.html',
120  'success_msg': (lambda desc, data: _('You have successfully edited virtual machine data.') % {'desc': desc}),
121  'confirmation': _('Save'),
122  'request_url_post': 'user/vm/edit/',
123  'request_url_get': 'user/vm/get_by_id/',
124  'form_class': EditVMForm,
125  'id_key': 'vm_id'},
126  name='vms_ajax_edit_vm'),
127 
128  url(r'^ajax/save_and_shutdown/(?P<id1>\d+)/$', user_permission(form_generic_id),
129  {'template_name': 'generic/form.html',
130  'success_msg': (lambda desc, data: _('Virtual machine will be saved.') % {'desc': desc}),
131  'ask_msg': (lambda desc: _('Enter a name to save virtual machine <b>%(desc)s</b>:') % {'desc': desc}),
132  'confirmation': _('Save and shutdown'),
133  'request_url_post': 'user/vm/save_and_shutdown/',
134  'request_url_get': 'user/vm/get_by_id/',
135  'form_class': EditVMForm,
136  'id_key': 'vm_id'},
137  name='vms_ajax_save_and_shutdown'),
138 
139  url(r'^ajax/set_vnc/(?P<id1>\d+)/$', user_permission(simple_generic_id),
140  {'template_name': 'generic/simple.html',
141  'success_msg': (lambda desc: _('You have successfully enabled VNC.') % {'desc': desc}),
142  'ask_msg': (lambda desc: _('Do you want to enable VNC?') % {'desc': desc}),
143  'request_url': 'user/vm/attach_vnc/',
144  'id_key': 'vm_id'
145  },
146  name='vms_ajax_set_vnc'),
147  url(r'^ajax/unset_vnc/(?P<id1>\d+)/$', user_permission(simple_generic_id),
148  {'template_name': 'generic/simple.html',
149  'success_msg': (lambda desc: _('You have successfully disabled VNC.') % {'desc': desc}),
150  'ask_msg': (lambda desc: _('Do you want to disable VNC?') % {'desc': desc}),
151  'request_url': 'user/vm/detach_vnc/',
152  'id_key': 'vm_id'
153  },
154  name='vms_ajax_unset_vnc'),
155 
156  url(r'^ajax/get_template_list/$', 'vms_ajax_get_template_list', name='vms_ajax_get_template_list'),
157 
158  url(r'^ajax/monitoring/(?P<id1>\d+)/$', user_permission(form_generic_id),
159  {'template_name': 'vms/ajax/monitoring.html',
160  'form_class': MonitoringVMForm,
161  'success_msg': (lambda desc, data: data),
162  'request_url_post': 'user/monia/vm_stats/',
163  'id_key': 'vm_id'
164  },
165  name='vms_ajax_vm_monitoring'),
166 )
167 
168 
169 urlpatterns = patterns('',
170  url(r'^vm/', include(vm_patterns)),
171 )
172