Statistics
| Branch: | Tag: | Revision:

root / ui / templates / machines_single.html @ f533f224

History | View | Annotate | Download (20.5 kB)

1
{% load i18n %}
2

    
3
<!-- the single view -->
4
<div id="machinesview-single" class="single">
5
    <div class="large-spinner"></div>
6
    <div class="single-container" id="machine-container-template" style="display:none;" >
7
        <div class="column1">
8
            <img src="/static/icons/machines/large/ubuntu-on.png" class="single-image" />
9
            <div class="state">
10
                <span class="state-label">{% trans "Running" %}</span>
11
            </div>
12
            <div class="single-actions">
13
                <div class="single-action action-start">{% trans "Start" %}</a></div>
14
                <div class="single-action action-console">{% trans "Console" %}</a></div>
15
                <div class="single-action action-reboot">{% trans "Reboot" %}</a></div>
16
                <div class="single-action action-shutdown">{% trans "Shutdown" %}</a></div>
17
                <div class="single-action action-destroy">{% trans "Destroy" %}</a></div>
18
            </div>
19
        </div>
20
        <div class="column2">
21
            <div class="machine-labels">
22
                <div class="machine-label name">{% trans "Name" %}:</div>
23
                <div class="machine-label cpus">{% trans "CPUs" %}:</div>
24
                <div class="machine-label ram">{% trans "RAM (MB)" %}:</div>
25
                <div class="machine-label disk">{% trans "System Disk (GB)" %}:</div>
26
                <div class="machine-label image-name">{% trans "Image Name" %}:</div>
27
                <div class="machine-label image-size">{% trans "Image Size (GB)" %}:</div>
28
                <div class="machine-label ipv4">{% trans "Public IPv4" %}:</div>
29
                <div class="machine-label ipv6">{% trans "Public IPv6" %}:</div>
30
                <div class="machine-label groups">{% trans "Groups" %}:</div>
31
            </div>
32
            <div class="machine-details">
33
                <div class="machine-detail name">My Desktop</div>
34
                <div class="machine-detail cpus">4</div>
35
                <div class="machine-detail ram">2048</div>
36
                <div class="machine-detail disk">100</div>
37
                <div class="machine-detail image-name">windos_XP_blah_blah</div>
38
                <div class="machine-detail image-size">2.3</div>
39
                <div class="machine-detail ipv4">no ipv4</div>
40
                <div class="machine-detail ipv6">2001:db8:1f70::999:de8:7648:6e8</div>
41
                <div class="machine-detail groups">
42
                    <div class="machine-detail group">group</div>
43
                </div>
44
            </div>
45
        </div>
46
        <div class="disks">
47
            {% trans "disks" %}<span class="toggler">&#710;</span>
48
        </div>
49
        <div class="disks-content">
50

    
51
        </div>
52
        <div class="networks">
53
            {% trans "networks" %}<span class="toggler">&#710;</span>
54
        </div>
55
        <div class="networks-content">
56

    
57
        </div>
58
        <div class="stats">
59
            {% trans "stats" %}<span class="toggler">&#710;</span>
60
        </div>
61
        <div class="stats-content">
62

    
63
        </div>
64
    </div>
65
    <div class="column3">
66
        <div class="controls">
67
            <div class="previous">
68
                &lt;{% trans "previous" %}
69
            </div>
70
            <div class="next">
71
                {% trans "next" %}&gt;
72
            </div>
73
        </div>
74
        <div class="separator">
75
        </div>
76
        <div class="servers">
77
            <div class="server-name" id="servers-widget-template" style="display:none;">server1</div>
78
        </div>
79
    </div>
80
</div>
81

    
82
<script>
83

84
//hide the all of the info contents
85
$("#machinesview-single.single .disks-content").hide();
86
$("#machinesview-single.single .networks-content").hide();
87
$("#machinesview-single.single .stats-content").hide();
88

