Change in vdsm[master]: WIP vm payload: cloud-init - multiple files, custom volume l...
gpadgett at redhat.com
gpadgett at redhat.com
Tue Apr 30 18:56:13 UTC 2013
Greg Padgett has uploaded a new change for review.
Change subject: WIP vm payload: cloud-init - multiple files, custom volume label
......................................................................
WIP vm payload: cloud-init - multiple files, custom volume label
Changes required for cloud-init integration: support multiple files and
custom volume labels in VM Payloads.
Change-Id: I5247d8f4ee01c0c871912a7998bdf958fc71ddd1
Signed-off-by: Greg Padgett <gpadgett at redhat.com>
---
M tests/mkimageTests.py
M vdsm/clientIF.py
M vdsm/mkimage.py
M vdsm/supervdsmServer.py
4 files changed, 32 insertions(+), 16 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/47/14347/1
diff --git a/tests/mkimageTests.py b/tests/mkimageTests.py
index 8c8c59e..ac1252c 100644
--- a/tests/mkimageTests.py
+++ b/tests/mkimageTests.py
@@ -107,7 +107,7 @@
Tests mkimage.mkFloppyFs creating an image and checking its content.
Requires root permissions for writing into the floppy image.
"""
- floppy = mkimage.mkFloppyFs("vmId_floppy", self.files)
+ floppy = mkimage.mkFloppyFs("vmId_floppy", self.files, None)
self.assertTrue(os.path.exists(floppy))
m = storage.mount.Mount(floppy, self.workdir)
m.mount(mntOpts='loop')
@@ -123,7 +123,8 @@
"""
checkSudo(["mount", "-o", "loop", "somefile", "target"])
checkSudo(["umount", "target"])
- iso_img = mkimage.mkIsoFs("vmId_iso", self.files)
+ iso_img = mkimage.mkIsoFs("vmId_iso", self.files, None)
+ # TODO add test for label, same in test_mkFloppyFs above
self.assertTrue(os.path.exists(iso_img))
m = storage.mount.Mount(iso_img, self.workdir)
m.mount(mntOpts='loop')
diff --git a/vdsm/clientIF.py b/vdsm/clientIF.py
index ed7db4b..0c9f9ce 100644
--- a/vdsm/clientIF.py
+++ b/vdsm/clientIF.py
@@ -297,7 +297,8 @@
'vmPayload' in drive['specParams']:
'''
vmPayload is a key in specParams
- 'vmPayload': {'file': {'filename': 'content'}}
+ 'vmPayload': {'volId': 'volume id', # volId is optional
+ 'file': {'filename': 'content', ...}}
'''
mkFsNames = {'cdrom': 'mkIsoFs', 'floppy': 'mkFloppyFs'}
try:
@@ -307,10 +308,11 @@
raise vm.VolumeError("Unsupported 'device': %s in "
"drive: %" % (drive['device'], drive))
else:
- # the only reason for adding this variable is that
+ # the only reason for adding these variables is that
# you can not write this without breaking PEP8
- file_name = drive['specParams']['vmPayload']['file']
- volPath = mkFsFunction(vmId, file_name)
+ file_list = drive['specParams']['vmPayload']['file']
+ volId = drive['specParams']['vmPayload'].get('volId', None)
+ volPath = mkFsFunction(vmId, file_list, volId)
elif "path" in drive:
volPath = drive['path']
diff --git a/vdsm/mkimage.py b/vdsm/mkimage.py
index 0eabae2..7e5ff18 100644
--- a/vdsm/mkimage.py
+++ b/vdsm/mkimage.py
@@ -35,7 +35,7 @@
_P_PAYLOAD_IMAGES = os.path.join(P_VDSM_RUN, 'payload')
-def _decodeFilesIntoDir(files, dirname):
+def _decodeFilesIntoDir(files, parentdir):
'''
create temp files from files list
@@ -47,7 +47,14 @@
'''
for name, content in files.iteritems():
- filename = os.path.join(dirname, name)
+ filename = os.path.join(parentdir, name)
+ dirname = os.path.dirname(filename)
+ if not os.path.exists(dirname):
+ try:
+ os.makedirs(dirname)
+ except OSError as e:
+ if e.errno != os.errno.EEXIST:
+ raise
with file(filename, 'w') as f:
f.write(base64.b64decode(content))
@@ -74,11 +81,14 @@
return path
-def mkFloppyFs(vmId, files):
+def mkFloppyFs(vmId, files, volId):
floppy = dirname = None
try:
floppy = _getFileName(vmId, files)
- command = [EXT_MKFS_MSDOS, '-C', floppy, '1440']
+ if volId:
+ command = [EXT_MKFS_MSDOS, '-C', floppy, '1440', '-n', volId]
+ else:
+ command = [EXT_MKFS_MSDOS, '-C', floppy, '1440']
rc, out, err = storage.misc.execCmd(command, raw=True)
if rc:
raise OSError(errno.EIO, "could not create floppy file: "
@@ -97,14 +107,17 @@
return floppy
-def mkIsoFs(vmId, files):
+def mkIsoFs(vmId, files, volId):
dirname = isopath = None
try:
dirname = tempfile.mkdtemp()
_decodeFilesIntoDir(files, dirname)
isopath = _getFileName(vmId, files)
- command = [EXT_MKISOFS, '-r', '-o', isopath, dirname]
+ if volId:
+ command = [EXT_MKISOFS, '-r', '-o', isopath, '-V', volId, dirname]
+ else:
+ command = [EXT_MKISOFS, '-r', '-o', isopath, dirname]
rc, out, err = storage.misc.execCmd(command, raw=True)
if rc:
raise OSError(errno.EIO, "could not create iso file: "
diff --git a/vdsm/supervdsmServer.py b/vdsm/supervdsmServer.py
index 28d5955..4d80bbe 100755
--- a/vdsm/supervdsmServer.py
+++ b/vdsm/supervdsmServer.py
@@ -293,12 +293,12 @@
tc.unsetPortMirroring(networkName, target)
@logDecorator
- def mkFloppyFs(self, vmId, files):
- return mkimage.mkFloppyFs(vmId, files)
+ def mkFloppyFs(self, vmId, files, volId):
+ return mkimage.mkFloppyFs(vmId, files, volId)
@logDecorator
- def mkIsoFs(self, vmId, files):
- return mkimage.mkIsoFs(vmId, files)
+ def mkIsoFs(self, vmId, files, volId):
+ return mkimage.mkIsoFs(vmId, files, volId)
@logDecorator
def removeFs(self, path):
--
To view, visit http://gerrit.ovirt.org/14347
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5247d8f4ee01c0c871912a7998bdf958fc71ddd1
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Greg Padgett <gpadgett at redhat.com>
More information about the vdsm-patches
mailing list