Revision 4ee73bb2 lib/utils/__init__.py
b/lib/utils/__init__.py | ||
---|---|---|
797 | 797 |
|
798 | 798 |
""" |
799 | 799 |
return [val for val in items if not self.Matches(val)] |
800 |
|
|
801 |
|
|
802 |
def ValidateDeviceNames(kind, container): |
|
803 |
"""Validate instance device names. |
|
804 |
|
|
805 |
Check that a device container contains only unique and valid names. |
|
806 |
|
|
807 |
@type kind: string |
|
808 |
@param kind: One-word item description |
|
809 |
@type container: list |
|
810 |
@param container: Container containing the devices |
|
811 |
|
|
812 |
""" |
|
813 |
|
|
814 |
valid = [] |
|
815 |
for device in container: |
|
816 |
if isinstance(device, dict): |
|
817 |
if kind == "NIC": |
|
818 |
name = device.get(constants.INIC_NAME, None) |
|
819 |
elif kind == "disk": |
|
820 |
name = device.get(constants.IDISK_NAME, None) |
|
821 |
else: |
|
822 |
raise errors.OpPrereqError("Invalid container kind '%s'" % kind, |
|
823 |
errors.ECODE_INVAL) |
|
824 |
else: |
|
825 |
name = device.name |
|
826 |
# Check that a device name is not the UUID of another device |
|
827 |
valid.append(device.uuid) |
|
828 |
|
|
829 |
try: |
|
830 |
int(name) |
|
831 |
except (ValueError, TypeError): |
|
832 |
pass |
|
833 |
else: |
|
834 |
raise errors.OpPrereqError("Invalid name '%s'. Purely numeric %s names" |
|
835 |
" are not allowed" % (name, kind), |
|
836 |
errors.ECODE_INVAL) |
|
837 |
|
|
838 |
if name is not None: |
|
839 |
if name in valid: |
|
840 |
raise errors.OpPrereqError("%s name '%s' already used" % (kind, name), |
|
841 |
errors.ECODE_NOTUNIQUE) |
|
842 |
else: |
|
843 |
valid.append(name) |
Also available in: Unified diff