89
// intercept start click
90
$("#machinesview-single.single div.action-start").live('click', function(){
91
    var serverID = $(this).parent().parent().parent().attr("id");
92
    var serverName = $(this).parent().parent().parent().find(".machine-details div.name").text();
93
    var found = false;
94
    $(this).parent().children('a').removeClass('selected');
95
    $(this).addClass('selected');
96
    $(this).parent().addClass('display')
97
    $(this).parent().parent().find('.action_error').hide();
98

99
    for (i=0;i<pending_actions.length;i++){ // if there is already a pending action for this server replace it
100
        if (pending_actions[i][1]==serverID){
101
            pending_actions[i][0] = start;
102
            found = true
103
        }
104
    }
105
    if (!found) // no pending action for this server was found, so let's just add it to the list
106
        pending_actions.push([start, serverID, serverName])
107
    update_confirmations()
108
    return false;
109
});
110

111
// update the servers list
112
function update_machines_view(data){
113
    /*
114
    Go through the servers in the input data. Update existing entries, add
115
    new ones to the list
116
    */
117

118
    $.each(data.servers.values, function(i,server){
119

120
        existing = $('#machinesview-single.single #' + server.id);
121

122
        //hide next button if there is only one vm
123
        if (data.servers.values.length == 1) {
124
            $("#machinesview-single.single .column3 .next").hide();
125
        }
126

127
        // if multiple machines exist in the DOM, delete all but one
128
        // defensive coding - that shouldn't happen normally
129
        while (existing.length > 1){
130
            existing.remove();
131
        }
132

133
        var server_image = os_icon(server.metadata);
134

135
        // server already exists in DOM
136
        if (existing.length){
137
            $("#machinesview-single.single div.single-container:last-child").find("div.separator").show();
138
            //  if the status is deleted, delete it from the DOM
139
            if (server.status == 'DELETED') {
140
                existing.remove();
141
                try {
142
                    console.info(existing.find("div.name span.name").text() + ' removed');
143
                } catch(err) {}
144
            } else if (existing.find(".status").text() != STATUSES[server.status]) {
145
                try { // firebug console logging
146
                    console.info(existing.find("div.name span.name").text() + ' from '
147
                                + existing.find(".status").text() + ' to ' + STATUSES[server.status]);
148
                } catch(err) {}
149
                // show console action only on active servers, else hide it
150
                if (server.status == 'ACTIVE') {
151
                    $('#machinesview-single.single div.#' + server.id + ' div.action-console').show();
152
                } else {
153
                    $('#machinesview-single.single div.#' + server.id + ' div.action-console').hide();
154
                }
155
                // show reboot and shutdown actions on active of rebooting servers
156
                if (server.status == 'ACTIVE' || server.status == 'REBOOT') {
157
                    $('#machinesview-single.single div.#' + server.id + ' div.action-reboot').show();
158
                    $('#machinesview-single.single div.#' + server.id + ' div.action-shutdown').show();
159
                    $('#machinesview-single.single div.#' + server.id + ' div.action-destroy').show();
160
                }
161
                if (['BUILD','ACTIVE','REBOOT'].indexOf(server.status) >= 0 &&
162
                    [STATUSES['STOPPED'], STATUSES['ERROR'],
163
                     TRANSITIONS['Starting']].indexOf(existing.find(".status").text()) >= 0) {
164
                    // from stopped, on error or starting to building, active or rebooting
165
                    // starting is not an api state, it means the vm is stopped or on error
166
                    existing.find("img.single-image").attr("src","static/icons/machines/large/" + server_image + '-on.png');
167
                    existing.find(".state-label").text(STATUSES[server.status]);
168
                } else if (['STOPPED','ERROR'].indexOf(server.status) >= 0 &&
169
                           [STATUSES['ACTIVE'], STATUSES['BUILD'], STATUSES['REBOOT'],
170
                            TRANSITIONS['Shutting down'], TRANSITIONS['Starting']].indexOf(existing.find(".status").text()) >= 0) {
171
                    // from active, building, rebooting, or shutting down to stopped or on error
172
                    // shutting down is not an api state, it means the server is active
173
                    existing.find("img.single-image").attr("src","static/icons/machines/large/" + server_image + '-off.png');
174
                    existing.find(".state-label").text(STATUSES[server.status]);
175
                } else if (['BUILD','ACTIVE','REBOOT'].indexOf(server.status) >= 0 &&
176
                            [STATUSES['ACTIVE'], STATUSES['BUILD'],
177
                             STATUSES['REBOOT']].indexOf(existing.find(".status").text()) >= 0) {
178
                    // the server changes status
179
                    existing.find(".state-label").text(STATUSES[server.status]);
180
                } else if (['STOPPED','ERROR'].indexOf(server.status) >= 0 &&
181
                    [STATUSES['STOPPED'],
182
                     STATUSES['ERROR']].indexOf(existing.find(".status").text()) >= 0) {
183
                    // the server changes status
184
                    existing.find(".state-label").text(STATUSES[server.status]);
185
                }
186
                existing.find('.spinner').hide();
187
                existing.find(' .wave').attr('src','static/wave.gif').show();
188
                setTimeout("$('#" + server.id +" .wave').attr('src','').hide()", 3000);
189
                // show spinner while the server is rebooting, starting or shutting down
190
                if ([STATUSES['REBOOT'],
191
                    TRANSITIONS['Starting'], TRANSITIONS['Shutting down']].indexOf(existing.find(".status").text()) >= 0 ) {
192
                    existing.find(' .wave').hide();
193
                    existing.find('.spinner').show();
194
                }
195
            } else if (existing.find(".status").text() == STATUSES['REBOOT'] && server.status == 'REBOOT') {
196
                    $('#machinesview-single.single div.#' + server.id + ' div.action-console').hide();
197
            }
198
            // find and display ips
199
            var ips = get_public_ips(server);
200
            existing.find(".machine-details div.ipv4").text(ips['ip4']);
201
            existing.find(".machine-details div.ipv6").text(ips['ip6']);
202
        } else if (server.status != 'DELETED') {
203
            // If it does not exist and it's not deleted, we should create it
204
            var serverwidget = $("#servers-widget-template").clone().attr("id", 'link-' + server.id);
205
            if (server.name.length > 18) {
206
                serverwidget.text(server.name.substring(0,15) + '...');
207
            } else {
208
                serverwidget.text(server.name)
209
            }
210
            serverwidget.appendTo('.servers');
211
            serverwidget.show();
212
            //find and hide the previous selected server
213
            $('.single').find('.single-container').hide();
214
            $('.single .column3').find('.selected').removeClass('selected');
215
            //create and select the new one
216
            var machine = $("#machinesview-single.single #machine-container-template").clone().attr("id", server.id);
217
            machine.find(".machine-details div.name").text(server.name.substring(0,100));
218
            machine.find("img.single-image").attr("src","static/icons/machines/large/"+server_image+'-on.png');
219
            machine.find("span.imagetag").text(server_image);
220
            machine.find(".state-label").text(STATUSES[server.status]);
221
            // find and display ips
222
            var ips = get_public_ips(server);
223
            machine.find(".machine-details div.ipv4").text(ips['ip4']);
224
            machine.find(".machine-details div.ipv6").text(ips['ip6']);
225
            // find and display flavor parameters
226
            var CPUs, RAM, disk, image_name, image_size;
227
            if ( flavors.length > 0 ) {
228
                var current_flavor = '';
229
                for (i=0; i<flavors.length; i++) {
230
                    if (flavors[i]['id'] == server.flavorRef) {
231
                        current_flavor = flavors[i];
232
                    }
233
                }
234
                CPUs = current_flavor['cpu'];
235
                RAM = current_flavor['ram'];
236
                disk = current_flavor['disk'];
237
            } else {
238
                CPUs = 0;
239
                RAM = 0;
240
                disk = 0;
241
            }
242
            if ( images.length > 0 ) {
243
                var current_image = '';
244
                for (i=0; i<images.length; i++) {
245
                    if (images[i]['id'] == server.imageRef) {
246
                        current_image = images[i];
247
                    }
248
                }
249
                image_name = current_image['name'];
250
                image_size = current_image['metadata']['values']['size'];
251
            } else {
252
                image_name = ''
253
                image_size = ''
254
            }
255
            machine.find(".machine-details div.cpus").text(CPUs);
256
            machine.find(".machine-details div.ram").text(RAM);
257
            machine.find(".machine-details div.disk").text(disk);
258
            machine.find(".machine-details div.image-name").text(image_name.substring(0,15));
259
            machine.find(".machine-details div.image-size").text(image_size);
260
            //show off image if server is not active
261
            if (['BUILD', 'ACTIVE', 'REBOOT'].indexOf(server.status) < 0){
262
                    machine.find("img.single-image").attr("src","static/icons/machines/large/"+server_image+'-off.png');
263
            }
264
            //show spinner while machine is building
265
            if (server.status == 'BUILD' ||
266
                [TRANSITIONS['Starting'], TRANSITIONS['Shutting down']].indexOf(existing.find(".status").text()) >= 0 ) {
267
                machine.find('.spinner').show();
268
            }
269
            machine.appendTo("#machinesview-single.single");
270
            //disable reboot and shutdown actions while machine is building
271
            if (server.status == 'BUILD') {
272
                $('#machinesview-single.single div.#' + server.id + ' div.action-reboot').hide();
273
                $('#machinesview-single.single div.#' + server.id + ' div.action-shutdown').hide();
274
            }
275
            // show console action only on active servers
276
            if (server.status == 'ACTIVE') {
277
                $('#machinesview-single.single div.#' + server.id + ' div.action-console').show();
278
                $('#machinesview-single.single div.#' + server.id + ' div.action-start').hide();
279
            } else if (server.status == 'REBOOT'){
280
                $('#machinesview-single.single div.#' + server.id + ' div.action-console').hide();
281
            } else {
282
                $('#machinesview-single.single div.#' + server.id + ' div.action-console').hide();
283
                $('#machinesview-single.single div.#' + server.id + ' div.action-reboot').hide();
284
                $('#machinesview-single.single div.#' + server.id + ' div.action-shutdown').hide();
285
            }
286
        }
287
    });
288

289
    $("#machinesview-single.single > div.large-spinner").hide();
290

291
    // show message in case user has no servers!
292
    //if ($('.single-container').length < 2) {
293
    //    showWelcome();
294
    //} else {
295
    //    hideWelcome();
296
    //}
297

298
    // set confirm box position
299
    if (window.innerHeight - 220 < $('#machinesview-single').height())
300
        $('.confirm_multiple').addClass('fixed');
301
    else
302
        $('.confirm_multiple').removeClass('fixed');
303

304
    //show the first machine and select it in the widget
305
    $('.single-container:eq(1)').show();
306
    $('.single .column3').find('.server-name:eq(1)').addClass('selected');
307

308
    //enable widget links
309
    $(".server-name").live('click', function() {
310
        $('.single').find('.single-container').hide()
311
        $('.single').find('#' + $(this).attr('id').substring(5)).show();
312
        $('.single .column3').find('.selected').removeClass('selected');
313
        $(this).addClass('selected');
314
        $(".single .column3 .previous").show();
315
        $(".single .column3 .next").show();
316
        if ($(this).attr("id") == $(".single .column3 .server-name:eq(1)").attr("id")) {
317
            $(".single .column3 .previous").hide();
318
        } else if ($(this).attr("id") == $(".single .column3 .server-name:last").attr("id")) {
319
            $(".single .column3 .next").hide();
320
        }
321
    });
322

323
    //toggle content
324
    $("div.disks").toggle(function() {
325
            $(this).find('.toggler').html("&#711;");
326
            $(this).next(".disks-content").slideToggle(600);
327
            return false;
328
        }, function() {
329
            $(this).find('.toggler').html('&#710;');
330
            $(this).next(".disks-content").slideToggle(600);
331
            return false;
332
    });
333
    $("div.networks").toggle(function() {
334
            $(this).find('.toggler').html("&#711;");
335
            $(this).next(".networks-content").slideToggle(600);
336
            return false;
337
        }, function() {
338
            $(this).find('.toggler').html('&#710;');
339
            $(this).next(".networks-content").slideToggle(600);
340
            return false;
341
    });
342
    $("div.stats").toggle(function() {
343
            $(this).find('.toggler').html("&#711;");
344
            $(this).next(".stats-content").slideToggle(600);
345
            return false;
346
        }, function() {
347
            $(this).find('.toggler').html('&#710;');
348
            $(this).next(".stats-content").slideToggle(600);
349
            return false;
350
    });
351

352
    if ($.cookie('server')) {
353
        $('div#link-' + $.cookie('server')).click();
354
        $.cookie('server', null);
355
    }
356

357
    //if it is the last vm, hide the next button
358
    if ($("#machinesview-single.single .column3 .selected").attr("id") == $("#machinesview-single.single .column3 .server-name:last").attr("id")) {
359
        $("#machinesview-single.single .column3 .next").hide()
360
    } else {
361
        $("#machinesview-single.single .column3 .next").show()
362
    }
363

364
    //if it is the first vm, hide the prev button
365
    if ($("#machinesview-single.single .column3 .selected").attr("id") == $("#machinesview-single.single .column3 .server-name:eq(1)").attr("id")) {
366
        $("#machinesview-single.single .column3 .previous").hide()
367
    } else {
368
        $("#machinesview-single.single .column3 .previous").show()
369
    }
370

371
}
372

