Interface: Fix status return

Interface status returned by function operstate() is expected to be a
string, but a list has been returned.

Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com>
Issue #240: The bridge address of nat and isolated network is invalid, fix it

issue: https://github.com/kimchi-project/kimchi/issues/240

ref: http://libvirt.org/formatnetwork.html
libvirt says:
The address attribute of IP defines will be configured on the bridge
device associated with the virtual network.

But we should let user give a subnet address instead of a normal ip
address.

In this patch, kimchi will check the address.
If the address is a subnet address, kimchi will change it, and then
pass it to libvirt.

Test it:
Create a nat or isolated network in UI.
$ sudo virsh net-dumpxml your-network

Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
UI: Enhancement & Fixes for Host Monitoring

Several items:

1) Tab Page Lifecycle
     Added cleanup when a page is unloaded (user switchs to other
   tab), mainly clear timers for auto refreshing (host monitoring
   and guests status).

2) Fixed bugs in kimchi.widget.Grid
     There are 2 listeners registered to document.body, and these
   listeners will accumulate when user switchs back to host page.
   Added destroy() function to unload these listeners for Grid.

3) Added confirm dialog for debug report deletion

4) Corrected Disk and Network I/O Rate Units
     Memory is in B(ytes) unit, though disk/network I/O are in B(
   ytes)/s. Added a function to allow customize unit.

v1 -> v2:
  2a) Unified units to binary prefix (Ki - 2^10, Mi - 2^20, etc.)

Signed-off-by: Hongliang Wang <hlwang@linux.vnet.ibm.com>
Tests: fix test_model.ModelTests.test_debug_reports

There are three problems in test_model.ModelTests.test_debug_reports.

Problem 1
It waits just 20 seconds for debug report tool to finish. It may be too
short for a big Linux installation. This patch lengthens the timeout to
60 seconds.

Problem 2
There is a time window between
  inst.debugreports_create({'name': 'report1'})
and
  rollback.prependDefer(inst.debugreport_delete, 'report1')

If the timeout mentioned above is too short, it triggers assertion
failure and it does not get a chance to insert the undo action, so a
half generated "report1" is not deleted. This in turn leads to failure
of an earlier assertion if we run the test again. That assertion is as
follow.
  self.assertFalse('report1' in report_list)

This patch put the undo inserting code right after the
debugreports_create() invocation to minimize this time window.

Problem 3
It is possible for the actions to occur in a order of following.
  debugreports_create('report1')
  debug report tool collecting information, no report file is generated yet
  asyn task wait timeout
  assertion failure: debug report async task is not finished
  rollback runs, inst.debugreport_delete('report1') is called
  current test is over, next test is run
  the debug report tool subprocess is not killed, it continues to run
    and generates a file named report1
This is possible if the system is big slow. The result is that a leftover
report file is created after the test finishes. It also triggers an
earlier assertion error mentioned above if you run "make check" twice.
The correct way is to kill the async taks and related subprocess before we
exit the test, but it requires a lot of changes in the underlying facility.
This patch just deletes the report file explicitly before running the test.

Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
interface bug fix: only expose the unused interfaces to the front end

libvirt allows multi bridge networks on a same bridge or nic.
It is not harmful.

But kimchi does not allow this, so if a bridge or a nic is used by a bridge
network, kimchi interfaces API will not expose it to front end.

Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
Deep scan result deduplication

Multiple deep scan will touch the same path, and UI filter same result
by name/distro/version tuple. So constructing link with UUID result in
same path mapping to different link. Change it to use path md5 so that
UI can filter same result.

Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com>
Deep scan: Adding scan ignore path

Exclude kimchi constructed path to avoid duplicate scan of scan result.
In the future, more ignore path will be added due to performance.

Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com>
Deduplication: deduplication in shallow scan

Shallow scan reported scan result in format of "pool name" plus "volume name",
this resulted in deep scans same result appears to be many times in shallow scan.
Just report volume name in shallow scan.

Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com>
Nit fix of scan_dir_prepare

Delete redundant param in scan_dir_prepare().

Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com>
Packaging: add the disks.py to src/kimchi/Makefile.am

src/kimchi/disks.py is for listing host partitions and is imported in
src/kimchi/model.py. disks.py is not in src/kimchi/Makefile.am, so
make install, make dist and make rpm do not install or package this
file. You get an import error when kimchi is run from the installed
directory tree.

This patch adds disks.py to Makefile.am and sovle the problem.

v2: Adjust the listing according to alphabetic order.

Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
Add logical pool UI support

