CA-110835: check XAPI session existence before trying to get the timeout

The NFS timeout config setting was introduced by CA-106558 as a
SR.other-config field. So when mounting a NFS share, the SM backend will
call back to XAPI to get this config. Normally this won't be a problem,
because SM backend driver is usually launched up by XAPI, so there is (almost)
always a XAPI session available in hand. However, in some cases, this is
not true. E.g. when HA is enabled, the heartbeat VDI needs to be mounted even
before XAPI starts, and it's invoked by the attach-static-vdi script not XAPI.
In such case, calling XAPI to get config will fail ultimately.

The patch is a shortcut fix, it verifies whether there is a valid XAPI session
around before attempting to read the config, and will just fall back to
default if there is none. A better approach would be putting the timeout
setting as part of the SMmaster's PBD device config, so that the information
will always be accessible during a relevant SMAPI call (no need for the extra
XAPI field getting), and will be dumped/loaded automatically as part of the
static VDI attaching configuration file. This could be a future improvement,
currently registered as CP-5683.

Signed-off-by: Zheng Li <zheng.li@eu.citrix.com>

GitHub: closes #10 on xapi-project/sm
CP-5737: Fix typo in comment

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
CP-5737: Properly format output string.

Add missing operator to format a string.

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
CP-5737: Avoid to mix different types during checks.

'f' was either integer or fileobject, this could cause type errors, use None
to have always an object.

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
CP-5737: Find proper lvm tools directory

Directory is /usr/bin or /sbin base on distro (CentOS 6.4 uses /sbin).

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
CP-5737: Add a function to silently ignore ENOENT while deleting files

This function is useful to delete a file/directory and avoiding race
conditions if another process/thread do the same thing.

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
CP-5737: Ignore error while deleting LVM files if file is not present.

LVM seems to remove files faster then SM so trying to delete LVM files
ignore error if file is not present.
Catch ENOENT error instead of checking for existence to avoid race
conditions and limiting system calls.

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
CP-5737: Do not use /etc/init.d scripts but service instead.

To be compatible with upstart is better to start services using service
command.

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
Merge changes for CP-5737

GitHub: closes #12 on xapi-project/sm