373
//enable prev-next buttons
374
$("#machinesview-single.single .column3 .previous").live('click', function(){
375
    if ($("#machinesview-single.single .column3 .selected").attr("id") == $("#machinesview-single.single .column3 .server-name:eq(1)").attr("id")) {
376
        return false;
377
    } else {
378
        current_server = $('#machinesview-single.single .column3').find('.selected').attr("id").substring(5);
379
        $('#machinesview-single.single').find('#' + current_server).hide();
380
        $('#machinesview-single.single').find('#' + current_server).prev().show();
381
        $('#machinesview-single.single .column3').find('#link-' + current_server).removeClass('selected');
382
        $('#machinesview-single.single .column3').find('#link-' + current_server).prev().addClass('selected');
383
        if ($("#machinesview-single.single .column3 .selected").attr("id") == $("#machinesview-single.single .column3 .server-name:eq(1)").attr("id")) {
384
            $(this).hide()
385
        }
386
        $("#machinesview-single.single .column3 .next").show()
387
    }
388
});
389

390
$("#machinesview-single.single .column3 .next").live('click', function(){
391
    if ($("#machinesview-single.single .column3 .selected").attr("id") == $("#machinesview-single.single .column3 .server-name:last").attr("id")) {
392
        return false;
393
        } else {
394
        current_server = $('#machinesview-single.single .column3').find('.selected').attr("id").substring(5);
395
        $('#machinesview-single.single').find('#' + current_server).hide();
396
        $('#machinesview-single.single').find('#' + current_server).next().show();
397
        $('#machinesview-single.single .column3').find('#link-' + current_server).removeClass('selected');
398
        $('#machinesview-single.single .column3').find('#link-' + current_server).next().addClass('selected');
399
        //if it is the last vm, hide the next button
400
        if ($("#machinesview-single.single .column3 .selected").attr("id") == $("#machinesview-single.single .column3 .server-name:last").attr("id")) {
401
            $(this).hide()
402
        }
403
        $("#machinesview-single.single .column3 .previous").show();
404
    }
405
});
406

407
//hide prev button on startup
408
$("#machinesview-single.single .column3 .previous").hide()
409

410
// basic functions executed on page load
411
if ( flavors.length == 0 && images.length == 0 ) {
412
    // configure flavors, this also calls update_vms(UPDATE_INTERVAL)
413
    update_flavors();
414
    // populate image list
415
    update_images();
416
} else if ( flavors.length == 0 && images.length != 0 ) {
417
    // configure flavors, this also calls update_vms(UPDATE_INTERVAL)
418
    update_flavors();
419
} else if ( flavors.length != 0 && images.length == 0 ) {
420
    // populate image list
421
    update_images();
422
    update_vms(UPDATE_INTERVAL);
423
} else {
424
    // start updating vm list
425
    update_vms(UPDATE_INTERVAL);
426
}
427

428
//FIXME: Hide and show welcome depending on number of machines
429
hideWelcome();
430
</script>