Simone Tiraboschi has uploaded a new change for review.

Change subject: iscsi: checking image size against VG free space
......................................................................

iscsi: checking image size against VG free space

On block devices we are preallocating the
disk image so we need to check if we have enought
free space before starting

Change-Id: I17f861a053f6ac38983967ffb07ecca9ff9b8de1
Bug-Url: https://bugzilla.redhat.com/1142710
Signed-off-by: Simone Tiraboschi <stira...@redhat.com>
---
M src/ovirt_hosted_engine_setup/constants.py
M src/plugins/ovirt-hosted-engine-setup/vm/image.py
2 files changed, 38 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-hosted-engine-setup 
refs/changes/40/34940/1

diff --git a/src/ovirt_hosted_engine_setup/constants.py 
b/src/ovirt_hosted_engine_setup/constants.py
index 5ddd7cf..fcbd638 100644
--- a/src/ovirt_hosted_engine_setup/constants.py
+++ b/src/ovirt_hosted_engine_setup/constants.py
@@ -276,6 +276,10 @@
     HA_BROCKER_SERVICE = 'ovirt-ha-broker'
     HOSTED_ENGINE_VM_NAME = 'HostedEngine'
     METADATA_CHUNK_SIZE = 4096
+
+    # TODO: VDSM APIs currently don't expose this value
+    # get from there when available
+    EXTENT_SIZE = 134217728  # 128 MiB
     MAX_HOST_ID = 250
     HA_NOTIF_SMTP_SERVER = 'smtp-server'
     HA_NOTIF_SMTP_PORT = 'smtp-port'
diff --git a/src/plugins/ovirt-hosted-engine-setup/vm/image.py 
b/src/plugins/ovirt-hosted-engine-setup/vm/image.py
index dba5863..48c3512 100644
--- a/src/plugins/ovirt-hosted-engine-setup/vm/image.py
+++ b/src/plugins/ovirt-hosted-engine-setup/vm/image.py
@@ -45,6 +45,7 @@
 
     def __init__(self, context):
         super(Plugin, self).__init__(context=context)
+        self.serv = None
 
     @plugin.event(
         stage=plugin.Stages.STAGE_INIT,
@@ -81,9 +82,28 @@
         ),
     )
     def _disk_customization(self):
+        self.serv = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
         interactive = self.environment[
             ohostedcons.StorageEnv.IMAGE_SIZE_GB
         ] is None
+
+        vgmaxavailable = None
+        if self.environment[ohostedcons.StorageEnv.DOMAIN_TYPE] in (
+            ohostedcons.DomainTypes.ISCSI,
+        ):
+            # Can't use sparse volume on block devices
+            vginfo = self.serv.s.getVGInfo(
+                self.environment[ohostedcons.StorageEnv.VG_UUID]
+            )
+            self.logger.debug(vginfo)
+            if vginfo['status']['code'] != 0:
+                raise RuntimeError(vginfo['status']['message'])
+            vgfree = int(vginfo['info']['vgfree'])
+            vgmaxavailable = (
+                vgfree / ohostedcons.Const.MINIMUM_SPACE_STORAGEDOMAIN_MB *
+                ohostedcons.Const.MINIMUM_SPACE_STORAGEDOMAIN_MB
+            )
+
         valid = False
         while not valid:
             if interactive:
@@ -100,7 +120,19 @@
                 )
             try:
                 valid = True
-                if int(
+                if vgmaxavailable is not None and int(
+                    self.environment[ohostedcons.StorageEnv.IMAGE_SIZE_GB]
+                ) * pow(2, 30) > vgmaxavailable:
+                    self.logger.warning(
+                        _(
+                            'Not enough free space, '
+                            'only {free:.2f} GiB are available'
+                        ).format(
+                            free=float(vgmaxavailable)/pow(2, 30)
+                        )
+                    )
+                    valid = False
+                if valid and int(
                     self.environment[ohostedcons.StorageEnv.IMAGE_SIZE_GB]
                 ) < ohostedcons.Defaults.DEFAULT_IMAGE_SIZE_GB:
                     self.logger.warning(
@@ -158,7 +190,6 @@
         spUUID = self.environment[ohostedcons.StorageEnv.SP_UUID]
         imgUUID = self.environment[ohostedcons.StorageEnv.IMG_UUID]
         volUUID = self.environment[ohostedcons.StorageEnv.VOL_UUID]
-        serv = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
         self.logger.info(_('Creating VM Image'))
         self.logger.debug('createVolume')
         volFormat = ohostedcons.VolumeFormat.RAW_FORMAT
@@ -170,7 +201,7 @@
             preallocate = ohostedcons.VolumeTypes.PREALLOCATED_VOL
 
         diskType = 2
-        status, message = serv.createVolume([
+        status, message = self.serv.createVolume([
             sdUUID,
             spUUID,
             imgUUID,


-- 
To view, visit http://gerrit.ovirt.org/34940
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I17f861a053f6ac38983967ffb07ecca9ff9b8de1
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-hosted-engine-setup
Gerrit-Branch: master
Gerrit-Owner: Simone Tiraboschi <stira...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to