MCPcopy
hub / github.com/cockpit-project/cockpit / settings_from_nm

Function settings_from_nm

pkg/networkmanager/interfaces.js:507–637  ·  view source on GitHub ↗
(settings)

Source from the content-addressed store, hash-verified

505 }
506
507 function settings_from_nm(settings) {
508 function get(first, second, def) {
509 if (settings[first] && settings[first][second])
510 return settings[first][second].v;
511 else
512 return def;
513 }
514
515 function get_ip(first, ip_to_text) {
516 const dns_data = self.supports_dns_data
517 ? get(first, "dns-data", [])
518 : get(first, "dns", []).map(ip_to_text);
519
520 return {
521 method: get(first, "method", "auto"),
522 ignore_auto_dns: get(first, "ignore-auto-dns", false),
523 ignore_auto_routes: get(first, "ignore-auto-routes", false),
524 address_data: get(first, "address-data", []).map(ip_address_from_nm),
525 gateway: get(first, "gateway", ""),
526 dns_data,
527 dns_search: get(first, "dns-search", []),
528 route_data: get(first, "route-data", []).map(route_from_nm),
529 };
530 }
531
532 const result = {
533 connection: {
534 type: get("connection", "type"),
535 uuid: get("connection", "uuid"),
536 interface_name: get("connection", "interface-name"),
537 timestamp: get("connection", "timestamp", 0),
538 id: get("connection", "id", _("Unknown")),
539 autoconnect: get("connection", "autoconnect", true),
540 autoconnect_priority: get("connection", "autoconnect-priority", 0),
541 autoconnect_members:
542 get("connection", "autoconnect-slaves", -1),
543 member_type: get("connection", "slave-type"),
544 group: get("connection", "master"),
545 multi_connect: get("connection", "multi-connect"),
546 }
547 };
548
549 if (!settings.connection.master) {
550 result.ipv4 = get_ip("ipv4", utils.ip4_to_text);
551 result.ipv6 = get_ip("ipv6", utils.ip6_to_text);
552 }
553
554 if (settings["802-3-ethernet"]) {
555 result.ethernet = {
556 mtu: get("802-3-ethernet", "mtu"),
557 assigned_mac_address: get("802-3-ethernet", "assigned-mac-address")
558 };
559 }
560
561 if (settings.bond) {
562 /* Options are documented as part of the Linux bonding driver.
563 https://www.kernel.org/doc/Documentation/networking/bonding.txt
564 */

Callers 1

refresh_settingsFunction · 0.85

Calls 4

get_ipFunction · 0.85
JSON_parse_carefullyFunction · 0.85
getFunction · 0.70
mapMethod · 0.45

Tested by

no test coverage detected