|
389 | 389 | from blivet3 import devices |
390 | 390 | from blivet3.deviceaction import ActionConfigureFormat, ActionResizeFormat, ActionAddMember, ActionRemoveMember |
391 | 391 | from blivet3.devicefactory import DEFAULT_THPOOL_RESERVE |
| 392 | + from blivet3.errors import RaidError |
392 | 393 | from blivet3.flags import flags as blivet_flags |
393 | 394 | from blivet3.formats import fslib, get_format |
394 | 395 | from blivet3.partitioning import do_partitioning |
|
405 | 406 | from blivet import devices |
406 | 407 | from blivet.deviceaction import ActionConfigureFormat, ActionResizeFormat, ActionAddMember, ActionRemoveMember |
407 | 408 | from blivet.devicefactory import DEFAULT_THPOOL_RESERVE |
| 409 | + from blivet.errors import RaidError |
408 | 410 | from blivet.flags import flags as blivet_flags |
409 | 411 | from blivet.formats import fslib, get_format |
410 | 412 | from blivet.partitioning import do_partitioning |
@@ -538,6 +540,17 @@ def _new_mdarray(self, members, raid_name=""): |
538 | 540 | if raid_name == "": |
539 | 541 | raid_name = self._spec_dict["name"] |
540 | 542 |
|
| 543 | + |
| 544 | + raid_level = self._spec_dict["raid_level"] |
| 545 | + try: |
| 546 | + blivet_level = devicelibs.raid.get_raid_level(raid_level) |
| 547 | + except RaidError: |
| 548 | + raise BlivetAnsibleError("%s is not a valid RAID level" % raid_level) |
| 549 | + else: |
| 550 | + if len(members) < blivet_level.min_members: |
| 551 | + raise BlivetAnsibleError("not enough disks selected to create %s array, at least %d " |
| 552 | + "disks needed" % (raid_level, blivet_level.min_members)) |
| 553 | + |
541 | 554 | # calculate and verify active and spare devices counts |
542 | 555 | active_count = len(members) |
543 | 556 | spare_count = 0 |
@@ -571,7 +584,7 @@ def _new_mdarray(self, members, raid_name=""): |
571 | 584 |
|
572 | 585 | try: |
573 | 586 | raid_array = self._blivet.new_mdarray(name=raid_name, |
574 | | - level=self._spec_dict["raid_level"], |
| 587 | + level=raid_level, |
575 | 588 | member_devices=active_count, |
576 | 589 | total_devices=len(members), |
577 | 590 | parents=members, |
|
0 commit comments