Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / ui / views.py @ 9cd9bfe7

History | View | Annotate | Download (19 kB)

1
# Copyright 2011 GRNET S.A. All rights reserved.
2
#
3
# Redistribution and use in source and binary forms, with or
4
# without modification, are permitted provided that the following
5
# conditions are met:
6
#
7
#   1. Redistributions of source code must retain the above
8
#      copyright notice, this list of conditions and the following
9
#      disclaimer.
10
#
11
#   2. Redistributions in binary form must reproduce the above
12
#      copyright notice, this list of conditions and the following
13
#      disclaimer in the documentation and/or other materials
14
#      provided with the distribution.
15
#
16
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
# POSSIBILITY OF SUCH DAMAGE.
28
#
29
# The views and conclusions contained in the software and
30
# documentation are those of the authors and should not be
31
# interpreted as representing official policies, either expressed
32
# or implied, of GRNET S.A.
33
#
34

    
35
import os
36

    
37
from django.conf import settings
38
from django.utils.translation import gettext_lazy as _
39
from django.template import loader
40
from django.http import HttpResponse
41
from django.utils.translation import get_language
42
from django.utils import simplejson as json
43
from synnefo_branding.utils import render_to_string
44
from django.core.urlresolvers import reverse
45
from django.template import RequestContext
46
from synnefo_branding import settings as snf_settings
47

    
48
from synnefo.util.version import get_component_version
49
from synnefo.lib import join_urls
50

    
51
from snf_django.lib.astakos import get_user
52

    
53
SYNNEFO_JS_LIB_VERSION = get_component_version('app')
54

    
55
# api configuration
56
COMPUTE_API_URL = getattr(settings, 'COMPUTE_API_URL', '/api/v1.1')
57

    
58
# UI preferences settings
59
TIMEOUT = getattr(settings, "TIMEOUT", 10000)
60
UPDATE_INTERVAL = getattr(settings, "UI_UPDATE_INTERVAL", 5000)
61
CHANGES_SINCE_ALIGNMENT = getattr(settings, "UI_CHANGES_SINCE_ALIGNMENT", 0)
62
UPDATE_INTERVAL_INCREASE = getattr(settings, "UI_UPDATE_INTERVAL_INCREASE", 500)
63
UPDATE_INTERVAL_INCREASE_AFTER_CALLS_COUNT = \
64
    getattr(settings, "UI_UPDATE_INTERVAL_INCREASE_AFTER_CALLS_COUNT", 3)
65
UPDATE_INTERVAL_FAST = getattr(settings, "UI_UPDATE_INTERVAL_FAST", 2500)
66
UPDATE_INTERVAL_MAX = getattr(settings, "UI_UPDATE_INTERVAL_MAX", 10000)
67

    
68
# predefined values settings
69
VM_IMAGE_COMMON_METADATA = \
70
    getattr(settings, "UI_VM_IMAGE_COMMON_METADATA", ["OS", "users"])
71
SUGGESTED_FLAVORS_DEFAULT = {}
72
SUGGESTED_FLAVORS = getattr(settings, "VM_CREATE_SUGGESTED_FLAVORS",
73
                            SUGGESTED_FLAVORS_DEFAULT)
74
SUGGESTED_ROLES_DEFAULT = ["Database server", "File server", "Mail server",
75
                           "Web server", "Proxy"]
76
SUGGESTED_ROLES = getattr(settings, "VM_CREATE_SUGGESTED_ROLES",
77
                          SUGGESTED_ROLES_DEFAULT)
78
IMAGE_ICONS = settings.IMAGE_ICONS
79
IMAGE_DELETED_TITLE = \
80
    getattr(settings, 'UI_IMAGE_DELETED_TITLE', '(deleted)')
81
IMAGE_DELETED_SIZE_TITLE = \
82
    getattr(settings, 'UI_IMAGE_DELETED_SIZE_TITLE', '(none)')
