mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
ipalib: PEP8 fixes for host plugin
Part of: https://fedorahosted.org/freeipa/ticket/3979 Reviewed-By: Petr Viktorin <pviktori@redhat.com> Reviewed-By: Petr Vobornik <pvoborni@redhat.com> Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
This commit is contained in:
parent
3e2e5a4d28
commit
f48a7bb730
@ -108,7 +108,8 @@ register = Registry()
|
|||||||
|
|
||||||
# Characters to be used by random password generator
|
# Characters to be used by random password generator
|
||||||
# The set was chosen to avoid the need for escaping the characters by user
|
# The set was chosen to avoid the need for escaping the characters by user
|
||||||
host_pwd_chars=string.digits + string.ascii_letters + '_,.@+-='
|
host_pwd_chars = string.digits + string.ascii_letters + '_,.@+-='
|
||||||
|
|
||||||
|
|
||||||
def remove_fwd_ptr(ipaddr, host, domain, recordtype):
|
def remove_fwd_ptr(ipaddr, host, domain, recordtype):
|
||||||
api.log.debug('deleting ipaddr %s' % ipaddr)
|
api.log.debug('deleting ipaddr %s' % ipaddr)
|
||||||
@ -118,24 +119,25 @@ def remove_fwd_ptr(ipaddr, host, domain, recordtype):
|
|||||||
# in case domain is in FQDN form with a trailing dot, we needn't add
|
# in case domain is in FQDN form with a trailing dot, we needn't add
|
||||||
# another one, in case it has no trailing dot, dnsrecord-del will
|
# another one, in case it has no trailing dot, dnsrecord-del will
|
||||||
# normalize the entry
|
# normalize the entry
|
||||||
delkw = { 'ptrrecord' : "%s.%s" % (host, domain) }
|
delkw = {'ptrrecord': "%s.%s" % (host, domain)}
|
||||||
|
|
||||||
api.Command['dnsrecord_del'](revzone, revname, **delkw)
|
api.Command['dnsrecord_del'](revzone, revname, **delkw)
|
||||||
except errors.NotFound:
|
except errors.NotFound:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
delkw = { recordtype : ipaddr }
|
delkw = {recordtype: ipaddr}
|
||||||
api.Command['dnsrecord_del'](domain, host, **delkw)
|
api.Command['dnsrecord_del'](domain, host, **delkw)
|
||||||
except errors.NotFound:
|
except errors.NotFound:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def update_sshfp_record(zone, record, entry_attrs):
|
def update_sshfp_record(zone, record, entry_attrs):
|
||||||
if 'ipasshpubkey' not in entry_attrs:
|
if 'ipasshpubkey' not in entry_attrs:
|
||||||
return
|
return
|
||||||
|
|
||||||
pubkeys = entry_attrs['ipasshpubkey'] or ()
|
pubkeys = entry_attrs['ipasshpubkey'] or ()
|
||||||
sshfps=[]
|
sshfps = []
|
||||||
for pubkey in pubkeys:
|
for pubkey in pubkeys:
|
||||||
try:
|
try:
|
||||||
sshfp = SSHPublicKey(pubkey).fingerprint_dns_sha1()
|
sshfp = SSHPublicKey(pubkey).fingerprint_dns_sha1()
|
||||||
@ -143,6 +145,7 @@ def update_sshfp_record(zone, record, entry_attrs):
|
|||||||
continue
|
continue
|
||||||
if sshfp is not None:
|
if sshfp is not None:
|
||||||
sshfps.append(sshfp)
|
sshfps.append(sshfp)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
sshfp = SSHPublicKey(pubkey).fingerprint_dns_sha256()
|
sshfp = SSHPublicKey(pubkey).fingerprint_dns_sha256()
|
||||||
except (ValueError, UnicodeDecodeError):
|
except (ValueError, UnicodeDecodeError):
|
||||||
@ -200,16 +203,18 @@ host_output_params = (
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def validate_ipaddr(ugettext, ipaddr):
|
def validate_ipaddr(ugettext, ipaddr):
|
||||||
"""
|
"""
|
||||||
Verify that we have either an IPv4 or IPv6 address.
|
Verify that we have either an IPv4 or IPv6 address.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
ip = CheckedIPAddress(ipaddr, match_local=False)
|
CheckedIPAddress(ipaddr, match_local=False)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
return unicode(e)
|
return unicode(e)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def normalize_hostname(hostname):
|
def normalize_hostname(hostname):
|
||||||
"""Use common fqdn form without the trailing dot"""
|
"""Use common fqdn form without the trailing dot"""
|
||||||
if hostname.endswith(u'.'):
|
if hostname.endswith(u'.'):
|
||||||
@ -217,15 +222,16 @@ def normalize_hostname(hostname):
|
|||||||
hostname = hostname.lower()
|
hostname = hostname.lower()
|
||||||
return hostname
|
return hostname
|
||||||
|
|
||||||
|
|
||||||
def _hostname_validator(ugettext, value):
|
def _hostname_validator(ugettext, value):
|
||||||
try:
|
try:
|
||||||
validate_hostname(value)
|
validate_hostname(value)
|
||||||
except ValueError, e:
|
except ValueError, e:
|
||||||
return _('invalid domain-name: %s') \
|
return _('invalid domain-name: %s') % unicode(e)
|
||||||
% unicode(e)
|
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@register()
|
@register()
|
||||||
class host(LDAPObject):
|
class host(LDAPObject):
|
||||||
"""
|
"""
|
||||||
@ -441,7 +447,8 @@ class host(LDAPObject):
|
|||||||
Str('macaddress*',
|
Str('macaddress*',
|
||||||
normalizer=lambda value: value.upper(),
|
normalizer=lambda value: value.upper(),
|
||||||
pattern='^([a-fA-F0-9]{2}[:|\-]?){5}[a-fA-F0-9]{2}$',
|
pattern='^([a-fA-F0-9]{2}[:|\-]?){5}[a-fA-F0-9]{2}$',
|
||||||
pattern_errmsg='Must be of the form HH:HH:HH:HH:HH:HH, where each H is a hexadecimal character.',
|
pattern_errmsg=('Must be of the form HH:HH:HH:HH:HH:HH, where '
|
||||||
|
'each H is a hexadecimal character.'),
|
||||||
csv=True,
|
csv=True,
|
||||||
label=_('MAC address'),
|
label=_('MAC address'),
|
||||||
doc=_('Hardware MAC address(es) on this host'),
|
doc=_('Hardware MAC address(es) on this host'),
|
||||||
@ -517,7 +524,6 @@ class host(LDAPObject):
|
|||||||
entry_attrs['memberofindirect'].remove(member)
|
entry_attrs['memberofindirect'].remove(member)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@register()
|
@register()
|
||||||
class host_add(LDAPCreate):
|
class host_add(LDAPCreate):
|
||||||
__doc__ = _('Add a new host.')
|
__doc__ = _('Add a new host.')
|
||||||
@ -637,7 +643,6 @@ class host_add(LDAPCreate):
|
|||||||
return dn
|
return dn
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@register()
|
@register()
|
||||||
class host_del(LDAPDelete):
|
class host_del(LDAPDelete):
|
||||||
__doc__ = _('Delete a host.')
|
__doc__ = _('Delete a host.')
|
||||||
@ -703,7 +708,8 @@ class host_del(LDAPDelete):
|
|||||||
domain, 'aaaarecord')
|
domain, 'aaaarecord')
|
||||||
else:
|
else:
|
||||||
# Try to delete all other record types too
|
# Try to delete all other record types too
|
||||||
_attribute_types = [str('%srecord' % t.lower()) for t in _record_types]
|
_attribute_types = [str('%srecord' % t.lower())
|
||||||
|
for t in _record_types]
|
||||||
for attr in _attribute_types:
|
for attr in _attribute_types:
|
||||||
if attr not in ['arecord', 'aaaarecord'] and attr in record:
|
if attr not in ['arecord', 'aaaarecord'] and attr in record:
|
||||||
for i in xrange(len(record[attr])):
|
for i in xrange(len(record[attr])):
|
||||||
@ -749,7 +755,6 @@ class host_del(LDAPDelete):
|
|||||||
return dn
|
return dn
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@register()
|
@register()
|
||||||
class host_mod(LDAPUpdate):
|
class host_mod(LDAPUpdate):
|
||||||
__doc__ = _('Modify information about a host.')
|
__doc__ = _('Modify information about a host.')
|
||||||
@ -779,7 +784,9 @@ class host_mod(LDAPUpdate):
|
|||||||
entry = {}
|
entry = {}
|
||||||
self.obj.get_password_attributes(ldap, dn, entry)
|
self.obj.get_password_attributes(ldap, dn, entry)
|
||||||
if not entry['has_password'] and entry['has_keytab']:
|
if not entry['has_password'] and entry['has_keytab']:
|
||||||
raise errors.ValidationError(name='password', error=_('Password cannot be set on enrolled host.'))
|
raise errors.ValidationError(
|
||||||
|
name='password',
|
||||||
|
error=_('Password cannot be set on enrolled host.'))
|
||||||
|
|
||||||
# Once a principal name is set it cannot be changed
|
# Once a principal name is set it cannot be changed
|
||||||
if 'cn' in entry_attrs:
|
if 'cn' in entry_attrs:
|
||||||
@ -897,7 +904,6 @@ class host_mod(LDAPUpdate):
|
|||||||
return dn
|
return dn
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@register()
|
@register()
|
||||||
class host_find(LDAPSearch):
|
class host_find(LDAPSearch):
|
||||||
__doc__ = _('Search for hosts.')
|
__doc__ = _('Search for hosts.')
|
||||||
@ -952,7 +958,8 @@ class host_find(LDAPSearch):
|
|||||||
for target_hosts, filter_op in ((hosts, ldap.MATCH_ANY),
|
for target_hosts, filter_op in ((hosts, ldap.MATCH_ANY),
|
||||||
(not_hosts, ldap.MATCH_NONE)):
|
(not_hosts, ldap.MATCH_NONE)):
|
||||||
hosts_avas = [DN(host)[0][0] for host in target_hosts]
|
hosts_avas = [DN(host)[0][0] for host in target_hosts]
|
||||||
hosts_filters = [ldap.make_filter_from_attr(ava.attr, ava.value) for ava in hosts_avas]
|
hosts_filters = [ldap.make_filter_from_attr(ava.attr, ava.value)
|
||||||
|
for ava in hosts_avas]
|
||||||
hosts_filter = ldap.combine_filters(hosts_filters, filter_op)
|
hosts_filter = ldap.combine_filters(hosts_filters, filter_op)
|
||||||
|
|
||||||
filter = ldap.combine_filters(
|
filter = ldap.combine_filters(
|
||||||
@ -982,7 +989,6 @@ class host_find(LDAPSearch):
|
|||||||
return truncated
|
return truncated
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@register()
|
@register()
|
||||||
class host_show(LDAPRetrieve):
|
class host_show(LDAPRetrieve):
|
||||||
__doc__ = _('Display information about a host.')
|
__doc__ = _('Display information about a host.')
|
||||||
@ -1030,7 +1036,6 @@ class host_show(LDAPRetrieve):
|
|||||||
return super(host_show, self).forward(*keys, **options)
|
return super(host_show, self).forward(*keys, **options)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@register()
|
@register()
|
||||||
class host_disable(LDAPQuery):
|
class host_disable(LDAPQuery):
|
||||||
__doc__ = _('Disable the Kerberos key, SSL certificate and all services of a host.')
|
__doc__ = _('Disable the Kerberos key, SSL certificate and all services of a host.')
|
||||||
@ -1142,7 +1147,6 @@ class host_add_managedby(LDAPAddMember):
|
|||||||
return (completed, dn)
|
return (completed, dn)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@register()
|
@register()
|
||||||
class host_remove_managedby(LDAPRemoveMember):
|
class host_remove_managedby(LDAPRemoveMember):
|
||||||
__doc__ = _('Remove hosts that can manage this host.')
|
__doc__ = _('Remove hosts that can manage this host.')
|
||||||
|
Loading…
Reference in New Issue
Block a user