Exemple #1
0
 def test_str(self):
     target = iscsi.IscsiTarget(
         iscsi.IscsiPortal("3ffe:2a00:100:7031::1", 3260), 1,
         "iqn.2014-06.com.example:t1")
     self.assertEquals(
         str(target),
         "[3ffe:2a00:100:7031::1]:3260,1 iqn.2014-06.com.example:t1")
Exemple #2
0
 def test_address(self):
     target = iscsi.IscsiTarget(
         iscsi.IscsiPortal(
             "3ffe:2a00:100:7031::1",
             3260),
         2, "iqn.2014-06.com.example:t1")
     self.assertEqual(target.address, "[3ffe:2a00:100:7031::1]:3260,2")
Exemple #3
0
 def test_is_ipv6(self, hostname, port, expected):
     target = iscsi.IscsiPortal(hostname, port)
     self.assertEquals(target.is_ipv6(), expected)
Exemple #4
0
 def test_str(self, hostname, port, expected):
     self.assertEquals(str(iscsi.IscsiPortal(hostname, port)), expected)
Exemple #5
0
def _connectionDict2ConnectionInfo(conTypeId, conDict):
    def getIntParam(optDict, key, default):
        res = optDict.get(key, default)
        if res is None:
            return res

        try:
            return int(res)
        except ValueError:
            raise se.InvalidParameterException(key, res)

    # FIXME: Remove when nfs_mount_options is no longer supported.  This is
    # in the compatibility layer so that the NFSConnection class stays clean.
    # Engine options have precendence, so use deprecated nfs_mount_options
    # only if engine passed nothing (indicated by default params of 'None').
    def tryDeprecatedNfsParams(conDict):
        if (conDict.get('protocol_version',
                        None), conDict.get('retrans', None),
                conDict.get('timeout', None)) == (None, None, None):
            conf_options = config.get('irs',
                                      'nfs_mount_options').replace(' ', '')
            if (frozenset(conf_options.split(',')) != frozenset(
                    NFSConnection.DEFAULT_OPTIONS)):
                logging.warning(
                    "Using deprecated nfs_mount_options from"
                    " vdsm.conf to mount %s: %s",
                    conDict.get('connection', '(unknown)'), conf_options)
                return PosixFsConnectionParameters(
                    conDict["id"], conDict.get('connection', None), 'nfs',
                    conf_options)
        return None

    typeName = CON_TYPE_ID_2_CON_TYPE[conTypeId]
    if typeName == 'localfs':
        params = LocaFsConnectionParameters(conDict["id"],
                                            conDict.get('connection', None))
    elif typeName == 'nfs':
        params = tryDeprecatedNfsParams(conDict)
        if params is not None:
            # Hack to support vdsm.conf nfs_mount_options
            typeName = 'posixfs'
        else:
            version = conDict.get('protocol_version', "3")
            version = str(version)
            if version == "auto":
                version = None

            params = NfsConnectionParameters(
                conDict["id"], conDict.get('connection', None),
                getIntParam(conDict, 'retrans', None),
                getIntParam(conDict, 'timeout', None), version,
                conDict.get('mnt_options', None))
    elif typeName == 'posixfs':
        params = PosixFsConnectionParameters(conDict["id"],
                                             conDict.get('connection', None),
                                             conDict.get('vfs_type', None),
                                             conDict.get('mnt_options', None))
    elif typeName == 'glusterfs':
        params = GlusterFsConnectionParameters(
            conDict["id"], conDict.get('connection', None),
            conDict.get('vfs_type', None), conDict.get('mnt_options', None))
    elif typeName == 'iscsi':
        portal = iscsi.IscsiPortal(conDict.get('connection', None),
                                   int(conDict.get('port', None)))
        tpgt = int(conDict.get('tpgt', iscsi.DEFAULT_TPGT))

        target = iscsi.IscsiTarget(portal, tpgt, conDict.get('iqn', None))

        iface = iscsi.resolveIscsiIface(conDict.get('ifaceName', None),
                                        conDict.get('initiatorName', None),
                                        conDict.get('netIfaceName', None))

        # NOTE: ChapCredentials must match the way we initialize username and
        # password when reading session info in iscsi.readSessionInfo(). Empty
        # or missing username or password are stored as None.

        username = conDict.get('user')
        if not username:
            username = None
        password = conDict.get('password')
        if not getattr(password, "value", None):
            password = None
        cred = None
        if username or password:
            cred = iscsi.ChapCredentials(username, password)

        params = IscsiConnectionParameters(conDict["id"], target, iface, cred)
    elif typeName == 'fcp':
        params = FcpConnectionParameters(conDict["id"])
    else:
        raise se.StorageServerActionError()

    return ConnectionInfo(typeName, params)