def get_interface_name(name, prefix='', max_len=n_const.DEVICE_NAME_MAX_LEN):
 requested_name = (prefix + name)
 if (len(requested_name) <= max_len):
  return requested_name
 if ((len(prefix) + INTERFACE_HASH_LEN) > max_len):
  raise ValueError(_('Too long prefix provided. New name would exceed given length for an interface name.'))
 namelen = ((max_len - len(prefix)) - INTERFACE_HASH_LEN)
 hashed_name = hashlib.sha1(encodeutils.to_utf8(name))
 new_name = ('%(prefix)s%(truncated)s%(hash)s' % {'prefix': prefix, 'truncated': name[0:namelen], 'hash': hashed_name.hexdigest()[0:INTERFACE_HASH_LEN]})
 LOG.info(_LI('The requested interface name %(requested_name)s exceeds the %(limit)d character limitation. It was shortened to %(new_name)s to fit.'), {'requested_name': requested_name, 'limit': max_len, 'new_name': new_name})
 return new_name

def get_interface_name ( name , prefix = '' , max_len = n_const . DEVICE_NAME_MAX_LEN ) : requested_name = ( prefix + name ) if ( len ( requested_name ) <= max_len ) : return requested_name if ( ( len ( prefix ) + INTERFACE_HASH_LEN ) > max_len ) : raise ValueError ( _ ( 'Too long prefix provided. New name would exceed given length for an interface name.' ) ) namelen = ( ( max_len - len ( prefix ) ) - INTERFACE_HASH_LEN ) hashed_name = hashlib . sha1 ( encodeutils . to_utf8 ( name ) ) new_name = ( '%(prefix)s%(truncated)s%(hash)s' % { 'prefix' : prefix , 'truncated' : name [ 0 : namelen ] , 'hash' : hashed_name . hexdigest ( ) [ 0 : INTERFACE_HASH_LEN ] } ) LOG . info ( _LI ( 'The requested interface name %(requested_name)s exceeds the %(limit)d character limitation. It was shortened to %(new_name)s to fit.' ) , { 'requested_name' : requested_name , 'limit' : max_len , 'new_name' : new_name } ) return new_name
construct an interface name based on the prefix and name .