Storage pool support unicode correctly

For unicode, we have handle the incoming text from
kimchi server and outgoing text to kimchi server correctly.

But we do not handle the incoming text from libvirt and outgoing
text to libvirt correctly.

For some variables of storage pool, such as pool name and pool xml
do not follow our principle.
https://github.com/kimchi-project/kimchi/wiki/support-unicode

This patch will improve the follow:
1. Handle storage pool xml and pool name as unicode in kimchi, and
decode them when pass them to libvirt.
2. Decode the pool name from libvirt.

We should guarantee:
All text strings, everywhere should be of type unicode, not str.
If we're handling text, and our variable is a str, it's a bug!

Test this patch:
1. create a pool
$ curl -u <user> -H 'Accept: application/json' \
-H 'Content-type: application/json' \
http://localhost:8000/storagepools/ -X POST -d '
{
   "name":"kīмсhī-pool",
   "type":"dir",
   "path":"/tmp/test"
} '

2. get this pool
$ curl -u <user> -H 'Accept: application/json' \
-H 'Content-type: application/json' \
http://localhost:8000/storagepools/kīмсhī-pool

3. delete this pool
$ curl -u <user> -H 'Accept: application/json' \
-H 'Content-type: application/json' -X DELETE \
http://localhost:8000/storagepools/kīмсhī-pool

Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
Firewall: Adding WebSocket port in firewall rules

Added port 64667 into src/firewalld.xml to attend Debian/Ubuntu, RHEL7+ and Fedora.
Also added iptables rules to attend RHEL6 into contrib/kimchi.spec.fedora.in

Signed-off-by: Paulo Vital <pvital@linux.vnet.ibm.com>
update test case for storage pool support unicode

update test case for it to avoid regression.

Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
bug fix: failed to update vm with unicode name

update a vm's name with unicode name, kimchi will report error.
$ curl -u <user> -H 'Accept: application/json' \
-H 'Content-type: application/json' \
http://localhost:8000/vms/u13.10 -X PUT -d '
{"name":  "kīмсhī-∨м"}'

There are two bugs:
1. typo
encode the ident with "utf8" when HTTPRedirect
change it to "utf-8"

2. The name form libvirt is str, need decode.
ref:
https://github.com/kimchi-project/kimchi/wiki/support-unicode

Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
update test case for updating vm with unicode name

update test case for it to avoid regression.

Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
change the vm name in test case

change kīмkhī to kīмсhī
kīмсhī looks like the acssii "kimchi"

Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
Fix controller base code: Update function is not using model_args

The model_args variable is used to pass information to functions.
Specially in functions of sub-collections and sub-resources, it is used
to pass the main collections and resources names/classes. The wrapper
update function from control base was not using model_args, then some
resouces might miss this information.

Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com>
Fix missing report-add html page in rpm

The file report-add.hml.tmpl is missing in rpms. This patch fixes this
problem adding the file name to Makefile.am.

Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com>
Add disks to LVM pool: control and model changes

Added a new update parameter to storagepool resource. Changed the
logic in the model to accept any update parameter ('autostart' or
'disks'). 'disks' parameter will add disks/partitions to the
target LVM pool.

Signed-off-by: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com>
Add disks to LVM pool: API.md changes

Adding documentation about the new 'disks' update parameter,
pool type 'logical' only.

Signed-off-by: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com>
Add disks to LVM pool: mockmodel changes

Eliminated the parameter validation that is now being done
in API.json.

To simulate the operation of add disks in the mockmodel, for
each disk (which is validated with real data from the host),
for each new disk added a fixed amount is added in the
'capacity' and 'available' fields on the pool.

Signed-off-by: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com>
Add disks to LVM pool: API.json changes

This patch adds a new section 'storagepool_update' in API.json
in order to remove parameter validation inside the model.

Signed-off-by: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com>
Fix wrong "Failed to list guest" message

The module vmscreenshot is preventing this error using Image.load
function inside a try/except. However right after the except block,
the code calls Image.thumbnail() function, which calls the same
load() function internally. Then the error could happen again.
This patch fixes this possible problem.

Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com>
pass params to create method of all Collections.

We can pass params as an argument to create method, do not need call
parse_request in every create method.

create means the HTTP POST method, and POST requires body.
So every create needs params parsed from body.
But we do not need to parse params in every create.

Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
Fix path of plugins dir

Fix the wrong path of plugins dir introduced in commit 44be0d2d.

Signed-off-by: Mark Wu <wudxw@linux.vnet.ibm.com>
refactor exception: Create a common Exception to translate error messages

KimchiException will be the base for all other Exception types in Kimchi
It will translate the error message before raising it.
Then UI can use the message directly. That way we avoid duplicating messages
on UI and backend.
Also add i18n.py which will contain all the backend messages to be translated.

Signed-off-by: Aline Manera <alinefm@br.ibm.com>
refactor exception: Add messages to be translated on backend

src/kimchi/i18n.py and plugins/sample/i18n.py contain all messages used
in backend to report error to the user

The messages are associated with a code which will be used to identify
the error independent of the language used in Kimchi.
The code has a basic rule:
- Start with KCH -> as it is related to Kimchi and not to any other
  plugin
- Follow by the resource it references to: VM, TMPL, POOL, VOL, etc
- And a number to represent the error: starting with 0001, 0002, etc for
  backend and for UI it starts in 6001, 6002, etc
- And at the end which the message is: E (for error), M (for message), W
  (for warning), I (for info)

So we will have some codes as: KCHVM0001E, KCHTMPL0001E, KCHPOOL0001E,
KCHVM60001M, KCHPOOL6001M

Signed-off-by: Aline Manera <alinefm@br.ibm.com>
refactor exception: Set error messages for jsonschema validation

While validating data with jsonschema it raises English messages.
To allow translate all error messages to the supported languages it is
needed to set a custom error message.
In this case, the message code is being used. Then KimchiException can
get the correct message based on code and display the translated
message.

Signed-off-by: Aline Manera <alinefm@br.ibm.com>
refator exception: Update control to raise the exception message

The error messages raised on control were being built in there instead of
using the exception message
And the errors from jsonschema validation also were displayed to the user
without a customization what can cause a misunderstanding as it contains
technical words.
Fix it in order to raise the translated messages to the user.

Signed-off-by: Aline Manera <alinefm@br.ibm.com>
refactor exception: Update all exceptions

Update all Kimchi exceptions to translate backend messages.
Use message code to get the correct messages in i18n.py and raise a
message like: "<code>: <translated-message>"

Signed-off-by: Aline Manera <alinefm@br.ibm.com>