source: package_branches/invirt-web/cherrypy/code/templates/list.mako @ 2395

Last change on this file since 2395 was 2395, checked in by quentin, 15 years ago

Port list to Mako

File size: 4.6 KB
Line 
1<%inherit file="skeleton.mako" />
2<%!
3        from invirt.config import structs as config
4        import datetime
5%>
6
7
8<%def name="title()">
9VM List
10</%def>
11
12<%def name="createForm()">
13% if cant_add_vm:
14<p>${cant_add_vm}</p>
15% else:
16<h2>Create a new VM</h2>
17% if err:
18<p class="error">We had a problem with your request:</p>
19% elif new_machine:
20<p>Congratulations! You successfully created a new VM called ${new_machine}.</p>
21% endif
22    <form action="create" method="POST">
23    <input type="hidden" name="back" value="list"/>
24      <table>
25        ${errorRow('create', err)}
26        <tr>
27          <td>Name</td>
28          <td><input type="text" name="name" value="${defaults.name}"/>.${config.dns.domains[0]}</td>
29        </tr>
30        ${errorRow('name', err)}
31        <tr>
32          <td>Description</td>
33          <td><textarea name="description" rows="4" cols="60">${defaults.description}</textarea></td>
34        </tr>
35        ${errorRow('description', err)}
36        <tr>
37          <td>Memory</td>
38          <td><input type="text" name="memory" value="${defaults.memory}" size=3/> MiB (${max_memory} max)</td>
39        </tr>
40        ${errorRow('memory', err)}
41        <tr>
42          <td>Disk</td>
43          <td><input type="text" name="disksize" value="${defaults.disk}" size=3/> GiB (${"%0.1f" % (max_disk-0.05)} max)</td>
44        </tr>
45        ${errorRow('disk', err)}
46        <tr>
47          <td>HVM/ParaVM${fn.helppopup('HVM/ParaVM')}</td>
48          <td>
49          ${vmTypeList(defaults.type)}
50          </td>
51        </tr>
52        ${errorRow('vmtype', err)}
53        ${errorRow('autoinstall', err)}
54        <tr>
55          <td>Autoinstall${fn.helppopup('Autoinstalls')}</td>
56          <td><input type="radio" name="cd_or_auto" id="cd_or_auto_auto"
57                 onchange="\$('cdromlist').value = ''; \$('vmtype-linux').checked = true">
58${autoList(defaults.cdrom, "$('cd_or_auto_auto').checked = true;$('cdromlist').value = '';$('vmtype-linux').checked = true")}
59              (experimental; 2-3 minutes, and you have a machine with empty root password.)
60          </input>
61        </tr>
62        <tr>
63          <td>Boot CD</td>
64          <td><input type="radio" name="cd_or_auto" id="cd_or_auto_cd" checked="checked"
65                onchange="\$('autoinstalllist').value = ''; \$('vmtype-linux-hvm').checked = true">
66${cdromList(defaults.cdrom, "$('cd_or_auto_cd').checked = true;$('autoinstalllist').value = '';$('vmtype-linux-hvm').checked = true")}
67</td>
68          </input>
69        </tr>
70        ${errorRow('cdrom', err)}
71        ${errorRow('cdrom', err)}
72        <tr>
73          <td>Owner</td>
74          <td><input type="text" name="owner" value="${defaults.owner}"/></td>
75        </tr>
76        ${errorRow('owner', err)}
77      </table>
78      <input type="submit" class="button" value="Create it!"/><br />
79      Windows notes: ${fn.helppopup('Windows')}
80    </form>
81% endif
82</%def>
83
84<%def name="machineRow(machine)">
85      <tr>
86        <td rowspan="2">
87          <form action="command" method="post">
88            <input type="hidden" name="back" value="list"/>
89            <input type="hidden" name="machine_id"
90                   value="${machine.machine_id}"/>
91<input type="submit" class="power ${'on' if machine.uptime else 'off'}" name="action" value="${'Power off' if machine.uptime else 'Power on'}"\
92% if machine.uptime:
93 onclick="return confirm('Are you sure you want to power off this VM?');"
94% endif
95/>
96          </form>
97        </td>
98        <td><a href="info?machine_id=${machine.machine_id}">${machine.name}</a></td>
99        <td>${machine.memory}M</td>
100        <td>${machine.owner}</td>
101        <td>${machine.administrator}</td>
102% if machine.nics:
103        <td>${', '.join(map(lambda x: x.ip, machine.nics))}</td>
104% else:
105        <td></td>
106% endif
107<td>\
108% if machine.uptime:
109${datetime.timedelta(seconds=int(machine.uptime))}\
110% endif
111</td>
112        <td>\
113% if has_vnc[machine] == True:
114<a href="vnc?machine_id=${machine.machine_id}">Console</a>\
115% elif has_vnc[machine] != 'Off':
116${has_vnc[machine]}
117% endif
118</td>
119      </tr>
120      <tr>
121        <td colspan="7" style="padding-left: 1em; color: #666">${machine.description}</td>
122      </tr>
123</%def>
124
125<%def name="machineList(machines)">
126    <table cellspacing="0" cellpadding="2">
127      <tr>
128        <th></th>
129        <th>Name</th>
130        <th>Memory</th>
131        <th>Owner${fn.helppopup('Owner')}</th>
132        <th>Administrator${fn.helppopup('Administrator')}</th>
133        <th>IP</th>
134        <th>Uptime</th>
135        <th>VNC</th>
136      </tr>
137% for machine in machines:
138        ${machineRow(machine)}
139% endfor
140    </table>
141    <script type="text/javascript" src="/static/stripe.js"></script>
142    <script type="text/javascript">
143        document.observe("dom:loaded", function() {
144            stripe(\$('machinelist').getElementsByTagName('table')[0],
145                   'stripedrow');
146        });
147    </script>
148</%def>
149
150<p style="font-size: 125%;"><a href="http://${config.web.hostname}">What is XVM?</a></p>
151% if not machines:
152<p>You don't currently control any VMs.</p>  
153% endif
154    <p><a href="list">refresh</a></p>
155    <div id="machinelist">
156    ${machineList(machines)}
157    </div>
158${createForm()}
Note: See TracBrowser for help on using the repository browser.