1313#
1414# Open vStorage is distributed in the hope that it will be useful,
1515# but WITHOUT ANY WARRANTY of any kind.
16- from ovs . log . log_handler import LogHandler
16+
1717from ovs .dal .hybrids .vdisk import VDisk
1818from ovs .dal .lists .vdisklist import VDiskList
1919from ovs .dal .lists .vpoollist import VPoolList
20+ from ovs .log .log_handler import LogHandler
21+ from ..helpers .ci_constants import CIConstants
2022from ..helpers .exceptions import VPoolNotFoundError , VDiskNotFoundError
2123
2224
23- class VDiskHelper (object ):
25+ class VDiskHelper (CIConstants ):
2426 """
2527 vDiskHelper class
2628 """
@@ -105,8 +107,8 @@ def get_snapshot_by_guid(snapshot_guid, vdisk_name, vpool_name):
105107 raise RuntimeError ("Did not find snapshot with guid `{0}` on vdisk `{1}` on vpool `{2}`"
106108 .format (snapshot_guid , vdisk_name , vpool_name ))
107109
108- @staticmethod
109- def get_config_params (vdisk_name , vpool_name , api , timeout = GET_CONFIG_PARAMS_TIMEOUT ):
110+ @classmethod
111+ def get_config_params (cls , vdisk_name , vpool_name , timeout = GET_CONFIG_PARAMS_TIMEOUT , * args , ** kwargs ):
110112 """
111113 Fetch the config parameters of a vDisk
112114
@@ -115,8 +117,6 @@ def get_config_params(vdisk_name, vpool_name, api, timeout=GET_CONFIG_PARAMS_TIM
115117 :type vdisk_name: str
116118 :param vpool_name: name of a existing vpool
117119 :type vpool_name: str
118- :param api: specify a valid api connection to the setup
119- :type api: ci.helpers.api.OVSClient
120120 :param timeout: time to wait for the task to complete
121121 :type timeout: int
122122 :return: a dict with config parameters, e.g.
@@ -133,8 +133,8 @@ def get_config_params(vdisk_name, vpool_name, api, timeout=GET_CONFIG_PARAMS_TIM
133133 """
134134
135135 vdisk = VDiskHelper .get_vdisk_by_name (vdisk_name = vdisk_name , vpool_name = vpool_name )
136- task_guid = api .get (api = '/vdisks/{0}/get_config_params' .format (vdisk .guid ))
137- task_result = api .wait_for_task (task_id = task_guid , timeout = timeout )
136+ task_guid = cls . api .get (api = '/vdisks/{0}/get_config_params' .format (vdisk .guid ))
137+ task_result = cls . api .wait_for_task (task_id = task_guid , timeout = timeout )
138138
139139 if not task_result [0 ]:
140140 error_msg = "Setting config vDisk `{0}` has failed with error {1}" .format (vdisk_name , task_result [1 ])
@@ -144,23 +144,21 @@ def get_config_params(vdisk_name, vpool_name, api, timeout=GET_CONFIG_PARAMS_TIM
144144 VDiskHelper .LOGGER .info ("Setting config vDisk `{0}` should have succeeded" .format (vdisk_name ))
145145 return task_result [1 ]
146146
147- @staticmethod
148- def scrub_vdisk (vdisk_guid , api , timeout = 15 * 60 , wait = True ):
147+ @classmethod
148+ def scrub_vdisk (cls , vdisk_guid , timeout = 15 * 60 , wait = True , * args , ** kwargs ):
149149 """
150150 Scrub a specific vdisk
151151 :param vdisk_guid: guid of the vdisk to scrub
152152 :type vdisk_guid: str
153- :param api: specify a valid api connection to the setup
154- :type api: ci.helpers.api.OVSClient
155153 :param timeout: time to wait for the task to complete
156154 :type timeout: int
157155 :param wait: wait for task to finish or not
158156 :type wait: bool
159- :return:
157+ :return:
160158 """
161- task_guid = api .post (api = '/vdisks/{0}/scrub/' .format (vdisk_guid ), data = {})
159+ task_guid = cls . api .post (api = '/vdisks/{0}/scrub/' .format (vdisk_guid ), data = {})
162160 if wait is True :
163- task_result = api .wait_for_task (task_id = task_guid , timeout = timeout )
161+ task_result = cls . api .wait_for_task (task_id = task_guid , timeout = timeout )
164162 if not task_result [0 ]:
165163 error_msg = "Scrubbing vDisk `{0}` has failed with error {1}" .format (vdisk_guid , task_result [1 ])
166164 VDiskHelper .LOGGER .error (error_msg )
@@ -170,3 +168,24 @@ def scrub_vdisk(vdisk_guid, api, timeout=15 * 60, wait=True):
170168 return task_result [1 ]
171169 else :
172170 return task_guid
171+
172+ @classmethod
173+ def delete_vdisk (cls , vdisk_guid , timeout = GET_CONFIG_PARAMS_TIMEOUT ):
174+ """
175+ Delete a specific vdisk
176+ :param vdisk_guid: guid of the vdisk to delete
177+ :type vdisk_guid: str
178+ :param timeout: time to wait for the task to complete
179+ :type timeout: int
180+ :return: bool
181+ """
182+ task_guid = cls .api .delete (api = '/vdisks/{0}' .format (vdisk_guid ))
183+ task_result = cls .api .wait_for_task (task_id = task_guid , timeout = timeout )
184+
185+ if not task_result [0 ]:
186+ error_msg = "Deleting of vDisk `{0}` has failed with error {1}" .format (vdisk_guid , task_result [1 ])
187+ VDiskHelper .LOGGER .error (error_msg )
188+ raise RuntimeError (error_msg )
189+ else :
190+ VDiskHelper .LOGGER .info ("Deleting of vDisk `{0}` should have succeeded" .format (vdisk_guid ))
191+ return True
0 commit comments