Statistics
| Branch: | Tag: | Revision:

root / ui / templates / machines_list.html @ f533f224

History | View | Annotate | Download (17.1 kB)

1
{% load i18n %}
2

    
3
<div id="machinesview-list" class="list">
4
    <div class="large-spinner"></div>
5
    <div id="machinesview_content">
6
        <div class="actions">
7
            <a id="action-start">{% trans "Start" %}</a>
8
            <a id="action-reboot">{% trans "Reboot" %}</a>
9
            <a id="action-shutdown">{% trans "Shutdown" %}</a>
10
            <br />
11
            <a id="action-destroy">{% trans "Destroy" %}</a>
12
            <br />
13
            <a id="action-details">{% trans "Show Details" %}</a>
14
            <a id="action-group">{% trans "Add to group" %}</a>
15
            <br />
16
            <a id="action-console">{% trans "Console" %}</a>
17
            <br />
18
            <a id="action-attach">{% trans "Attach disk" %}</a>
19
            <a id="action-detach">{% trans "Detach disk" %}</a>
20
            <br />
21
            <a id="action-connect">{% trans "Connect to network" %}</a>
22
            <a id="action-disconnect">{% trans "Disconnect from net" %}</a>
23
        </div>
24
        <table class="list-machines" style="display: none">
25
            <thead>
26
                <tr>
27
                    <th class="selection select-running">
28
                        <input type="checkbox"/>
29
                        <div class="expand-icon"></div>
30
                    </th>
31
                    <th class="vmos">{% trans "OS" %}</th>
32
                    <th class="vmname">{% trans "Name" %}</th>
33
                    <th class="vmflavor">{% trans "Flavor" %}</th>
34
                    <th class="vmgroup">{% trans "Group" %}</th>
35
                    <th class="vmstatus">{% trans "Status" %}</th>
36
                </tr>
37
            </thead>
38
            <tbody class="machines"></tbody>
39
        </table>
40
        <ul class="dropdown-selector" style="display: none">
41
            <li class="select-all" ><a href="#">{% trans "all" %}</a></li>
42
            <li class="select-none"><a href="#">{% trans "none" %}</a></li>
43
            <li class="select-group"><a href="#">{% trans "group" %}</a></li>
44
        </ul>
45
    </div>
46
</div>
47

    
48
<script>
49

50
// select/deselect all from checkbox widget of table headers
51
$("#machinesview .list table thead tr th.selection :checkbox").live('change', function() {
52
    if ( $(this).is(":checked") ) {
53
        $(":checkbox").attr("checked", true);
54
    }
55
    else {
56
        $(":checkbox").attr("checked", false);
57
    }
58
    update_listview_actions();
59
    return false;
60
});
61

62
// select all from drop down menu
63
$("#machinesview .list ul.dropdown-selector li.select-all a").live('click', function() {
64
    $(":checkbox").attr("checked", true);
65
    $(".dropdown-selector").slideToggle('medium');
66
    update_listview_actions();
67
    return false;
68
});
69

70
// select none from drop down menu
71
$("#machinesview .list ul.dropdown-selector li.select-none a").live('click', function() {
72
    $(":checkbox").attr("checked", false);
73
    $(".dropdown-selector").slideToggle('medium');
74
    update_listview_actions();
75
    return false;
76
});
77

78
// select group from drop down menu
79
$("#machinesview .list ul.dropdown-selector li.select-group a").live('click', function() {
80
    $(":checkbox").attr("checked", true);
81
    $(".dropdown-selector").slideToggle('medium');
82
    update_listview_actions();
83
    return false;
84
});
85

86
// menu toggle, running menu
87
$("#machinesview .list table.list-machines thead tr th.selection .expand-icon").click( function (obj) {
88
    $(".dropdown-selector").slideToggle('medium');
89
    return false;
90
});
91

92
// TODO: This should be populated with more rules for all available states
93
var actions = { 'reboot':        ['UNKOWN', 'ACTIVE', 'REBOOT', 'multiple'],
94
                'shutdown':      ['UNKOWN', 'ACTIVE', 'REBOOT', 'multiple'],
95
                'connect':       ['UNKOWN', 'ACTIVE'],
96
                'disconnect':    ['UNKOWN', 'ACTIVE', 'network'],
97
                'console':       ['UNKOWN', 'ACTIVE', 'multiple'],
98
                'details':       ['UNKOWN', 'ACTIVE', 'REBOOT', 'STOPPED'],
99
                'start':         ['UNKOWN', 'STOPPED', 'multiple'],
100
                'destroy':       ['UNKOWN', 'ACTIVE', 'STOPPED', 'REBOOT', 'ERROR', 'BUILD', 'multiple'],
101
                'group':         ['UNKOWN', 'ACTIVE', 'STOPPED', 'REBOOT','multiple'],
102
               };