83

    
84
SUPPORT_SSH_OS_LIST = getattr(settings, "UI_SUPPORT_SSH_OS_LIST",)
85
OS_CREATED_USERS = getattr(settings, "UI_OS_DEFAULT_USER_MAP")
86
UNKNOWN_OS = getattr(settings, "UI_UNKNOWN_OS", "unknown")
87
LOGOUT_URL = getattr(settings, "UI_LOGOUT_URL", '/im/authenticate')
88
LOGIN_URL = getattr(settings, "UI_LOGIN_URL", '/im/login')
89
AUTH_COOKIE_NAME = getattr(settings, "UI_AUTH_COOKIE_NAME", 'synnefo_user')
90

    
91
# UI behaviour settings
92
DELAY_ON_BLUR = getattr(settings, "UI_DELAY_ON_BLUR", True)
93
UPDATE_HIDDEN_VIEWS = getattr(settings, "UI_UPDATE_HIDDEN_VIEWS", False)
94
HANDLE_WINDOW_EXCEPTIONS = \
95
    getattr(settings, "UI_HANDLE_WINDOW_EXCEPTIONS", True)
96
SKIP_TIMEOUTS = getattr(settings, "UI_SKIP_TIMEOUTS", 1)
97

    
98
# Additional settings
99
VM_NAME_TEMPLATE = getattr(settings, "VM_CREATE_NAME_TPL", "My {0} server")
100
VM_HOSTNAME_FORMAT = getattr(settings, "UI_VM_HOSTNAME_FORMAT",
101
                                    'snf-%(id)s.vm.synnefo.org')
102

    
103
if isinstance(VM_HOSTNAME_FORMAT, basestring):
104
    VM_HOSTNAME_FORMAT = VM_HOSTNAME_FORMAT % {'id': '{0}'}
105

    
106
MAX_SSH_KEYS_PER_USER = getattr(settings, "USERDATA_MAX_SSH_KEYS_PER_USER")
107
FLAVORS_DISK_TEMPLATES_INFO = \
108
    getattr(settings, "UI_FLAVORS_DISK_TEMPLATES_INFO", {})
109
SYSTEM_IMAGES_OWNERS = getattr(settings, "UI_SYSTEM_IMAGES_OWNERS", {})
110
CUSTOM_IMAGE_HELP_URL = getattr(settings, "UI_CUSTOM_IMAGE_HELP_URL", None)
111

    
112
# MEDIA PATHS
113
UI_MEDIA_URL = \
114
    getattr(settings, "UI_MEDIA_URL",
115
            "%ssnf-%s/" % (settings.MEDIA_URL, SYNNEFO_JS_LIB_VERSION))
116
UI_SYNNEFO_IMAGES_URL = \
117
    getattr(settings,
118
            "UI_SYNNEFO_IMAGES_URL", UI_MEDIA_URL + "images/")
119
UI_SYNNEFO_CSS_URL = \
120
    getattr(settings,
121
            "UI_SYNNEFO_CSS_URL", UI_MEDIA_URL + "css/")
122
UI_SYNNEFO_JS_URL = \
123
    getattr(settings,
124
            "UI_SYNNEFO_JS_URL", UI_MEDIA_URL + "js/")
125
UI_SYNNEFO_JS_LIB_URL = \
126
    getattr(settings,
127
            "UI_SYNNEFO_JS_LIB_URL", UI_SYNNEFO_JS_URL + "lib/")
128
UI_SYNNEFO_JS_WEB_URL = \
129
    getattr(settings, "UI_SYNNEFO_JS_WEB_URL", UI_SYNNEFO_JS_URL + "ui/web/")
130

    
131
# extensions
132
ENABLE_GLANCE = getattr(settings, 'UI_ENABLE_GLANCE', True)
133
GLANCE_API_URL = getattr(settings, 'UI_GLANCE_API_URL', '/glance')
134
DIAGNOSTICS_UPDATE_INTERVAL = \
135
    getattr(settings, 'UI_DIAGNOSTICS_UPDATE_INTERVAL', 2000)
136

    
137
# network settings
138
DEFAULT_NETWORK_TYPES = {'MAC_FILTERED': 'mac-filtering',
139
                         'PHYSICAL_VLAN': 'physical-vlan'}
140
NETWORK_TYPES = \
141
    getattr(settings,
142
            'UI_NETWORK_AVAILABLE_NETWORK_TYPES', DEFAULT_NETWORK_TYPES)
