storagepool: refactor _get_pool_xml()

In src/kimchi/model.py, _get_pool_xml() is to generate libvirt storage
pool XML definition from arguments provided by the POST data (a JSON
dict). It has to support various types of pool such as dir, netfs and
logical. Now it uses "if ... elif ... elif" to check the requested type
of pool and go in to the respective branch and generates the correct
XML. It also performs some preparations such as create target directory.
This is OK for now but in future we'll have more types of pool, and add
more validation and preparation code. So it needs a little refactor.

In this patch we define StoragePoolDef object along with a factory
methoed named "create". The factory method instantiates DirPoolDef,
NetfsPoolDef or LogicalPoolDef according to the requested pool type.
Then we can call defObj.prepare() to check NFS mount and iSCSI
login/password. We can inspect defObj.xml to get the generated XML for
the respective poolType.

v2 -> v3
  Call pool.build() for netfs, dir and logical pool. So do not need to
  create dirs any longer. Since NFS and iSCSI pool need validation,
  extract a StoragePoolDef object with "prepare" and "get_xml" methods.

v3 -> v4
  Turn 'defObj.get_xml()' into a lazily calculated property 'defObj.xml'.

v4 -> v5
  Do not cache generated xml, have subclass of StoragePoolDef override
  the '.xml' property. This makes the interface cleaner.

Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
storagepool: rename and consolidate arguments of creating (back-end)

As we are adding support to new type of storage pool, the current naming
scheme of the storage pool creating arguments should be rearranged to be
more extendable. This patch renames some arguments and consolidates the
argument of the same purposes as follow. This patch moves storage source
related arguments under "source" key, while "source" itself is a
dictionary.

nfsserver -> source.host
This is because in future patches, iSCSI pool can use this host info as
well. Other network backed storage pool can also make use of this
argument.

nfspath -> source.path
This is because other netfs pool can also make use of this argument.

devices -> source.devices
To differentiate source arguments from the target arguments, we move
this argument under "source" key.

The patch also adds unit test to check the generated XML is correct.

v2 -> v3
  test_storagepool.py: fix typo, reorganize import.

v3 -> v4
  Update API.json according to the changes in model.py.

v4 -> v5
  No changes.

Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
storagepool: rename and consolidate arguments of creating (front-end)

As we are adding support to new type of storage pool, the current naming
scheme of the storage pool creating arguments should be rearranged to be
more extendable. This patch renames some arguments and consolidates the
argument of the same purposes as follow.

nfsserver -> source.host
nfspath -> source.path
devices -> source.devices

This patch contains the front end changes of the consolidation work. It
just changes the formData transferred to kimchi backend, and leaves the
templates and other related scripts untouched.

v2 -> v5
  No changes

Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
storagepool: Support Creating iSCSI storagepool in model.py

This patch implements creating iSCSI storagepool for libvirt.
Each LUN in iSCSI storagepool can be used as a volume, but iSCSI
storagepool does not provide ability to create volume. For now in kimchi
we create volume for each newly created VM. Next is to implement
attaching existing volume to a new VM.

This patch also adds validation for the iSCSI back-end. It tries to
login the target using the auth before actually creating the pool.
On RedHat family distributions, libiscsi comes with a Python binding,
but not on other distributions. So in this patch it invokes iscsiadm to
check iSCSI target.

As regard to iSCSI CHAP authentication, it's somewhat broken before
libvirt 1.1.1. It was reworked in libvirt commit eb0d79, and this patch
goes with libvirt 1.1.1, but it doesn't require libvirt in the spec
file. This is because libvirt 1.1.1 is not available on Ubuntu 12.04
LTS. The user can just ignore this feature.

How to test it manually

Prerequisite
An running iSCSI target on the network.

Create:
curl -u root -H 'Content-type: application/json' \
  -H 'Accept: application/json' \
  -d '{"source": {
          "target": "iqn.YouriSCSITargetIQN.XXX",
          "host": "10.0.0.X"},
       "type": "iscsi",
       "name": "iscsipool"}' \
  http://127.0.0.1:8000/storagepools

Show Info:
curl -u root -H 'Accept: application/json' \
  http://127.0.0.1:8000/storagepools/iscsipool

Activate:
curl -u root -H 'Content-type: application/json' \
  -H 'Accept: application/json' \
  -d '' http://127.0.0.1:8000/storagepools/iscsipool/activate

Examine:
iscsiadm -m session

Deactivate:
curl -u root -H 'Content-type: application/json' \
  -H 'Accept: application/json' \
  -d '' http://127.0.0.1:8000/storagepools/iscsipool/deactivate

Delete:
curl -u root -X DELETE -H 'Accept: application/json' \
  http://127.0.0.1:8000/storagepools/iscsipool

v2 -> v3
  1) Support CHAP authentication.
  2) Validate iSCSI target before creating the pool.
  3) Add XML generation unit test with "port" and "auth".

v3 -> v4
  1) Update RPM spec file and Debian control file.
  2) Update API.json.
  3) Give a proper name for the iSCSI target client class, TargetClient.

v4 -> v5
  Fix description string of 'auth' in API.json.

Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
test_model: test creating iSCSI storage pool

This patch adds iSCSI storage pool test to
test_model.ModelTests.test_storagepool. It firstly checks if there exist
an iSCSI target named "iqn.2013-12.localhost.kimchiUnitTest" on local
host. If not, skip the test; if yes, continue to run the test already
defined in test_storagepool.

v2 -> v3
  Do not create dir for the pool, pool.build() called by
  storagepools_create() does this automatically.

v3 -> v5
  No changes.

Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>