pyocf: rio: Introduce copy()

This allows to create a Rio prototype object and the copy it for every
invocations so that some parameters can be overwritten without modifying
the prototype object itself.

Signed-off-by: Robert Baldyga <robert.baldyga@huawei.com>
Signed-off-by: Michal Mielewczyk <michal.mielewczyk@huawei.com>
This commit is contained in:
Robert Baldyga 2024-02-02 17:55:25 +01:00 committed by Michal Mielewczyk
parent d892e3b0d5
commit 8d4661bdc9

View File

@ -11,7 +11,7 @@ from dataclasses import dataclass, field
from datetime import timedelta, datetime
from itertools import cycle
from threading import Thread, Condition, Event
from copy import deepcopy
import copy
from pyocf.utils import Size
from pyocf.types.volume import Volume
@ -173,6 +173,11 @@ class Rio:
self.errors = {}
self.error_count = 0
def copy(self):
r = copy.copy(self)
r.global_jobspec = copy.copy(self.global_jobspec)
return r
def readwrite(self, rw: ReadWrite):
self.global_jobspec.readwrite = rw
return self
@ -269,7 +274,7 @@ class Rio:
def run_async(self, queues):
self.clear()
jobs = deepcopy(self.jobs)
jobs = copy.deepcopy(self.jobs)
if not jobs:
jobs = [self.global_jobspec for _ in range(self.global_jobspec.njobs)]