本文整理汇总了Python中utils.grep函数的典型用法代码示例。如果您正苦于以下问题:Python grep函数的具体用法?Python grep怎么用?Python grep使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了grep函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_add_del_ip_string
def test_add_del_ip_string(self):
ifname = self.ifname()
ifaddr1 = '%s/24' % (self.ifaddr())
ifaddr2 = '%s/24' % (self.ifaddr())
(self
.ndb
.interfaces
.create(ifname=ifname, kind='dummy', state='down')
.add_ip(ifaddr1)
.add_ip(ifaddr2)
.commit())
assert grep('%s ip -o addr show' % self.ssh,
pattern='%s.*%s' % (ifname, ifaddr1))
assert grep('%s ip -o addr show' % self.ssh,
pattern='%s.*%s' % (ifname, ifaddr2))
(self
.ndb
.interfaces[ifname]
.del_ip(ifaddr2)
.del_ip(ifaddr1)
.commit())
assert not grep('%s ip -o addr show' % self.ssh,
pattern='%s.*%s' % (ifname, ifaddr1))
assert not grep('%s ip -o addr show' % self.ssh,
pattern='%s.*%s' % (ifname, ifaddr2))
开发者ID:svinota,项目名称:pyroute2,代码行数:29,代码来源:test_ndb.py
示例2: test_route_replace_existing
def test_route_replace_existing(self):
# route('replace', ...) should succeed, if route exists
require_user('root')
naddr = str(self.ipnets[1].network)
ifaddr1 = self.ifaddr()
ifaddr2 = self.ifaddr()
ifaddr3 = self.ifaddr()
self.ip.link('set', index=self.ifaces[0], state='up')
self.ip.addr('add', self.ifaces[0], address=ifaddr1, mask=24)
self.ip.route('replace',
dst=naddr,
mask=24,
gateway=ifaddr2,
table=100)
assert grep('ip route show table 100',
pattern='%s/24.*%s' % (naddr, ifaddr2))
self.ip.route('replace',
dst=naddr,
mask=24,
gateway=ifaddr3,
table=100)
assert not grep('ip route show table 100',
pattern='%s/24.*%s' % (naddr, ifaddr2))
assert grep('ip route show table 100',
pattern='%s/24.*%s' % (naddr, ifaddr3))
self.ip.flush_routes(table=100)
assert not grep('ip route show table 100',
pattern='%s/24.*%s' % (naddr, ifaddr3))
开发者ID:svinota,项目名称:pyroute2,代码行数:28,代码来源:test_ipr.py
示例3: test_add_del_ip_dict
def test_add_del_ip_dict(self):
ifname = self.ifname()
ifaddr1 = self.ifaddr()
ifaddr2 = self.ifaddr()
(self
.ndb
.interfaces
.create(ifname=ifname, kind='dummy', state='down')
.add_ip({'address': ifaddr1, 'prefixlen': 24})
.add_ip({'address': ifaddr2, 'prefixlen': 24})
.commit())
assert grep('%s ip -o addr show' % self.ssh,
pattern='%s.*%s' % (ifname, ifaddr1))
assert grep('%s ip -o addr show' % self.ssh,
pattern='%s.*%s' % (ifname, ifaddr2))
(self
.ndb
.interfaces[ifname]
.del_ip({'address': ifaddr2, 'prefixlen': 24})
.del_ip({'address': ifaddr1, 'prefixlen': 24})
.commit())
assert not grep('%s ip -o addr show' % self.ssh,
pattern='%s.*%s' % (ifname, ifaddr1))
assert not grep('%s ip -o addr show' % self.ssh,
pattern='%s.*%s' % (ifname, ifaddr2))
开发者ID:svinota,项目名称:pyroute2,代码行数:29,代码来源:test_ndb.py
示例4: test_multipath_ipv4
def test_multipath_ipv4(self):
ifname = self.ifname()
ifaddr = self.ifaddr()
hop1 = self.ifaddr()
hop2 = self.ifaddr()
(self
.ndb
.interfaces
.create(ifname=ifname, kind='dummy', state='up')
.ipaddr
.create(address=ifaddr, prefixlen=24)
.commit())
(self
.ndb
.routes
.create(**{'dst_len': 24,
'dst': str(self.ipnets[1].network),
'multipath': [{'gateway': hop1},
{'gateway': hop2}]})
.commit())
assert grep('%s ip link show' % self.ssh,
pattern=ifname)
assert grep('%s ip addr show dev %s' % (self.ssh, ifname),
pattern=ifaddr)
assert grep('%s ip route show' % self.ssh,
pattern='%s' % str(self.ipnets[1]))
assert grep('%s ip route show' % self.ssh,
pattern='nexthop.*%s.*%s' % (hop1, ifname))
assert grep('%s ip route show' % self.ssh,
pattern='nexthop.*%s.*%s' % (hop2, ifname))
开发者ID:svinota,项目名称:pyroute2,代码行数:34,代码来源:test_ndb.py
示例5: test_basic
def test_basic(self):
ifaddr = self.ifaddr()
router = self.ifaddr()
ifname = self.ifname()
i = (self
.ndb
.interfaces
.create(ifname=ifname, kind='dummy', state='up'))
i.commit()
a = (self
.ndb
.addresses
.create(index=i['index'],
address=ifaddr,
prefixlen=24))
a.commit()
r = (self
.ndb
.routes
.create(dst_len=24,
dst=str(self.ipnets[1].network),
gateway=router))
r.commit()
assert grep('%s ip link show' % self.ssh,
pattern=ifname)
assert grep('%s ip addr show dev %s' % (self.ssh, ifname),
pattern=ifaddr)
assert grep('%s ip route show' % self.ssh,
pattern='%s.*%s' % (str(self.ipnets[1]), ifname))
开发者ID:svinota,项目名称:pyroute2,代码行数:32,代码来源:test_ndb.py
示例6: test_veth_simple
def test_veth_simple(self):
ifname = uifname()
peername = uifname()
(self
.ndb
.interfaces
.create(ifname=ifname, peer=peername, kind='veth')
.commit())
iflink = self.ndb.interfaces[ifname]['link']
plink = self.ndb.interfaces[peername]['link']
assert iflink == self.ndb.interfaces[peername]['index']
assert plink == self.ndb.interfaces[ifname]['index']
assert grep('%s ip link show' % self.ssh, pattern=ifname)
assert grep('%s ip link show' % self.ssh, pattern=peername)
(self
.ndb
.interfaces[ifname]
.remove()
.commit())
assert not grep('%s ip link show' % self.ssh, pattern=ifname)
assert not grep('%s ip link show' % self.ssh, pattern=peername)
开发者ID:svinota,项目名称:pyroute2,代码行数:26,代码来源:test_ndb.py
示例7: test_flush_routes
def test_flush_routes(self):
require_user('root')
self.ip.link('set', index=self.ifaces[0], state='up')
self.ip.addr('add', self.ifaces[0], address='172.16.0.2', mask=24)
self.ip.route('add',
prefix='172.16.1.0',
mask=24,
gateway='172.16.0.1',
table=100)
self.ip.route('add',
prefix='172.16.2.0',
mask=24,
gateway='172.16.0.1',
table=100)
assert grep('ip route show table 100',
pattern='172.16.1.0/24.*172.16.0.1')
assert grep('ip route show table 100',
pattern='172.16.2.0/24.*172.16.0.1')
self.ip.flush_routes(table=100)
assert not grep('ip route show table 100',
pattern='172.16.1.0/24.*172.16.0.1')
assert not grep('ip route show table 100',
pattern='172.16.2.0/24.*172.16.0.1')
开发者ID:jazzmes,项目名称:pyroute2,代码行数:26,代码来源:test_ipr.py
示例8: test_route_multipath
def test_route_multipath(self):
require_user('root')
self.ip.route('add',
dst='172.16.243.0/24',
multipath=[{'gateway': '127.0.0.2'},
{'gateway': '127.0.0.3'}])
assert grep('ip route show', pattern='172.16.243.0/24')
assert grep('ip route show', pattern='nexthop.*127.0.0.2')
assert grep('ip route show', pattern='nexthop.*127.0.0.3')
self.ip.route('del', dst='172.16.243.0', mask=24)
开发者ID:celebdor,项目名称:pyroute2,代码行数:10,代码来源:test_ipr.py
示例9: _test_shadow
def _test_shadow(self, kind):
a = self.ip.create(ifname='bala', kind=kind).commit()
if a._mode == 'explicit':
a.begin()
a.shadow().commit()
assert 'bala' in self.ip.interfaces
assert not grep('ip link', pattern='bala')
b = self.ip.create(ifname='bala', kind=kind).commit()
assert a == b
assert grep('ip link', pattern='bala')
开发者ID:hegusung,项目名称:pyroute2,代码行数:10,代码来源:test_ipdb.py
示例10: test_vlan_filter_add
def test_vlan_filter_add(self):
require_user('root')
(bn, bx) = self.create('bridge')
(sn, sx) = self.create('dummy')
self.ip.link('set', index=sx, master=bx)
assert not grep('bridge vlan show', pattern=' 568')
self.ip.vlan_filter('add', index=sx, vlan_info={'vid': 568})
assert grep('bridge vlan show', pattern=' 568')
self.ip.vlan_filter('del', index=sx, vlan_info={'vid': 568})
assert not grep('bridge vlan show', pattern=' 568')
开发者ID:svinota,项目名称:pyroute2,代码行数:10,代码来源:test_ipr.py
示例11: test_route_multipath
def test_route_multipath(self):
require_user('root')
naddr = str(self.ipnets[1].network)
self.ip.route('add',
dst='%s/24' % naddr,
multipath=[{'gateway': '127.0.0.2'},
{'gateway': '127.0.0.3'}])
assert grep('ip route show', pattern='%s/24' % naddr)
assert grep('ip route show', pattern='nexthop.*127.0.0.2')
assert grep('ip route show', pattern='nexthop.*127.0.0.3')
self.ip.route('del', dst=naddr, mask=24)
开发者ID:svinota,项目名称:pyroute2,代码行数:11,代码来源:test_ipr.py
示例12: test_simple_deps
def test_simple_deps(self):
# register NDB handler to wait for the interface
self.if_simple = uifname()
ifaddr = self.ifaddr()
router = self.ifaddr()
dst = str(self.ipnets[1].network)
#
# simple dummy interface with one address and
# one dependent route
#
(self
.interfaces
.append(self
.ndb
.interfaces
.create(ifname=self.if_simple, kind='dummy')
.set('state', 'up')
.commit()['index']))
(self
.ndb
.addresses
.create(address=ifaddr,
prefixlen=24,
index=self.interfaces[-1])
.commit())
(self
.ndb
.routes
.create(dst=dst, dst_len=24, gateway=router)
.commit())
iface = self.ndb.interfaces[self.if_simple]
# check everything is in place
assert grep('%s ip link show' % self.ssh, pattern=self.if_simple)
assert grep('%s ip route show' % self.ssh, pattern=self.if_simple)
assert grep('%s ip route show' % self.ssh,
pattern='%s.*%s' % (dst, router))
# remove the interface
iface.remove()
iface.commit()
# check there is no interface, no route
assert not grep('%s ip link show' % self.ssh, pattern=self.if_simple)
assert not grep('%s ip route show' % self.ssh, pattern=self.if_simple)
assert not grep('%s ip route show' % self.ssh,
pattern='%s.*%s' % (dst, router))
# revert the changes using the implicit last_save
iface.rollback()
assert grep('%s ip link show' % self.ssh, pattern=self.if_simple)
assert grep('%s ip route show' % self.ssh, pattern=self.if_simple)
assert grep('%s ip route show' % self.ssh,
pattern='%s.*%s' % (dst, router))
开发者ID:svinota,项目名称:pyroute2,代码行数:58,代码来源:test_ndb.py
示例13: _test_shadow
def _test_shadow(self, kind):
ifA = self.get_ifname()
a = self.ip.create(ifname=ifA, kind=kind).commit()
if a._mode == 'explicit':
a.begin()
a.shadow().commit()
assert ifA in self.ip.interfaces
assert not grep('ip link', pattern=ifA)
b = self.ip.create(ifname=ifA, kind=kind).commit()
assert a == b
assert grep('ip link', pattern=ifA)
开发者ID:0x90,项目名称:pyroute2,代码行数:12,代码来源:test_ipdb.py
示例14: _test_shadow
def _test_shadow(self, kind):
ifA = self.get_ifname()
a = self.ip.create(ifname=ifA, kind=kind).commit()
if a._mode == "explicit":
a.begin()
a.shadow().commit()
assert ifA in self.ip.interfaces
assert not grep("ip link", pattern=ifA)
time.sleep(0.5)
b = self.ip.create(ifname=ifA, kind=kind).commit()
assert a == b
assert grep("ip link", pattern=ifA)
开发者ID:abn,项目名称:pyroute2,代码行数:13,代码来源:test_ipdb.py
示例15: test_global_create
def test_global_create(self):
require_user('root')
ifA = self.get_ifname()
ifB = self.get_ifname()
self.ip.create(ifname=ifA, kind='dummy')
self.ip.create(ifname=ifB, kind='dummy')
self.ip.commit()
assert ifA in self.ip.interfaces
assert ifB in self.ip.interfaces
assert grep('ip link', pattern=ifA)
assert grep('ip link', pattern=ifB)
开发者ID:thezeep,项目名称:pyroute2,代码行数:13,代码来源:test_ipdb.py
示例16: test_route_onlink_multipath_strflags
def test_route_onlink_multipath_strflags(self):
require_user('root')
self.ip.route('add',
dst='172.16.245.0/24',
multipath=[{'gateway': '10.100.1.1',
'oif': 1,
'flags': ['onlink']},
{'gateway': '10.100.1.2',
'oif': 1,
'flags': RTNH_F_ONLINK}])
assert grep('ip route show', pattern='172.16.245.0/24')
assert grep('ip route show', pattern='nexthop.*10.100.1.1.*onlink')
assert grep('ip route show', pattern='nexthop.*10.100.1.2.*onlink')
self.ip.route('del', dst='172.16.245.0', mask=24)
开发者ID:celebdor,项目名称:pyroute2,代码行数:14,代码来源:test_ipr.py
示例17: test_route_multipath_helper
def test_route_multipath_helper(self):
require_user('root')
req = IPRouteRequest({'dst': '172.16.242.0/24',
'multipath': [{'hops': 20,
'ifindex': 1,
'gateway': '127.0.0.2'},
{'hops': 30,
'ifindex': 1,
'gateway': '127.0.0.3'}]})
self.ip.route('add', **req)
assert grep('ip route show', pattern='172.16.242.0/24')
assert grep('ip route show', pattern='nexthop.*127.0.0.2.*weight 21')
assert grep('ip route show', pattern='nexthop.*127.0.0.3.*weight 31')
self.ip.route('del', dst='172.16.242.0', mask=24)
开发者ID:thezeep,项目名称:pyroute2,代码行数:14,代码来源:test_ipr.py
示例18: test_ovs_kind_aliases
def test_ovs_kind_aliases(self):
require_user('root')
ifA = self.get_ifname()
ifB = self.get_ifname()
self.ip.create(ifname=ifA,
kind='ovs-bridge').commit()
self.ip.create(ifname=ifB,
kind='openvswitch').commit()
assert ifA in self.ip.interfaces
assert ifB in self.ip.interfaces
assert grep('ip link', pattern=ifA)
assert grep('ip link', pattern=ifB)
开发者ID:thezeep,项目名称:pyroute2,代码行数:14,代码来源:test_ipdb.py
示例19: test_routes_multipath_gateway
def test_routes_multipath_gateway(self):
require_user("root")
ifR = self.get_ifname()
with self.ip.create(ifname=ifR, kind="dummy") as i:
i.add_ip("172.16.231.1/24")
i.up()
r = self.ip.routes.add(
{
"dst": "172.16.232.0/24",
"multipath": [
{"gateway": "172.16.231.2", "hops": 20},
{"gateway": "172.16.231.3", "hops": 30},
{"gateway": "172.16.231.4"},
],
}
)
r.commit()
assert grep("ip ro", pattern="172.16.232.0/24")
assert grep("ip ro", pattern="nexthop.*172.16.231.2.*weight.*21")
assert grep("ip ro", pattern="nexthop.*172.16.231.3.*weight.*31")
assert grep("ip ro", pattern="nexthop.*172.16.231.4.*weight.*1")
with self.ip.routes["172.16.232.0/24"] as r:
r.add_nh({"gateway": "172.16.231.5", "hops": 50})
r.del_nh({"gateway": "172.16.231.2"})
assert grep("ip ro", pattern="172.16.232.0/24")
assert grep("ip ro", pattern="nexthop.*172.16.231.5.*weight.*51")
assert grep("ip ro", pattern="nexthop.*172.16.231.3.*weight.*31")
assert grep("ip ro", pattern="nexthop.*172.16.231.4.*weight.*1")
开发者ID:abn,项目名称:pyroute2,代码行数:31,代码来源:test_ipdb.py
示例20: test_routes_multipath_gateway
def test_routes_multipath_gateway(self):
require_user('root')
ifR = self.get_ifname()
with self.ip.create(ifname=ifR, kind='dummy') as i:
i.add_ip('172.16.231.1/24')
i.up()
r = self.ip.routes.add({'dst': '172.16.232.0/24',
'multipath': [{'gateway': '172.16.231.2',
'hops': 20},
{'gateway': '172.16.231.3',
'hops': 30},
{'gateway': '172.16.231.4'}]})
r.commit()
assert grep('ip ro', pattern='172.16.232.0/24')
assert grep('ip ro', pattern='nexthop.*172.16.231.2.*weight.*21')
assert grep('ip ro', pattern='nexthop.*172.16.231.3.*weight.*31')
assert grep('ip ro', pattern='nexthop.*172.16.231.4.*weight.*1')
with self.ip.routes['172.16.232.0/24'] as r:
r.add_nh({'gateway': '172.16.231.5', 'hops': 50})
r.del_nh({'gateway': '172.16.231.2'})
assert grep('ip ro', pattern='172.16.232.0/24')
assert grep('ip ro', pattern='nexthop.*172.16.231.5.*weight.*51')
assert grep('ip ro', pattern='nexthop.*172.16.231.3.*weight.*31')
assert grep('ip ro', pattern='nexthop.*172.16.231.4.*weight.*1')
开发者ID:thezeep,项目名称:pyroute2,代码行数:27,代码来源:test_ipdb.py
注:本文中的utils.grep函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论