143
DEFAULT_NETWORK_SUBNETS = ['10.0.0.0/24', '192.168.1.1/24']
144
NETWORK_SUBNETS = \
145
    getattr(settings,
146
            'UI_NETWORK_AVAILABLE_SUBNETS', DEFAULT_NETWORK_SUBNETS)
147
NETWORK_DUPLICATE_NICS = \
148
    getattr(settings,
149
            'UI_NETWORK_ALLOW_DUPLICATE_VM_NICS', False)
150
NETWORK_STRICT_DESTROY = \
151
    getattr(settings,
152
            'UI_NETWORK_STRICT_DESTROY', False)
153
NETWORK_ALLOW_MULTIPLE_DESTROY = \
154
    getattr(settings,
155
            'UI_NETWORK_ALLOW_MULTIPLE_DESTROY', False)
156
AUTOMATIC_NETWORK_RANGE_FORMAT = getattr(settings,
157
                                         'UI_AUTOMATIC_NETWORK_RANGE_FORMAT',
158
                                         "192.168.%d.0/24").replace("%d",
159
                                                                    "{0}")
160
GROUP_PUBLIC_NETWORKS = getattr(settings, 'UI_GROUP_PUBLIC_NETWORKS', True)
161
GROUPED_PUBLIC_NETWORK_NAME = \
162
    getattr(settings, 'UI_GROUPED_PUBLIC_NETWORK_NAME', 'Internet')
163

    
164
ASTAKOS_BASE_URL = '/'
165
ASTAKOS_API_URL = join_urls(ASTAKOS_BASE_URL, 'astakos/api')
166

    
167
USER_CATALOG_URL = getattr(settings, 'UI_USER_CATALOG_URL',
168
                           join_urls(ASTAKOS_API_URL, 'user_catalogs'))
169
FEEDBACK_POST_URL = getattr(settings, 'UI_FEEDBACK_POST_URL',
170
                            join_urls(ASTAKOS_API_URL, 'feedback'))
171
ACCOUNTS_API_URL = getattr(settings, 'UI_ACCOUNTS_API_URL', ASTAKOS_API_URL)
172
TRANSLATE_UUIDS = not getattr(settings, 'TRANSLATE_UUIDS', False)
173

    
174

    
175
def template(name, request, context):
176
    template_path = os.path.join(os.path.dirname(__file__), "templates/")
177
    current_template = template_path + name + '.html'
178
    t = loader.get_template(current_template)
179
    media_context = {
180
       'UI_MEDIA_URL': UI_MEDIA_URL,
181
       'SYNNEFO_JS_URL': UI_SYNNEFO_JS_URL,
182
       'SYNNEFO_JS_LIB_URL': UI_SYNNEFO_JS_LIB_URL,
183
       'SYNNEFO_JS_WEB_URL': UI_SYNNEFO_JS_WEB_URL,
184
       'SYNNEFO_IMAGES_URL': UI_SYNNEFO_IMAGES_URL,
185
       'SYNNEFO_CSS_URL': UI_SYNNEFO_CSS_URL,
186
       'SYNNEFO_JS_LIB_VERSION': SYNNEFO_JS_LIB_VERSION,
187
       'DEBUG': settings.DEBUG
188
    }
189
    context.update(media_context)
190
    return HttpResponse(t.render(RequestContext(request, context)))
