<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>Reviewed by: Archana Singh <a class="moz-txt-link-rfc2396E"
href="mailto:archus@linux.vnet.ibm.com"><archus@linux.vnet.ibm.com></a></p>
<br>
<div class="moz-cite-prefix">On 09/12/2016 03:25 PM,
<a class="moz-txt-link-abbreviated" href="mailto:harshalp@linux.vnet.ibm.com">harshalp@linux.vnet.ibm.com</a> wrote:<br>
</div>
<blockquote
cite="mid:1473674117-26930-1-git-send-email-harshalp@linux.vnet.ibm.com"
type="cite">
<pre wrap="">From: Harshal Patil <a class="moz-txt-link-rfc2396E" href="mailto:harshalp@linux.vnet.ibm.com"><harshalp@linux.vnet.ibm.com></a>
This patch enables direct storage attachment to guests running
on s390x arch without going through libvirt
Signed-off-by: Harshal Patil <a class="moz-txt-link-rfc2396E" href="mailto:harshalp@linux.vnet.ibm.com"><harshalp@linux.vnet.ibm.com></a>
---
docs/API.md | 3 +++
i18n.py | 3 +++
model/vmstorages.py | 25 +++++++++++++++++++++++--
utils.py | 2 +-
4 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/docs/API.md b/docs/API.md
index 6678ac5..c9d5d2a 100644
--- a/docs/API.md
+++ b/docs/API.md
@@ -239,6 +239,9 @@ Represents a snapshot of the Virtual Machine's primary monitor.
* path: Path of cdrom iso.
* pool: Storage pool which disk image file locate in.
* vol: Storage volume name of disk image.
+ * dir_path: s390x specific attribute to attach direct storage without libvirt
+ * format: s390x specific attribute specify the format of direct storage
+ * size: s390x specific attribute to specify the size of direct storage
### Sub-resource: storage
**URI:** /plugins/kimchi/vms/*:name*/storages/*:dev*
diff --git a/i18n.py b/i18n.py
index fc7dbc7..ceb4286 100644
--- a/i18n.py
+++ b/i18n.py
@@ -332,6 +332,9 @@ messages = {
"KCHVMSTOR0016E": _("Volume already in use by other virtual machine."),
"KCHVMSTOR0017E": _("Only one of path or pool/volume can be specified to add a new virtual machine disk"),
"KCHVMSTOR0018E": _("Volume chosen with format %(format)s does not fit in the storage type %(type)s"),
+ "KCHVMSTOR0019E": _("On s390x arch one of pool, path of dir_path must be specified"),
+ "KCHVMSTOR0020E": _("On s390x arch 'format' must be specified while attaching disk to virtual machine"),
+ "KCHVMSTOR0021E": _("Virtual disk already exists on the system: %(disk_path)s"),
"KCHSNAP0001E": _("Virtual machine '%(vm)s' must be stopped before creating a snapshot of it."),
"KCHSNAP0002E": _("Unable to create snapshot '%(name)s' on virtual machine '%(vm)s'. Details: %(err)s<a class="moz-txt-link-rfc2396E" href="mailto:),diff--gita/model/vmstorages.pyb/model/vmstorages.pyindex2e9f783..156a16f100644---a/model/vmstorages.py+++b/model/vmstorages.py@@-17,6+17,7@@#Licensealongwiththislibrary;ifnot,writetotheFreeSoftware#Foundation,Inc.,51FranklinStreet,FifthFloor,Boston,MA02110-1301USA+importosimportstringfromlxmlimportetree@@-30,6+31,7@@fromwok.plugins.kimchi.model.storagevolumesimportStorageVolumeModelfromwok.plugins.kimchi.model.utilsimportget_vm_config_flagfromwok.plugins.kimchi.model.vmsimportDOM_STATE_MAP,VMModelfromwok.plugins.kimchi.osinfoimportlookup+fromwok.plugins.kimchi.utilsimportcreate_disk_image,is_s390xfromwok.plugins.kimchi.xmlutils.diskimportget_device_node,get_disk_xmlfromwok.plugins.kimchi.xmlutils.diskimportget_vm_disk_info,get_vm_disks@@-82,11+84,30@@classVMStoragesModel(object):#PathwillneverbeblankduetoAPI.jsonverification.#Thereisnoneedtocoverthiscasehere.ifnot('vol'inparams)^('path'inparams):-raiseInvalidParameter(">"),
diff --git a/model/vmstorages.py b/model/vmstorages.py
index 2e9f783..156a16f 100644
--- a/model/vmstorages.py
+++ b/model/vmstorages.py
@@ -17,6 +17,7 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+import os
import string
from lxml import etree
@@ -30,6 +31,7 @@ from wok.plugins.kimchi.model.storagevolumes import StorageVolumeModel
from wok.plugins.kimchi.model.utils import get_vm_config_flag
from wok.plugins.kimchi.model.vms import DOM_STATE_MAP, VMModel
from wok.plugins.kimchi.osinfo import lookup
+from wok.plugins.kimchi.utils import create_disk_image, is_s390x
from wok.plugins.kimchi.xmlutils.disk import get_device_node, get_disk_xml
from wok.plugins.kimchi.xmlutils.disk import get_vm_disk_info, get_vm_disks
@@ -82,11 +84,30 @@ class VMStoragesModel(object):
# Path will never be blank due to API.json verification.
# There is no need to cover this case here.
if not ('vol' in params) ^ ('path' in params):
- raise InvalidParameter("</a>KCHVMSTOR0017E")
+ if not is_s390x():
+ raise InvalidParameter("KCHVMSTOR0017E")
+
+ if 'dir_path' not in params:
+ raise InvalidParameter("KCHVMSTOR0019E")
dom = VMModel.get_vm(vm_name, self.conn)
params['bus'] = _get_device_bus(params['type'], dom)
- params['format'] = 'raw'
+
+ if is_s390x() and params['type'] == 'disk':
+ if 'format' not in params:
+ raise InvalidParameter("KCHVMSTOR0020E")
+ if 'dir_path' in params:
+ size = params['size']
+ name = params['name']
+ dir_path = params.get('dir_path')
+ params['path'] = dir_path + "/" + name
+ if os.path.exists(params['path']):
+ raise InvalidParameter("KCHVMSTOR0021E",
+ {'disk_path': params['path']})
+ create_disk_image(format_type=params['format'],
+ path=params['path'], capacity=size)
+ else:
+ params['format'] = 'raw'
dev_list = [dev for dev, bus in get_vm_disks(dom).iteritems()
if bus == params['bus']]
diff --git a/utils.py b/utils.py
index 0fca191..7fdec02 100644
--- a/utils.py
+++ b/utils.py
@@ -305,4 +305,4 @@ def create_disk_image(format_type, path, capacity):
if rc != 0:
raise OperationFailed("KCHTMPL0035E", {'err': err})
- return
\ No newline at end of file
+ return
</pre>
</blockquote>
<br>
</body>
</html>