Revision 3796f345 snf-cyclades-app/synnefo/ui/views.py

b/snf-cyclades-app/synnefo/ui/views.py
96 96

  
97 97
# Additional settings
98 98
VM_NAME_TEMPLATE = getattr(settings, "VM_CREATE_NAME_TPL", "My {0} server")
99
VM_HOSTNAME_FORMAT = getattr(settings, "UI_VM_HOSTNAME_FORMAT",
100
                                    'snf-%(id)s.vm.okeanos.grnet.gr')
99 101
MAX_SSH_KEYS_PER_USER = getattr(settings, "USERDATA_MAX_SSH_KEYS_PER_USER")
100 102
FLAVORS_DISK_TEMPLATES_INFO = getattr(settings, "UI_FLAVORS_DISK_TEMPLATES_INFO", {})
101 103
SYSTEM_IMAGES_OWNERS = getattr(settings, "UI_SYSTEM_IMAGES_OWNERS", {})
......
199 201
               'network_allow_multiple_destroy': json.dumps(NETWORK_ALLOW_MULTIPLE_DESTROY),
200 202
               'grouped_public_network_name': json.dumps(GROUPED_PUBLIC_NETWORK_NAME),
201 203
               'group_public_networks': json.dumps(GROUP_PUBLIC_NETWORKS),
202
               'diagnostics_update_interval': json.dumps(DIAGNOSTICS_UPDATE_INTERVAL)
204
               'diagnostics_update_interval': json.dumps(DIAGNOSTICS_UPDATE_INTERVAL),
205
               'vm_hostname_format': json.dumps(VM_HOSTNAME_FORMAT % {'id':'{0}'})
203 206
    }
204 207
    return template('home', request, context)
205 208

  
......
239 242
CONNECT_WINDOWS_WINDOWS_MESSAGE = _("""A direct connection to this machine can be
240 243
established using Remote Desktop. Click on the following link, and if asked
241 244
open it using "Remote Desktop Connection".
242
IMPORTANT: It may take up to 15 minutes for your Windows VM to become available
243
after its creation.""")
244
CONNECT_WINDOWS_WINDOWS_SUBMESSAGE = _("""Save this file to disk for future use""")
245
<br /><span class="important">IMPORTANT: It may take up to 15 minutes for your Windows VM to become available
246
after its creation.</span>""")
247
CONNECT_WINDOWS_WINDOWS_SUBMESSAGE = _("""Save this file to disk for future use.""")
245 248

  
246 249
# info/subinfo for all os combinations
247 250
#
......
252 255
    'linux': {
253 256
            'linux': [CONNECT_LINUX_LINUX_MESSAGE, ""],
254 257
            'windows': [CONNECT_LINUX_WINDOWS_MESSAGE,
255
                        CONNECT_LINUX_WINDOWS_SUBMESSAGE]
256
        },
258
                        CONNECT_LINUX_WINDOWS_SUBMESSAGE],
259
            'ssh_message': "ssh %(user)s@%(hostname)s"
260
    },
257 261
    'windows': {
258 262
            'linux': [CONNECT_WINDOWS_LINUX_MESSAGE,
259 263
                      CONNECT_WINDOWS_LINUX_SUBMESSAGE],
260 264
            'windows': [CONNECT_WINDOWS_WINDOWS_MESSAGE,
261
                        CONNECT_WINDOWS_WINDOWS_SUBMESSAGE]
262
        }
263
    }
265
                        CONNECT_WINDOWS_WINDOWS_SUBMESSAGE],
266
            'ssh_message': "%(user)s@%(hostname)s"
267
    },
268
}
269

  
270
APPEND_CONNECT_PROMPT_MESSAGES = getattr(settings, 'UI_CONNECT_PROMPT_MESSAGES',
271
                                       {})
272
for k, v in APPEND_CONNECT_PROMPT_MESSAGES.iteritems():
273
    CONNECT_PROMPT_MESSAGES[k].update(v)
264 274

  
265 275
# retrieve domain prefix from settings
266 276
DOMAIN_PREFIX = getattr(settings, 'MACHINE_DOMAIN_PREFIX', getattr(settings,
......
271 281

  
272 282
def machines_connect(request):
273 283
    ip_address = request.GET.get('ip_address','')
284
    hostname = request.GET.get('hostname','')
274 285
    operating_system = metadata_os = request.GET.get('os','')
275 286
    server_id = request.GET.get('srv', 0)
276 287
    host_os = request.GET.get('host_os','Linux').lower()
......
303 314

  
304 315
        # UI sent domain info (from vm metadata) use this
305 316
        # otherwise use our default snf-<vm_id> domain
317
        EXTRA_RDP_CONTENT = getattr(settings, 'UI_EXTRA_RDP_CONTENT', '')
318
        if callable(EXTRA_RDP_CONTENT):
319
            extra_rdp_content = EXTRA_RDP_CONTENT(server_id, ip_address,
320
                                                  hostname, username)
321
        else:
322
            extra_rdp_content = EXTRA_RDP_CONTENT % {
323
                    'server_id':server_id,
324
                    'ip_address': ip_address,
325
                    'hostname': hostname,
326
                    'user': username
327
                  }
328

  
306 329
        rdp_context = {
307 330
                'username': username,
308 331
                'domain': domain,
309
                'ip_address': ip_address
332
                'ip_address': ip_address,
333
                'extra_content': extra_rdp_content
310 334
        }
311 335

  
312 336
        rdp_file_data = render_to_string("synnefo-windows.rdp", rdp_context)
313 337
        response = HttpResponse(rdp_file_data, mimetype='application/x-rdp')
314 338

  
315 339
        # proper filename, use server id and ip address
316
        filename = "%d-%s.rdp" % (int(server_id), ip_address)
340
        filename = "%d-%s.rdp" % (int(server_id), hostname)
317 341
        response['Content-Disposition'] = 'attachment; filename=%s' % filename
318 342
    else:
319
        link_title = _("Remote desktop to %s") % ip_address
320
        link_url = "%s?ip_address=%s&os=%s&rdp=1&srv=%d&username=%s&domain=%s" % (
321
                reverse("ui_machines_connect"), ip_address, operating_system,int(server_id), username, domain)
322

  
343
        ssh_message = CONNECT_PROMPT_MESSAGES['linux'].get('ssh_message')
344
        if host_os == 'windows':
345
            ssh_message = CONNECT_PROMPT_MESSAGES['windows'].get('ssh_message')
346
        if callable(ssh_message):
347
            link_title = ssh_message(server_id, ip_address, hostname, username)
348
        else:
349
            link_title = ssh_message % {
350
                    'server_id':server_id,
351
                    'ip_address': ip_address,
352
                    'hostname': hostname,
353
                    'user': username
354
                  }
323 355
        if (operating_system != "windows"):
324
            link_title = "ssh %s@%s" % (username, ip_address)
325 356
            link_url = None
326 357

  
327
            if host_os == "windows":
328
                link_title = "%s@%s" % (username, ip_address)
358
        else:
359
            link_title = _("Remote desktop to %s") % ip_address
360
            link_url = "%s?ip_address=%s&os=%s&rdp=1&srv=%d&username=%s&domain=%s&hostname=%s" % (
361
                    reverse("ui_machines_connect"), ip_address,
362
                    operating_system, int(server_id), username, domain, hostname)
329 363

  
330 364
        # try to find a specific message
331 365
        try:

Also available in: Unified diff