Skip to content

Commit

Permalink
Merge 1033e81 into 58daf40
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Sep 20, 2019
2 parents 58daf40 + 1033e81 commit 69d41db
Show file tree
Hide file tree
Showing 424 changed files with 20,509 additions and 8,913 deletions.
27 changes: 25 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
# Copyright (c) [2019] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "yast/rake"

Yast::Tasks.configuration do |conf|
# lets ignore license check for now
conf.skip_license_check << /.*/
conf.skip_license_check << /doc\//
conf.skip_license_check << /test\/data/
conf.skip_license_check << /\.desktop$/
conf.skip_license_check << /\.rnc$/
# ensure we are not getting worse with documentation
conf.documentation_minimal = 61 if conf.respond_to?(:documentation_minimal=)
end
113 changes: 94 additions & 19 deletions doc/network-ng.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
This document tries to describe the details of the network-ng data model and how all the pieces are
combined.

## Overall Approach
## Data Model

### Overall Approach

{Y2Network::Config} and other associated classes represent the network configuration in a backend
agnostic way. It should not matter whether you are using `sysconfig` files, NetworkManager or
Expand All @@ -25,7 +27,7 @@ filesystem by using a *configuration writer*.
Obviously, we should implement configuration readers and writers for whathever backend we would like
to support. At this point of time, only `Sysconfig` and `Autoinst` are supported.

## The Configuration Classes
### The Configuration Classes

{Y2Network::Config} offers and API to deal with network configuration, but it collaborates with
other classes.
Expand All @@ -38,31 +40,77 @@ other classes.
Currently it is bound to an interface name, but we plan to provide more advanced matchers.
* {Y2Network::Routing}: holds routing information, including IP forwarding settings, routing tables, etc.

## Backend Support
### Multi-Backend Support

As mentioned above, Y2Network is designed to support different backends. It is expected to implement
a reader and a writer for each backend (except for AutoYaST, which is an special case). The reader
will be responsible for checking the system's configuration and building a {Y2Network::Config}
object, containing interfaces, configurations, routes, etc. On the other hand, the writer will be
responsible for updating the system using that configuration object.

