rename interface

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

View File

@ -1473,6 +1473,18 @@ class ApplyNodeNetworking(BaseMaasAction):
machine.refresh()
for i in n.interfaces:
self.logger.debug(
"The variable, name is : %s"
% (i.name))
self.logger.debug(
"The variable, id is : %s"
% (i.id))
# rename only ens ones
if [val for key, val in i.items() if "ens" in val]:
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

@ -14,6 +14,7 @@
"""Model representing MAAS node/machine resource."""
import logging
import base64
import json
from threading import Lock, Condition
@ -82,6 +83,38 @@ class Machine(model_base.ResourceBase):
return i
return None
def get_commissioning_results(self):
"""Load the commissioning script results"""
url = self.interpolate_url()
resp = self.api_client.get(url, op='results', params={"filters": "99-netiface-names.sh"})
output_str = resp.decode('utf-8')
data_dict = json.loads(output_str)
if resp.status_code == 200:
self.results = data_dict
def rename_interface(self, interface_name, interface_id):
"""rename interface"""
url = self.interpolate_url()
int_names = self.get_commissioning_results()
path_name = int_names.get(interface_name, "")
if path_name:
self.logger.info("Interface %s rename to %s"
% (interface_name, path_name))
resp = self.api_client.put(url, op='interfaces',
params={"name": path_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``.