191

    
192

    
193
def home(request):
194
    context = {'timeout': TIMEOUT,
195
               'project': '+nefo',
196
               'request': request,
197
               'current_lang': get_language() or 'en',
198
               'compute_api_url': json.dumps(COMPUTE_API_URL),
199
               'user_catalog_url': json.dumps(USER_CATALOG_URL),
200
               'feedback_post_url': json.dumps(FEEDBACK_POST_URL),
201
               'accounts_api_url': json.dumps(ACCOUNTS_API_URL),
202
               'translate_uuids': json.dumps(TRANSLATE_UUIDS),
203
               # update interval settings
204
               'update_interval': UPDATE_INTERVAL,
205
               'update_interval_increase': UPDATE_INTERVAL_INCREASE,
206
               'update_interval_increase_after_calls':
207
                UPDATE_INTERVAL_INCREASE_AFTER_CALLS_COUNT,
208
               'update_interval_fast': UPDATE_INTERVAL_FAST,
209
               'update_interval_max': UPDATE_INTERVAL_MAX,
210
               'changes_since_alignment': CHANGES_SINCE_ALIGNMENT,
211
               'image_icons': IMAGE_ICONS,
212
               'logout_redirect': LOGOUT_URL,
213
               'login_redirect': LOGIN_URL,
214
               'auth_cookie_name': AUTH_COOKIE_NAME,
215
               'suggested_flavors': json.dumps(SUGGESTED_FLAVORS),
216
               'suggested_roles': json.dumps(SUGGESTED_ROLES),
217
               'vm_image_common_metadata': json.dumps(VM_IMAGE_COMMON_METADATA),
218
               'synnefo_version': SYNNEFO_JS_LIB_VERSION,
219
               'delay_on_blur': json.dumps(DELAY_ON_BLUR),
220
               'update_hidden_views': json.dumps(UPDATE_HIDDEN_VIEWS),
221
               'handle_window_exceptions': json.dumps(HANDLE_WINDOW_EXCEPTIONS),
222
               'skip_timeouts': json.dumps(SKIP_TIMEOUTS),
223
               'vm_name_template': json.dumps(VM_NAME_TEMPLATE),
224
               'flavors_disk_templates_info':
225
               json.dumps(FLAVORS_DISK_TEMPLATES_INFO),
226
               'support_ssh_os_list': json.dumps(SUPPORT_SSH_OS_LIST),
227
               'unknown_os': json.dumps(UNKNOWN_OS),
228
               'os_created_users': json.dumps(OS_CREATED_USERS),
229
               'userdata_keys_limit': json.dumps(MAX_SSH_KEYS_PER_USER),
230
               'use_glance': json.dumps(ENABLE_GLANCE),
231
               'glance_api_url': json.dumps(GLANCE_API_URL),
232
               'system_images_owners': json.dumps(SYSTEM_IMAGES_OWNERS),
233
               'custom_image_help_url': CUSTOM_IMAGE_HELP_URL,
234
               'image_deleted_title': json.dumps(IMAGE_DELETED_TITLE),
235
               'image_deleted_size_title': json.dumps(IMAGE_DELETED_SIZE_TITLE),
236
               'network_suggested_subnets': json.dumps(NETWORK_SUBNETS),
237
               'network_available_types': json.dumps(NETWORK_TYPES),
238
               'network_allow_duplicate_vm_nics':
239
               json.dumps(NETWORK_DUPLICATE_NICS),
240
               'network_strict_destroy': json.dumps(NETWORK_STRICT_DESTROY),
241
               'network_allow_multiple_destroy':
242
               json.dumps(NETWORK_ALLOW_MULTIPLE_DESTROY),
243
               'automatic_network_range_format':
244
               json.dumps(AUTOMATIC_NETWORK_RANGE_FORMAT),
245
               'grouped_public_network_name':
246
               json.dumps(GROUPED_PUBLIC_NETWORK_NAME),
247
               'group_public_networks': json.dumps(GROUP_PUBLIC_NETWORKS),
248
               'diagnostics_update_interval':
249
               json.dumps(DIAGNOSTICS_UPDATE_INTERVAL),
250
               'vm_hostname_format': json.dumps(VM_HOSTNAME_FORMAT)
251
               }
252
    return template('home', request, context)
253

    
254
def machines_console(request):
255
    host, port, password = ('', '', '')
256
    host = request.GET.get('host', '')
257
    port = request.GET.get('port', '')
258
    password = request.GET.get('password', '')
259
    machine = request.GET.get('machine', '')
260
    host_ip = request.GET.get('host_ip', '')
261
    host_ip_v6 = request.GET.get('host_ip_v6', '')
262
    context = {'host': host, 'port': port, 'password': password,
263
               'machine': machine, 'host_ip': host_ip, 'host_ip_v6': host_ip_v6}
264
    return template('machines_console', request, context)
265

    
266

    
267
def js_tests(request):
268
    return template('tests', request, {})
