示例#1
0
 def state(self):
     """
     Returns either 'up' or 'down', depending on interface state.
     Setting to one of these values immediately changes interface state.
     """
     flags = ip(['link', 'show', 'dev', self.name])[self.name]['flags']
     return 'up' if 'UP' in flags else 'down'
示例#2
0
 def destroy(self):
     """Destroy the VLAN interface."""
     ip(['link', 'delete', self.name, 'type', 'vlan'])
示例#3
0
 def create(cls, parent, tag):
     """Create VLAN-tagged interface on specified parent."""
     name = '%s.%i' % (parent, tag)
     ip(['link', 'add', name, 'link', parent,
                              'type', 'vlan', 'id', str(tag)])
     return cls(name)
示例#4
0
 def destroy(self):
     """Destroy the VXLAN tunnel interface."""
     ip(['link', 'delete', self.name, 'type', 'vxlan'])
示例#5
0
 def create(cls, name, group, tag):
     """Create VXLAN tunnel with a tag and mcast group."""
     ip(['link', 'add', name, 'type', 'vxlan', 'id', str(tag), 'group', group])
     return cls(name)
示例#6
0
 def hwaddr(self, value):
     if value != self.hwaddr:
         ip(['link', 'set', 'address', value, 'dev', self.name])
示例#7
0
 def state(self, value):
     if value not in ('up', 'down'):
         raise ValueError('link can be either "up" or "down"')
     ip(['link', 'set', value, 'dev', self.name])
示例#8
0
 def addr_del(self, addr):
     """
     Removes IPv4 or IPv6 address from the interface.
     You should use the canonical form with prefix.
     """
     ip(['addr', 'del', addr, 'dev', self.name])
示例#9
0
 def addr_add(self, addr):
     """
     Adds another IPv4 or IPv6 address to the interface.
     The address string should include network prefix.
     """
     ip(['addr', 'add', addr, 'dev', self.name])
示例#10
0
 def inet6(self):
     """List of interface IPv6 addresses."""
     inet6 = ip(['addr', 'show', 'dev', self.name])[self.name]\
             .get('inet6', [])
     return [x['address'] for x in inet6]
示例#11
0
 def mtu(self, value):
     ip(['link', 'set', 'mtu', str(value)])
示例#12
0
 def destroy(self):
     """Destroy the bridge."""
     ip(['link', 'delete', self.name, 'type', 'bridge'])
示例#13
0
 def create(cls, name):
     """Create new bridge with specified name."""
     ip(['link', 'add', name, 'type', 'bridge'])
     return cls(name)