103

104
// on checkbox click, update the actions
105
$("#machinesview .list tbody input[type='checkbox']").live('change', function() {
106
    update_listview_actions();
107
    pending_actions = [];
108
    $(".selected").removeClass('selected');
109
    update_confirmations();
110
});
111

112
$("div.confirm_multiple button").click(function() {
113
    $(".selected").removeClass('selected');
114
});
115

116
// destroy action
117
$("#machinesview .list a.enabled#action-destroy").live('click', function() {
118
    var checked = $("#machinesview .list table.list-machines tbody input[type='checkbox']:checked");
119
    $("#machinesview .list .selected").removeClass('selected');
120
    $(this).addClass('selected');
121
    pending_actions = []; // reset pending actions
122
    checked.each(function(i,c) {
123
        serverID=c.id;
124
        serverName = $('#machinesview .list #'+serverID+' span.name').text();
125
        pending_actions.push([destroy, serverID]);
126
    });
127
    update_confirmations();
128
    return false;
129
});
130

131
$("#machinesview .list a.enabled#action-reboot").live('click', function() {
132
    var checked = $("#machinesview .list table.list-machines tbody input[type='checkbox']:checked");
133
    $("#machinesview .list .selected").removeClass('selected');
134
    $(this).addClass('selected');
135
    pending_actions = []; // reset pending actions
136
    checked.each(function(i,c) {
137
        serverID=c.id;
138
        serverName = $('#machinesview .list #'+serverID+' span.name').text();
139
        pending_actions.push([reboot, serverID]);
140
    });
141
    update_confirmations();
142
    return false;
143
});
144

145
$("#machinesview .list a.enabled#action-start").live('click', function() {
146
    var checked = $("#machinesview .list table.list-machines tbody input[type='checkbox']:checked");
147
    $("#machinesview .list .selected").removeClass('selected');
148
    $(this).addClass('selected');
149
    pending_actions = []; // reset pending actions
150
    checked.each(function(i,c) {
151
        serverID=c.id;
152
        serverName = $('#machinesview .list #'+serverID+' span.name').text();
153
        pending_actions.push([start, serverID]);
154
    });
155
    update_confirmations();
156
    return false;
157
});
158

159
$("#machinesview .list a.enabled#action-shutdown").live('click', function() {
160
    var checked = $("#machinesview .list table.list-machines tbody input[type='checkbox']:checked");
161
    $("#machinesview .list .selected").removeClass('selected');
162
    $(this).addClass('selected');
163
    pending_actions = []; // reset pending actions
164
    checked.each(function(i,c) {
165
        serverID=c.id;
166
        serverName = $('#machinesview .list #'+serverID+' span.name').text();
167
        pending_actions.push([shutdown, serverID]);
168
    });
169
    update_confirmations();
170
    return false;
171
});
172

173
$("#machinesview .list a.enabled#action-console").live('click', function() {
174
    var checked = $("#machinesview .list table.list-machines tbody input[type='checkbox']:checked");
175
    $("#machinesview .list .selected").removeClass('selected');
176
    $(this).addClass('selected');
177
    pending_actions = []; // reset pending actions
178
    checked.each(function(i,c) {
179
        serverID=c.id;
180
        serverName = $('#machinesview .list #'+serverID+' span.name').text();
181
        pending_actions.push([open_console, serverID]);
182
    });
183
    update_confirmations();
184
    return false;
185
});
186