269

    
270

    
271
CONNECT_LINUX_LINUX_MESSAGE = \
272
    _("""A direct connection to this machine can be established using the
273
<a target="_blank" href="http://en.wikipedia.org/wiki/Secure_Shell">
274
SSH Protocol</a>.
275
To do so open a terminal and type the following at the prompt to connect
276
to your machine:""")
277
CONNECT_LINUX_WINDOWS_MESSAGE = \
278
    _("""A direct connection to this machine can be established using
279
<a target="_blank"
280
href="http://en.wikipedia.org/wiki/Remote_Desktop_Services">
281
Remote Desktop Service</a>.
282
To do so, open the following file with an appropriate remote desktop client.""")
283
CONNECT_LINUX_WINDOWS_SUBMESSAGE = \
284
    _("""If you don't have a Remote Desktop client already installed,
285
we suggest the use of <a target="_blank"
286
href=
287
"http://sourceforge.net/projects/tsclient/files/latest/download?source=files">
288
tsclient</a>.<br /><span class="important">IMPORTANT: It may take up to 15
289
minutes for your Windows VM to become available
290
after its creation.</span>""")
291
CONNECT_WINDOWS_LINUX_MESSAGE = \
292
    _("""A direct connection to this machine can be established using the
293
<a target="_blank"
294
href="http://en.wikipedia.org/wiki/Secure_Shell">SSH Protocol</a>.
295
Open an ssh client such as PuTTY and type the following:""")
296
CONNECT_WINDOWS_LINUX_SUBMESSAGE = \
297
    _("""If you do not have an ssh client already installed,
298
<a target="_blank"
299
href="http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe">
300
Download PuTTY</a>""")
301

    
302
CONNECT_WINDOWS_WINDOWS_MESSAGE = \
303
    _("""A direct connection to this machine can be
304
established using Remote Desktop. Click on the following link, and if asked
305
open it using "Remote Desktop Connection".
306
<br /><span class="important">
307
IMPORTANT: It may take up to 15 minutes for your Windows VM to become available
308
after its creation.</span>""")
309
CONNECT_WINDOWS_WINDOWS_SUBMESSAGE = \
310
    _("""Save this file to disk for future use.""")
311

    
312
# info/subinfo for all os combinations
313
#
314
# [0] info gets displayed on top of the message box
315
# [1] subinfo gets displayed on the bottom as extra info
316
# provided to the user when needed
317
CONNECT_PROMPT_MESSAGES = {
318
    'linux': {
319
        'linux': [CONNECT_LINUX_LINUX_MESSAGE, ""],
320
        'windows': [CONNECT_LINUX_WINDOWS_MESSAGE,
321
                    CONNECT_LINUX_WINDOWS_SUBMESSAGE],
322
        'ssh_message': "ssh %(user)s@%(hostname)s"
323
    },
324
    'windows': {
325
        'linux': [CONNECT_WINDOWS_LINUX_MESSAGE,
326
                  CONNECT_WINDOWS_LINUX_SUBMESSAGE],
327
        'windows': [CONNECT_WINDOWS_WINDOWS_MESSAGE,
328
                    CONNECT_WINDOWS_WINDOWS_SUBMESSAGE],
329
        'ssh_message': "%(user)s@%(hostname)s"
330
    },
331
}
332

    
333
APPEND_CONNECT_PROMPT_MESSAGES = \
334
    getattr(settings, 'UI_CONNECT_PROMPT_MESSAGES', {})
335
for k, v in APPEND_CONNECT_PROMPT_MESSAGES.iteritems():
336
    CONNECT_PROMPT_MESSAGES[k].update(v)
337

    
338
# retrieve domain prefix from settings
339
DOMAIN_PREFIX = getattr(settings, 'MACHINE_DOMAIN_PREFIX', getattr(settings,
340
                        'BACKEND_PREFIX_ID', ""))
341

    
342
# domain template string
343
DOMAIN_TPL = "%s%%s" % DOMAIN_PREFIX
344

    
345

    
346
def machines_connect(request):
347
    ip_address = request.GET.get('ip_address', '')
348
    hostname = request.GET.get('hostname', '')
349
    operating_system = metadata_os = request.GET.get('os', '')
