Change in vdsm[master]: sp.py: adding attachSDHsm

laravot at redhat.com laravot at redhat.com
Mon Jun 8 08:48:32 UTC 2015


Liron Aravot has uploaded a new change for review.

Change subject: sp.py: adding attachSDHsm
......................................................................

sp.py: adding attachSDHsm

Change-Id: I39212f56b5cbfa179c616169b536d4c40a30b0f1
Signed-off-by: laravot at redhat.com <laravot at redhat.com>
---
M client/vdsClient.py
M vdsm/API.py
M vdsm/rpc/BindingXMLRPC.py
M vdsm/rpc/vdsmapi-schema.json
M vdsm/storage/hsm.py
M vdsm/storage/sp.py
M vdsm/storage/storage_exception.py
7 files changed, 103 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/27/42027/1

diff --git a/client/vdsClient.py b/client/vdsClient.py
index c267b75..02bafa7 100755
--- a/client/vdsClient.py
+++ b/client/vdsClient.py
@@ -656,6 +656,14 @@
             return dom['status']['code'], dom['status']['message']
         return 0, ''
 
+    def attachStorageDomainHsm(self, args):
+        sdUUID = args[0]
+        spUUID = args[1]
+        dom = self.s.attachStorageDomainHsm(sdUUID, spUUID)
+        if dom['status']['code']:
+            return dom['status']['code'], dom['status']['message']
+        return 0, ''
+
     def detachStorageDomain(self, args):
         sdUUID = args[0]
         spUUID = args[1]
diff --git a/vdsm/API.py b/vdsm/API.py
index 2ceb85e..9f66400f 100644
--- a/vdsm/API.py
+++ b/vdsm/API.py
@@ -994,6 +994,9 @@
     def attach(self, storagepoolID):
         return self._irs.attachStorageDomain(self._UUID, storagepoolID)
 
+    def attachHsm(self, storagepoolID):
+        return self._irs.attachStorageDomainHsm(self._UUID, storagepoolID)
+
     def create(self, domainType, typeArgs, name, domainClass, version=None):
         if version is None:
             version = constants.SUPPORTED_DOMAIN_VERSIONS[0]
diff --git a/vdsm/rpc/BindingXMLRPC.py b/vdsm/rpc/BindingXMLRPC.py
index 96eda1d..e86bba9 100644
--- a/vdsm/rpc/BindingXMLRPC.py
+++ b/vdsm/rpc/BindingXMLRPC.py
@@ -611,6 +611,10 @@
         domain = API.StorageDomain(sdUUID)
         return domain.attach(spUUID)
 
+    def domainAttachHSM(self, sdUUID, spUUID):
+        domain = API.StorageDomain(sdUUID)
+        return domain.attachHsm(spUUID)
+
     def domainCreate(self, storageType, sdUUID, domainName,
                      typeSpecificArg, domClass,
                      domVersion=None, options=None):
@@ -1068,7 +1072,8 @@
                 (self.vmSetIoTune, 'setIoTune'),
                 (self.vmGetIoTunePolicy, 'getIoTunePolicy'),
                 (self.getExternalVMs, 'getExternalVMs'),
-                (self.convertExternalVm, 'convertExternalVm'))
+                (self.convertExternalVm, 'convertExternalVm'),
+                (self.domainAttachHSM, 'attachStorageDomainHSM'))
 
     def getIrsMethods(self):
         return ((self.domainActivate, 'activateStorageDomain'),
diff --git a/vdsm/rpc/vdsmapi-schema.json b/vdsm/rpc/vdsmapi-schema.json
index 3409e81..96918b9 100644
--- a/vdsm/rpc/vdsmapi-schema.json
+++ b/vdsm/rpc/vdsmapi-schema.json
@@ -4982,6 +4982,20 @@
  'data': {'storagedomainID': 'UUID', 'storagepoolID': 'UUID'}}
 
 ##
+# @StorageDomain.attachHsm:
+#
+# Attach a Storage Domain to a Storage Pool.
+#
+# @storagedomainID:  The UUID of the Storage Domain
+#
+# @storagepoolID:    The UUID of the Storage Pool
+#
+# Since: 4.18.0
+##
+{'command': {'class': 'StorageDomain', 'name': 'attachHsm'},
+ 'data': {'storagedomainID': 'UUID', 'storagepoolID': 'UUID'}}
+
+##
 # @StorageDomainCreateArgumentsBlock:
 #
 # Creation argument for Block-based Storage Domains.
