示例#1
0
文件: bridge.py 项目: tyll/nmstate
def _get_bridge_setting(context, nmdev):
    bridge_setting = None
    bridge_con_profile = connection.ConnectionProfile(context)
    bridge_con_profile.import_by_device(nmdev)
    if bridge_con_profile.profile:
        bridge_setting = bridge_con_profile.profile.get_setting_bridge()
    return bridge_setting
示例#2
0
def test_clear_route(nm_ip, routes, client_mock):
    setting_ip = nm_ip.create_setting(
        {InterfaceIP.ENABLED: True, BaseIface.ROUTES_METADATA: routes},
        base_con_profile=None,
    )
    con_profile = nm_connection.ConnectionProfile(client_mock)
    con_profile.create([setting_ip])
    new_setting_ip = nm_ip.create_setting(
        {InterfaceIP.ENABLED: True, BaseIface.ROUTES_METADATA: []},
        base_con_profile=con_profile.profile,
    )
    assert not [_nm_route_to_dict(r) for r in new_setting_ip.props.routes]
示例#3
0
def test_clear_route(nm_ip, routes):
    setting_ip = nm_ip.create_setting(
        {InterfaceIP.ENABLED: True, metadata.ROUTES: routes},
        base_con_profile=None,
    )
    con_profile = nm_connection.ConnectionProfile()
    con_profile.create([setting_ip])
    new_setting_ip = nm_ip.create_setting(
        {InterfaceIP.ENABLED: True, metadata.ROUTES: []},
        base_con_profile=con_profile.profile,
    )
    assert not [_nm_route_to_dict(r) for r in new_setting_ip.props.routes]
示例#4
0
def test_clear_gateway(nm_ip, routes, gateways):
    setting_ip = nm_ip.create_setting(
        {InterfaceIP.ENABLED: True, metadata.ROUTES: routes + gateways[:1]},
        base_con_profile=None,
    )
    con_profile = nm_connection.ConnectionProfile()
    con_profile.create([setting_ip])
    setting_ip = nm_ip.create_setting(
        {InterfaceIP.ENABLED: True, metadata.ROUTES: routes},
        base_con_profile=con_profile.profile,
    )
    assert [_nm_route_to_dict(r) for r in setting_ip.props.routes] == routes
    assert not setting_ip.get_gateway()
    assert setting_ip.get_route_table() == Route.USE_DEFAULT_ROUTE_TABLE
    assert setting_ip.props.route_metric == Route.USE_DEFAULT_METRIC
示例#5
0
def test_clear_dns(nm_ip, get_test_dns_func):
    dns_conf = get_test_dns_func()
    setting_ip = nm_ip.create_setting(
        {
            'enabled': True,
            nm_dns.DNS_METADATA: dns_conf
        },
        base_con_profile=None)
    con_profile = nm_connection.ConnectionProfile()
    con_profile.create([setting_ip])
    new_setting_ip = nm_ip.create_setting(
        {
            'enabled': True,
            nm_dns.DNS_METADATA: {}
        },
        base_con_profile=con_profile.profile,
    )

    _assert_dns(new_setting_ip, {})
示例#6
0
文件: lldp.py 项目: tyll/nmstate
def _get_lldp_status(nm_client, nmdev):
    """
    Default means NM global config file value which is by default disabled.
    According to NM folks, there is no way from libnm to know if lldp is
    enable or not with libnm if the value in the profile is default.
    Therefore, the best option is to force the users to enable it explicitly.
    This is going to be solved by a property in the NM.Device object to know if
    the device is listening on LLDP.

    Ref: https://bugzilla.redhat.com/1832273
    """
    lldp_status = None
    con_profile = connection.ConnectionProfile(nm_client)
    con_profile.import_by_device(nmdev)
    if con_profile.profile:
        con_setting = con_profile.profile.get_setting_connection()
        if con_setting:
            lldp_status = con_setting.get_lldp()

    return lldp_status
示例#7
0
def _get_destination_port(device):
    """
    Retrieve the destination port.

    The destination port is retrieved from the profile settings instead
    of the device (which represents the kernel state)
    due to an existing issue [1].

    [1] https://bugzilla.redhat.com/show_bug.cgi?id=1768388
    """
    if nm.nmclient.nm_version() >= StrictVersion("1.20.6"):
        return device.get_dst_port()
    else:
        con = connection.ConnectionProfile()
        con.import_by_device(device)
        if con.profile:
            vxlan_settings = con.profile.get_setting_vxlan()
            if vxlan_settings:
                return vxlan_settings.get_destination_port()
    return 0
示例#8
0
文件: dns_test.py 项目: tyll/nmstate
def test_clear_dns(client_mock, nm_ip, get_test_dns_func):
    dns_conf = get_test_dns_func()
    setting_ip = nm_ip.create_setting(
        {
            InterfaceIP.ENABLED: True,
            BaseIface.DNS_METADATA: dns_conf
        },
        base_con_profile=None,
    )
    con_profile = nm_connection.ConnectionProfile(client_mock)
    con_profile.create([setting_ip])
    new_setting_ip = nm_ip.create_setting(
        {
            InterfaceIP.ENABLED: True,
            BaseIface.DNS_METADATA: {}
        },
        base_con_profile=con_profile.profile,
    )

    _assert_dns(new_setting_ip, {})
示例#9
0
 def _check_rollback_result(self, client, result, dbus_path):
     ret = client.checkpoint_rollback_finish(result)
     logging.debug(f"Checkpoint {dbus_path} rollback executed")
     for path in ret:
         nm_dev = client.get_device_by_path(path)
         iface = path if nm_dev is None else nm_dev.get_iface()
         if nm_dev and (
             (nm_dev.get_state_reason()
              == common.NM.DeviceStateReason.NEW_ACTIVATION)
                 or nm_dev.get_state() == common.NM.DeviceState.IP_CONFIG):
             nm_ac = nm_dev.get_active_connection()
             if not is_activated(nm_ac, nm_dev):
                 profile = connection.ConnectionProfile(self._ctx)
                 profile.nmdevice = nm_dev
                 action = f"Waiting for rolling back {iface}"
                 self._ctx.register_async(action)
                 profile.wait_dev_activation(action)
         if ret[path] != 0:
             logging.error(f"Interface {iface} rollback failed")
         else:
             logging.debug(f"Interface {iface} rollback succeeded")
示例#10
0
def get_info(device):
    """
    Get description from user settings for a connection
    """
    info = {}

    connection = nm_connection.ConnectionProfile()
    connection.import_by_device(device)
    if not connection.profile:
        return info

    try:
        user_setting = connection.profile.get_setting_by_name(
            nmclient.NM.SETTING_USER_SETTING_NAME)
        description = user_setting.get_data(NMSTATE_DESCRIPTION)
        if description:
            info["description"] = description
    except AttributeError:
        pass

    return info
示例#11
0
def get_info(device):
    """
    Provide the current active teamd values for an interface.
    Ref: https://bugzilla.redhat.com/1792232
    """
    info = {}

    connection = nm_connection.ConnectionProfile()
    connection.import_by_device(device)
    if not connection.profile:
        return info

    team_setting = connection.profile.get_setting_by_name(
        nmclient.NM.SETTING_TEAM_SETTING_NAME)

    if team_setting:
        teamd_json = team_setting.get_config()
        if teamd_json:
            teamd_config = json.loads(teamd_json)
            team_config = _convert_teamd_config_to_nmstate_config(teamd_config)
            info[Team.CONFIG_SUBTREE] = team_config

    return info