Exemple #1
0
def _write_config(server, state):
    """Write the configuration file."""
    dhcpd_config, interfaces_config = state.get_config(server)
    try:
        sudo_write_file(server.config_filename,
                        dhcpd_config.encode("utf-8"),
                        mode=0o640)
        sudo_write_file(
            server.interfaces_filename,
            interfaces_config.encode("utf-8"),
            mode=0o640,
        )
    except ExternalProcessError as e:
        # ExternalProcessError.__str__ contains a generic failure message
        # as well as the command and its error output. On the other hand,
        # ExternalProcessError.output_as_unicode contains just the error
        # output which is probably the best information on what went wrong.
        # Log the full error information, but keep the exception message
        # short and to the point.
        maaslog.error(
            "Could not rewrite %s server configuration (for network "
            "interfaces %s): %s",
            server.descriptive_name,
            interfaces_config,
            str(e),
        )
        raise CannotConfigureDHCP(
            "Could not rewrite %s server configuration: %s" %
            (server.descriptive_name, e.output_as_unicode))
Exemple #2
0
 def eb(failure):
     message = "%s server failed to %s: %s" % (server.descriptive_name,
                                               action, failure.value)
     # A ServiceActionError will have already been logged by the
     # service monitor, so don't log a second time.
     if not failure.check(ServiceActionError):
         maaslog.error(message)
     # Squash everything into CannotConfigureDHCP.
     raise CannotConfigureDHCP(message) from failure.value