예제 #1
0
def vpp_startup_conf_remove_nat(params):
    filename = params['vpp_config_filename']
    config   = fwtool_vpp_startupconf_dict.load(filename)
    if config.get('nat'):
        del config['nat']
    fwtool_vpp_startupconf_dict.dump(config, filename)
    return (True, None)   # 'True' stands for success, 'None' - for the returned object or error string.
예제 #2
0
def vpp_startup_conf_add_nat(params):
    filename = params['vpp_config_filename']
    config   = fwtool_vpp_startupconf_dict.load(filename)
    config['nat'] = []
    config['nat'].append('endpoint-dependent')
    config['nat'].append('translation hash buckets 1048576')
    config['nat'].append('translation hash memory 268435456')
    config['nat'].append('user hash buckets 1024')
    config['nat'].append('max translations per user 10000')
    fwtool_vpp_startupconf_dict.dump(config, filename)
    return (True, None)   # 'True' stands for success, 'None' - for the returned object or error string.
예제 #3
0
def vpp_startup_conf_add_devices(params):
    filename = params['vpp_config_filename']
    config   = fwtool_vpp_startupconf_dict.load(filename)

    if not config.get('dpdk'):
        config['dpdk'] = []
    for dev in params['devices']:
        config_param = 'dev %s' % dev
        if not config_param in config['dpdk']:
            config['dpdk'].append(config_param)

    fwtool_vpp_startupconf_dict.dump(config, filename)
    return (True, None)   # 'True' stands for success, 'None' - for the returned object or error string.
예제 #4
0
def vpp_startup_conf_remove_devices(params):
    filename = params['vpp_config_filename']
    config   = fwtool_vpp_startupconf_dict.load(filename)

    if not config.get('dpdk'):
        return
    for dev in params['devices']:
        config_param = 'dev %s' % dev
        if config_param in config['dpdk']:
            config['dpdk'].remove(config_param)
    if len(config['dpdk']) == 0:
        config['dpdk'].append('ELEMENT_TO_BE_REMOVED')  # Need this to avoid empty list section before dump(), as yaml goes crazy with empty list sections

    fwtool_vpp_startupconf_dict.dump(config, filename)
    return (True, None)   # 'True' stands for success, 'None' - for the returned object or error string.
    def __init__(self, debug=False):
        """Constructor method
        """
        fwglobals.initialize()

        self.CFG_VPP_CONF_FILE = fwglobals.g.VPP_CONFIG_FILE
        self.CFG_FWAGENT_CONF_FILE = fwglobals.g.FWAGENT_CONF_FILE
        self.debug = debug  # Don't use fwglobals.g.cfg.DEBUG to prevent temporary checker files even DEBUG is enabled globally
        self.wan_interfaces = None
        self.nameservers = None
        self.detected_nics = None
        self.supported_nics = None
        self.vpp_configuration = fwtool_vpp_startupconf_dict.load(
            self.CFG_VPP_CONF_FILE)
        self.vpp_config_modified = False

        supported_nics_filename = os.path.join(
            os.path.dirname(os.path.realpath(__file__)),
            'dpdk_supported_nics.json')
        with open(supported_nics_filename, 'r') as f:
            self.supported_nics = json.load(f)
예제 #6
0
def vpp_startup_conf_update(filename, path, param, val, add, filename_backup=None):
    """Updates the /etc/vpp/startup.conf

    :param filename:    /etc/vpp/startup.conf
    :param path:        path to parameter in the startup.conf, e.g. 'dpdk/dev 0000:02:00.1'
    :param param:       name of the parameter, e.g. 'name'
    :param val:         value of the paremeter, e.g. 'eth0'
    :param add:         if True the parameter will be added or modified,
                        if False the parameter will be commented out

     :returns: None.
     """

    # Load file into dictionary
    conf = fwtool_vpp_startupconf_dict.load(filename)

    # Goto the leaf sub-section according the path.
    # If some of sections don't exist, create them.
    # Section is a list that might contains parameters (list) or sub-sections (dictionaries),
    # so steps in path stands for dictionaries, when the last step is list.
    section = conf
    steps = path.split('/')
    prev_section = section
    prev_step    = steps[0]
    for (idx, step) in enumerate(steps):
        if step not in section:
            if idx < len(steps)-1:
                section[step] = {}
            else:
                section[step] = []  # Last step which is list
        prev_section = section
        prev_step    = step
        section      = section[step]

    # If leaf section is empty (it is possible if path exists, but section is empty)
    # initialize it with empty list of parameters.
    if section is None:
        prev_section[prev_step] = []
        section = prev_section[prev_step]

    # Update parameter.
    # Firstly find it in section list of parameter
    found_elements = [ el for el in section if param in el ]
    if add:
        # If element was found, update it. Otherwise - add new parameter
        if len(found_elements) > 0:
            if not val is None:     # If there is a value to update ...
                found_elements[0][param] = val
        else:
            if val is None:
                section.append(param)
            else:
                section.append({param: val})
    else:
        if len(found_elements) > 0:
            section.remove(found_elements[0])
            section.append('ELEMENT_TO_BE_REMOVED')
        if len(section) == 0:
            prev_section[prev_step] = None

    # Dump dictionary back into file
    fwtool_vpp_startupconf_dict.dump(conf, filename)