Repository navigation
Add guest network IP configuration API for NETH interfaces - #989
Conversation
0262afa to
26f848c
Compare
| if len(net_conf_files) > 0: | ||
| path_contents.extend(net_conf_files) | ||
|
|
||
| for (path, contents) in path_contents: |
There was a problem hiding this comment.
Nit: this loop (path_contents → files_map → _add_file/_add_yaml_file), plus the _create_invokeScript/_create_network_doscript calls after it, matches _generate_network_doscript (lines 180–195) line for line. Could it move into a small shared helper? Then a later fix to one copy, such as the 'yaml' in path check, can't miss the other.
Related, also minor: one request calls parse_dist three times. There's the rhel10 check at line 325, and get_linux_dist runs it again at lines 390 and 395. Building linuxdist once in zdirect_network_configuration and passing it down would remove the repeats.
Generated by Claude Code
| # ifcfg files, cloud-init netplan files, etc.) untouched. | ||
| clean_cmd = '' | ||
| if first: | ||
| clean_cmd = linuxdist._get_neth_clean_command(intf_name) |
There was a problem hiding this comment.
Nit: _get_neth_clean_command only removes the file that _create_invokeScript overwrites right after with cat <src> > <target>, so the rm -f adds nothing. It also works against the comment in _create_invokeScript ("using cat does not change the target file selinux file type"): once the file is deleted first, the new one no longer keeps the original SELinux label.
Dropping the clean step would also remove the three _get_neth_clean_command methods in dist.py (base, ubuntu, ubuntu20). Each of them repeats the filename logic from the matching get_neth_cfg, so the two can drift apart.
Generated by Claude Code
| else: | ||
| cidr_prefix = '' | ||
| if network.get('cidr') and '/' in network['cidr']: | ||
| cidr_prefix = network['cidr'].split('/')[1] |
There was a problem hiding this comment.
Nit: _parse_neth_params already parses the CIDR with netaddr.IPNetwork. It could return ip_net.prefixlen, and this would no longer need to split the string again. Similarly, the ip_addr/cidr presence check in _parse_neth_params (line 283) repeats what _validate_guest_network(require_ip=True) already enforces, with a different error message. (The SLES DNS re-check in get_neth_dns_cmd is fine to keep, since that value goes into a root shell command.)
Generated by Claude Code
| Find the network interface name configured on the PCI device (Network | ||
| Express adapter) assigned to the instance userid. | ||
|
|
||
| Two-step approach inside the guest (via IUCV): |
There was a problem hiding this comment.
The docstring describes a two-step lspci -D + domain-match approach, but the code scans /sys/bus/pci/devices/*/function_id. Could the docstring be updated to match? The example output "enc1600" (line 739) is also a CCW-style name, while NETH interfaces get PCI-style names.
Generated by Claude Code
| pcif_function: | ||
| description: | | ||
| PCI function ID of the Network Express (NETH) adapter attached to the | ||
| guest, as an 8-character hexadecimal string, e.g. ``00000110``. The |
There was a problem hiding this comment.
This says "8-character hexadecimal string", but all three validators accept 1–8 hex digits (parameter_types.py:308, api.py:2373, getVM.py:746). Maybe "up to 8 hexadecimal digits"? The same regex is also defined in those three places, so a shared constant would keep them from drifting.
Generated by Claude Code
There was a problem hiding this comment.
added the constant variable and used in in api.py and getVM.py. We are not using any constants in the parameters_type.yaml file, hence i have not added in parameters_types.yaml
26f848c to
d4e61dc
Compare
There was a problem hiding this comment.
Eric
Thank you. An extension of the Feilong API is always nice.
I asked Claude for another detailed review. It came back with design questions (including about the Linux distributions), and a list of small suggestions (see below).
Claude, prompted by Eric
I reviewed the current head of the branch (07e4e30), and compared it with the head I reviewed in #970 (cfbfdb6) and with the head Rajat reviewed here (26f848c).
Thanks a lot for the rework! This is a big step forward: there is now a PR description, one writer per distribution, a single network per call, an exact PCIF match through sysfs, a factored input validation, documentation and many unit tests. The remaining points are mostly questions about distribution behaviour, plus a few small items.
tox -e pep8 passes. Unit tests with Python 3.13: zvmsdk/tests/unit runs 1106 tests on master and 1144 on this branch, all OK. smtLayer/tests/unit runs 197 tests on master and 205 on this branch, all OK. No new failure.
Previous remarks (my review of #970)
| Previous remark | Status |
|---|---|
Bug 1: posOpsList in smtLayer/getVM.py turned into a tuple, which broke FCPINFO |
Fixed, and covered by test_parseCmdline_fcpinfo_populates_status |
Bug 2: rm -f .../ifcfg-en* removed too many files |
Fixed: the clean step is gone |
Bug 3: KeyError with DHCP or missing optional fields |
Fixed in LinuxDist._parse_neth_params(), with DHCP and minimal tests |
| Bug 4: only the last network was written | Fixed by design: the API now takes one guest_network dict |
Bug 5: pcif not required in the REST schema |
Fixed, with test_guest_configure_network_interface_ip_missing_pcif |
| Bug 6: substring match on the PCI address | Fixed: exact match on /sys/bus/pci/devices/*/function_id (see question 4 below) |
Design 1: only RHEL ≤ 8 file format, os_version unused |
Mostly fixed: RHEL, SLES, Ubuntu 16 and netplan writers, RHEL 10 and RHCOS rejected. Some questions remain (points 1 to 3 below) |
| Design 2: unconditional reboot | Fixed: reboot only with active=True, and documented |
| Design 3: copy/pasted validation with wrong API name | Fixed: SDKAPI._validate_guest_network() with api_name and require_ip |
| Tests: none | Fixed: 38 new tests in zvmsdk, 8 in smtLayer (two small gaps, see point 7) |
| Documentation: none | Mostly fixed: restapi.rst, parameters.yaml, errcode.csv and the .tpl sample (a few additions suggested in point 9) |
| PR description: missing | Fixed (it is slightly outdated now, see point 9) |
I also went through Rajat's remarks on #970 and here. Almost all of them are addressed: args_required is 4, RHCOS raises an explicit error, the .tpl uses true, no bare mtu line, netplan uses routes and an integer mtu, DNS is written on RHEL and through NETCONFIG_DNS_STATIC_SERVERS on SLES, ip_addr is only required by the new API (require_ip=True), no f-strings or annotations, the clean step is dropped, prefixlen comes from _parse_neth_params(), the getNethIntInfo() docstring is updated, and the shared _bundle_network_doscript() helper exists. Two of them are still open, see points 5 and 7.
Questions about distributions
- SLES default gateway
sles.get_neth_cfg() in zvmsdk/dist.py writes GATEWAY='...' into the ifcfg file. The existing SLES code does not do that: it writes the default route into a route file (sles._get_route_str(), default <gw> - -). Does wicked honour GATEWAY= in an ifcfg file? If not, a static NETH interface on SLES gets no default route after the reboot. Writing /etc/sysconfig/network/ifroute-<intf> would follow the existing code.
NETTYPE="NETH"
Both rhel.get_neth_cfg() and sles.get_neth_cfg() write NETTYPE with the value NETH. As far as I understand, NETTYPE is meant for CCW group devices (qeth, lcs, ctc) together with SUBCHANNELS, and a NETH adapter is a PCI device. Is NETH a value that the s390 tools know? If it is ignored, it would be clearer to leave it out; if it triggers something, a comment would help.
- Supported distributions
- RHEL 9: as far as I know, NetworkManager on RHEL 9 still reads ifcfg files, but they are deprecated in favour of keyfiles. Was this tested on RHEL 9? Writing a keyfile into
/etc/NetworkManager/system-connections/would also make RHEL 10 possible, which is now rejected. - The list includes RHEL 6 and 7, SLES 11 and 12, and Ubuntu 16. Do these releases support Network Express adapters at all? If not, I suggest only listing the releases that were actually tested, so that users are not misled.
- SLES 16 (NetworkManager, no wicked) is rejected implicitly by
LinuxDistManager.parse_dist()with "Can not handle os". That is fine, but it may be worth saying in the documentation, since recent hardware will often come with recent distributions. - Ubuntu 16:
ubuntu.get_neth_cfg()writes/etc/network/interfaces.d/<intf>. Is that directory sourced by the default/etc/network/interfacesof the supported images? Anddns-nameserversneeds theresolvconfpackage. - Ubuntu 20+: recent netplan versions warn when a file under
/etc/netplanis readable by everyone._create_invokeScript()creates60-neth-<intf>.yamlwith the default umask. Achmod 600would avoid the warning.
- PCI function ID seen by the guest
getNethIntInfo() in smtLayer/getVM.py compares pcif with function_id in sysfs inside the guest. POST /guests takes pcif as <fid>:<vdev> (see #969: the schema was fixed on master by a38544b, although the issue is still open). Under z/VM, does the guest see the real FID, or the virtual one given as second part? Since the author confirmed it on a device in #970, a short sentence in parameters.yaml (pcif_function) saying which of the two IDs is expected, ideally with a reference to the pcif field of GET /host/pcif, would avoid confusion.
Design questions
net_setside effect
NetworkOPS.zdirect_network_configuration() still calls is_first_network_config() and update_guestdb_with_net_set(). Rajat suggested dropping this in #970, and I did not find an answer. first is not used for anything else in the NETH path, but setting net_set changes what a later guest_create_network_interface() does: on Ubuntu 20+ it then raises "Ubuntu20 is not supported to create interface after VM deployed", and on SLES it appends to the udev and route files instead of writing them. Without the flag, on the other hand, a later first guest_create_network_interface() would run rm -f /etc/netplan/*.yaml on Ubuntu 20+, which removes the NETH file. Could you explain which order of calls is intended, and document the interaction?
- Failure in the middle
When active=True and execute_cmd() fails (for example an IUCV problem), the API raises an error, but the doscript is already in the guest reader, so the configuration may still be applied at the next boot. Similarly, SLES DNS replaces NETCONFIG_DNS_STATIC_SERVERS for the whole guest, not only for the NETH interface (sles.get_neth_dns_cmd()). I think both deserve a sentence in restapi.rst.
Tests
- Two gaps
- The refactoring of
SDKAPI.guest_create_network_interface()changes its validation slightly:dns_addris now checked also for DHCP,mtumust be between 576 and 65535, and DNS entries must bestr. REST clients are protected by the schema already, but Python callers may see new errors. Rajat asked in #970 for a test showing that the old call withoutip_addrstill succeeds; there is still no test ofguest_create_network_interface()inzvmsdk/tests/unit/test_api.py. Could you add one? SMTClient.get_neth_interface_info()(request string and parsing of the response) is always mocked and has no test of its own intest_smtclient.py.
Small points
- Style
parameter_types.network_infohas no'additionalProperties': False, andtest_guest_configure_network_interface_ip_extra_keyschecks on purpose thatnic_idis accepted. Keys likenic_idormac_addrare then silently ignored. I suggest rejecting them, or listing them inguest_network_infoas "accepted and ignored"._bundle_network_doscript()innetworkops.py: theif znetconfig: ... else: ...could be a singleself._create_invokeScript(network_file_path, clean_cmd, files_map, znetconfig=znetconfig)._generate_zdirect_network_doscript()and_create_neth_configuration_files()still accept a string and callget_linux_dist()again. Since the caller now passes the object, that branch could go.parameter_types.neth_pcifduplicatesconstants.NETH_PCIF_PATTERN.parameter_types.pycould simply importzvmsdk.constants.re.fullmatch(),shlex.quote()andisinstance(dns, str)are Python 3 only, whilesetup.pystill lists Python 2.7. Python 2 is long dead, so updating the classifiers in a separate PR may be the simpler answer.- Hardening, optional:
netaddr.valid_ipv4()is strict with netaddr 1.x, but older versions allowed byrequirements.txt(netaddr>=0.7.5) accept for instance'1.2.3.4 $(id)'(I checked with netaddr 0.8.0). Through the Python API, such a value would end up in the generated files. Passingflags=netaddr.INET_PTONin_validate_guest_network()would close that door. The same applies to master's code, so it is not specific to this PR.
Documentation
- Documentation
The new section in doc/source/restapi.rst, the parameters.yaml entries, errcode.csv and the .tpl sample are good. I suggest adding:
- which PCI function ID is expected (point 4), and its relationship with
pcifofPOST /guests(<fid>:<vdev>), which is a different format under the same name; - the z/VM prerequisites for attaching a NETH PCI function (z/VM level, APARs), if any;
- the behaviour on failure and the global SLES DNS change (point 6);
- the interaction with
guest_create_network_interface(point 5); - that
activehere means "reboot the guest", unlikeactiveinPOST /guests/{userid}/interface(the separateactive_flag_rebootentry already says it well; a short warning sentence would make the difference obvious); - the PR description still says that the operation always reboots the guest; it would be nice to update it.
Points 1 (SLES gateway) and 5 (net_set) are the most important; if point 1 turns out to be a real problem, I think it should be fixed before merging.
b5b9b2d to
06221ed
Compare
|
Thank you for the review comments.
Other comments are also fixed and tested |
Bischoff
left a comment
There was a problem hiding this comment.
Eric
Thanks Malar. I offloaded the detailed review work to Claude. I agree with Claude's opinion that none of the remaining points is blocking, but still, having a look seems worth it.
Claude, prompted by Eric
I reviewed the current head of the branch (06221ed), and compared it with the head I reviewed last time (07e4e30).
Thank you for the quick and careful rework, and for testing on RHEL 7, 8, 9, SLES 15 and Ubuntu 20+! Almost all my points are addressed, often with new unit tests. What remains is small: one interaction to document on Ubuntu 20+, one question about the PCI function ID, and a few optional items.
The branch is now a single commit on the same base as before (cae3071). Nothing was lost in the squash: all 21 files of the previous diff are still there (plus test_smtclient.py), no function or test of master disappeared, and the only removed test (test_zdirect_network_configuration_rhel10) became test_zdirect_network_configuration_rhel9_rhel10.
Checks: flake8 (the tox -e pep8 commands) passes. Unit tests with Python 3.13: zvmsdk/tests/unit runs 1106 tests on master and 1160 on this branch, smtLayer/tests/unit 197 and 205, all OK.
Previous remarks
| Previous remark | Status |
|---|---|
| My review of #970 (bugs 1 to 6, designs 2 and 3, tests) | Still fixed after the squash |
| 1. SLES default gateway | Fixed: sles.get_neth_route_files() writes ifroute-<intf> with the existing _get_route_str(), tested (see point 3 below for a small question) |
2. NETTYPE="NETH" |
Fixed: removed for RHEL and SLES |
| 3. RHEL 9 ifcfg files | Fixed: rhel9.get_neth_cfg() writes a NetworkManager keyfile created with mode 0600. RHEL 10 is now accepted too (see point 2 below) |
| 3. Old releases in the list | Fixed in restapi.rst, but still accepted by the code (see point 2 below) |
| 3. SLES 16 | OK: only sles15.x is listed now |
3. Ubuntu 16 interfaces.d / resolvconf |
Out of the documented list now (point 2 below) |
| 3. Netplan file mode | Fixed: ubuntu20.get_neth_file_cmd(), tested |
| 4. PCI function ID seen by the guest | Documented in restapi.rst and parameters.yaml (a question remains, see point 1 below) |
5. net_set side effect |
Fixed: removed from zdirect_network_configuration() |
5. Interaction with guest_create_network_interface |
Documented, but one case is missing on Ubuntu 20+ (point 1 below) |
| 6. Failure in the middle, SLES DNS for the whole guest | Fixed: documented in restapi.rst |
7. Tests of guest_create_network_interface() |
Fixed: 5 new tests in test_api.py, including the old call without ip_addr |
7. Tests of SMTClient.get_neth_interface_info() |
Fixed: 4 new tests in test_smtclient.py |
8. Unknown keys in network_info |
Partly fixed: mac_addr, nic_id and hostname are now validated and documented as ignored, but other unknown keys are still accepted silently (point 4 below) |
8. if znetconfig: ... else: ... |
Fixed |
8. String branch calling get_linux_dist() again |
Fixed |
8. Duplicated neth_pcif regex |
Fixed: parameter_types.py uses constants.NETH_PCIF_PATTERN |
8. Python 3 only code vs Python 2.7 in setup.py |
Not changed; fine for a separate PR |
8. netaddr.valid_ipv4() without INET_PTON |
Not changed; optional, and the same on master |
9. Documentation: PCI function ID, prerequisites, failure, SLES DNS, interaction, active warning |
Fixed: nice new sections in restapi.rst |
| 9. PR description outdated | Still says the guest is always rebooted, and the list of distributions differs from restapi.rst (no rhel10.x) |
Rajat: shared helper, parse_dist called three times |
Fixed: _bundle_network_doscript(), linuxdist built once |
| Rajat: useless clean step | Fixed (already on 07e4e30) |
Rajat: prefixlen from _parse_neth_params() |
Fixed |
Rajat: getNethIntInfo() docstring |
Fixed (but see point 1 below) |
| Rajat: "8-character" and shared regex constant | Fixed: "up to 8 hexadecimal digits", one constant used in the three places |
Remaining points
- Two small documentation questions
- Ubuntu 20+: the new "Relationship with Create network interface" section says that both APIs are independent. Now that
net_setis no longer set, a later firstguest_create_network_interface()on Ubuntu 20+ runs the clean command ofubuntu._get_clean_command(), which isrm -f /etc/netplan/*.yamlwith the file names ofubuntu20, and this also removes60-neth-<intf>.yaml. I suggest one sentence there: on Ubuntu 20+, configure the NETH interface after the virtual NICs, or call this API again afterwards. - PCI function ID: the documentation now says that the guest sees the virtual ID given after
:inPOST /guests, while the docstring ofgetNethIntInfo()insmtLayer/getVM.pyspeaks of the "32-bit hardware function ID". Was this checked on a guest where the real FID and the virtual one differ? If yes, aligning the docstring would avoid confusion.
- Distributions accepted but not listed
restapi.rst no longer lists rhel6.x, sles11.x, sles12.x and ubuntu16.x, but zdirect_network_configuration() still accepts them (only RHCOS is rejected), and ubuntu.get_neth_cfg() is still there. On the other hand, rhel10.x is now listed but was not part of your tests. I suggest either rejecting the untested releases explicitly, like RHCOS, or saying in the documentation which ones were tested.
- SLES: stale route file
sles.get_neth_route_files() writes nothing for DHCP or without a gateway. If a static configuration with a gateway is later replaced by DHCP, the old ifroute-<intf> stays and keeps the old default route. Could the SLES path remove it in that case (for example in get_neth_file_cmd())?
- Unknown keys (optional)
parameter_types.network_info still has no 'additionalProperties': False, so a typo like gateway instead of gateway_addr is silently ignored. Now that the three accepted keys are listed, adding it would be easy.
- Documentation
The documentation is now in good shape. Remaining items: the Ubuntu 20+ sentence and the docstring of point 1, the tested distributions of point 2, and updating the PR description (reboot only with active=true, list of distributions).
None of these points is blocking in my opinion.
Add guest_configure_network_interface_ip (POST /guests/{userid}/interface/ip)
to configure the IP settings of a Network Express (NETH) interface.
- getVM NETHINTERFACEINFO: resolve the interface name from the s390 PCI
function_id in sysfs, validating pcif before it is used in the command
- dist: add get_neth_cfg for rhel, sles, ubuntu16 and ubuntu20+ with shared
parsing in _parse_neth_params; omit empty gateway/broadcast lines
- networkops: zdirect_network_configuration punches the config and
activates it with the distro specific zvmguestconfigure command;
temp folder is always cleaned up
- rhcos is not supported and is rejected with SDKFunctionNotImplementError
- REST client/server, schema, docs and unit tests
Signed-off-by: Malar2703 <ponmalarkaruppasamy@gmail.com>
06221ed to
3924524
Compare
|
Thanks @Bischoff
|
Bischoff
left a comment
There was a problem hiding this comment.
Eric
I offloaded this new review to Claude again. Based on its analysis, I approve the PR, with thanks to your patience.
Still, Claude has a small question/suggestion, that I reproduce here to avoid you searching it:
A small question out of curiosity, not blocking: was the PCI function ID part checked on a guest where the real function ID and the virtual one differ? If not, it might be worth trying once when such a setup is available.
I find that question interesting, and it would be worth having a look.
Claude, prompted by Eric
I reviewed the current head of the branch (d468651), and compared it with the head I reviewed last time (06221ed).
Thank you Malar for addressing every point, including the optional ones, and for adding tests for them! From my side, nothing remains: this PR looks ready to me.
The branch is now commit 3924524, on the same base as before (cae3071), plus a merge of master (653cf6a) without conflicts. Nothing was lost: the diff against master has the same 22 files, and its changed lines are exactly those of 3924524 against its base. No function or test of master disappeared from the changed files. Compared with 06221ed, only 7 files changed (65 lines added, 9 removed), all of them for the points below.
Checks: flake8 (the tox -e pep8 commands) passes. Unit tests with Python 3.13: zvmsdk/tests/unit runs 1163 tests on master and 1219 on this branch, smtLayer/tests/unit 197 and 205, all OK.
Previous remarks
| Previous remark | Status |
|---|---|
1. Ubuntu 20+: a later first guest_create_network_interface() removes 60-neth-<intf>.yaml |
Fixed: one sentence in the "Relationship with Create network interface" section of restapi.rst |
1. PCI function ID: docstring of getNethIntInfo() vs documentation |
Fixed: the docstring and the comment in smtLayer/getVM.py now speak of the function ID as seen by the guest, which can differ from the real one |
2. Distributions accepted but not listed, rhel10.x not tested |
Fixed: a new note in restapi.rst says that rhel10.x is not tested, and that rhel6.x, sles11.x, sles12.x and ubuntu16.x are not supported nor rejected |
3. SLES: stale ifroute-<intf> when going back to DHCP |
Fixed: new sles.get_neth_file_cmd() removes the old ifroute-<intf> before the files are written, with a new test in test_networkops.py |
4. Unknown keys in network_info (optional) |
Fixed: 'additionalProperties': False in parameter_types.network_info, documented in parameters.yaml, with a new test in test_guest.py. Since network_info is only used by the new route, existing clients are not affected |
| 5. PR description | Fixed: reboot only with active=true, and the same list of distributions as restapi.rst |
Python 3 only code vs Python 2.7 in setup.py (optional) |
Not changed; fine for a separate PR |
netaddr.valid_ipv4() without INET_PTON (optional) |
Not changed; optional, and the same on master |
| Rajat's remarks (12/11) | Still fixed |
A small question out of curiosity, not blocking: was the PCI function ID part checked on a guest where the real function ID and the virtual one differ? If not, it might be worth trying once when such a setup is available.
|
@Bischoff |
PR Info:
Exposed an API to assign an IP address to the interface created by the VM when the PCIF is attached.
This PR accepts network information and the PCIF ID as input. The PCIF ID is used to identify the corresponding network interface name (e.g., ens327) configured on the VM. The IP address is then assigned to the identified interface by creating the appropriate ifcfg-en* configuration file in the OS-specific /etc directory. Finally, the VM must be restarted to apply the updated network configuration.
API Info:
POST /guests/{userid}/interface/ip
Configure the IP address and network settings for a Network Express (NETH)
interface on a running guest. The guest must be powered on and reachable
through IUCV, and the NETH PCI function (
pcif) must already be attachedto the guest before this call is made.
Reboot behavior:
active=false(default): the configuration is only punched to the guest reader and applied at the next boot. The guest is not rebooted.active=true: the configuration is applied throughzvmguestconfigureand the guest is rebooted, which interrupts all workloads running on it. If applying fails, the API raises an error and the guest is not rebooted.Supported distributions (case-insensitive):
rhel7.x,rhel8.x,rhel9.x,rhel10.x,sles15.x,ubuntu20.x,ubuntu22.x,ubuntu24.xandubuntu25.x.rhcos4.xis not supported and is rejected before the guest is modified.rhel10.xis implemented but not tested on a real guest.rhel6.x,sles11.x,sles12.xandubuntu16.xare not supported or tested. They are not rejected, but the result is not guaranteed.Request Body:
Response: HTTP 200 with the
guest_networkobject that was applied.