util: move validate_name to XMLBuilder.validate_generic_name
This commit is contained in:
parent
c2de4d7c36
commit
5ed8f2aa5f
|
@ -105,7 +105,7 @@ class Guest(XMLBuilder):
|
|||
@staticmethod
|
||||
def validate_name(conn, name, check_collision=True, validate=True):
|
||||
if validate:
|
||||
util.validate_name(_("Guest"), name)
|
||||
XMLBuilder.validate_generic_name(_("Guest"), name)
|
||||
if not check_collision:
|
||||
return
|
||||
|
||||
|
|
|
@ -194,7 +194,7 @@ class Network(XMLBuilder):
|
|||
|
||||
@staticmethod
|
||||
def validate_name(conn, name):
|
||||
util.validate_name(_("Network"), name)
|
||||
XMLBuilder.validate_generic_name(_("Network"), name)
|
||||
|
||||
try:
|
||||
conn.networkLookupByName(name)
|
||||
|
|
|
@ -285,7 +285,7 @@ class StoragePool(_StorageObject):
|
|||
|
||||
@staticmethod
|
||||
def validate_name(conn, name):
|
||||
util.validate_name(_("Storage object"), name)
|
||||
XMLBuilder.validate_generic_name(_("Storage object"), name)
|
||||
|
||||
try:
|
||||
conn.storagePoolLookupByName(name)
|
||||
|
@ -624,7 +624,7 @@ class StorageVolume(_StorageObject):
|
|||
|
||||
@staticmethod
|
||||
def validate_name(pool, name):
|
||||
util.validate_name(_("Storage object"), name)
|
||||
XMLBuilder.validate_generic_name(_("Storage object"), name)
|
||||
|
||||
try:
|
||||
pool.storageVolLookupByName(name)
|
||||
|
|
|
@ -33,21 +33,6 @@ def libvirt_collision(collision_cb, val):
|
|||
return check
|
||||
|
||||
|
||||
def validate_name(name_type, val):
|
||||
# Rather than try and match libvirt's regex, just forbid things we
|
||||
# know don't work
|
||||
forbid = [" "]
|
||||
if not val:
|
||||
raise ValueError(
|
||||
_("A name must be specified for the %s") % name_type)
|
||||
for c in forbid:
|
||||
if c not in val:
|
||||
continue
|
||||
raise ValueError(
|
||||
_("%s name '%s' can not contain '%s' character.") %
|
||||
(name_type, val, c))
|
||||
|
||||
|
||||
def generate_name(base, collision_cb, suffix="", lib_collision=True,
|
||||
start_num=1, sep="-", force_num=False, collidelist=None):
|
||||
"""
|
||||
|
|
|
@ -449,6 +449,21 @@ class XMLBuilder(object):
|
|||
def register_namespace(nsname, uri):
|
||||
XMLAPI.register_namespace(nsname, uri)
|
||||
|
||||
@staticmethod
|
||||
def validate_generic_name(name_label, val):
|
||||
# Rather than try and match libvirt's regex, just forbid things we
|
||||
# know don't work
|
||||
forbid = [" "]
|
||||
if not val:
|
||||
raise ValueError(
|
||||
_("A name must be specified for the %s") % name_label)
|
||||
for c in forbid:
|
||||
if c not in val:
|
||||
continue
|
||||
raise ValueError(
|
||||
_("%s name '%s' can not contain '%s' character.") %
|
||||
(name_label, val, c))
|
||||
|
||||
|
||||
def __init__(self, conn, parsexml=None,
|
||||
parentxmlstate=None, relative_object_xpath=None):
|
||||
|
|
Loading…
Reference in New Issue