Ejemplo n.º 1
0
def normalize_path(path):
    """
    Normalizes any path using fileUtils.normpath.
    The input's form can be:
    1. Remote path - "server:port:/path", where:
        - The "port:" part is not mandatory.
        - The "server" part can be a dns name, an ipv4 address
        or an ipv6 address using quoted form.
        - If the input doesn't contain a colon, a HosttailError will be raised.
        Since this format is ambiguous, we treat an input that looks like a
        port as a port, and otherwise as a path without a leading slash.
    2. Local path - "/path/to/device"
    3. Other, where we just call os.path.normpath.
    """
    if path.startswith("/") or ":" not in path:
        return normpath(path)

    host, tail = address.hosttail_split(path)
    if ":" in tail:
        port, path = tail.split(':', 1)
        if is_port(port):
            tail = port + ":" + normpath(path)
        else:
            tail = normpath(tail)
    else:
        tail = normpath(tail)
    return address.hosttail_join(host, tail)
Ejemplo n.º 2
0
def normalize_path(path):
    """
    Normalizes a path using normpath.
    This method expects an input of one of the forms:
    1. "server:port:/path", where:
        - The "port:" part is not mandatory.
        - The "server" part can be a dns name, an ipv4 address
        or an ipv6 address using quoted form.
        - If the input doesn't contain a colon, a HosttailError will be raised.
        Since this format is ambiguous, we treat an input that looks like a
        port as a port, and otherwise as a path without a leading slash.
    2. "/path/to/device"
    """
    if path.startswith("/"):
        return normpath(path)

    host, tail = address.hosttail_split(path)
    if ":" in tail:
        port, path = tail.split(':', 1)
        if is_port(port):
            tail = port + ":" + normpath(path)
        else:
            tail = normpath(tail)
    else:
        tail = normpath(tail)
    return address.hosttail_join(host, tail)
Ejemplo n.º 3
0
def normalize_path(path):
    """
    Normalizes a path using normpath.
    This method expects an input of one of the forms:
    1. "server:port:/path", where:
        - The "port:" part is not mandatory.
        - The "server" part can be a dns name, an ipv4 address
        or an ipv6 address using quoted form.
        - If the input doesn't contain a colon, a HosttailError will be raised.
        Since this format is ambiguous, we treat an input that looks like a
        port as a port, and otherwise as a path without a leading slash.
    2. "/path/to/device"
    """
    if path.startswith("/"):
        return normpath(path)

    host, tail = address.hosttail_split(path)
    if ":" in tail:
        port, path = tail.split(':', 1)
        if is_port(port):
            tail = port + ":" + normpath(path)
        else:
            tail = normpath(tail)
    else:
        tail = normpath(tail)
    return address.hosttail_join(host, tail)
Ejemplo n.º 4
0
def discoverydb_discover(discoveryType, iface, portal):
    rc, out, err = _runCmd(["-m", "discoverydb", "-t", discoveryType, "-I",
                            iface, "-p", portal, "--discover"])
    if rc == 0:
        res = []
        for line in out:
            rest, iqn = line.split()
            rest, tpgt = rest.split(",")
            ip, port = hosttail_split(rest)
            res.append((ip, int(port), int(tpgt), iqn))

        return res

    if not iface_exists(iface):
        raise IscsiInterfaceDoesNotExistError(iface)

    if rc == ISCSI_ERR_LOGIN_AUTH_FAILED:
        raise IscsiAuthenticationError(rc, out, err)

    raise IscsiDiscoverdbError(rc, out, err)
Ejemplo n.º 5
0
def discoverydb_discover(discoveryType, iface, portal):
    rc, out, err = _runCmd([
        "-m", "discoverydb", "-t", discoveryType, "-I", iface, "-p", portal,
        "--discover"
    ])
    if rc == 0:
        res = []
        for line in out:
            rest, iqn = line.split()
            rest, tpgt = rest.split(",")
            ip, port = hosttail_split(rest)
            res.append((ip, int(port), int(tpgt), iqn))

        return res

    if not iface_exists(iface):
        raise IscsiInterfaceDoesNotExistError(iface)

    if rc == ISCSI_ERR_LOGIN_AUTH_FAILED:
        raise IscsiAuthenticationError(rc, out, err)

    raise IscsiDiscoverdbError(rc, out, err)
Ejemplo n.º 6
0
def discoverydb_discover(discoveryType, iface, portal):
    try:
        out = run_cmd([
            "-m", "discoverydb", "-t", discoveryType, "-I", iface, "-p",
            portal, "--discover"
        ])
    except cmdutils.Error as e:
        if not iface_exists(iface):
            raise IscsiInterfaceDoesNotExistError(iface)

        if e.rc == ISCSI_ERR_LOGIN_AUTH_FAILED:
            raise IscsiAuthenticationError(e.rc, e.out, e.err)

        raise IscsiDiscoverdbError(e.rc, e.out, e.err)

    res = []
    for line in out.splitlines():
        rest, iqn = line.split()
        rest, tpgt = rest.split(",")
        ip, port = hosttail_split(rest)
        res.append((ip, int(port), int(tpgt), iqn))

    return res
Ejemplo n.º 7
0
 def test_hosttail_ipv6_no_brackets_returns_garbage(self):
     self.assertNotEqual(('2001::1', '4321'),
                         ipaddress.hosttail_split('2001::1:4321'))
Ejemplo n.º 8
0
 def test_hosttail_only_port(self):
     with self.assertRaises(ipaddress.HosttailError):
         ipaddress.hosttail_split(':123')
Ejemplo n.º 9
0
 def test_hosttail_only_host(self):
     with self.assertRaises(ipaddress.HosttailError):
         ipaddress.hosttail_split('hostname:')
Ejemplo n.º 10
0
 def test_hosttail_no_colon(self):
     with self.assertRaises(ipaddress.HosttailError):
         ipaddress.hosttail_split('bad hostname')
Ejemplo n.º 11
0
 def test_hosttail_ipv6_with_colon_in_path(self):
     self.assertEqual(('2001::1', '/a:b:c/path'),
                      ipaddress.hosttail_split('[2001::1]:/a:b:c/path'))
Ejemplo n.º 12
0
 def test_hosttail_hostpath_with_colon_in_path(self):
     self.assertEqual(('FQDN.host', '/path/a:b:c'),
                      ipaddress.hosttail_split(
                          'FQDN.host:/path/a:b:c'))
Ejemplo n.º 13
0
 def test_hosttail_hostpath(self):
     self.assertEqual(('FQDN.host', '/ovirt/rules/the/world'),
                      ipaddress.hosttail_split(
                          'FQDN.host:/ovirt/rules/the/world'))
Ejemplo n.º 14
0
 def test_hosttail_namedhost(self):
     self.assertEqual(('TestHost', '4321'),
                      ipaddress.hosttail_split('TestHost:4321'))
Ejemplo n.º 15
0
 def test_hosttail_ipv6(self):
     self.assertEqual(('2001::1', '4321'),
                      ipaddress.hosttail_split('[2001::1]:4321'))
Ejemplo n.º 16
0
 def test_hosttail_ipv4(self):
     self.assertEqual(('1.2.3.4', '4321'),
                      ipaddress.hosttail_split('1.2.3.4:4321'))