350
    server_id = request.GET.get('srv', 0)
351
    host_os = request.GET.get('host_os', 'Linux').lower()
352
    username = request.GET.get('username', None)
353
    domain = request.GET.get("domain", DOMAIN_TPL % int(server_id))
354

    
355
    # guess host os
356
    if host_os != "windows":
357
        host_os = 'linux'
358

    
359
    # guess username
360
    if not username:
361
        username = "root"
362

    
363
        if metadata_os.lower() in ['ubuntu', 'kubuntu', 'fedora']:
364
            username = "user"
365

    
366
        if metadata_os.lower() == "windows":
367
            username = "Administrator"
368

    
369
    # operating system provides ssh access
370
    ssh = False
371
    if operating_system != "windows":
372
        operating_system = "linux"
373
        ssh = True
374

    
375
    # rdp param is set, the user requested rdp file
376
    # check if we are on windows
377
    if operating_system == 'windows' and request.GET.get("rdp", False):
378

    
379
        # UI sent domain info (from vm metadata) use this
380
        # otherwise use our default snf-<vm_id> domain
381
        EXTRA_RDP_CONTENT = getattr(settings, 'UI_EXTRA_RDP_CONTENT', '')
382
        if callable(EXTRA_RDP_CONTENT):
383
            extra_rdp_content = EXTRA_RDP_CONTENT(server_id, ip_address,
384
                                                  hostname, username)
385
        else:
386
            extra_rdp_content = EXTRA_RDP_CONTENT % \
387
                {
388
                    'server_id': server_id,
389
                    'ip_address': ip_address,
390
                    'hostname': hostname,
391
                    'user': username
392
                  }
393

    
394
        rdp_context = {
395
            'username': username,
396
            'domain': domain,
397
            'ip_address': ip_address,
398
            'hostname': hostname,
399
            'extra_content': extra_rdp_content
400
        }
401

    
402
        rdp_file_data = render_to_string("synnefo-windows.rdp", rdp_context)
403
        response = HttpResponse(rdp_file_data, mimetype='application/x-rdp')
404

    
405
        # proper filename, use server id and ip address
406
        filename = "%d-%s.rdp" % (int(server_id), hostname)
407
        response['Content-Disposition'] = 'attachment; filename=%s' % filename
408
    else:
409
        ssh_message = CONNECT_PROMPT_MESSAGES['linux'].get('ssh_message')
410
        if host_os == 'windows':
411
            ssh_message = CONNECT_PROMPT_MESSAGES['windows'].get('ssh_message')
412
        if callable(ssh_message):
413
            link_title = ssh_message(server_id, ip_address, hostname, username)
414
        else:
415
            link_title = ssh_message % {
416
                'server_id': server_id,
417
                'ip_address': ip_address,
418
                'hostname': hostname,
419
                'user': username
420
            }
421
        if (operating_system != "windows"):
422
            link_url = None
423

    
424
        else:
425
            link_title = _("Remote desktop to %s") % ip_address
426
            link_url = \
427
                "%s?ip_address=%s&os=%s&rdp=1&srv=%d&username=%s&domain=%s" \
428
                "&hostname=%s" % (
429
                    reverse("ui_machines_connect"), ip_address,
430
                    operating_system, int(server_id), username,
431
                    domain, hostname)
432

    
433
        # try to find a specific message
434
        try:
435
            connect_message = \
436
                CONNECT_PROMPT_MESSAGES[host_os][operating_system][0]
437
            subinfo = CONNECT_PROMPT_MESSAGES[host_os][operating_system][1]
438
        except KeyError:
439
            connect_message = \
440
                _("You are trying to connect from a %s "
441
                  "machine to a %s machine") % (host_os, operating_system)
442
            subinfo = ""
443

    
444
        response_object = {
445
            'ip': ip_address,
446
            'os': operating_system,
447
            'ssh': ssh,
448
            'info': unicode(connect_message),
449
            'subinfo': unicode(subinfo),
450
            'link': {'title': unicode(link_title), 'url': link_url}
451
        }
452
        response = \
453
            HttpResponse(json.dumps(response_object),
454
                         mimetype='application/json')  # no windows, no rdp
455

    
456
    return response
457