|
| 1 | +{% extends "app/layout.html" %} |
| 2 | + |
| 3 | +{% block content %} |
| 4 | +<div class="container-fluid"> |
| 5 | + <div class="row"> |
| 6 | + <h1 class="page-header">Change Memory</h1> |
| 7 | + </div> |
| 8 | + <div class="row" style="width: 50%"> |
| 9 | + <div id='progressbar' style='display:none' align="center"> |
| 10 | + <img src='../../static/app/img/progressbar.gif'/> |
| 11 | + </div> |
| 12 | + <form action="changememory" class="crawl" method="POST" id="ChangeMemoryForm"> |
| 13 | + {% csrf_token %} |
| 14 | + {{ form.duration.errors }} |
| 15 | + {{ form.nodeCount.errors }} |
| 16 | + <p style="color: #e38d13">{{ message }}</p> |
| 17 | + <table class="table table-striped table-bordered table-hover" id="ChangeMemoryTable"> |
| 18 | + <tbody> |
| 19 | + <tr> |
| 20 | + <td style="width: 30%;">ESXi</td> |
| 21 | + <td style="width: 70%;"> |
| 22 | + <select id="esxihost" name="esxihost" class="form-control"> |
| 23 | + <option selected value="0">Please Select...</option> |
| 24 | + {% if esxihosts %} |
| 25 | + {% for esxihost in esxihosts %} |
| 26 | + <option value="{{ esxihost.id }}">{{ esxihost.esxiIP }}</option> |
| 27 | + {% endfor %} |
| 28 | + {% endif %} |
| 29 | + </select> |
| 30 | + </td> |
| 31 | + </tr> |
| 32 | + <tr> |
| 33 | + <td style="width: 30%;">VM Name</td> |
| 34 | + <td style="width: 70%;"> |
| 35 | + <select id="vmname" name="vmname" class="form-control" onchange="seleceVMName.value = this.options[this.selectedIndex].value"> |
| 36 | + <option value="0">Please Select...</option> |
| 37 | + </select> |
| 38 | + <input type="hidden" name="seleceVMName" id="seleceVMName" value="0"> |
| 39 | + </td> |
| 40 | + </tr> |
| 41 | + <tr> |
| 42 | + <td style="width: 30%;">Memory Size(MB)</td> |
| 43 | + <td style="width: 70%;"> |
| 44 | + <input name="memorysize" id="memorysize" placeholder="4"> |
| 45 | + </td> |
| 46 | + </tr> |
| 47 | + <tr> |
| 48 | + <td style="width: 30%;"></td> |
| 49 | + <td style="width: 70%;"><button id="changeMemorybutton" name="changeMemorybutton" type="button" class="btn btn-default">Update Memory</button> |
| 50 | + </td> |
| 51 | + </tr> |
| 52 | + </tbody> |
| 53 | + </table> |
| 54 | + </form> |
| 55 | + </div> |
| 56 | +</div> |
| 57 | + |
| 58 | +<script type="text/javascript" src="../../static/app/scripts/jquery.min.js"></script> |
| 59 | + |
| 60 | +<script> |
| 61 | +$('#esxihost').change(function() { |
| 62 | + var esxi = $('#esxihost').val() |
| 63 | + $.ajax({ |
| 64 | + type: 'GET', |
| 65 | + url: '../api/v1/esxi/'+esxi+'/getvms', |
| 66 | + dataType: 'json', |
| 67 | + success: function (output) { |
| 68 | + if(output.indexOf("Failed") >= 0){ |
| 69 | + var $vmname = $('#vmname').empty(); |
| 70 | + $vmname.append('<option selected value="0">Please Select...</option>') |
| 71 | + alert("Fail to get the vms information. Please check your ESXi host information!"); |
| 72 | + } |
| 73 | + else{ |
| 74 | + var parsed = JSON.parse(output); |
| 75 | + var $vmname = $('#vmname').empty(); |
| 76 | + $vmname.append('<option selected value="0">Please Select...</option>') |
| 77 | + $.each(parsed, function(index, value) { |
| 78 | + var $html = '<option value="' + value["name"] + '">' + value["name"] + '</option>' |
| 79 | + $('#vmname').append($html) |
| 80 | + }) |
| 81 | + } |
| 82 | + }, |
| 83 | + error: function(){ |
| 84 | + alert("Fail to get the vms information. Please consult system admin for the permission."); |
| 85 | + } |
| 86 | + }); |
| 87 | +}) |
| 88 | + |
| 89 | +$('#changeMemorybutton').click(function() { |
| 90 | + $('#progressbar').show(); |
| 91 | + var id = $('#esxihost').val(); |
| 92 | + var vmname = $('#vmname').val(); |
| 93 | + var size = $('#memorysize').val(); |
| 94 | + $.ajax({ |
| 95 | + type: 'POST', |
| 96 | + url: '../api/v1/esxi/'+ id +'/changemem', |
| 97 | + data: {'csrfmiddlewaretoken': '{{csrf_token}}', "id": id, "name": vmname, "size": size}, |
| 98 | + dataType: 'json', |
| 99 | + success: function (output) { |
| 100 | + $('#progressbar').hide(); |
| 101 | + if(output.indexOf("fail") >= 0){ |
| 102 | + alert("Fail to update memory information, please power off your VM first!"); |
| 103 | + } |
| 104 | + else { |
| 105 | + $('#progressbar').hide(); |
| 106 | + alert("Update memory successfully!") |
| 107 | + } |
| 108 | + }, |
| 109 | + error: function(){ |
| 110 | + $('#progressbar').hide(); |
| 111 | + alert("Fail to update memory. Please power off your VM first."); |
| 112 | + } |
| 113 | + }); |
| 114 | +}) |
| 115 | +</script> |
| 116 | + |
| 117 | +{% endblock %} |
0 commit comments