187
function update_machines_view(data){
188
    /*
189
    Go through the servers in the input data. Update existing entries, add
190
    new ones to the list
191
    */
192
    tableData = vmTable.fnGetData();
193

194
    $.each(data.servers.values, function(i,server){
195
        current = -1;
196
        // check server status to select the appropriate OS icon, defaults to on state
197
        osTag = os_icon(server.metadata);
198
        var osIcon = osTag + "-on.png", imgStr, imgSrc;
199

200
        // check if the server already exists in the datatable
201
        tableData.forEach(function(row,index){
202

203
            if (row[0].split(' ')[2].replace('id=','') == server.id){
204
                current = index;
205
            }
206
        });
207
        if (current != -1) { // if it's there, update the values
208
            // get current status description, including non api states
209
            var server_row = $('#machinesview .list #' + server.id).parent().parent();
210
            var status_desc = server_row.find('span.status').text();
211
            // firebug console logging
212
            try {
213
                console.info(server.name + ' from ' + status_desc + ' to ' + STATUSES[server.status]);
214
            } catch(err) {}
215
            // when server is in deleted status it must be removed from the list
216
            if (server.status == "DELETED") {
217
                vmTable.fnDeleteRow(current);
218
            } else { // when server is not deleted, it should be updated
219
                if (['BUILD','ACTIVE','REBOOT'].indexOf(server.status) >= 0 &&
220
                    [STATUSES['STOPPED'], STATUSES['ERROR'], STATUSES['UNKNOWN'],
221
                     TRANSITIONS['Starting']].indexOf(server_row.find('span.status').text()) >= 0) {
222
                    // from stopped, on error or starting to building, active or rebooting
223
                    // starting is not an api state, it means the server is stopped or on error
224
                    tableData[current][0] = "<input class="+server.status+" id="+server.id+" type=checkbox>";
225
                    imgSrc = "static/icons/indicators/small/wave.gif";
226
                    imgStr = "<img class=list-logo src=" + imgSrc + " title=" + osTag + "></img>";
227
                    tableData[current][1] = "<span class=imagetag>" + osTag + "</span>" + imgStr;
228
                    tableData[current][2] = "<a class=name><span class=name>" + server.name.substring(0,60) + "</span></a>";
229
                    //tableData[current][4] = "group"; //TODO
230
                    tableData[current][5] = "<span class=status>" + STATUSES[server.status] + "</span>";
231
                    vmTable.fnUpdate(tableData[current],current);
232
                    setTimeout("$('#machinesview .list #"+server.id+"').parent().parent().find('.list-logo').attr('src','static/icons/machines/small/" + osIcon + "')", 1600);
233
                } else if (['STOPPED','ERROR', 'UNKNOWN'].indexOf(server.status) >= 0 &&
234
                           [STATUSES['ACTIVE'], STATUSES['BUILD'], STATUSES['REBOOT'],
235
                            TRANSITIONS['Shutting down']].indexOf(server_row.find('span.status').text()) >= 0) {
236
                    tableData[current][0] = "<input class="+server.status+" id="+server.id+" type=checkbox>";
237
                    imgSrc = "static/icons/indicators/small/wave.gif";
238
                    imgStr = "<img class=list-logo src=" + imgSrc + " title=" + osTag + "></img>";
239
                    tableData[current][1] = "<span class=imagetag>" + osTag + "</span>" + imgStr;
240
                    tableData[current][2] = "<a class=name><span class=name>" + server.name.substring(0,60) + "</span></a>";
241
                    //tableData[current][4] = "group"; //TODO
242
                    tableData[current][5] = "<span class=status>" + STATUSES[server.status] + "</span>";
243
                    vmTable.fnUpdate(tableData[current],current);
244
                    setTimeout("$('#machinesview .list #"+server.id+"').parent().parent().find('.list-logo').attr('src','static/icons/machines/small/" + osTag + "-off.png')", 1600);
245
                } else if ( STATUSES[server.status] == server_row.find('span.status').text()) {
246

247
                } else if (server.status == 'ACTIVE' &&
248
                           [STATUSES['BUILD'],TRANSITIONS['Rebooting']].indexOf(server_row.find('span.status').text()) >= 0) {
249
                    tableData[current][0] = "<input class="+server.status+" id="+server.id+" type=checkbox>";
250
                    imgSrc = "static/icons/indicators/small/wave.gif";
251
                    imgStr = "<img class=list-logo src=" + imgSrc + " title=" + osTag + "></img>";
252
                    tableData[current][1] = "<span class=imagetag>" + osTag + "</span>" + imgStr;
253
                    tableData[current][2] = "<a class=name><span class=name>" + server.name.substring(0,60) + "</span></a>";
254
                    //tableData[current][4] = "group"; //TODO
255
                    tableData[current][5] = "<span class=status>" + STATUSES[server.status] + "</span>";
256
                    vmTable.fnUpdate(tableData[current],current);
257
                    setTimeout("$('#machinesview .list #"+server.id+"').parent().parent().find('.list-logo').attr('src','static/icons/machines/small/" + osIcon + "')", 1600);
258
                }
259
            }
260
            update_listview_actions();
261
        } else if (server.status != "DELETED") { // does not exist, we should create it
262
            // check server status to select the appropriate OS icon
263
            if (['ERROR', 'STOPPED', 'UNKNOWN'].indexOf(server.status) >= 0) {
264
                osIcon = "static/icons/machines/small/" + osTag + "-off.png";
265
            } else if ( server.status == 'BUILD') {
266
                osIcon = "static/icons/indicators/small/progress.gif";
267
            } else {
268
                osIcon = "static/icons/machines/small/" + osTag + "-on.png";
269
            }
270
            // find flavor parameters
271
            var flavorLabel;
272
            if ( flavors.length > 0 ) {
273
                var current_flavor = '';
274
                for (i=0; i<flavors.length; i++) {
275
                    if (flavors[i]['id'] == server.flavorRef) {
276
                        current_flavor = flavors[i];
277
                    }
278
                }
279
                var flavor_label = '';
280
                if (current_flavor['cpu'] == '1') {
281
                    flavorLabel = '1 CPU, ';
282
                } else {
283
                    flavorLabel = current_flavor['cpu'] + ' CPUs, ';
284
                }
285
                flavorLabel = flavorLabel + current_flavor['ram'] + 'MB, ' + current_flavor['disk'] + 'GB';
286
            } else {
287
                flavorLabel = 'No flavor data';
288
            }
289

290
            // add new row to the table
291
            vmTable.fnAddData([
292
                "<input class=" + server.status + " id=" + server.id + " type=checkbox>",
293
                "<span class=imagetag>" + osTag + "</span><img class=list-logo src=" + osIcon +
294
                    " title=" + osTag + ">",
295
                "<a class=name><span class=name>" + server.name.substring(0,60) + "</span></a>",
296
                "<a class=flavor><span>"+ flavorLabel + "</span></a>",
297
                "group",
298
                "<span class=status>" + STATUSES[server.status] + "</span>"
299
            ]);
300
        }
301
    });
302
    update_listview_actions();
303
    $("#machinesview .list > div.large-spinner").hide();
304
    // in case there are no data, leave the page empty
305
    if ($("#machinesview .list table.list-machines tbody").length > 0) {
306
        $("#machinesview .list div.dataTables_filter").show();
307
        $("#machinesview .list div.dataTables_filter input").show();
308
        $("#machinesview .list table.list-machines").show();
309
        $("#machinesview .list div.actions").show();
310
    }
311

312
    // show message in case user has no servers!
313
    if ($("#machinesview .list tbody.machines .dataTables_empty").length > 0) {
314
        standard_view();
315
    } else {
316
        hideWelcome();
317
        $("#machinesview_content").fadeIn("fast");
318
    }
319

320
    // set confirm box position
321
    if (window.innerHeight - 200 < $('#machinesview').height())
322
        $('.confirm_multiple').addClass('fixed');
323
    else
324
        $('.confirm_multiple').removeClass('fixed');
325

326
    $('#machinesview .list .dataTables_scrollHeadInner table').attr('style','');
327
    $('#machinesview .list .dataTables_scrollHeadInner th').attr('style','');
328

329
}
330

