示例#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)
示例#2
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)
示例#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)
示例#4
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)
示例#5
0
 def test_hosttail_join(self, host, tail, expected):
     self.assertEqual(expected, ipaddress.hosttail_join(host, tail))
示例#6
0
文件: iscsi.py 项目: rollandf/vdsm
 def __str__(self):
     return hosttail_join(self.hostname, str(self.port))