<filename>src/genie/libs/parser/cimc/show_network.py
''' show_network.py

Parser for the following show commands:
    * show network detail
returns  network ip configuration
'''

# Python
import re

# Metaparser
from genie.metaparser import MetaParser
from genie.metaparser.util.schemaengine import Schema, Any, Optional

# ====================================================
#  schema for show network detail
# ====================================================
class ShowNetworkDetail(MetaParser):
    """Schema for show network detail"""
    schema = {
        'network':{
                Optional('ipv4enabled'): str,
                Optional('ipv4address'): str,
                Optional('ipv4netmask'): str,
                Optional('ipv4gateway'): str,
                Optional('preferreddns'): str,
                Optional('alternatedns'): str,
                Optional('dhcpenabled'): str,
                Optional('ipv6enabled'): str,
                Optional('ipv6address'): str,
                Optional('ipv6prefix'): str,
                Optional('ipv6gateway'): str,
                Optional('ipv4preferreddns'): str,
                Optional('ipv4alternatedns'): str,
                Optional('ipv6dhcpenabled'): str,
                Optional('hostname'): str,
                Optional('macaddress'): str
                },
    }

# ====================================================
#  parser for network detail
# ====================================================
class ShowNetworkDetail(ShowNetworkDetail):
    """Parser for show network detail"""

    cli_command = 'show network detail'

    def cli(self, output=None):
        if output is None:
            out = self.device.execute(self.cli_command)
        else:
            out = output
      
        ret_dict = {}
        p1 = re.compile(r'^IPv4\sEnabled\:\s(?P<ipv4enabled>\S*)$')
        p2 = re.compile(r'^IPv4\sAddress\:\s(?P<ipv4address>\S*)$')
        p3 = re.compile(r'^IPv4\sNetmask\:\s(?P<ipv4netmask>\S*)$')
        p4 = re.compile(r'^IPv4\sGateway\:\s(?P<ipv4gateway>\S*)$')
        p5 = re.compile(r'^Preferred\sDNS\:\s(?P<preferreddns>\S*)$')
        p6 = re.compile(r'^Alternate\sDNS\:\s(?P<alternatedns>\S*)$')
        p7 = re.compile(r'^DHCP\sEnabled\:(?P<dhcpenabled>\S*)$')
        p8 = re.compile(r'^IPv6\sEnabled\:\s(?P<ipv6enabled>\S*)$')
        p9 = re.compile(r'^IPv6\sAddress\:\s(?P<ipv6address>\S*)$')
        p10 = re.compile(r'^IPv6\sPrefix\:\s(?P<ipv6prefix>\S*)$')
        p11 = re.compile(r'^IPv6\sGateway\:\s(?P<ipv6gateway>\S*)$')
        p12 = re.compile(r'^IPv6\sPreferred\sDNS\:\s(?P<ipv6preferred>\S*)$')
        p13 = re.compile(r'^IPv6\sAlternate\sDNS\:\s(?P<ipv6alternate>\S*)$')
        p14 = re.compile(r'^IPv6\sDHCP\sEnabled\:(?P<ipv6dhcpenabled>\S*)$')
        p15 = re.compile(r'^Hostname\:\s(?P<hostname>\S*)$')
        p16 = re.compile(r'^MAC\sAddress\:\s(?P<macaddress>\S*)$')        



        for line in out.splitlines():
            line = line.strip()
            m = p1.match(line)
            if m:
                groups = m.groupdict()
                dict_name = ret_dict.setdefault('network', {})
                #dict_name['mem'] = {}
                dict_name['ipv4enabled'] = groups['ipv4enabled']
                continue
            
            m = p2.match(line)
            if m:
                groups = m.groupdict()
                dict_name['ipv4address'] = groups['ipv4address']
                continue

            m = p3.match(line)
            if m:
                groups = m.groupdict()
                dict_name['ipv4netmask'] = groups['ipv4netmask']
                continue

            m = p4.match(line)
            if m:
                groups = m.groupdict()
                dict_name['ipv4gateway'] = groups['ipv4gateway']
                continue

            m = p5.match(line)
            if m:
                groups = m.groupdict()
                dict_name['preferreddns'] = groups['preferreddns']
                continue

            m = p6.match(line)
            if m:
                groups = m.groupdict()
                dict_name['alternatedns'] = groups['alternatedns']
                continue


            

            m = p7.match(line)
            if m:
                groups = m.groupdict()
                dict_name['dhcpenabled'] = groups['dhcpenabled']
                continue


            m = p8.match(line)
            if m:
                groups = m.groupdict()
                dict_name['ipv6enabled'] = groups['ipv6enabled']
                continue

            m = p9.match(line)
            if m:
                groups = m.groupdict()
                dict_name['ipv6address'] = groups['ipv6address']
                continue

            m = p10.match(line)
            if m:
                groups = m.groupdict()
                dict_name['ipv6prefix'] = groups['ipv6prefix']
                continue
            

            m = p11.match(line)
            if m:
                groups = m.groupdict()
                dict_name['ipv6gateway'] = groups['ipv6gateway']
                continue

            m = p11.match(line)
            if m:
                groups = m.groupdict()
                dict_name['ipv6gateway'] = groups['ipv6gateway']    
                continue


            m = p12.match(line)
            if m:
                groups = m.groupdict()
                dict_name['ipv6prefereeddns'] = groups['ipv6preferreddns']    
                continue

            m = p13.match(line)
            if m:
                groups = m.groupdict()
                dict_name['ipv6alternatedns'] = groups['ipv6alternatedns']    
                continue

            m = p14.match(line)
            if m:
                groups = m.groupdict()
                dict_name['ipv6dhcpenabled'] = groups['ipv6dhcpenabled']    
                continue

            m = p15.match(line)
            if m:
                groups = m.groupdict()
                dict_name['hostname'] = groups['hostname']    
                continue

            m = p16.match(line)
            if m:
                groups = m.groupdict()
                dict_name['macaddress'] = groups['macaddress']    
                continue


        return ret_dict