331
function display_success(serverID) {
332
    // do nothing
333
}
334

335
// indicate that the requested action was not completed
336
function display_failure(status, serverID, action, responseText) {
337
    osIcon = $('#machinesview .list #'+serverID).parent().parent().find('.list-logo');
338
    osIcon.attr('src',osIcon.attr('os'));
339
    ajax_error(status, serverID, action, responseText);
340
}
341

342
var vmTable = $("div.list table.list-machines").dataTable({
343
    "bInfo": false,
344
    "bRetrieve": true,
345
    "bPaginate": false,
346
    "bAutoWidth": false,
347
    "bSort": true,
348
    "bStateSave": true,
349
    "sScrollY": "270px",
350
    "sScrollX": "515px",
351
    "sScrollXInner": "500px",
352
    "aoColumnDefs": [
353
        { "bSortable": false, "aTargets": [ 0 ] }
354
    ]
355
});
356

357
// basic functions executed on page load
358
if ( flavors.length == 0 && images.length == 0 ) {
359
    // configure flavors, this also calls update_vms(UPDATE_INTERVAL)
360
    update_flavors();
361
    // populate image list
362
    update_images();
363
} else if ( flavors.length == 0 && images.length != 0 ) {
364
    // configure flavors, this also calls update_vms(UPDATE_INTERVAL)
365
    update_flavors();
366
} else if ( flavors.length != 0 && images.length == 0 ) {
367
    // populate image list
368
    update_images();
369
    update_vms(UPDATE_INTERVAL);
370
} else {
371
    // start updating vm list
372
    update_vms(UPDATE_INTERVAL);
373
}
374

375
// reposition multiple confirmation box on window resize
376
$(window).resize(function(){
377
    if (this.innerHeight - 200 < $('#machinesview').height())
378
        $('.confirm_multiple').addClass('fixed');
379
    else
380
        $('.confirm_multiple').removeClass('fixed');
381
});
382

383
// set the label of the multiple buttons
384
$('.confirm_multiple button.yes').text({% trans 'Confirm' %});
385
$('.confirm_multiple button.no').text({% trans 'Cancel' %});
386
</script>