This patch is working for add the logical disk create UI.
1 Make all storage pool type in to list box.
2 add host partition checkbox.
Signed-off-by: zhoumeina <zhoumein@linux.vnet.ibm.com>
Add build in localdisk back-end

1 Make the storage path generate at back-end
2 Add build process to logic storage pool
Signed-off-by: zhoumeina <zhoumein@linux.vnet.ibm.com>
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
Packaging: add host.html.tmpl to ui/pages/tabs/Makefile.am

The file ui/pages/tabs/host.html.tmpl is the template of Host tab, the new tab
that shows host information. This file was not listed in
ui/pages/tabs/Makefile.am file resulting on make install, make dist and make rpm
do not install or package this file. You get a "blank" screen when clicking on
host tab.

Also, adjusted the listing according to alphabetic order.

Signed-off-by: Paulo Vital <pvital@linux.vnet.ibm.com>
Issue #263: network: bridge network shows network/prefix

Now kimchi network show hostip/prefix

Change it to network/prefix

issue: https://github.com/kimchi-project/kimchi/issues/263

Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
bug fix: Don't use shell=True in subprocess.Popen while running qemu-io test

On Ubuntu 13.10, when using subprocess.Popen with shell=True two processes will
be created:

1) /bin/sh -c qemu-io http://localhost:8000/images/icon-fedora.png -c 'read -v 0 512'
2) qemu-io http://localhost:8000/images/icon-fedora.png -c read -v 0 512

Special in this case, qemu-io command hangs (because it can't resolve hostname)
and we kill the process to interrupt the operation but in this case proc.kill()
will only kill the first process and the second one will keep alive consuming
memory.
Also with the second process alive we can complete feature tests as it waits the
qemu-io command to finish. And then we get the following error while trying to
stop kimchi.

Traceback (most recent call last):
  File "./src/kimchid", line 86, in <module>
    sys.exit(main(sys.argv[1:]))
  File "./src/kimchid", line 83, in main
    kimchi.server.main(options)
  File "/home/alinefm/kimchi/src/kimchi/server.py", line 254, in main
    srv.start()
  File "/home/alinefm/kimchi/src/kimchi/server.py", line 245, in start
    cherrypy.engine.start()
  File "/usr/lib/python2.7/dist-packages/cherrypy/process/wspbus.py", line 235, in start
    self.publish('start')
  File "/usr/lib/python2.7/dist-packages/cherrypy/process/wspbus.py", line 197, in publish
    output.append(listener(*args, **kwargs))
  File "/home/alinefm/kimchi/src/kimchi/model.py", line 224, in _set_capabilities
    self.qemu_stream_dns = FeatureTests.qemu_iso_stream_dns()
  File "/home/alinefm/kimchi/src/kimchi/featuretests.py", line 110, in qemu_iso_stream_dns
    thread.join()
  File "/usr/lib/python2.7/threading.py", line 947, in join
    self.__block.wait()
  File "/usr/lib/python2.7/threading.py", line 339, in wait
    waiter.acquire()
KeyboardInterrupt

So use shell=False to avoid creating two processes and then proc.kill() will not
leave any one running.

Signed-off-by: Aline Manera <alinefm@br.ibm.com>
bug fix #257: Specify the mime type for debugreports static dir

When no mime type is configured for cherrypy static dirs, cherrypy uses python
mimetypes module to guess the corret mime type based on file extension.
Then mimetypes modules checks some configuration files such as /etc/mime.types
to get the corret mime type to a given file extension.
But on Ubuntu there is no entry to .xz extension so cherrypy assumes text/html
Because that when the user try to download a debugreport from kimchi it try to
open it in another browser tab.
So add the correct mime type for .xz extension for debugreports static dir in
cherrypy configuration.

Reference: http://docs.cherrypy.org/stable/progguide/files/static.html#specify-\
           the-content-type-of-static-resource

Signed-off-by: Aline Manera <alinefm@br.ibm.com>
Signed-off-by: Adam King <rak@linux.vnet.ibm.com>
bug fix #254: Reset guest statistics when vm is powered off

The guests statistics are collected in a separated thread and it has its own
time frame to collect data.
If a vm is powered off during the sleep time frame, all the requests to the vm
will get incorrect data (previous data when vm was running).
So reset vm stats when powering off.

Signed-off-by: Aline Manera <alinefm@br.ibm.com>
Issue #273: unittest.TestCase has no attribute 'assertLessEqual'

change it to assertTrue

Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
Bug Fix: Wrong host available memory value

Host backend was using psutil.phymem* functions which are deprecated.
Also, 'available' memory has the same value of 'free' memory.
The function psutil.virtmem_usage() gives the right values, including
the amount of memory available (free + cached + buffers).

Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com>