@@ -0,0 +1,2258 @@
+import re%0Aimport string%0A%0Aclass Interface(object):%0A    %22%22%22%0A    Represents a physical interface on a switch.%0A    %22%22%22%0A    def __init__(self, switch, identifier):%0A        %22%22%22%0A        Construct a new Interface with the given %60identifier%60 located on the given %60switch%60.%0A        %22%22%22%0A        self.switch = switch%0A        self.identifier = identifier%0A%0A    def _get_name(self):%0A        %22%22%22%0A        Get the friendly name configured for this interface.%0A        %22%22%22%0A        run_output = self.switch.execute_command(%22show running-config interface %22 + str(self.identifier))%0A        # Try to extract the interface name, which may also contain spaces. This is achieved by greedily matching%0A        # whitespace at the end of the line and matching the %60   name %60 prefix a the beginning and using whatever%0A        # remains of the string as the interface name. The %60name%60 group is matched in a non-greedy fashion as to not%0A        # %22eat up%22 all the following whitespace which is not part of the name.%0A        name_match = re.search(r%22%5E   name %5C%22(?P%3Cname%3E.*?)%5C%22%5Cs*$%22, run_output, re.MULTILINE)%0A        # Only return the name of the interface if a name was found.%0A        if name_match:%0A            return name_match.group('name')%0A        # If no name was configured, return None.%0A        return None%0A%0A    def _set_name(self, value):%0A        %22%22%22%0A        Configure the name %60value%60 as the friendly name for this interface.%0A        %22%22%22%0A        # Make sure that the name is legal according to the allowed interface names detailed in section 2-23 of the HP%0A        # Management and Configuration Guide%0A        assert(all(map(lambda letter: letter in (string.ascii_letters + string.digits), value)))%0A        # Issue the commands on the switch to set the new name.%0A        self.switch.execute_command(%22config%22)%0A        self.switch.execute_command(%22interface %7B0%7D name %7B1%7D%22.format(self.identifier, value))%0A        self.switch.execute_command(%22exit%22)%0A%0A    def _del_name(self):%0A        %22%22%22%0A        Deconfigure the friendly name on this interface.%0A        %22%22%22%0A        self.switch.execute_command(%22config%22)%0A        self.switch.execute_command(%22no interface %7B0%7D name%22.format(self.identifier))%0A        self.switch.execute_command(%22exit%22)%0A%0A    name = property(_get_name, _set_name, _del_name)%0A

Add physical interface handling and name configuration