As a developer, you rarely will need to access to readers/writers because `Yast::Lan` already offers
an API to read and write the configuration. See the [Accessing the
Configuration](#accessing-the-configuration) section for further details.

In order to support a new backend, we need to implement a configuration readers and writers. The
{Y2Network::Sysconfig} module implements support to deal with `sysconfig` files.
#### Sysconfig

The sysconfig backend support is composed by these files:

src/lib/y2network/sysconfig
├── config_reader.rb <- READER
├── config_writer.rb <- WRITER
├── connection_config_reader_handlers
│ ├── eth.rb
│ ├── wlan.rb
│ └── ...
├── connection_config_reader.rb
├── connection_config_readers
│   ├── ethernet.rb
│   ├── wireless.rb
│ └── ...
├── connection_config_writer.rb
├── connection_config_writers
│   ├── ethernet.rb
│   ├── wireless.rb
│ └── ...
├── dns_reader.rb
├── dns_writer.rb
├── interface_file.rb
├── interfaces_reader.rb
├── interfaces_writer.rb
└── routes_file.rb

As you can see, there are many classes, but the relevant ones are just `ConfigReader` and `ConfigWriter`.
{Y2Network::Sysconfig::ConfigReader} and {Y2Network::Sysconfig::ConfigWriter} are the reader and
writer classes. Each of them cooperates with a set of ancillary classes in order to get the job
done.

{Y2Network::Sysconfig::DNSReader}, {Y2Network::Sysconfig::InterfacesReader} and
{Y2Network::Sysconfig::ConnectionConfigReader} are involved in reading the configuration. The logic
to read the configuration for a connection (e.g., `ifcfg-eth0`, `ifcfg-wlan0`, etc.) is implemented
in a set of smaller classes (one for each time of connection) under
{Y2Network::Sysconfig::ConnectionConfigReaders}.

{Y2Network::Sysconfig::DNSWriter} and {Y2Network::Sysconfig::ConnectionConfigWriter}, including
smaller classes under {Y2Network::Sysconfig::ConnectionConfigWriters}, are involved in writing the
configuration. In this case, it does not exist a `InterfacesWriter` class, because when it comes to
interfaces the configuration is handled through connection configuration files.

## Accessing the Configuration
Last but not least, there are additional classes like {Y2Network::Sysconfig::RoutesFile} and
{Y2Network::Sysconfig::InterfaceFile} which abstract the details of reading/writing `ifcfg` files.

The `Yast::Lan` module is still the entry point to read and write the network configuration. Basically, it keeps two configuration objects, one for the running system and another want for the wanted configuration.
#### AutoYaST

AutoYaST is a special case in the sense that it reads the information from a profile, instead of
using the running system as reference. Additionally, it does not implement a writer because the
configuration will be written using a different backend (like sysconfig).

src/lib/y2network/autoinst/
├── config_reader.rb
├── dns_reader.rb
└── routing_reader.rb

For the time being, it only implements support to read DNS and routing information.

### Accessing the Configuration

The `Yast::Lan` module is still the entry point to read and write the network configuration.
Basically, it keeps two configuration objects, one for the running system and another want for the
wanted configuration.

Yast.import "Lan"
Yast::Lan.read(:cache)
Expand All @@ -78,20 +126,41 @@ The `Yast::Lan` module is still the entry point to read and write the network co
Any change you want to apply to the running system should be performed by modifying the
`yast_config` and writing the changes.

## AutoYaST Support
## New UI layer

### Interface Configuration Builders

In the old code, there was no clear separation between UI and business logic. In order to improve
the situation, we introduced the concept of [interface configuration
builders](https://github.com/yast/yast-network/blob/network-ng/src/lib/y2network/interface_config_builder.rb).

We already have implemented support for several interface types. You can find them under the
[Y2Network::InterfaceConfigBuilders
namespace](https://github.com/yast/yast-network/tree/843f75bfdb71d4026b3f97facf18eece479b8a0e/src/lib/y2network/interface_config_builders).

AutoYaST is somehow and special case, as the configuration is read from the profile instead of the
running system. So in this scenario, YaST2 Network will read the configuration using the `Autoinst`
reader and will write it to the final system using the one corresponding to the wanted backend.
### Widgets

The user interaction is driven by a set of sequences, which determine which dialogs are shown to the
user. Each of those dialogs contain a set of widgets, usually grouped in tabs. The content of the
dialog depends on the interface type.

Below you can find some pointers to relevant sequences, dialogs and widgets:

* Sequences:
* [Sequences::Interface](https://github.com/yast/yast-network/blob/358bcd13b4e92e7c4e9c0e477c83196ca67b578e/src/lib/y2network/sequences/interface.rb)
* Dialogs:
* [Dialogs::AddInterface](https://github.com/yast/yast-network/blob/358bcd13b4e92e7c4e9c0e477c83196ca67b578e/src/lib/y2network/dialogs/add_interface.rb)
* [Dialogs::EditInterface](https://github.com/yast/yast-network/blob/358bcd13b4e92e7c4e9c0e477c83196ca67b578e/src/lib/y2network/dialogs/edit_interface.rb)
* [Y2Network::Widgets](https://github.com/yast/yast-network/tree/358bcd13b4e92e7c4e9c0e477c83196ca67b578e/src/lib/y2network/widgets)

## Current Status

### Reading/Writing Interfaces

| Interface type | read | write |
|-----------------|------|-------|
| Ethernet || |
| Wireless || |
| Ethernet || |
| Wireless || |
| InfiniBand || |
| Bridge || |
| Bonding | | |
Expand All @@ -101,3 +170,9 @@ reader and will write it to the final system using the one corresponding to the
| USB | | |
| Dummy | | |
| s390 types | | |

## (Short Term) Plan

- [ ] Finish reading/writing interfaces
- [ ] Move missing UI logic to interface configuration builders
- [ ] Replace LanItems with the new data model
19 changes: 19 additions & 0 deletions examples/connection.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# Copyright (c) [2019] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "yast"
require "y2network/config"
require "y2network/virtual_interface"
Expand Down
1 change: 1 addition & 0 deletions src/autoyast-rnc/networking.rnc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ device =
element type { text }? &
element layer2 { BOOLEAN}? &
element chanids { text }? &
# ignored, present for backward compatibility
element portname { text }? &
element protocol { text }? &
element router { text }?
Expand Down
61 changes: 6 additions & 55 deletions src/clients/lan_auto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ def main
elsif @func == "Packages"
@ret = Lan.AutoPackages
elsif @func == "SetModified"
@ret = LanItems.SetModified
@ret = Lan.SetModified
elsif @func == "GetModified"
@ret = LanItems.GetModified
@ret = Lan.Modified
elsif @func == "Export"
@settings2 = Lan.Export
Builtins.y2debug("settings: %1", @settings2)
Expand Down Expand Up @@ -133,66 +133,17 @@ def main
# @return [Hash] autoyast network settings
def ToAY(settings)
settings = deep_copy(settings)
interfaces = []
discard = ["UDI", "_nm_name"]
Builtins.foreach(Ops.get_map(settings, "devices", {})) do |_type, devsmap|
Builtins.foreach(
Convert.convert(devsmap, from: "map", to: "map <string, map>")
) do |device, devmap|
newmap = {}
Builtins.foreach(
Convert.convert(devmap, from: "map", to: "map <string, any>")
) do |key, val|
Builtins.y2milestone("Adding: %1=%2", key, val)
if key != "_aliases"
if Ops.greater_than(Builtins.size(Convert.to_string(val)), 0) &&
!Builtins.contains(discard, key) &&
!Builtins.contains(discard, Builtins.tolower(key))
Ops.set(newmap, Builtins.tolower(key), Convert.to_string(val))
end
else
# handle aliases
Builtins.y2debug("val: %1", val)
# if aliases are empty, then ommit it
if Ops.greater_than(Builtins.size(Convert.to_map(val)), 0)
# replace key "0" into "alias0" (bnc#372678)
Builtins.foreach(
Convert.convert(
val,
from: "any",
to: "map <string, map <string, any>>"
)
) do |k, v|
Ops.set(
newmap,
Builtins.tolower("aliases"),
Builtins.add(
Ops.get_map(newmap, Builtins.tolower("aliases"), {}),
Builtins.sformat("alias%1", k),
v
)
)
end
end
end
end
newmap["device"] = device
interfaces = Builtins.add(interfaces, newmap)
end
end
interfaces = settings["interfaces"] || []
Builtins.y2milestone("interfaces: #{interfaces.inspect})")
net_udev = settings["net-udev"] || []
Builtins.y2milestone("net-udev: #{net_udev.inspect})")

# Modules

s390_devices = []
Builtins.foreach(Ops.get_map(settings, "s390-devices", {})) do |_device, mod|
s390_devices = Builtins.add(s390_devices, mod)
end

net_udev = []
Builtins.foreach(Ops.get_map(settings, "net-udev", {})) do |_device, mod|
net_udev = Builtins.add(net_udev, mod)
end

modules = []
Builtins.foreach(Ops.get_map(settings, "hwcfg", {})) do |device, mod|
newmap = {}
Expand Down
41 changes: 18 additions & 23 deletions src/include/network/summary.rb → src/clients/lan_export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,28 @@
# you may find current contact information at www.novell.com
#
# **************************************************************************
# File: include/network/summary.ycp
# Package: Network configuration
# Summary: Summary and overview functions
# Authors: Michal Svec <msvec@suse.cz>
#
#
# All config settings are stored in a global variable Devices.
# All hardware settings are stored in a global variable Hardware.
# Deleted devices are in the global list DELETED.

require "yaml"

module Yast
module NetworkSummaryInclude
def initialize_network_summary(_include_target)
# Client for testing autoyast export and writes result to /tmp/test.yaml
# DEVELOPMENT ONLY, not for production use
class LanExportClient < Client
def main
Yast.import "UI"

textdomain "network"

Yast.import "String"
Yast.import "NetworkInterfaces"
end
# Open Trivial UI to get error messages
Yast::UI.OpenDialog(Yast::Term.new(:PushButton, "Test"))
WFM.CallFunction("lan_auto", ["Read"])
res = WFM.CallFunction("lan_auto", ["Export"])
File.write("/tmp/test.yaml", res.to_yaml)
Yast::UI.CloseDialog

# Create list of Table items
# @param [Array<String>] types list of types
# @param [String] cur current type
# @return Table items
def BuildTypesList(types, cur)
types = deep_copy(types)
Builtins.maplist(types) do |t|
Item(Id(t), NetworkInterfaces.GetDevTypeDescription(t, false), t == cur)
end
nil
end
end
end

Yast::LanExportClient.new.main
11 changes: 0 additions & 11 deletions src/data/network/s390_defaults.yml

This file was deleted.

0 comments on commit 69d41db

Please sign in to comment.