def ip_tag(self):

        ips = net.get_host_ip4()
        ips = net.ips_prefer(ips, net.INN)
        ip = (ips + [ 'x.x.x.x' ])[ 0 ]

        return ip
Esempio n. 2
0
    def test_ips_prefer(self):

        cases = (
            ([], net.PUB, []),
            ([], net.INN, []),
            (['1.2.3.4'], net.PUB, ['1.2.3.4']),
            (['1.2.3.4'], net.INN, ['1.2.3.4']),
            (['172.16.0.1'], net.PUB, ['172.16.0.1']),
            (['172.16.0.1'], net.INN, ['172.16.0.1']),
            (['172.16.0.1', '1.2.3.4'], net.PUB, ['1.2.3.4', '172.16.0.1']),
            (['172.16.0.1', '1.2.3.4'], net.INN, ['172.16.0.1', '1.2.3.4']),
            (['1.2.3.4', '172.16.0.1'], net.PUB, ['1.2.3.4', '172.16.0.1']),
            (['1.2.3.4', '172.16.0.1'], net.INN, ['172.16.0.1', '1.2.3.4']),
        )

        for inp_ips, inp_class, outp in cases:
            self.assertEqual(outp, net.ips_prefer(inp_ips, inp_class))
    def test_ips_prefer(self):

        cases = (
            ([], net.PUB, []),
            ([], net.INN, []),

            (['1.2.3.4'], net.PUB, ['1.2.3.4']),
            (['1.2.3.4'], net.INN, ['1.2.3.4']),

            (['172.16.0.1'], net.PUB, ['172.16.0.1']),
            (['172.16.0.1'], net.INN, ['172.16.0.1']),

            (['172.16.0.1', '1.2.3.4'], net.PUB, ['1.2.3.4', '172.16.0.1']),
            (['172.16.0.1', '1.2.3.4'], net.INN, ['172.16.0.1', '1.2.3.4']),

            (['1.2.3.4', '172.16.0.1'], net.PUB, ['1.2.3.4', '172.16.0.1']),
            (['1.2.3.4', '172.16.0.1'], net.INN, ['172.16.0.1', '1.2.3.4']),
        )

        for inp_ips, inp_class, outp in cases:
            self.assertEqual(outp, net.ips_prefer(inp_ips, inp_class))
    'r': 'read',
    'w': 'write',
    'a': 'admin',
}

PERM_TO_SHORT = {
    'create': 'c',
    'delete': 'd',
    'read': 'r',
    'write': 'w',
    'admin': 'a',
}

# We assumes that ip does not change during process running.
# Display intra ip if presents, or display pub ip.
host_ip4 = net.ips_prefer(net.get_host_ip4(), net.INN)


class PermTypeError(Exception):
    pass


class ZkPathError(Exception):
    pass


def close_zk(zk):
    if not isinstance(zk, KazooClient):
        raise TypeError('expect KazooClient or KazooClientExt, but got {t}'.format(t=type(zk)))

    try:
Esempio n. 5
0
File: zkutil.py Progetto: bsc-s2/ops
    'r': 'read',
    'w': 'write',
    'a': 'admin',
}

PERM_TO_SHORT = {
    'create': 'c',
    'delete': 'd',
    'read': 'r',
    'write': 'w',
    'admin': 'a',
}

# We assumes that ip does not change during process running.
# Display intra ip if presents, or display pub ip.
host_ip4 = net.ips_prefer(net.get_host_ip4(), net.INN)


class PermTypeError(Exception):
    pass


class ZkPathError(Exception):
    pass


def close_zk(zk):
    if not isinstance(zk, KazooClient):
        raise TypeError(
            'expect KazooClient or KazooClientExt, but got {t}'.format(
                t=type(zk)))