rename interface

Change-Id: I413e3d1770401e58cbf5b801892b46378d7840b0
This commit is contained in:
Wahlstedt, Walter (ww229g) 2023-05-24 12:16:02 -04:00
parent 375abedb8a
commit 58b6a2d28d
2 changed files with 60 additions and 0 deletions

View File

@ -1473,6 +1473,11 @@ class ApplyNodeNetworking(BaseMaasAction):
machine.refresh()
for i in n.interfaces:
# rename only ens ones
if "ens" in i.name:
machine.rename_interface(i.name, i.id)
if not i.network_link:
self.logger.debug(
"Interface %s has no network link, skipping configuration."

View File

@ -82,6 +82,61 @@ class Machine(model_base.ResourceBase):
return i
return None
def get_commissioning_results(self):
"""Load the commissioning script results"""
url = self.interpolate_url()
# Node-Scripts
resp = self.api_client.get(url, op='results', params="filters=99-netiface-names.sh")
# ens2f0: enp94s0f0
# ens2f1: enp94s0f1
# ens5f0: enp134s0f0
# ens5f1: enp134s0f1
# ens7f0: enp135s0f0
# ens7f1: enp135s0f1
if resp.status_code == 200:
self.results = resp.json()
def get_interface_results(self, interface):
"""Load the commissioning script results"""
url = self.interpolate_url()
# Node-Scripts
resp = self.api_client.get(url, op='results', params={"filters": "99-netiface-names.sh"})
# ens2f0: enp94s0f0
# ens2f1: enp94s0f1
# ens5f0: enp134s0f0
# ens5f1: enp134s0f1
# ens7f0: enp135s0f0
# ens7f1: enp135s0f1
if resp.status_code == 200:
self.results = resp.json()
def rename_interface(self, interface_name, interface_id):
"""rename interface"""
url = self.interpolate_url()
int_names = self.get_commissioning_results() # extract the appropriate name for the specific interface
# "ens-123: enp-123,"
# "ens-456: enp-456,"
for int_name in int_names:
if interface_name in int_name:
enp_name = int_name[1]
self.logger.info("Interface %s rename to %s" %
(int_name[0], int_name[1]))
resp = self.api_client.put(url, op='interfaces', params={"name": enp_name, "id":interface_id})
if not resp.ok:
brief_msg = ("Error updating interface name, received HTTP %s from MaaS" %
resp.status_code)
self.logger.error(brief_msg)
self.logger.debug("MaaS response: %s" % resp.text)
raise errors.DriverError(brief_msg)
def interface_for_mac(self, mac_address):
"""Find the machine interface that owns the specified ``mac_address``.