Revision 479c3051 snf-cyclades-app/synnefo/ui/views.py
b/snf-cyclades-app/synnefo/ui/views.py | ||
---|---|---|
36 | 36 |
|
37 | 37 |
from django.conf import settings |
38 | 38 |
from django.utils.translation import gettext_lazy as _ |
39 |
from django.template import Context, loader
|
|
39 |
from django.template import loader |
|
40 | 40 |
from django.http import HttpResponse |
41 | 41 |
from django.utils.translation import get_language |
42 | 42 |
from django.utils import simplejson as json |
43 |
from django.shortcuts import render_to_response |
|
44 | 43 |
from django.template.loader import render_to_string |
45 | 44 |
from django.core.urlresolvers import reverse |
46 |
from django.core.mail import send_mail |
|
47 |
from django.http import Http404 |
|
48 | 45 |
from django.template import RequestContext |
49 | 46 |
|
50 | 47 |
from synnefo.util.version import get_component_version |
... | ... | |
61 | 58 |
UPDATE_INTERVAL = getattr(settings, "UI_UPDATE_INTERVAL", 5000) |
62 | 59 |
CHANGES_SINCE_ALIGNMENT = getattr(settings, "UI_CHANGES_SINCE_ALIGNMENT", 0) |
63 | 60 |
UPDATE_INTERVAL_INCREASE = getattr(settings, "UI_UPDATE_INTERVAL_INCREASE", 500) |
64 |
UPDATE_INTERVAL_INCREASE_AFTER_CALLS_COUNT = getattr(settings, |
|
65 |
"UI_UPDATE_INTERVAL_INCREASE_AFTER_CALLS_COUNT", |
|
66 |
3) |
|
61 |
UPDATE_INTERVAL_INCREASE_AFTER_CALLS_COUNT = \ |
|
62 |
getattr(settings, "UI_UPDATE_INTERVAL_INCREASE_AFTER_CALLS_COUNT", 3) |
|
67 | 63 |
UPDATE_INTERVAL_FAST = getattr(settings, "UI_UPDATE_INTERVAL_FAST", 2500) |
68 | 64 |
UPDATE_INTERVAL_MAX = getattr(settings, "UI_UPDATE_INTERVAL_MAX", 10000) |
69 | 65 |
QUOTAS_UPDATE_INTERVAL = getattr(settings, "UI_QUOTAS_UPDATE_INTERVAL", 10000) |
70 | 66 |
|
71 | 67 |
# predefined values settings |
72 |
VM_IMAGE_COMMON_METADATA = getattr(settings, "UI_VM_IMAGE_COMMON_METADATA", ["OS", "users"]) |
|
68 |
VM_IMAGE_COMMON_METADATA = \ |
|
69 |
getattr(settings, "UI_VM_IMAGE_COMMON_METADATA", ["OS", "users"]) |
|
73 | 70 |
SUGGESTED_FLAVORS_DEFAULT = {} |
74 | 71 |
SUGGESTED_FLAVORS = getattr(settings, "VM_CREATE_SUGGESTED_FLAVORS", |
75 | 72 |
SUGGESTED_FLAVORS_DEFAULT) |
... | ... | |
78 | 75 |
SUGGESTED_ROLES = getattr(settings, "VM_CREATE_SUGGESTED_ROLES", |
79 | 76 |
SUGGESTED_ROLES_DEFAULT) |
80 | 77 |
IMAGE_ICONS = settings.IMAGE_ICONS |
81 |
IMAGE_DELETED_TITLE = getattr(settings, 'UI_IMAGE_DELETED_TITLE',
|
|
82 |
'(deleted)')
|
|
83 |
IMAGE_DELETED_SIZE_TITLE = getattr(settings, 'UI_IMAGE_DELETED_SIZE_TITLE',
|
|
84 |
'(none)')
|
|
78 |
IMAGE_DELETED_TITLE = \
|
|
79 |
getattr(settings, 'UI_IMAGE_DELETED_TITLE', '(deleted)')
|
|
80 |
IMAGE_DELETED_SIZE_TITLE = \
|
|
81 |
getattr(settings, 'UI_IMAGE_DELETED_SIZE_TITLE', '(none)')
|
|
85 | 82 |
|
86 | 83 |
SUPPORT_SSH_OS_LIST = getattr(settings, "UI_SUPPORT_SSH_OS_LIST",) |
87 | 84 |
OS_CREATED_USERS = getattr(settings, "UI_OS_DEFAULT_USER_MAP") |
... | ... | |
92 | 89 |
# UI behaviour settings |
93 | 90 |
DELAY_ON_BLUR = getattr(settings, "UI_DELAY_ON_BLUR", True) |
94 | 91 |
UPDATE_HIDDEN_VIEWS = getattr(settings, "UI_UPDATE_HIDDEN_VIEWS", False) |
95 |
HANDLE_WINDOW_EXCEPTIONS = getattr(settings, "UI_HANDLE_WINDOW_EXCEPTIONS", True) |
|
92 |
HANDLE_WINDOW_EXCEPTIONS = \ |
|
93 |
getattr(settings, "UI_HANDLE_WINDOW_EXCEPTIONS", True) |
|
96 | 94 |
SKIP_TIMEOUTS = getattr(settings, "UI_SKIP_TIMEOUTS", 1) |
97 | 95 |
|
98 | 96 |
# Additional settings |
99 | 97 |
VM_NAME_TEMPLATE = getattr(settings, "VM_CREATE_NAME_TPL", "My {0} server") |
100 | 98 |
VM_HOSTNAME_FORMAT = getattr(settings, "UI_VM_HOSTNAME_FORMAT", |
101 |
'snf-%(id)s.vm.okeanos.grnet.gr')
|
|
99 |
'snf-%(id)s.vm.okeanos.grnet.gr') |
|
102 | 100 |
|
103 | 101 |
if isinstance(VM_HOSTNAME_FORMAT, basestring): |
104 |
VM_HOSTNAME_FORMAT = VM_HOSTNAME_FORMAT % {'id':'{0}'}
|
|
102 |
VM_HOSTNAME_FORMAT = VM_HOSTNAME_FORMAT % {'id': '{0}'}
|
|
105 | 103 |
|
106 | 104 |
MAX_SSH_KEYS_PER_USER = getattr(settings, "USERDATA_MAX_SSH_KEYS_PER_USER") |
107 |
FLAVORS_DISK_TEMPLATES_INFO = getattr(settings, "UI_FLAVORS_DISK_TEMPLATES_INFO", {}) |
|
105 |
FLAVORS_DISK_TEMPLATES_INFO = \ |
|
106 |
getattr(settings, "UI_FLAVORS_DISK_TEMPLATES_INFO", {}) |
|
108 | 107 |
SYSTEM_IMAGES_OWNERS = getattr(settings, "UI_SYSTEM_IMAGES_OWNERS", {}) |
109 | 108 |
CUSTOM_IMAGE_HELP_URL = getattr(settings, "UI_CUSTOM_IMAGE_HELP_URL", None) |
110 | 109 |
|
111 | 110 |
# MEDIA PATHS |
112 |
UI_MEDIA_URL = getattr(settings, "UI_MEDIA_URL", |
|
113 |
"%ssnf-%s/" % (settings.MEDIA_URL, SYNNEFO_JS_LIB_VERSION)) |
|
114 |
UI_SYNNEFO_IMAGES_URL = getattr(settings, |
|
115 |
"UI_SYNNEFO_IMAGES_URL", UI_MEDIA_URL + "images/") |
|
116 |
UI_SYNNEFO_CSS_URL = getattr(settings, |
|
117 |
"UI_SYNNEFO_CSS_URL", UI_MEDIA_URL + "css/") |
|
118 |
UI_SYNNEFO_JS_URL = getattr(settings, |
|
119 |
"UI_SYNNEFO_JS_URL", UI_MEDIA_URL + "js/") |
|
120 |
UI_SYNNEFO_JS_LIB_URL = getattr(settings, |
|
121 |
"UI_SYNNEFO_JS_LIB_URL", UI_SYNNEFO_JS_URL + "lib/") |
|
122 |
UI_SYNNEFO_JS_WEB_URL = getattr(settings, |
|
123 |
"UI_SYNNEFO_JS_WEB_URL", |
|
124 |
UI_SYNNEFO_JS_URL + "ui/web/") |
|
111 |
UI_MEDIA_URL = \ |
|
112 |
getattr(settings, "UI_MEDIA_URL", |
|
113 |
"%ssnf-%s/" % (settings.MEDIA_URL, SYNNEFO_JS_LIB_VERSION)) |
|
114 |
UI_SYNNEFO_IMAGES_URL = \ |
|
115 |
getattr(settings, |
|
116 |
"UI_SYNNEFO_IMAGES_URL", UI_MEDIA_URL + "images/") |
|
117 |
UI_SYNNEFO_CSS_URL = \ |
|
118 |
getattr(settings, |
|
119 |
"UI_SYNNEFO_CSS_URL", UI_MEDIA_URL + "css/") |
|
120 |
UI_SYNNEFO_JS_URL = \ |
|
121 |
getattr(settings, |
|
122 |
"UI_SYNNEFO_JS_URL", UI_MEDIA_URL + "js/") |
|
123 |
UI_SYNNEFO_JS_LIB_URL = \ |
|
124 |
getattr(settings, |
|
125 |
"UI_SYNNEFO_JS_LIB_URL", UI_SYNNEFO_JS_URL + "lib/") |
|
126 |
UI_SYNNEFO_JS_WEB_URL = \ |
|
127 |
getattr(settings, "UI_SYNNEFO_JS_WEB_URL", UI_SYNNEFO_JS_URL + "ui/web/") |
|
125 | 128 |
|
126 | 129 |
# extensions |
127 | 130 |
ENABLE_GLANCE = getattr(settings, 'UI_ENABLE_GLANCE', True) |
128 | 131 |
GLANCE_API_URL = getattr(settings, 'UI_GLANCE_API_URL', '/glance') |
129 |
DIAGNOSTICS_UPDATE_INTERVAL = getattr(settings,
|
|
130 |
'UI_DIAGNOSTICS_UPDATE_INTERVAL', 2000)
|
|
132 |
DIAGNOSTICS_UPDATE_INTERVAL = \
|
|
133 |
getattr(settings, 'UI_DIAGNOSTICS_UPDATE_INTERVAL', 2000)
|
|
131 | 134 |
|
132 | 135 |
# network settings |
133 |
DEFAULT_NETWORK_TYPES = {'MAC_FILTERED': 'mac-filtering', 'PHYSICAL_VLAN': 'physical-vlan'} |
|
134 |
NETWORK_TYPES = getattr(settings, |
|
135 |
'UI_NETWORK_AVAILABLE_NETWORK_TYPES', DEFAULT_NETWORK_TYPES) |
|
136 |
DEFAULT_NETWORK_TYPES = {'MAC_FILTERED': 'mac-filtering', |
|
137 |
'PHYSICAL_VLAN': 'physical-vlan'} |
|
138 |
NETWORK_TYPES = \ |
|
139 |
getattr(settings, |
|
140 |
'UI_NETWORK_AVAILABLE_NETWORK_TYPES', DEFAULT_NETWORK_TYPES) |
|
136 | 141 |
DEFAULT_NETWORK_SUBNETS = ['10.0.0.0/24', '192.168.1.1/24'] |
137 |
NETWORK_SUBNETS = getattr(settings, |
|
138 |
'UI_NETWORK_AVAILABLE_SUBNETS', DEFAULT_NETWORK_SUBNETS) |
|
139 |
NETWORK_DUPLICATE_NICS = getattr(settings, |
|
140 |
'UI_NETWORK_ALLOW_DUPLICATE_VM_NICS', False) |
|
141 |
NETWORK_STRICT_DESTROY = getattr(settings, |
|
142 |
'UI_NETWORK_STRICT_DESTROY', False) |
|
143 |
NETWORK_ALLOW_MULTIPLE_DESTROY = getattr(settings, |
|
144 |
'UI_NETWORK_ALLOW_MULTIPLE_DESTROY', False) |
|
142 |
NETWORK_SUBNETS = \ |
|
143 |
getattr(settings, |
|
144 |
'UI_NETWORK_AVAILABLE_SUBNETS', DEFAULT_NETWORK_SUBNETS) |
|
145 |
NETWORK_DUPLICATE_NICS = \ |
|
146 |
getattr(settings, |
|
147 |
'UI_NETWORK_ALLOW_DUPLICATE_VM_NICS', False) |
|
148 |
NETWORK_STRICT_DESTROY = \ |
|
149 |
getattr(settings, |
|
150 |
'UI_NETWORK_STRICT_DESTROY', False) |
|
151 |
NETWORK_ALLOW_MULTIPLE_DESTROY = \ |
|
152 |
getattr(settings, |
|
153 |
'UI_NETWORK_ALLOW_MULTIPLE_DESTROY', False) |
|
145 | 154 |
AUTOMATIC_NETWORK_RANGE_FORMAT = getattr(settings, |
146 | 155 |
'UI_AUTOMATIC_NETWORK_RANGE_FORMAT', |
147 |
"192.168.%d.0/24").replace("%d", "{0}") |
|
156 |
"192.168.%d.0/24").replace("%d", "{0}")
|
|
148 | 157 |
GROUP_PUBLIC_NETWORKS = getattr(settings, 'UI_GROUP_PUBLIC_NETWORKS', True) |
149 |
GROUPED_PUBLIC_NETWORK_NAME = getattr(settings, 'UI_GROUPED_PUBLIC_NETWORK_NAME', 'Internet') |
|
158 |
GROUPED_PUBLIC_NETWORK_NAME = \ |
|
159 |
getattr(settings, 'UI_GROUPED_PUBLIC_NETWORK_NAME', 'Internet') |
|
150 | 160 |
|
151 | 161 |
USER_CATALOG_URL = getattr(settings, 'UI_USER_CATALOG_URL', '/user_catalogs') |
152 | 162 |
FEEDBACK_POST_URL = getattr(settings, 'UI_FEEDBACK_POST_URL', '/feedback') |
153 | 163 |
TRANSLATE_UUIDS = not getattr(settings, 'TRANSLATE_UUIDS', False) |
154 | 164 |
|
165 |
|
|
155 | 166 |
def template(name, request, context): |
156 | 167 |
template_path = os.path.join(os.path.dirname(__file__), "templates/") |
157 | 168 |
current_template = template_path + name + '.html' |
158 | 169 |
t = loader.get_template(current_template) |
159 | 170 |
media_context = { |
160 |
'UI_MEDIA_URL': UI_MEDIA_URL, |
|
161 |
'SYNNEFO_JS_URL': UI_SYNNEFO_JS_URL, |
|
162 |
'SYNNEFO_JS_LIB_URL': UI_SYNNEFO_JS_LIB_URL, |
|
163 |
'SYNNEFO_JS_WEB_URL': UI_SYNNEFO_JS_WEB_URL, |
|
164 |
'SYNNEFO_IMAGES_URL': UI_SYNNEFO_IMAGES_URL, |
|
165 |
'SYNNEFO_CSS_URL': UI_SYNNEFO_CSS_URL, |
|
166 |
'SYNNEFO_JS_LIB_VERSION': SYNNEFO_JS_LIB_VERSION, |
|
167 |
'DEBUG': settings.DEBUG |
|
171 |
'UI_MEDIA_URL': UI_MEDIA_URL,
|
|
172 |
'SYNNEFO_JS_URL': UI_SYNNEFO_JS_URL,
|
|
173 |
'SYNNEFO_JS_LIB_URL': UI_SYNNEFO_JS_LIB_URL,
|
|
174 |
'SYNNEFO_JS_WEB_URL': UI_SYNNEFO_JS_WEB_URL,
|
|
175 |
'SYNNEFO_IMAGES_URL': UI_SYNNEFO_IMAGES_URL,
|
|
176 |
'SYNNEFO_CSS_URL': UI_SYNNEFO_CSS_URL,
|
|
177 |
'SYNNEFO_JS_LIB_VERSION': SYNNEFO_JS_LIB_VERSION,
|
|
178 |
'DEBUG': settings.DEBUG
|
|
168 | 179 |
} |
169 | 180 |
context.update(media_context) |
170 | 181 |
return HttpResponse(t.render(RequestContext(request, context))) |
171 | 182 |
|
183 |
|
|
172 | 184 |
def home(request): |
173 | 185 |
context = {'timeout': TIMEOUT, |
174 | 186 |
'project': '+nefo', |
... | ... | |
178 | 190 |
'user_catalog_url': json.dumps(USER_CATALOG_URL), |
179 | 191 |
'feedback_post_url': json.dumps(FEEDBACK_POST_URL), |
180 | 192 |
'translate_uuids': json.dumps(TRANSLATE_UUIDS), |
181 |
# update interval settings
|
|
193 |
# update interval settings |
|
182 | 194 |
'update_interval': UPDATE_INTERVAL, |
183 | 195 |
'update_interval_increase': UPDATE_INTERVAL_INCREASE, |
184 |
'update_interval_increase_after_calls': UPDATE_INTERVAL_INCREASE_AFTER_CALLS_COUNT, |
|
196 |
'update_interval_increase_after_calls': |
|
197 |
UPDATE_INTERVAL_INCREASE_AFTER_CALLS_COUNT, |
|
185 | 198 |
'update_interval_fast': UPDATE_INTERVAL_FAST, |
186 | 199 |
'update_interval_max': UPDATE_INTERVAL_MAX, |
187 | 200 |
'changes_since_alignment': CHANGES_SINCE_ALIGNMENT, |
... | ... | |
199 | 212 |
'handle_window_exceptions': json.dumps(HANDLE_WINDOW_EXCEPTIONS), |
200 | 213 |
'skip_timeouts': json.dumps(SKIP_TIMEOUTS), |
201 | 214 |
'vm_name_template': json.dumps(VM_NAME_TEMPLATE), |
202 |
'flavors_disk_templates_info': json.dumps(FLAVORS_DISK_TEMPLATES_INFO), |
|
215 |
'flavors_disk_templates_info': |
|
216 |
json.dumps(FLAVORS_DISK_TEMPLATES_INFO), |
|
203 | 217 |
'support_ssh_os_list': json.dumps(SUPPORT_SSH_OS_LIST), |
204 | 218 |
'os_created_users': json.dumps(OS_CREATED_USERS), |
205 | 219 |
'userdata_keys_limit': json.dumps(MAX_SSH_KEYS_PER_USER), |
... | ... | |
211 | 225 |
'image_deleted_size_title': json.dumps(IMAGE_DELETED_SIZE_TITLE), |
212 | 226 |
'network_suggested_subnets': json.dumps(NETWORK_SUBNETS), |
213 | 227 |
'network_available_types': json.dumps(NETWORK_TYPES), |
214 |
'network_allow_duplicate_vm_nics': json.dumps(NETWORK_DUPLICATE_NICS), |
|
228 |
'network_allow_duplicate_vm_nics': |
|
229 |
json.dumps(NETWORK_DUPLICATE_NICS), |
|
215 | 230 |
'network_strict_destroy': json.dumps(NETWORK_STRICT_DESTROY), |
216 |
'network_allow_multiple_destroy': json.dumps(NETWORK_ALLOW_MULTIPLE_DESTROY), |
|
217 |
'automatic_network_range_format': json.dumps(AUTOMATIC_NETWORK_RANGE_FORMAT), |
|
218 |
'grouped_public_network_name': json.dumps(GROUPED_PUBLIC_NETWORK_NAME), |
|
231 |
'network_allow_multiple_destroy': |
|
232 |
json.dumps(NETWORK_ALLOW_MULTIPLE_DESTROY), |
|
233 |
'automatic_network_range_format': |
|
234 |
json.dumps(AUTOMATIC_NETWORK_RANGE_FORMAT), |
|
235 |
'grouped_public_network_name': |
|
236 |
json.dumps(GROUPED_PUBLIC_NETWORK_NAME), |
|
219 | 237 |
'group_public_networks': json.dumps(GROUP_PUBLIC_NETWORKS), |
220 |
'diagnostics_update_interval': json.dumps(DIAGNOSTICS_UPDATE_INTERVAL), |
|
238 |
'diagnostics_update_interval': |
|
239 |
json.dumps(DIAGNOSTICS_UPDATE_INTERVAL), |
|
221 | 240 |
'vm_hostname_format': json.dumps(VM_HOSTNAME_FORMAT) |
222 |
} |
|
241 |
}
|
|
223 | 242 |
return template('home', request, context) |
224 | 243 |
|
244 |
|
|
225 | 245 |
def machines_console(request): |
226 |
host, port, password = ('','','')
|
|
227 |
host = request.GET.get('host','') |
|
228 |
port = request.GET.get('port','') |
|
229 |
password = request.GET.get('password','') |
|
230 |
machine = request.GET.get('machine','') |
|
231 |
host_ip = request.GET.get('host_ip','') |
|
232 |
host_ip_v6 = request.GET.get('host_ip_v6','') |
|
246 |
host, port, password = ('', '', '')
|
|
247 |
host = request.GET.get('host', '')
|
|
248 |
port = request.GET.get('port', '')
|
|
249 |
password = request.GET.get('password', '')
|
|
250 |
machine = request.GET.get('machine', '')
|
|
251 |
host_ip = request.GET.get('host_ip', '')
|
|
252 |
host_ip_v6 = request.GET.get('host_ip_v6', '')
|
|
233 | 253 |
context = {'host': host, 'port': port, 'password': password, |
234 | 254 |
'machine': machine, 'host_ip': host_ip, 'host_ip_v6': host_ip_v6} |
235 | 255 |
return template('machines_console', request, context) |
236 | 256 |
|
257 |
|
|
237 | 258 |
def user_quota(request): |
238 | 259 |
try: |
239 | 260 |
get_user(request, settings.ASTAKOS_URL, usage=True) |
... | ... | |
248 | 269 |
# try to mimic astakos response using cyclades quota settings |
249 | 270 |
networks_limit_for_user = \ |
250 | 271 |
settings.NETWORKS_USER_QUOTA.get(request.user_uniq, |
251 |
settings.MAX_NETWORKS_PER_USER) |
|
272 |
settings.MAX_NETWORKS_PER_USER)
|
|
252 | 273 |
vms_limit_for_user = \ |
253 | 274 |
settings.VMS_USER_QUOTA.get(request.user_uniq, |
254 |
settings.MAX_NETWORKS_PER_USER) |
|
255 |
usage = [{'name':'cyclades.vm', |
|
256 |
'maxValue': vms_limit_for_user |
|
257 |
}, |
|
258 |
{'name':'cyclades.network.private', |
|
259 |
'maxValue': networks_limit_for_user |
|
260 |
}] |
|
261 |
response = json.dumps(usage); |
|
275 |
settings.MAX_NETWORKS_PER_USER) |
|
276 |
usage = [{'name': 'cyclades.vm', |
|
277 |
'maxValue': vms_limit_for_user}, |
|
278 |
{'name': 'cyclades.network.private', |
|
279 |
'maxValue': networks_limit_for_user}] |
|
280 |
response = json.dumps(usage) |
|
262 | 281 |
|
263 | 282 |
return HttpResponse(response, mimetype="application/json") |
264 | 283 |
|
284 |
|
|
265 | 285 |
def js_tests(request): |
266 | 286 |
return template('tests', request, {}) |
267 | 287 |
|
268 |
CONNECT_LINUX_LINUX_MESSAGE = _("""A direct connection to this machine can be established using the <a target="_blank" |
|
269 |
href="http://en.wikipedia.org/wiki/Secure_Shell">SSH Protocol</a>. |
|
270 |
To do so open a terminal and type the following at the prompt to connect to your machine:""") |
|
271 |
CONNECT_LINUX_WINDOWS_MESSAGE = _("""A direct connection to this machine can be |
|
272 |
established using <a target="_blank" href="http://en.wikipedia.org/wiki/Remote_Desktop_Services">Remote Desktop Service</a>. |
|
273 |
To do so, open the following file with an appropriate remote desktop client. |
|
274 |
""") |
|
275 |
CONNECT_LINUX_WINDOWS_SUBMESSAGE = _("""If you don't have a Remote Desktop client already installed, |
|
288 |
|
|
289 |
CONNECT_LINUX_LINUX_MESSAGE = \ |
|
290 |
_("""A direct connection to this machine can be established using the |
|
291 |
<a target="_blank" href="http://en.wikipedia.org/wiki/Secure_Shell"> |
|
292 |
SSH Protocol</a>. |
|
293 |
To do so open a terminal and type the following at the prompt to connect |
|
294 |
to your machine:""") |
|
295 |
CONNECT_LINUX_WINDOWS_MESSAGE = \ |
|
296 |
_("""A direct connection to this machine can be established using |
|
297 |
<a target="_blank" |
|
298 |
href="http://en.wikipedia.org/wiki/Remote_Desktop_Services"> |
|
299 |
Remote Desktop Service</a>. |
|
300 |
To do so, open the following file with an appropriate remote desktop client.""") |
|
301 |
CONNECT_LINUX_WINDOWS_SUBMESSAGE = \ |
|
302 |
_("""If you don't have a Remote Desktop client already installed, |
|
276 | 303 |
we suggest the use of <a target="_blank" |
277 |
href="http://sourceforge.net/projects/tsclient/files/latest/download?source=files">tsclient</a>.<br |
|
278 |
/><span class="important">IMPORTANT: It may take up to 15 minutes for your Windows VM to become available |
|
304 |
href= |
|
305 |
"http://sourceforge.net/projects/tsclient/files/latest/download?source=files"> |
|
306 |
tsclient</a>.<br /><span class="important">IMPORTANT: It may take up to 15 |
|
307 |
minutes for your Windows VM to become available |
|
279 | 308 |
after its creation.</span>""") |
280 |
CONNECT_WINDOWS_LINUX_MESSAGE = _("""A direct connection to this machine can be established using the <a target="_blank" |
|
309 |
CONNECT_WINDOWS_LINUX_MESSAGE = \ |
|
310 |
_("""A direct connection to this machine can be established using the |
|
311 |
<a target="_blank" |
|
281 | 312 |
href="http://en.wikipedia.org/wiki/Secure_Shell">SSH Protocol</a>. |
282 | 313 |
Open an ssh client such as PuTTY and type the following:""") |
283 |
CONNECT_WINDOWS_LINUX_SUBMESSAGE = _("""If you do not have an ssh client already installed, |
|
284 |
<a target="_blank" href="http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe">Download PuTTY</a>""") |
|
285 |
|
|
286 |
CONNECT_WINDOWS_WINDOWS_MESSAGE = _("""A direct connection to this machine can be |
|
314 |
CONNECT_WINDOWS_LINUX_SUBMESSAGE = \ |
|
315 |
_("""If you do not have an ssh client already installed, |
|
316 |
<a target="_blank" |
|
317 |
href="http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe"> |
|
318 |
Download PuTTY</a>""") |
|
319 |
|
|
320 |
CONNECT_WINDOWS_WINDOWS_MESSAGE = \ |
|
321 |
_("""A direct connection to this machine can be |
|
287 | 322 |
established using Remote Desktop. Click on the following link, and if asked |
288 | 323 |
open it using "Remote Desktop Connection". |
289 |
<br /><span class="important">IMPORTANT: It may take up to 15 minutes for your Windows VM to become available |
|
324 |
<br /><span class="important"> |
|
325 |
IMPORTANT: It may take up to 15 minutes for your Windows VM to become available |
|
290 | 326 |
after its creation.</span>""") |
291 |
CONNECT_WINDOWS_WINDOWS_SUBMESSAGE = _("""Save this file to disk for future use.""") |
|
327 |
CONNECT_WINDOWS_WINDOWS_SUBMESSAGE = \ |
|
328 |
_("""Save this file to disk for future use.""") |
|
292 | 329 |
|
293 | 330 |
# info/subinfo for all os combinations |
294 | 331 |
# |
... | ... | |
297 | 334 |
# provided to the user when needed |
298 | 335 |
CONNECT_PROMPT_MESSAGES = { |
299 | 336 |
'linux': { |
300 |
'linux': [CONNECT_LINUX_LINUX_MESSAGE, ""],
|
|
301 |
'windows': [CONNECT_LINUX_WINDOWS_MESSAGE,
|
|
302 |
CONNECT_LINUX_WINDOWS_SUBMESSAGE],
|
|
303 |
'ssh_message': "ssh %(user)s@%(hostname)s"
|
|
337 |
'linux': [CONNECT_LINUX_LINUX_MESSAGE, ""], |
|
338 |
'windows': [CONNECT_LINUX_WINDOWS_MESSAGE, |
|
339 |
CONNECT_LINUX_WINDOWS_SUBMESSAGE], |
|
340 |
'ssh_message': "ssh %(user)s@%(hostname)s" |
|
304 | 341 |
}, |
305 | 342 |
'windows': { |
306 |
'linux': [CONNECT_WINDOWS_LINUX_MESSAGE,
|
|
307 |
CONNECT_WINDOWS_LINUX_SUBMESSAGE],
|
|
308 |
'windows': [CONNECT_WINDOWS_WINDOWS_MESSAGE,
|
|
309 |
CONNECT_WINDOWS_WINDOWS_SUBMESSAGE],
|
|
310 |
'ssh_message': "%(user)s@%(hostname)s"
|
|
343 |
'linux': [CONNECT_WINDOWS_LINUX_MESSAGE, |
|
344 |
CONNECT_WINDOWS_LINUX_SUBMESSAGE], |
|
345 |
'windows': [CONNECT_WINDOWS_WINDOWS_MESSAGE, |
|
346 |
CONNECT_WINDOWS_WINDOWS_SUBMESSAGE], |
|
347 |
'ssh_message': "%(user)s@%(hostname)s" |
|
311 | 348 |
}, |
312 | 349 |
} |
313 | 350 |
|
314 |
APPEND_CONNECT_PROMPT_MESSAGES = getattr(settings, 'UI_CONNECT_PROMPT_MESSAGES',
|
|
315 |
{})
|
|
351 |
APPEND_CONNECT_PROMPT_MESSAGES = \
|
|
352 |
getattr(settings, 'UI_CONNECT_PROMPT_MESSAGES', {})
|
|
316 | 353 |
for k, v in APPEND_CONNECT_PROMPT_MESSAGES.iteritems(): |
317 | 354 |
CONNECT_PROMPT_MESSAGES[k].update(v) |
318 | 355 |
|
... | ... | |
323 | 360 |
# domain template string |
324 | 361 |
DOMAIN_TPL = "%s%%s" % DOMAIN_PREFIX |
325 | 362 |
|
363 |
|
|
326 | 364 |
def machines_connect(request): |
327 |
ip_address = request.GET.get('ip_address','') |
|
328 |
hostname = request.GET.get('hostname','') |
|
329 |
operating_system = metadata_os = request.GET.get('os','') |
|
365 |
ip_address = request.GET.get('ip_address', '')
|
|
366 |
hostname = request.GET.get('hostname', '')
|
|
367 |
operating_system = metadata_os = request.GET.get('os', '')
|
|
330 | 368 |
server_id = request.GET.get('srv', 0) |
331 |
host_os = request.GET.get('host_os','Linux').lower() |
|
369 |
host_os = request.GET.get('host_os', 'Linux').lower()
|
|
332 | 370 |
username = request.GET.get('username', None) |
333 | 371 |
domain = request.GET.get("domain", DOMAIN_TPL % int(server_id)) |
334 | 372 |
|
... | ... | |
363 | 401 |
extra_rdp_content = EXTRA_RDP_CONTENT(server_id, ip_address, |
364 | 402 |
hostname, username) |
365 | 403 |
else: |
366 |
extra_rdp_content = EXTRA_RDP_CONTENT % { |
|
367 |
'server_id':server_id, |
|
404 |
extra_rdp_content = EXTRA_RDP_CONTENT % \ |
|
405 |
{ |
|
406 |
'server_id': server_id, |
|
368 | 407 |
'ip_address': ip_address, |
369 | 408 |
'hostname': hostname, |
370 | 409 |
'user': username |
371 |
}
|
|
410 |
} |
|
372 | 411 |
|
373 | 412 |
rdp_context = { |
374 |
'username': username,
|
|
375 |
'domain': domain,
|
|
376 |
'ip_address': ip_address,
|
|
377 |
'hostname': hostname,
|
|
378 |
'extra_content': extra_rdp_content
|
|
413 |
'username': username, |
|
414 |
'domain': domain, |
|
415 |
'ip_address': ip_address, |
|
416 |
'hostname': hostname, |
|
417 |
'extra_content': extra_rdp_content |
|
379 | 418 |
} |
380 | 419 |
|
381 | 420 |
rdp_file_data = render_to_string("synnefo-windows.rdp", rdp_context) |
... | ... | |
392 | 431 |
link_title = ssh_message(server_id, ip_address, hostname, username) |
393 | 432 |
else: |
394 | 433 |
link_title = ssh_message % { |
395 |
'server_id':server_id,
|
|
396 |
'ip_address': ip_address,
|
|
397 |
'hostname': hostname,
|
|
398 |
'user': username
|
|
399 |
}
|
|
434 |
'server_id': server_id,
|
|
435 |
'ip_address': ip_address, |
|
436 |
'hostname': hostname, |
|
437 |
'user': username |
|
438 |
} |
|
400 | 439 |
if (operating_system != "windows"): |
401 | 440 |
link_url = None |
402 | 441 |
|
403 | 442 |
else: |
404 | 443 |
link_title = _("Remote desktop to %s") % ip_address |
405 |
link_url = "%s?ip_address=%s&os=%s&rdp=1&srv=%d&username=%s&domain=%s&hostname=%s" % ( |
|
444 |
link_url = \ |
|
445 |
"%s?ip_address=%s&os=%s&rdp=1&srv=%d&username=%s&domain=%s" \ |
|
446 |
"&hostname=%s" % ( |
|
406 | 447 |
reverse("ui_machines_connect"), ip_address, |
407 |
operating_system, int(server_id), username, domain, hostname) |
|
448 |
operating_system, int(server_id), username, |
|
449 |
domain, hostname) |
|
408 | 450 |
|
409 | 451 |
# try to find a specific message |
410 | 452 |
try: |
411 |
connect_message = CONNECT_PROMPT_MESSAGES[host_os][operating_system][0] |
|
453 |
connect_message = \ |
|
454 |
CONNECT_PROMPT_MESSAGES[host_os][operating_system][0] |
|
412 | 455 |
subinfo = CONNECT_PROMPT_MESSAGES[host_os][operating_system][1] |
413 | 456 |
except KeyError: |
414 |
connect_message = _("You are trying to connect from a %s " |
|
415 |
"machine to a %s machine") % (host_os, operating_system) |
|
457 |
connect_message = \ |
|
458 |
_("You are trying to connect from a %s " |
|
459 |
"machine to a %s machine") % (host_os, operating_system) |
|
416 | 460 |
subinfo = "" |
417 | 461 |
|
418 | 462 |
response_object = { |
419 |
'ip': ip_address, |
|
420 |
'os': operating_system, |
|
421 |
'ssh': ssh, |
|
422 |
'info': unicode(connect_message), |
|
423 |
'subinfo': unicode(subinfo), |
|
424 |
'link': {'title': unicode(link_title), 'url': link_url} |
|
425 |
} |
|
426 |
response = HttpResponse(json.dumps(response_object), |
|
427 |
mimetype='application/json') #no windows, no rdp |
|
463 |
'ip': ip_address, |
|
464 |
'os': operating_system, |
|
465 |
'ssh': ssh, |
|
466 |
'info': unicode(connect_message), |
|
467 |
'subinfo': unicode(subinfo), |
|
468 |
'link': {'title': unicode(link_title), 'url': link_url} |
|
469 |
} |
|
470 |
response = \ |
|
471 |
HttpResponse(json.dumps(response_object), |
|
472 |
mimetype='application/json') # no windows, no rdp |
|
428 | 473 |
|
429 | 474 |
return response |
430 |
|
Also available in: Unified diff