def remove_vrrp_group(self, vlan_id, group_id): config = self.query(one_interface_vlan(vlan_id)) if len(config.xpath( "data/configuration/interfaces/interface/unit")) < 1: raise UnknownVlan(vlan_id) address_node = first( config.xpath( "data/configuration/interfaces/interface/unit/family" "/inet/address/vrrp-group/name[text()=\"{}\"]/../..".format( group_id))) if address_node is None: raise VrrpDoesNotExistForVlan(vlan=vlan_id, vrrp_group_id=group_id) vrrp_node = to_ele(""" <vrrp-group operation="delete"> <name>{group_id}</name> </vrrp-group>""".format(group_id=group_id)) update = Update() update.add_interface( irb_address_update(vlan_id, first_text(address_node.xpath("name")), children=[vrrp_node])) self._push(update)
def irb_address_update(vlan_number, ip_network, operation=None, children=None): content = to_ele(""" <interface> <name>irb</name> <unit> <name>{vlan_number}</name> <family> <inet> <address{operation}> <name>{ip_network}</name> </address> </inet> </family> </unit> </interface>""".format( vlan_number=vlan_number, ip_network=ip_network, operation=' operation="{}"'.format(operation) if operation else "")) if children is not None: address = first(content.xpath("//address")) for child in children: address.append(child) return content
def interface_update(self, name, unit, attributes=None, vlan_members=None): content = to_ele(""" <interface> <name>{interface}</name> <unit> <name>{unit}</name> <family> <ethernet-switching> </ethernet-switching> </family> </unit> </interface> """.format(interface=name, unit=unit)) ethernet_switching_node = first(content.xpath("//ethernet-switching")) for attribute in (attributes if attributes is not None else []): ethernet_switching_node.append(attribute) if vlan_members: vlan = new_ele("vlan") for attribute in vlan_members: vlan.append(attribute) ethernet_switching_node.append(vlan) return content
def set_vlan_icmp_redirects_state(self, vlan_number, state): config = self.query( self.custom_strategies.one_vlan_by_vlan_id(vlan_number), one_interface_vlan(vlan_number, extra_path="""<family> <inet> <no-redirects /> </inet> </family>""" )) self.custom_strategies.vlan_node(config, vlan_number) no_redirects_node = first( config.xpath( "data/configuration/interfaces/interface/unit/family/inet/no-redirects" )) update = Update() if no_redirects_node is None and state is False: self.custom_strategies.add_update_vlan_interface(update, vlan_number, name=None) update.add_interface(no_redirects(vlan_number=vlan_number)) self._push(update) elif no_redirects_node is not None and state is True: update.add_interface( no_redirects(vlan_number=vlan_number, operation="delete")) self._push(update)
def vlan_node(self, config, number): vlan_node = first( config.xpath( "data/configuration/bridge-domains/domain/vlan-id[text()=\"{}\"]/.." .format(number))) if vlan_node is None: raise UnknownVlan(number) return vlan_node
def interface_vlan_members_update(self, name, unit, members_modification): content = to_ele(""" <interface> <name>{}</name> <unit> <name>{}</name> <family> <bridge/> </family> </unit> </interface> """.format(name, unit)) vlan_node = first(content.xpath("//bridge")) for m in members_modification: vlan_node.append(m) return content
def interface_update(self, name, unit, attributes=None, vlan_members=None): content = to_ele(""" <interface> <name>{interface}</name> <unit> <name>{unit}</name> <family> <bridge> </bridge> </family> </unit> </interface> """.format(interface=name, unit=unit)) bridge = first(content.xpath("//bridge")) for attribute in (attributes if attributes is not None else []): bridge.append(attribute) if vlan_members: for attribute in vlan_members: bridge.append(attribute) return content
def get_l3_interface(self, vlan_node): if_name_node = first(vlan_node.xpath("routing-interface")) if if_name_node is not None: return if_name_node.text.split(".") else: return None, None
def parse_icmp_redirects(self, interface_unit): return first(interface_unit.xpath("family/inet/no-redirects")) is None