def _create_task(self, cb, params): type = params['type'] file_loc = params['file_loc'] cb('entering task to create swap file') with RollbackContext() as rollback: try: if type == 'file': cb('create a file') size = params['size'] utils._create_file(size, file_loc) elif type == 'device': utils.change_part_type(file_loc.split("/")[2], "82") cb('create swap from file') utils._make_swap(file_loc) cb('activate swap device') utils._activate_swap(file_loc) cb('persist swap device') import fs_utils fs_utils.persist_swap_dev(file_loc) cb('OK', True) except (OperationFailed), e: rollback.prependDefer(SwapsModel.delete_swap_file, file_loc) cb('OK', False) raise OperationFailed('GINSP00005E', {'file_loc': file_loc, 'err': e.message})
def _create_task(self, cb, params): type = params['type'] file_loc = params['file_loc'] cb('entering task to create swap file') with RollbackContext() as rollback: try: if type == 'file': cb('create a file') size = params['size'] utils._create_file(size, file_loc) except (InvalidParameter) as e: cb('OK', False) raise InvalidParameter("GINSP00020E") except (OperationFailed) as e: cb('OK', False) raise OperationFailed('GINSP00005E', { 'file_loc': file_loc, 'err': e.message }) try: if type == 'device': dev = file_loc.split("/")[-1] if dev.startswith('dm-'): dmname = utils.get_dm_name(file_loc.split("/")[-1]) else: dmname = dev part = PartitionModel(objstore=self.objstore) dev_type = part.lookup(dmname) if dev_type['type'] == 'part': type = '82' # hex value for type Linux Swap part.change_type(dmname, type) cb('create swap from file') utils._make_swap(file_loc) cb('activate swap device') utils._activate_swap(file_loc) cb('persist swap device') import fs_utils fs_utils.persist_swap_dev(file_loc) cb('OK', True) except (OperationFailed) as e: rollback.prependDefer(SwapsModel.delete_swap_file, file_loc) cb('OK', False) raise OperationFailed('GINSP00005E', { 'file_loc': file_loc, 'err': e.message })
def _create_task(self, cb, params): type = params['type'] file_loc = params['file_loc'] cb('entering task to create swap file') with RollbackContext() as rollback: try: if type == 'file': cb('create a file') size = params['size'] utils._create_file(size, file_loc) except (InvalidParameter) as e: cb('OK', False) raise InvalidParameter("GINSP00020E") except (OperationFailed) as e: cb('OK', False) raise OperationFailed('GINSP00005E', {'file_loc': file_loc, 'err': e.message}) try: if type == 'device': dev = file_loc.split("/")[-1] if dev.startswith('dm-'): dmname = utils.get_dm_name(file_loc.split("/")[-1]) else: dmname = dev part = PartitionModel(objstore=self.objstore) dev_type = part.lookup(dmname) if dev_type['type'] == 'part': type = '82' # hex value for type Linux Swap part.change_type(dmname, type) cb('create swap from file') utils._make_swap(file_loc) cb('activate swap device') utils._activate_swap(file_loc) cb('persist swap device') import fs_utils fs_utils.persist_swap_dev(file_loc) cb('OK', True) except (OperationFailed) as e: rollback.prependDefer(SwapsModel.delete_swap_file, file_loc) cb('OK', False) raise OperationFailed('GINSP00005E', {'file_loc': file_loc, 'err': e.message})