def update_edge_syslog(self, edge_id, syslog_config, router_id):
        if 'server_ip' not in syslog_config:
            LOG.warning("Server IP missing in syslog config for %s",
                        router_id)
            return

        protocol = syslog_config.get('protocol', 'tcp')
        if protocol not in ['tcp', 'udp']:
            LOG.warning("Invalid protocol in syslog config for %s",
                        router_id)
            return

        loglevel = syslog_config.get('log_level')
        if loglevel and loglevel not in edge_utils.SUPPORTED_EDGE_LOG_LEVELS:
            LOG.warning("Invalid loglevel in syslog config for %s",
                        router_id)
            return

        server_ip = syslog_config['server_ip']
        request = {'featureType': 'syslog',
                   'protocol': protocol,
                   'serverAddresses': {'ipAddress': [server_ip],
                                       'type': 'IpAddressesDto'}}

        # edge allows up to 2 syslog servers
        if 'server2_ip' in syslog_config:
            request['serverAddresses']['ipAddress'].append(
                    syslog_config['server2_ip'])

        self.vcns.update_edge_syslog(edge_id, request)

        # update log level for routing in separate API call
        if loglevel:
            edge_utils.update_edge_loglevel(self.vcns, edge_id,
                                            'routing', loglevel)
Exemple #2
0
def change_edge_loglevel(properties):
    """Update log level on edge

    Update log level either for specific module or for all modules.
    'none' disables logging, any other level enables logging
    Returns True if found any log level properties (regardless if action
    succeeded)
    """

    modules = {}
    if properties.get('log-level'):
        level = properties.get('log-level')
        # change log level for all modules
        modules = {k: level for k in edge_utils.SUPPORTED_EDGE_LOG_MODULES}
    else:
        # check for log level settings for specific modules
        for k, v in properties.items():
            if k.endswith('-log-level'):
                module = k[:-10]  # module is in parameter prefix
                modules[module] = v

    if not modules:
        # no log level properties
        return False

    edge_id = properties.get('edge-id')

    for module, level in modules.items():
        if level == 'none':
            LOG.info("Disabling logging for %s", module)
        else:
            LOG.info("Enabling logging for %(m)s with level %(l)s", {
                'm': module,
                'l': level
            })
        try:
            edge_utils.update_edge_loglevel(nsxv, edge_id, module, level)

        except nsxv_exceptions.ResourceNotFound as e:
            LOG.error("Edge %s not found", edge_id)
        except exceptions.NeutronException as e:
            LOG.error("%s", str(e))

    # take ownership for properties
    return True
Exemple #3
0
def change_edge_loglevel(properties):
    """Update log level on edge

    Update log level either for specific module or for all modules.
    'none' disables logging, any other level enables logging
    Returns True if found any log level properties (regardless if action
    succeeded)
    """

    modules = {}
    if properties.get('log-level'):
        level = properties.get('log-level')
        # change log level for all modules
        modules = {k: level for k in edge_utils.SUPPORTED_EDGE_LOG_MODULES}
    else:
        # check for log level settings for specific modules
        for k, v in properties.items():
            if k.endswith('-log-level'):
                module = k[:-10]   # module is in parameter prefix
                modules[module] = v

    if not modules:
        # no log level properties
        return False

    edge_id = properties.get('edge-id')

    for module, level in modules.items():
        if level == 'none':
            LOG.info("Disabling logging for %s", module)
        else:
            LOG.info("Enabling logging for %(m)s with level %(l)s",
                    {'m': module, 'l': level})
        try:
            edge_utils.update_edge_loglevel(nsxv, edge_id, module, level)

        except nsxv_exceptions.ResourceNotFound as e:
            LOG.error("Edge %s not found", edge_id)
        except exceptions.NeutronException as e:
            LOG.error("%s", str(e))

    # take ownership for properties
    return True
    def update_edge_syslog(self, edge_id, syslog_config, router_id):
        if 'server_ip' not in syslog_config:
            LOG.warning("Server IP missing in syslog config for %s", router_id)
            return

        protocol = syslog_config.get('protocol', 'tcp')
        if protocol not in ['tcp', 'udp']:
            LOG.warning("Invalid protocol in syslog config for %s", router_id)
            return

        loglevel = syslog_config.get('log_level')
        if loglevel and loglevel not in edge_utils.SUPPORTED_EDGE_LOG_LEVELS:
            LOG.warning("Invalid loglevel in syslog config for %s", router_id)
            return

        server_ip = syslog_config['server_ip']
        request = {
            'featureType': 'syslog',
            'protocol': protocol,
            'serverAddresses': {
                'ipAddress': [server_ip],
                'type': 'IpAddressesDto'
            }
        }

        # edge allows up to 2 syslog servers
        if 'server2_ip' in syslog_config:
            request['serverAddresses']['ipAddress'].append(
                syslog_config['server2_ip'])

        self.vcns.update_edge_syslog(edge_id, request)

        # update log level for routing in separate API call
        if loglevel:
            edge_utils.update_edge_loglevel(self.vcns, edge_id, 'routing',
                                            loglevel)