<filename>Lab_6/data/core/myservices/pcpingweb01.py
#
# CORE
# Copyright (c)2010-2012 the Boeing Company.
# See the LICENSE file included in this distribution.
#
''' WAN BGP user-defined service.
'''

import os

from core.service import CoreService, addservice
from core.misc.ipaddr import IPv4Prefix, IPv6Prefix

class PCPingWEB01(CoreService):
    ''' This service starts up a PPSP Peer in Leecher Mode playing 00_dg_2s_p2p_emu contents with local ~/cache/.
    '''
    # a unique name is required, without spaces
    _name = "PingWEB01"
    # you can create your own group here
    _group = "WAN_BGP"
    # list of other services this service depends on
    _depends = ()
    # per-node directories
    _dirs = ()
    # generated files (without a full path this file goes in the node's dir,
    #  e.g. /tmp/pycore.12345/n1.conf/)
    _configs = ('startpc.sh', )
    # this controls the starting order vs other enabled services
    _startindex = 60
    # list of startup commands, also may be generated during startup
    _startup = ('sh startpc.sh',)
    # list of shutdown commands
    _shutdown = ()

    @classmethod
    def generateconfig(cls, node, filename, services):
        ''' Return a string that will be written to filename, or sent to the
            GUI for user customization.
        '''
        cfg = "#!/bin/sh\n"
        cfg += "# auto-generated by PCPingWEB01 (pcpingweb01.py)\n"
        for ifc in node.netifs():
            cfg += 'echo "Node %s has interface %s"\n' % (node.name, ifc.name)
            # here we do something interesting
            cfg += "\n".join(map(cls.subnetentry, ifc.addrlist))
            break
        cfg += "\n"
        # Test network before starting operation
        cfg += "ping -n -D -c 50 -W 70 198.18.11.10 >/home/vagrant/output/pingtest%s.log\n" % (node.name)
        return cfg

    @staticmethod
    def subnetentry(x):
        ''' Generate a subnet declaration block given an IPv4 prefix string
            for inclusion in the config file.
        '''
        if x.find(":") >= 0:
            # this is an IPv6 address
            return ""
        else:
            net = IPv4Prefix(x)
            return 'echo "  network %s"' % (net)

# this line is required to add the above class to the list of available services
addservice(PCPingWEB01)

<filename>Lab_6/data/core/myservices/pcpingweb01.py
#
# CORE
# Copyright (c)2010-2012 the Boeing Company.
# See the LICENSE file included in this distribution.
#
''' WAN BGP user-defined service.
'''

import os

from core.service import CoreService, addservice
from core.misc.ipaddr import IPv4Prefix, IPv6Prefix

class PCPingWEB01(CoreService):
    ''' This service starts up a PPSP Peer in Leecher Mode playing 00_dg_2s_p2p_emu contents with local ~/cache/.
    '''
    # a unique name is required, without spaces
    _name = "PingWEB01"
    # you can create your own group here
    _group = "WAN_BGP"
    # list of other services this service depends on
    _depends = ()
    # per-node directories
    _dirs = ()
    # generated files (without a full path this file goes in the node's dir,
    #  e.g. /tmp/pycore.12345/n1.conf/)
    _configs = ('startpc.sh', )
    # this controls the starting order vs other enabled services
    _startindex = 60
    # list of startup commands, also may be generated during startup
    _startup = ('sh startpc.sh',)
    # list of shutdown commands
    _shutdown = ()

    @classmethod
    def generateconfig(cls, node, filename, services):
        ''' Return a string that will be written to filename, or sent to the
            GUI for user customization.
        '''
        cfg = "#!/bin/sh\n"
        cfg += "# auto-generated by PCPingWEB01 (pcpingweb01.py)\n"
        for ifc in node.netifs():
            cfg += 'echo "Node %s has interface %s"\n' % (node.name, ifc.name)
            # here we do something interesting
            cfg += "\n".join(map(cls.subnetentry, ifc.addrlist))
            break
        cfg += "\n"
        # Test network before starting operation
        cfg += "ping -n -D -c 50 -W 70 198.18.11.10 >/home/vagrant/output/pingtest%s.log\n" % (node.name)
        return cfg

    @staticmethod
    def subnetentry(x):
        ''' Generate a subnet declaration block given an IPv4 prefix string
            for inclusion in the config file.
        '''
        if x.find(":") >= 0:
            # this is an IPv6 address
            return ""
        else:
            net = IPv4Prefix(x)
            return 'echo "  network %s"' % (net)

# this line is required to add the above class to the list of available services
addservice(PCPingWEB01)

# # CORE # Copyright (c)2010-2012 the Boeing Company. # See the LICENSE file included in this distribution. # WAN BGP user-defined service. This service starts up a PPSP Peer in Leecher Mode playing 00_dg_2s_p2p_emu contents with local ~/cache/. # a unique name is required, without spaces # you can create your own group here # list of other services this service depends on # per-node directories # generated files (without a full path this file goes in the node's dir, #  e.g. /tmp/pycore.12345/n1.conf/) # this controls the starting order vs other enabled services # list of startup commands, also may be generated during startup # list of shutdown commands Return a string that will be written to filename, or sent to the             GUI for user customization. # here we do something interesting # Test network before starting operation Generate a subnet declaration block given an IPv4 prefix string             for inclusion in the config file. # this is an IPv6 address # this line is required to add the above class to the list of available services