<filename>src/genie/libs/parser/cimc/show_network.py
''' show_network.py

Parser for the following show commands:
    * show network detail
returns  network ip configuration
'''

# Python
import re

# Metaparser
from genie.metaparser import MetaParser
from genie.metaparser.util.schemaengine import Schema, Any, Optional

# ====================================================
#  schema for show network detail
# ====================================================
class ShowNetworkDetail(MetaParser):
    """Schema for show network detail"""
    schema = {
        'network':{
                Optional('ipv4enabled'): str,
                Optional('ipv4address'): str,
                Optional('ipv4netmask'): str,
                Optional('ipv4gateway'): str,
                Optional('preferreddns'): str,
                Optional('alternatedns'): str,
                Optional('dhcpenabled'): str,
                Optional('ipv6enabled'): str,
                Optional('ipv6address'): str,
                Optional('ipv6prefix'): str,
                Optional('ipv6gateway'): str,
                Optional('ipv4preferreddns'): str,
                Optional('ipv4alternatedns'): str,
                Optional('ipv6dhcpenabled'): str,
                Optional('hostname'): str,
                Optional('macaddress'): str
                },
    }

# ====================================================
#  parser for network detail
# ====================================================
class ShowNetworkDetail(ShowNetworkDetail):
    """Parser for show network detail"""

    cli_command = 'show network detail'

    def cli(self, output=None):
        if output is None:
            out = self.device.execute(self.cli_command)
        else:
            out = output
      
        ret_dict = {}
        p1 = re.compile(r'^IPv4\sEnabled\:\s(?P<ipv4enabled>\S*)$')
        p2 = re.compile(r'^IPv4\sAddress\:\s(?P<ipv4address>\S*)$')
        p3 = re.compile(r'^IPv4\sNetmask\:\s(?P<ipv4netmask>\S*)$')
        p4 = re.compile(r'^IPv4\sGateway\:\s(?P<ipv4gateway>\S*)$')
        p5 = re.compile(r'^Preferred\sDNS\:\s(?P<preferreddns>\S*)$')
        p6 = re.compile(r'^Alternate\sDNS\:\s(?P<alternatedns>\S*)$')
        p7 = re.compile(r'^DHCP\sEnabled\:(?P<dhcpenabled>\S*)$')
        p8 = re.compile(r'^IPv6\sEnabled\:\s(?P<ipv6enabled>\S*)$')
        p9 = re.compile(r'^IPv6\sAddress\:\s(?P<ipv6address>\S*)$')
        p10 = re.compile(r'^IPv6\sPrefix\:\s(?P<ipv6prefix>\S*)$')
        p11 = re.compile(r'^IPv6\sGateway\:\s(?P<ipv6gateway>\S*)$')
        p12 = re.compile(r'^IPv6\sPreferred\sDNS\:\s(?P<ipv6preferred>\S*)$')
        p13 = re.compile(r'^IPv6\sAlternate\sDNS\:\s(?P<ipv6alternate>\S*)$')
        p14 = re.compile(r'^IPv6\sDHCP\sEnabled\:(?P<ipv6dhcpenabled>\S*)$')
        p15 = re.compile(r'^Hostname\:\s(?P<hostname>\S*)$')
        p16 = re.compile(r'^MAC\sAddress\:\s(?P<macaddress>\S*)$')        



        for line in out.splitlines():
            line = line.strip()
            m = p1.match(line)
            if m:
                groups = m.groupdict()
                dict_name = ret_dict.setdefault('network', {})
                #dict_name['mem'] = {}
                dict_name['ipv4enabled'] = groups['ipv4enabled']
                continue
            
            m = p2.match(line)
            if m:
                groups = m.groupdict()
                dict_name['ipv4address'] = groups['ipv4address']
                continue

            m = p3.match(line)
            if m:
                groups = m.groupdict()
                dict_name['ipv4netmask'] = groups['ipv4netmask']
                continue

            m = p4.match(line)
            if m:
                groups = m.groupdict()
                dict_name['ipv4gateway'] = groups['ipv4gateway']
                continue

            m = p5.match(line)
            if m:
                groups = m.groupdict()
                dict_name['preferreddns'] = groups['preferreddns']
                continue

            m = p6.match(line)
            if m:
                groups = m.groupdict()
                dict_name['alternatedns'] = groups['alternatedns']
                continue


            

            m = p7.match(line)
            if m:
                groups = m.groupdict()
                dict_name['dhcpenabled'] = groups['dhcpenabled']
                continue


            m = p8.match(line)
            if m:
                groups = m.groupdict()
                dict_name['ipv6enabled'] = groups['ipv6enabled']
                continue

            m = p9.match(line)
            if m:
                groups = m.groupdict()
                dict_name['ipv6address'] = groups['ipv6address']
                continue

            m = p10.match(line)
            if m:
                groups = m.groupdict()
                dict_name['ipv6prefix'] = groups['ipv6prefix']
                continue
            

            m = p11.match(line)
            if m:
                groups = m.groupdict()
                dict_name['ipv6gateway'] = groups['ipv6gateway']
                continue

            m = p11.match(line)
            if m:
                groups = m.groupdict()
                dict_name['ipv6gateway'] = groups['ipv6gateway']    
                continue


            m = p12.match(line)
            if m:
                groups = m.groupdict()
                dict_name['ipv6prefereeddns'] = groups['ipv6preferreddns']    
                continue

            m = p13.match(line)
            if m:
                groups = m.groupdict()
                dict_name['ipv6alternatedns'] = groups['ipv6alternatedns']    
                continue

            m = p14.match(line)
            if m:
                groups = m.groupdict()
                dict_name['ipv6dhcpenabled'] = groups['ipv6dhcpenabled']    
                continue

            m = p15.match(line)
            if m:
                groups = m.groupdict()
                dict_name['hostname'] = groups['hostname']    
                continue

            m = p16.match(line)
            if m:
                groups = m.groupdict()
                dict_name['macaddress'] = groups['macaddress']    
                continue


        return ret_dict

show_network.py  Parser for the following show commands:     * show network detail returns  network ip configuration # Python # Metaparser # ==================================================== #  schema for show network detail # ==================================================== Schema for show network detail # ==================================================== #  parser for network detail # ==================================================== Parser for show network detail #dict_name['mem'] = {}