rtslib/utils.py
def generate_wwn(wwn_type):
    '''
    Generates a random WWN of the specified type:
        - unit_serial: T10 WWN Unit Serial.
        - iqn: iSCSI IQN
        - naa: SAS NAA address
    @param wwn_type: The WWN address type.
    @type wwn_type: str
    @returns: A string containing the WWN.
    '''
    wwn_type = wwn_type.lower()
    if wwn_type == 'free':
        return str(uuid.uuid4())
    if wwn_type == 'unit_serial':
        return str(uuid.uuid4())
    elif wwn_type == 'iqn':
        localname = socket.gethostname().split(".")[0].replace("_", "")
        localarch = os.uname()[4].replace("_", "")
        prefix = "iqn.2003-01.org.linux-iscsi.%s.%s" % (localname, localarch)
        prefix = prefix.strip().lower()
        serial = "sn.%s" % str(uuid.uuid4())[24:]
        return "%s:%s" % (prefix, serial)
    elif wwn_type == 'naa':
        # see http://standards.ieee.org/develop/regauth/tut/fibre.pdf
        # 5 = IEEE registered
        # 001405 = OpenIB OUI (they let us use it I guess?)
        # rest = random
        return "naa.5001405" + uuid.uuid4().hex[-9:]
    elif wwn_type == 'eui':
        return "eui.001405" + uuid.uuid4().hex[-10:]
    else:
        raise ValueError("Unknown WWN type: %s" % wwn_type)

    Generates a random WWN of the specified type:
        - unit_serial: T10 WWN Unit Serial.
        - iqn: iSCSI IQN
        - naa: SAS NAA address
    @param wwn_type: The WWN address type.
    @type wwn_type: str
    @returns: A string containing the WWN.
    
Generates a random WWN of the specified type:
unit_serial: T10 WWN Unit Serial.
iqn: iSCSI IQN
naa: SAS NAA address
Generates a random WWN of the specified type : unit_serial : T10 WWN Unit Serial . iqn : iSCSI IQN naa : SAS NAA address
def generate_wwn(wwn_type):
    wwn_type = wwn_type.lower()
    if wwn_type == 'free':
        return str(uuid.uuid4())
    if wwn_type == 'unit_serial':
        return str(uuid.uuid4())
    elif wwn_type == 'iqn':
        localname = socket.gethostname().split(".")[0].replace("_", "")
        localarch = os.uname()[4].replace("_", "")
        prefix = "iqn.2003-01.org.linux-iscsi.%s.%s" % (localname, localarch)
        prefix = prefix.strip().lower()
        serial = "sn.%s" % str(uuid.uuid4())[24:]
        return "%s:%s" % (prefix, serial)
    elif wwn_type == 'naa':
        return "naa.5001405" + uuid.uuid4().hex[-9:]
    elif wwn_type == 'eui':
        return "eui.001405" + uuid.uuid4().hex[-10:]
    else:
        raise ValueError("Unknown WWN type: %s" % wwn_type)
def generate_wwn ( wwn_type ) : wwn_type = wwn_type . lower ( ) if wwn_type == 'free' : return str ( uuid . uuid4 ( ) ) if wwn_type == 'unit_serial' : return str ( uuid . uuid4 ( ) ) elif wwn_type == 'iqn' : localname = socket . gethostname ( ) . split ( "." ) [ 0 ] . replace ( "_" , "" ) localarch = os . uname ( ) [ 4 ] . replace ( "_" , "" ) prefix = "iqn.2003-01.org.linux-iscsi.%s.%s" % ( localname , localarch ) prefix = prefix . strip ( ) . lower ( ) serial = "sn.%s" % str ( uuid . uuid4 ( ) ) [ 24 : ] return "%s:%s" % ( prefix , serial ) elif wwn_type == 'naa' : return "naa.5001405" + uuid . uuid4 ( ) . hex [ - 9 : ] elif wwn_type == 'eui' : return "eui.001405" + uuid . uuid4 ( ) . hex [ - 10 : ] else : raise ValueError ( "Unknown WWN type: %s" % wwn_type )
Generates a random WWN of the specified type:
 unit_serial: T10 WWN Unit Serial.
Generates a random WWN of the specified type : unit_serial : T10 WWN Unit Serial .
'''
    Generates a random WWN of the specified type:
        - unit_serial: T10 WWN Unit Serial.
        - iqn: iSCSI IQN
        - naa: SAS NAA address
    @param wwn_type: The WWN address type.
    @type wwn_type: str
    @returns: A string containing the WWN.
    ''' # see http://standards.ieee.org/develop/regauth/tut/fibre.pdf # 5 = IEEE registered # 001405 = OpenIB OUI (they let us use it I guess?) # rest = random
wwn_type
The WWN address type.
The WWN address type .
returns
A string containing the WWN.
A string containing the WWN .