def create(self, port): self._clear(port) LOG.debug("Creating port %s for hardware_id %s" % (port.interface, port.hardware_id)) LOG.debug("Attaching vlan %s to interface %s" % (port.vlan_id, port.interface)) cmds = commands.create_port(hardware_id=port.hardware_id, interface=port.interface, vlan_id=port.vlan_id, ip=port.ip, mac_address=port.mac_address, trunked=port.trunked) res = self._run_commands(port, cmds) # for some reason authentication errors happen apparently randomly when # running commands. All other port creation commnads are safe to run # twice during retry except for adding the vpc to the port-channel, as # it fails with 'ERROR: Operation failed: [vPC already exists]' if port.trunked: interface = port.interface po_int = commands._make_portchannel_interface(interface) cmds = commands._configure_interface('port-channel', po_int) cmds = cmds + commands._add_vpc(po_int) res = self._run_commands(port, cmds) self.save(port) return res
def _clear(self, port): """Remove all configuration for a given interface, which includes the ethernet interface, related port-channel, and any dhcp snooping bindings or other port security features. """ LOG.debug("clearing interface %s" % (port.interface)) interface = port.interface po_int = commands._make_portchannel_interface(interface) eth_int = commands._make_ethernet_interface(interface) # get and filter relevant dhcp snooping bindings dhcp_conf = self.show_dhcp_snooping_configuration(port) dhcp_conf = [cisco_utils.negate_conf(c) for c in dhcp_conf] # we need to configure the portchannel because there is no # guarantee that it exists, and you cannot remove snooping # bindings without the actual interface existing. cmds = [] if dhcp_conf: cmds = cmds + commands._configure_interface('port-channel', po_int) cmds = cmds + dhcp_conf # for some reason authentication errors happen apparently randomly when # running commands. All other port creation commands are safe to run # twice during retry except for removing the dhcp binding, which fails # with 'ERROR: Entry does not exist' if cmds: self._run_commands(port, cmds) # delete the portchannel and default the eth interface cmds = commands._delete_port_channel_interface(po_int) cmds = cmds + commands._delete_ethernet_interface(eth_int) return self._run_commands(port, cmds)
def create(self, port): self._clear(port) LOG.debug("Creating port %s for hardware_id %s" % (port.interface, port.hardware_id)) LOG.debug("Attaching vlan %s to interface %s" % (port.vlan_id, port.interface)) cmds = commands.create_port( hardware_id=port.hardware_id, interface=port.interface, vlan_id=port.vlan_id, ip=port.ip, mac_address=port.mac_address, trunked=port.trunked) res = self._run_commands(port, cmds) # for some reason authentication errors happen apparently randomly when # running commands. All other port creation commnads are safe to run # twice during retry except for adding the vpc to the port-channel, as # it fails with 'ERROR: Operation failed: [vPC already exists]' if port.trunked: interface = port.interface po_int = commands._make_portchannel_interface(interface) cmds = commands._configure_interface('port-channel', po_int) cmds = cmds + commands._add_vpc(po_int) res = self._run_commands(port, cmds) self.save(port) return res
def _clear(self, port): """Remove all configuration for a given interface, which includes the ethernet interface, related port-channel, and any dhcp snooping bindings or other port security features. """ LOG.debug("clearing interface %s" % (port.interface)) interface = port.interface po_int = commands._make_portchannel_interface(interface) eth_int = commands._make_ethernet_interface(interface) # get and filter relevant dhcp snooping bindings dhcp_conf = self.show_dhcp_snooping_configuration(port) dhcp_conf = [cisco_utils.negate_conf(c) for c in dhcp_conf] # we need to configure the portchannel because there is no # guarantee that it exists, and you cannot remove snooping # bindings without the actual interface existing. cmds = [] if dhcp_conf: cmds = cmds + commands._configure_interface('port-channel', po_int) cmds = cmds + dhcp_conf # delete the portchannel and default the eth interface cmds = cmds + commands._delete_port_channel_interface(po_int) cmds = cmds + commands._delete_ethernet_interface(eth_int) return self._run_commands(port, cmds)
def clear(self, port): """Remove all configuration for a given interface, which includes the ethernet interface, related port-channel, and any dhcp snooping bindings or other port security features. For some reason, you can't run 'no interface eth x/x' on the 3172. So we have to read the config for the interface first and manually negate each option. 'no interface port-channel' works as expected. You must remove entries from the dhcp snooping table before removing the underlying port-channel otherwise it won't work. """ LOG.debug("clearing interface %s" % (port.interface)) interface = port.interface po_int = commands._make_portchannel_interface(interface) eth_int = commands._make_ethernet_interface(interface) eth_conf = self.show(port, type='ethernet') eth_conf = [self._negate_conf(c) for c in eth_conf] dhcp_conf = self.show_dhcp_snooping_configuration(port) dhcp_conf = [self._negate_conf(c) for c in dhcp_conf] cmds = commands._configure_interface('port-channel', po_int) cmds = cmds + dhcp_conf cmds = cmds + commands._delete_port_channel_interface(po_int) cmds = cmds + commands._configure_interface('ethernet', eth_int) cmds = cmds + eth_conf + ['shutdown'] def _filter_clear_commands(c): for r in IGNORE_CLEAR: if r.match(c): return False return True cmds = [c for c in cmds if _filter_clear_commands(c)] return self._run_commands(port, cmds)