本文整理汇总了Python中utils.get_ip_addr函数的典型用法代码示例。如果您正苦于以下问题:Python get_ip_addr函数的具体用法?Python get_ip_addr怎么用?Python get_ip_addr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_ip_addr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_remove_secondaries
def test_remove_secondaries(self):
require_user('root')
ifA = self.get_ifname()
with self.ip.create(kind='dummy', ifname=ifA) as i:
i.add_ip('172.16.0.1', 24)
i.add_ip('172.16.0.2', 24)
assert ifA in self.ip.interfaces
assert ('172.16.0.1', 24) in self.ip.interfaces[ifA].ipaddr
assert ('172.16.0.2', 24) in self.ip.interfaces[ifA].ipaddr
assert '172.16.0.1/24' in get_ip_addr(interface=ifA)
assert '172.16.0.2/24' in get_ip_addr(interface=ifA)
if i._mode == 'explicit':
i.begin()
i.del_ip('172.16.0.1', 24)
i.del_ip('172.16.0.2', 24)
i.commit()
assert ('172.16.0.1', 24) not in self.ip.interfaces[ifA].ipaddr
assert ('172.16.0.2', 24) not in self.ip.interfaces[ifA].ipaddr
assert '172.16.0.1/24' not in get_ip_addr(interface=ifA)
assert '172.16.0.2/24' not in get_ip_addr(interface=ifA)
示例2: _create_master
def _create_master(self, kind):
require_user('root')
assert 'bala' not in self.ip.interfaces
assert 'bala_port0' not in self.ip.interfaces
assert 'bala_port1' not in self.ip.interfaces
self.ip.create(kind='dummy', ifname='bala_port0').commit()
self.ip.create(kind='dummy', ifname='bala_port1').commit()
with self.ip.create(kind=kind, ifname='bala') as i:
i.add_port(self.ip.interfaces.bala_port0)
i.add_port(self.ip.interfaces.bala_port1)
i.add_ip('172.16.0.1/24')
assert ('172.16.0.1', 24) in self.ip.interfaces.bala.ipaddr
assert '172.16.0.1/24' in get_ip_addr(interface='bala')
assert self.ip.interfaces.bala_port0.if_master == \
self.ip.interfaces.bala.index
assert self.ip.interfaces.bala_port1.if_master == \
self.ip.interfaces.bala.index
with self.ip.interfaces.bala as i:
i.del_port(self.ip.interfaces.bala_port0)
i.del_port(self.ip.interfaces.bala_port1)
i.del_ip('172.16.0.1/24')
assert ('172.16.0.1', 24) not in self.ip.interfaces.bala.ipaddr
assert '172.16.0.1/24' not in get_ip_addr(interface='bala')
assert self.ip.interfaces.bala_port0.if_master is None
assert self.ip.interfaces.bala_port1.if_master is None
示例3: _create_master
def _create_master(self, kind, **kwarg):
ifM = self.get_ifname()
ifP1 = self.get_ifname()
ifP2 = self.get_ifname()
self.ip.create(kind='dummy', ifname=ifP1).commit()
self.ip.create(kind='dummy', ifname=ifP2).commit()
with self.ip.create(kind=kind, ifname=ifM, **kwarg) as i:
i.add_port(self.ip.interfaces[ifP1])
i.add_port(self.ip.interfaces[ifP2])
i.add_ip('172.16.0.1/24')
assert ('172.16.0.1', 24) in self.ip.interfaces[ifM].ipaddr
assert '172.16.0.1/24' in get_ip_addr(interface=ifM)
assert self.ip.interfaces[ifP1].if_master == \
self.ip.interfaces[ifM].index
assert self.ip.interfaces[ifP2].if_master == \
self.ip.interfaces[ifM].index
with self.ip.interfaces[ifM] as i:
i.del_port(self.ip.interfaces[ifP1])
i.del_port(self.ip.interfaces[ifP2])
i.del_ip('172.16.0.1/24')
assert ('172.16.0.1', 24) not in self.ip.interfaces[ifM].ipaddr
assert '172.16.0.1/24' not in get_ip_addr(interface=ifM)
assert self.ip.interfaces[ifP1].if_master is None
assert self.ip.interfaces[ifP2].if_master is None
示例4: test_create_plain
def test_create_plain(self):
require_user('root')
assert 'bala' not in self.ip.interfaces
i = self.ip.create(kind='dummy', ifname='bala')
i.add_ip('172.16.0.1/24')
i.commit()
assert ('172.16.0.1', 24) in self.ip.interfaces.bala.ipaddr
assert '172.16.0.1/24' in get_ip_addr(interface='bala')
示例5: test_create_plain
def test_create_plain(self):
require_user('root')
ifA = self.get_ifname()
i = self.ip.create(kind='dummy', ifname=ifA)
i.add_ip('172.16.0.1/24')
i.commit()
assert ('172.16.0.1', 24) in self.ip.interfaces[ifA].ipaddr
assert '172.16.0.1/24' in get_ip_addr(interface=ifA)
示例6: test_create_and_remove
def test_create_and_remove(self):
require_user('root')
assert 'bala' not in self.ip.interfaces
with self.ip.create(kind='dummy', ifname='bala') as i:
i.add_ip('172.16.0.1/24')
assert ('172.16.0.1', 24) in self.ip.interfaces.bala.ipaddr
assert '172.16.0.1/24' in get_ip_addr(interface='bala')
with self.ip.interfaces.bala as i:
i.remove()
assert 'bala' not in self.ip.interfaces
示例7: test_create_and_remove
def test_create_and_remove(self):
require_user("root")
ifA = self.get_ifname()
with self.ip.create(kind="dummy", ifname=ifA) as i:
i.add_ip("172.16.0.1/24")
assert ("172.16.0.1", 24) in self.ip.interfaces[ifA].ipaddr
assert "172.16.0.1/24" in get_ip_addr(interface=ifA)
with self.ip.interfaces[ifA] as i:
i.remove()
assert ifA not in self.ip.interfaces
示例8: _create_master
def _create_master(self, kind, **kwarg):
ifM = self.get_ifname()
ifP1 = self.get_ifname()
ifP2 = self.get_ifname()
self.ip.create(kind="dummy", ifname=ifP1).commit()
self.ip.create(kind="dummy", ifname=ifP2).commit()
with self.ip.create(kind=kind, ifname=ifM, **kwarg) as i:
i.add_port(self.ip.interfaces[ifP1])
i.add_ip("172.16.0.1/24")
with self.ip.interfaces[ifM] as i:
i.add_port(self.ip.interfaces[ifP2])
i.add_ip("172.16.0.2/24")
assert ("172.16.0.1", 24) in self.ip.interfaces[ifM].ipaddr
assert ("172.16.0.2", 24) in self.ip.interfaces[ifM].ipaddr
assert "172.16.0.1/24" in get_ip_addr(interface=ifM)
assert "172.16.0.2/24" in get_ip_addr(interface=ifM)
assert self.ip.interfaces[ifP1].if_master == self.ip.interfaces[ifM].index
assert self.ip.interfaces[ifP2].if_master == self.ip.interfaces[ifM].index
with self.ip.interfaces[ifM] as i:
i.del_port(self.ip.interfaces[ifP1])
i.del_port(self.ip.interfaces[ifP2])
i.del_ip("172.16.0.1/24")
i.del_ip("172.16.0.2/24")
assert ("172.16.0.1", 24) not in self.ip.interfaces[ifM].ipaddr
assert ("172.16.0.2", 24) not in self.ip.interfaces[ifM].ipaddr
assert "172.16.0.1/24" not in get_ip_addr(interface=ifM)
assert "172.16.0.2/24" not in get_ip_addr(interface=ifM)
assert self.ip.interfaces[ifP1].if_master is None
assert self.ip.interfaces[ifP2].if_master is None
示例9: test_addr
def test_addr(self):
assert len(get_ip_addr()) == len(self.ip.get_addr())
示例10: test_add_addr
def test_add_addr(self):
require_user('root')
self.ip.addr('add', self.ifaces[0], address='172.16.0.1', mask=24)
assert '172.16.0.1/24' in get_ip_addr()
示例11: test_ips
def test_ips(self):
for name in self.ip.by_name:
assert len(self.ip.interfaces[name]['ipaddr']) == \
len(get_ip_addr(name))
示例12: test_addr_loaded
def test_addr_loaded(self):
for name in self.ip.by_name:
assert len(self.ip.interfaces[name]["ipaddr"]) == len(get_ip_addr(name))
示例13: ReplicaMusicService
import pygame
import time
import flask
import multiprocessing
import Queue
import socket
import sys
import threading
from flask import Flask
from flask import request
from constants import *
import utils
import os
import pickle
import collections
from replica_music_service import ReplicaMusicService
from election_service import ReplicaElectionService
if __name__ == "__main__":
# start replica service
ip_addr = utils.get_ip_addr()
response_queue = multiprocessing.Queue()
state_queue = multiprocessing.Queue()
replica_service = ReplicaMusicService(collections.deque([]), ip_addr, state_queue, response_queue)
election_service = ReplicaElectionService(ip_addr, state_queue, response_queue)
replica_service.start()
election_service.start()
示例14: test_addr_add
def test_addr_add(self):
require_user('root')
ifaddr = self.ifaddr()
self.ip.addr('add', self.ifaces[0], address=ifaddr, mask=24)
assert '{0}/24'.format(ifaddr) in get_ip_addr()
示例15: test_add_addr
def test_add_addr(self):
require_user('root')
dev = self.dev[0]
self.ip.addr('add', dev, address='172.16.0.1', mask=24)
assert '172.16.0.1/24' in get_ip_addr()