This patch creates basic functions that allow kimchi users to create
an libvirt SCSI storagepool using the rest API.
Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo(a)linux.vnet.ibm.com>
---
docs/API.md | 6 ++++++
src/kimchi/API.json | 18 +++++++++++++++++-
src/kimchi/model.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++----
3 files changed, 74 insertions(+), 5 deletions(-)
diff --git a/docs/API.md b/docs/API.md
index 4d7bdff..a09bd0c 100644
--- a/docs/API.md
+++ b/docs/API.md
@@ -205,6 +205,12 @@ Represents a snapshot of the Virtual Machine's primary monitor.
Pool types: 'iscsi'.
* username: Login username of the iSCSI target.
* password: Login password of the iSCSI target.
+ * adapter_type: Host adapter type: 'scsi_host' or 'fc_host'.
+ * adapter_name: Scsi host name.
+ Required if 'scsi_host' type is selected.
+ * wwnn: Word Wide Node Name.
+ * wwpn: Word Wide Port Name.
+
### Resource: Storage Pool
diff --git a/src/kimchi/API.json b/src/kimchi/API.json
index 3a3c48f..3ed5526 100644
--- a/src/kimchi/API.json
+++ b/src/kimchi/API.json
@@ -16,7 +16,7 @@
"type": {
"description": "The type of the defined Storage
Pool",
"type": "string",
- "pattern": "^dir|netfs|logical$",
+ "pattern": "^dir|netfs|logical|scsi$",
"required": true
},
"path": {
@@ -55,6 +55,22 @@
"minimum": 1,
"maximum": 65535
},
+ "adapter_type": {
+ "description": "Host adapter type:
'scsi_host' or 'fc_host'",
+ "type": "string"
+ },
+ "adapter_name": {
+ "description": "SCSI host name",
+ "type": "string"
+ },
+ "wwnn": {
+ "description": "Fibre channel Word Wide Node
Name",
+ "type": "string"
+ },
+ "wwpn": {
+ "description": "Fibre channel Word Wide Port
Name",
+ "type": "string"
+ },
"auth": {
"description": "Storage back-end
authentication information",
"type": "object",
diff --git a/src/kimchi/model.py b/src/kimchi/model.py
index ed613b1..9cfc91c 100644
--- a/src/kimchi/model.py
+++ b/src/kimchi/model.py
@@ -70,7 +70,8 @@ from kimchi.networkxml import to_network_xml
from kimchi.objectstore import ObjectStore
from kimchi.scan import Scanner
from kimchi.screenshot import VMScreenshot
-from kimchi.utils import get_enabled_plugins, is_digit, kimchi_log
+from kimchi.utils import get_enabled_plugins, is_digit
+from kimchi.utils import is_libvirt_version_lesser, kimchi_log
from kimchi.vmtemplate import VMTemplate
@@ -80,7 +81,11 @@ HOST_STATS_INTERVAL = 1
VM_STATIC_UPDATE_PARAMS = {'name': './name'}
VM_LIVE_UPDATE_PARAMS = {}
STORAGE_SOURCES = {'netfs': {'addr': '/pool/source/host/@name',
- 'path': '/pool/source/dir/@path'}}
+ 'path': '/pool/source/dir/@path'},
+ 'scsi': {'adapter_type':
'/pool/source/adapter/@type',
+ 'adapter_name':
'/pool/source/adapter/@name',
+ 'wwnn': '/pool/source/adapter/@wwnn',
+ 'wwpn': '/pool/source/adapter/@wwpn'}}
def _uri_to_name(collection, uri):
@@ -1024,9 +1029,10 @@ class Model(object):
return name
pool = conn.storagePoolDefineXML(xml, 0)
- if params['type'] in ['logical', 'dir',
'netfs']:
+ if params['type'] in ['logical', 'dir',
'netfs', 'scsi']:
pool.build(libvirt.VIR_STORAGE_POOL_BUILD_NEW)
- # autostart dir and logical storage pool created from kimchi
+ # autostart dir, logical, netfs and scsi storage pools created
+ # from kimchi
pool.setAutostart(1)
else:
# disable autostart for others
@@ -1563,6 +1569,47 @@ class LogicalPoolDef(StoragePoolDef):
return xml
+class ScsiPoolDef(StoragePoolDef):
+ poolType = 'scsi'
+
+ def prepare(self, conn=None):
+ # Adapters type are only available in libvirt >= 1.0.5
+ if is_libvirt_version_lesser('1.0.5'):
+ self.poolArgs['source']['adapter_type'] =
'scsi_host'
+ tmp_name = self.poolArgs['source']['adapter_name']
+ self.poolArgs['source']['adapter_name'] =
tmp_name.replace('scsi_','')
+ msg = "Libvirt version <= 1.0.5. Setting SCSI host name as
'%s'; "\
+ "setting SCSI adapter type as 'scsi_host'; "\
+ "ignoring wwnn and wwpn." %tmp_name
+ kimchi_log.info(msg)
+
+ @property
+ def xml(self):
+ # Required parameters
+ # name:
+ # source[adapter_type]:
+ # source[adapter_name]:
+ # source[wwnn]:
+ # source[wwpn]:
+ # path:
+
+ xml = """
+ <pool type='scsi'>
+ <name>{name}</name>
+ <source>
+ <adapter type='{source[adapter_type]}'\
+ name='{source[adapter_name]}'\
+ wwnn='{source[wwnn]}'\
+ wwpn='{source[wwpn]}'/>
+ </source>
+ <target>
+ <path>{path}</path>
+ </target>
+ </pool>
+ """.format(**self.poolArgs)
+ return xml
+
+
class IscsiPoolDef(StoragePoolDef):
poolType = 'iscsi'
--
1.8.1.4