예제 #1
0
    def test_ip_class_and_is_xxx(self):
        cases_pub = (
            '1.2.3.4',
            '255.255.0.0',
            '171.0.0.0',
            '173.0.0.0',
            '172.15.0.0',
            '172.32.0.0',
            '9.0.0.0',
            '11.0.0.0',
            '192.167.0.0',
            '192.169.0.0',
            '191.168.0.0',
            '193.168.0.0',
        )

        for inp in cases_pub:
            self.assertEqual(net.PUB, net.ip_class(inp), inp)

            # test is_xxx
            self.assertEqual(True, net.is_pub(inp))
            self.assertEqual(False, net.is_inn(inp))

            # test choose_xxx
            self.assertEqual([inp], net.choose_pub([inp, '192.168.0.0']))
            self.assertEqual([inp], net.choose_pub(['192.168.0.0', inp]))

        cases_inn = (
            '127.0.0.1',
            '127.0.0.255',
            '172.16.0.0',
            '172.17.0.0',
            '172.21.0.0',
            '172.30.0.0',
            '172.31.0.0',
            '10.0.0.0',
            '192.168.0.0',
        )

        for inp in cases_inn:
            self.assertEqual(net.INN, net.ip_class(inp), inp)

            # test is_xxx

            self.assertEqual(True, net.is_inn(inp))
            self.assertEqual(False, net.is_pub(inp))

            # test choose_xxx
            self.assertEqual([inp], net.choose_inn([inp, '1.1.1.1']))
            self.assertEqual([inp], net.choose_inn(['1.1.1.1', inp]))
예제 #2
0
파일: server.py 프로젝트: wenbobuaa/pykit
def make_serverrec(idc, idc_type, roles, allocated_drive_pre, **argkv):
    serverrec = {}

    ips = net.get_host_ip4(exclude_prefix="docker")
    inn_ips = net.choose_inn(ips)
    pub_ips = net.choose_pub(ips)

    memory = psutil.virtual_memory().total
    cpu_info = {}
    # count of logical cpus
    cpu_info['count'] = psutil.cpu_count()
    # Mhz
    if hasattr(psutil, 'cpu_freq'):
        cpu_info['frequency'] = psutil.cpu_freq().max

    serverrec['server_id'] = str(ServerID.local_server_id())
    serverrec['pub_ips'] = pub_ips
    serverrec['inn_ips'] = inn_ips
    serverrec['hostname'] = socket.gethostname()
    serverrec['memory'] = memory
    serverrec['cpu'] = cpu_info
    serverrec['idc'] = idc
    serverrec['idc_type'] = idc_type
    serverrec['roles'] = roles

    mps = _make_mountpoints_info()
    serverrec['mountpoints'] = mps
    serverrec['next_mount_index'] = 1
    serverrec['allocated_drive'] = _get_allocated_drive(
        allocated_drive_pre, mps)
    serverrec.update(argkv)

    return serverrec
예제 #3
0
def make_serverrec(server_id, idc, idc_type, roles, allocated_drive_pre, **argkv):
    serverrec = {}

    ips = net.get_host_ip4(exclude_prefix="docker")
    inn_ips = net.choose_inn(ips)
    pub_ips = net.choose_pub(ips)

    memory = psutil.virtual_memory().total
    cpu_info = {}
    # count of logical cpus
    cpu_info['count'] = psutil.cpu_count()
    # Mhz
    if hasattr(psutil, 'cpu_freq'):
        cpu_info['frequency'] = psutil.cpu_freq().max

    serverrec['server_id'] = server_id
    serverrec['pub_ips'] = pub_ips
    serverrec['inn_ips'] = inn_ips
    serverrec['hostname'] = socket.gethostname()
    serverrec['memory'] = memory
    serverrec['cpu'] = cpu_info
    serverrec['idc'] = idc
    serverrec['idc_type'] = idc_type
    serverrec['roles'] = roles

    mps = _make_mountpoints_info()
    serverrec['mountpoints'] = mps
    serverrec['next_mount_index'] = 1
    serverrec['allocated_drive'] = _get_allocated_drive(allocated_drive_pre, mps)
    serverrec.update(argkv)

    return serverrec
예제 #4
0
    def test_ip_class_and_is_xxx(self):

        self.assertRaises(ValueError, net.choose_ips, ['192.168.0.0'], 'xx')

        cases_pub = (
            '1.2.3.4',
            '255.255.0.0',
            '171.0.0.0',
            '173.0.0.0',
            '172.15.0.0',
            '172.32.0.0',
            '9.0.0.0',
            '11.0.0.0',
            '192.167.0.0',
            '192.169.0.0',
            '191.168.0.0',
            '193.168.0.0',
        )

        for inp in cases_pub:
            self.assertEqual(net.PUB, net.ip_class(inp), inp)

            # test is_xxx
            self.assertEqual(True, net.is_pub(inp))
            self.assertEqual(False, net.is_inn(inp))

            # test choose_xxx
            self.assertEqual([inp], net.choose_pub([inp, '192.168.0.0']))
            self.assertEqual([inp], net.choose_pub(['192.168.0.0', inp]))

            self.assertEqual([inp], net.choose_ips([inp, '192.168.0.0'], net.PUB))
            self.assertEqual([inp], net.choose_ips(['192.168.0.0', inp], net.PUB))
            self.assertEqual([inp, '192.168.0.0'], net.choose_ips([inp, '192.168.0.0']))
            self.assertEqual(['192.168.0.0', inp], net.choose_ips(['192.168.0.0', inp]))

        cases_inn = (
            '127.0.0.1',
            '127.0.0.255',
            '172.16.0.0',
            '172.17.0.0',
            '172.21.0.0',
            '172.30.0.0',
            '172.31.0.0',
            '10.0.0.0',
            '192.168.0.0',
        )

        for inp in cases_inn:
            self.assertEqual(net.INN, net.ip_class(inp), inp)

            # test is_xxx

            self.assertEqual(True, net.is_inn(inp))
            self.assertEqual(False, net.is_pub(inp))

            # test choose_xxx
            self.assertEqual([inp], net.choose_inn([inp, '1.1.1.1']))
            self.assertEqual([inp], net.choose_inn(['1.1.1.1', inp]))

            self.assertEqual([inp], net.choose_ips([inp, '1.1.1.1'], net.INN))
            self.assertEqual([inp], net.choose_ips(['1.1.1.1', inp], net.INN))
            self.assertEqual([inp, '1.1.1.1'], net.choose_ips([inp, '1.1.1.1']))
            self.assertEqual(['1.1.1.1', inp], net.choose_ips(['1.1.1.1', inp]))