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'
def destroy(self): """Destroy the VLAN interface.""" ip(['link', 'delete', self.name, 'type', 'vlan'])
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)
def destroy(self): """Destroy the VXLAN tunnel interface.""" ip(['link', 'delete', self.name, 'type', 'vxlan'])
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)
def hwaddr(self, value): if value != self.hwaddr: ip(['link', 'set', 'address', value, 'dev', self.name])
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])
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])
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])
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]
def mtu(self, value): ip(['link', 'set', 'mtu', str(value)])
def destroy(self): """Destroy the bridge.""" ip(['link', 'delete', self.name, 'type', 'bridge'])
def create(cls, name): """Create new bridge with specified name.""" ip(['link', 'add', name, 'type', 'bridge']) return cls(name)