예제 #1
0
def apply(desired_state, verify_change=True, commit=True, rollback_timeout=60):
    """
    Apply the desired state

    :param verify_change: Check if the outcome state matches the desired state
        and rollback if not.
    :param commit: Commit the changes after verification if the state matches.
    :param rollback_timeout: Revert the changes if they are not commited within
        this timeout (specified in seconds).
    :type verify_change: bool
    :type commit: bool
    :type rollback_timeout: int (seconds)
    :returns: Checkpoint identifier
    :rtype: str
    """
    desired_state = copy.deepcopy(desired_state)
    validator.validate(desired_state)
    validator.validate_capabilities(desired_state, netinfo.capabilities())
    validator.validate_dhcp(desired_state)
    validator.validate_dns(desired_state)

    checkpoint = _apply_ifaces_state(
        state.State(desired_state), verify_change, commit, rollback_timeout
    )
    if checkpoint:
        return str(checkpoint.dbuspath)
예제 #2
0
파일: netinfo.py 프로젝트: oshoval/nmstate
def show(include_status_data=False):
    """
    Reports configuration and status data on the system.
    Configuration data is the set of writable data which can change the system
    state.
    Status data is the additional data which is not configuration data,
    including read-only and statistics information.
    When include_status_data is set, both are reported, otherwise only the
    configuration data is reported.
    """
    client = nm.nmclient.client(refresh=True)

    report = {Constants.INTERFACES: interfaces()}
    if include_status_data:
        report['capabilities'] = capabilities()

    report[Constants.ROUTES] = {
        Route.RUNNING: (
            nm.ipv4.get_route_running() + nm.ipv6.get_route_running()
        ),
        Route.CONFIG: (
            nm.ipv4.get_route_config() + nm.ipv6.get_route_config()
        ),
    }

    report[Constants.DNS] = {
        DNS.RUNNING: nm_dns.get_running(),
        DNS.CONFIG: nm_dns.get_config(
            nm.ipv4.acs_and_ip_profiles(client),
            nm.ipv6.acs_and_ip_profiles(client),
        ),
    }

    validator.validate(report)
    return report