Revision 3796f345

b/snf-cyclades-app/synnefo/app_settings/default/ui.py
92 92
# vms. {0} gets replaced by the image OS value
93 93
VM_CREATE_NAME_TPL = "My {0} server"
94 94

  
95
# Template to use to build vm hostname
96
UI_VM_HOSTNAME_FORMAT = 'snf-%(id)s.vm.okeanos.grnet.gr'
97

  
95 98
# Name/description metadata for the available flavor disk templates
96 99
# Dict key is the disk_template value as stored in database
97 100
UI_FLAVORS_DISK_TEMPLATES_INFO = {
......
99 102
             'description': 'DRBD storage.'},
100 103
}
101 104

  
105
# Override default connect prompt messages. The setting gets appended to the
106
# ui default values so you only need to modify parameters you need to alter.
107
#
108
# Indicative format:
109
# {
110
#    '<browser os1>': {
111
#        '<vm os family1>': ['top message....', 'bottom message'],
112
#        '<vm os family 2>': ['top message....', 'bottom message'],
113
#        'ssh_message': 'ssh %(user)s@%(hostname)s'
114
# }
115
#
116
# you may use the following parameters to format ssh_message:
117
#
118
# * server_id: the database pk of the vm
119
# * ip_address: the ipv4 address of the public vm nic
120
# * hostname: vm hostname
121
# * user: vm username
122
#
123
# you may assign a callable python object to the ssh_message, if so the above
124
# parameters get passed as arguments to the provided object.
125
UI_CONNECT_PROMPT_MESSAGES = {}
126

  
127
# extend rdp file content. May be a string with format parameters similar to
128
# those used in UI_CONNECT_PROMPT_MESSAGES `ssh_message` or a callable object.
129
UI_EXTRA_RDP_CONTENT = None
130

  
102 131

  
103 132
#######################
104 133
# UI BEHAVIOUR SETTINGS
b/snf-cyclades-app/synnefo/ui/static/snf/js/models.js
1249 1249
            return this.get_nics(function(n){ return n.get_network().is_public() === true })[0];
1250 1250
        },
1251 1251

  
1252
        get_hostname: function() {
1253
          var hostname = this.get_meta('hostname');
1254
          if (!hostname) {
1255
            hostname = synnefo.config.vm_hostname_format.format(this.id);
1256
          }
1257
          return hostname;
1258
        },
1259

  
1252 1260
        get_nic: function(net_id) {
1253 1261
        },
1254 1262

  
......
1431 1439
        get_connection_info: function(host_os, success, error) {
1432 1440
            var url = "/machines/connect";
1433 1441
            params = {
1434
                ip_address: this.get_addresses().ip4,
1442
                ip_address: this.get_public_nic().get('ipv4'),
1443
                hostname: this.get_hostname(),
1435 1444
                os: this.get_os(),
1436 1445
                host_os: host_os,
1437 1446
                srv: this.id
b/snf-cyclades-app/synnefo/ui/templates/home.html
628 628
            synnefo.config.network_allow_multiple_destory = {{ network_allow_multiple_destroy }};
629 629
            synnefo.config.group_public_networks = {{ group_public_networks }};
630 630
            synnefo.config.grouped_public_network_name = {{ grouped_public_network_name|safe }};
631
            synnefo.config.vm_hostname_format = {{ vm_hostname_format|safe }};
631 632
            
632 633
            synnefo.auth_client = new synnefo.auth.AstakosClient({
633 634
                login_url: synnefo.config.login_redirect,
b/snf-cyclades-app/synnefo/ui/templates/partials/manage_metadata.html
21 21
            <span class="predefined-meta-key">OS</span>
22 22
            <span class="predefined-meta-key">Owner</span>
23 23
            <span class="predefined-meta-key">Role</span>
24
            <span class="predefined-meta-key">users</span>
25
            <span class="predefined-meta-key">hostname</span>
24 26
        </div>
25 27
    </div>
26 28

  
b/snf-cyclades-app/synnefo/ui/templates/synnefo-windows.rdp
35 35
promptcredentialonce:i:1
36 36
username:s:{{ username }}
37 37
domain:s:{{ domain }}
38
full address:s:{{ ip_address }}
38
full address:s:{{ ip_address }}{% if extra_content %}
39
{{ extra_content }}{% endif %}
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