diff --git a/vdsm/storage/hsm.py b/vdsm/storage/hsm.py
index f0e3eb8..7d1ce11 100644
--- a/vdsm/storage/hsm.py
+++ b/vdsm/storage/hsm.py
@@ -1207,14 +1207,38 @@
         :type spUUID: UUID
         :param options: ?
         """
+        pool = self._prepareAttachStorageDomain(sdUUID, spUUID)
+        pool.attachSD(sdUUID)
+
+    @public
+    def attachStorageDomainHsm(self, sdUUID, spUUID):
+        """
+        Attach a storage domain to a storage pool.
+        This marks the storage domain as status 'attached' and link it to the
+        storage pool
+
+        .. note::
+            The target domain must be accessible in this point
+            (storage connected)
+
+        :param sdUUID: The UUID of the storage domain that you want to attach.
+        :type sdUUID: UUID
+        :param spUUID: The UUID of the storage pool that contains the storage
+                       domain being attached.
+        :type spUUID: UUID
+        :param options: ?
+        """
+        pool = self._prepareAttachStorageDomain(sdUUID, spUUID)
+        pool.attachSDHsm(sdUUID)
+
+    def _prepareAttachStorageDomain(self, sdUUID, spUUID):
         vars.task.setDefaultException(
             se.StorageDomainActionError(
                 "sdUUID=%s, spUUID=%s" % (sdUUID, spUUID)))
 
         vars.task.getExclusiveLock(STORAGE, spUUID)
         vars.task.getExclusiveLock(STORAGE, sdUUID)
-        pool = self.getPool(spUUID)
-        pool.attachSD(sdUUID)
+        return self.getPool(spUUID)
 
     @public
     def deactivateStorageDomain(self, sdUUID, spUUID, msdUUID,
diff --git a/vdsm/storage/sp.py b/vdsm/storage/sp.py
index 2adee55..40991ec 100644
--- a/vdsm/storage/sp.py
+++ b/vdsm/storage/sp.py
@@ -480,11 +480,13 @@
         self.refresh(msdUUID, masterVersion)
 
     # TODO: Remove or rename this function.
+    @unsecured
     def validatePoolSD(self, sdUUID):
         if sdUUID not in self.getDomains():
             raise se.StorageDomainNotMemberOfPool(self.spUUID, sdUUID)
         return True
 
+    @unsecured
     def validateAttachedDomain(self, dom):
         """
         Avoid handling domains if not owned by pool.
@@ -874,6 +876,31 @@
         to the storage pool
          'sdUUID' - storage domain UUID
         """
+        self._attachSD(sdUUID)
+
+    @unsecured
+    def validateNoSpm(self):
+        if self.masterDomain is not None:
+            raise se.StoragePoolWithSpm
+
+    @unsecured
+    def attachSDHsm(self, sdUUID):
+        """
+        Attach a storage domain to the storage pool.
+        This marks the storage domain as "attached" and links it
+        to the storage pool
+         'sdUUID' - storage domain UUID
+        """
+        self.validateNoSpm()
+        self._attachSD(sdUUID)
+
+    def _attachSD(self, sdUUID):
+        """
+        Attach a storage domain to the storage pool.
+        This marks the storage domain as "attached" and links it
+        to the storage pool
+         'sdUUID' - storage domain UUID
+        """
         self.log.info("sdUUID=%s spUUID=%s", sdUUID, self.spUUID)
 
         domains = self.getDomains()
@@ -901,15 +928,16 @@
             dom.acquireClusterLock(self.id)
 
             try:
-                domVers = dom.getVersion()
-                mstVers = self.masterDomain.getVersion()
+                if self.masterDomain is not None:
+                    domVers = dom.getVersion()
+                    mstVers = self.masterDomain.getVersion()
 
-                # If you remove this condition, remove it from
-                # public_createStoragePool too.
-                if dom.isData() and domVers > mstVers:
-                    raise se.MixedSDVersionError(dom.sdUUID, domVers,
-                                                 self.masterDomain.sdUUID,
-                                                 mstVers)
+                    # If you remove this condition, remove it from
+                    # public_createStoragePool too.
+                    if dom.isData() and domVers > mstVers:
+                        raise se.MixedSDVersionError(dom.sdUUID, domVers,
+                                                     self.masterDomain.sdUUID,
+                                                     mstVers)
 
                 dom.attach(self.spUUID)
                 domains[sdUUID] = sd.DOM_ATTACHED_STATUS
@@ -1152,7 +1180,8 @@
         domain.refreshDirTree()
         linkName = os.path.join(self.poolPath, domain.sdUUID)
         self._linkStorageDomain(domain.domaindir, linkName)
-        if self.masterDomain.sdUUID == domain.sdUUID:
+        if self.masterDomain is not None and \
+                self.masterDomain.sdUUID == domain.sdUUID:
             masterName = os.path.join(self.poolPath, POOL_MASTER_DOMAIN)
             self._linkStorageDomain(domain.domaindir, masterName)
 
diff --git a/vdsm/storage/storage_exception.py b/vdsm/storage/storage_exception.py
index fac24b2..2077964 100644
--- a/vdsm/storage/storage_exception.py
+++ b/vdsm/storage/storage_exception.py
@@ -916,6 +916,14 @@
     message = "Storage Domain target is unsupported"
 
 
+class StoragePoolWithSpm(StorageException):
+    def __init__(self, spUUID):
+        self.value = "pool=%s" % spUUID
+        self.message = ("As the pool '%s' should have a SPM, the operation "
+                        "can be performed only by it" % (spUUID,))
+    code = 443
+
+
 #################################################
 # Task Exceptions
 #################################################


-- 
To view, visit https://gerrit.ovirt.org/42027
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I39212f56b5cbfa179c616169b536d4c40a30b0f1
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Liron Aravot <laravot at redhat.com>


More information about the vdsm-patches mailing list