rename interface

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

View File

@ -1472,7 +1472,23 @@ class ApplyNodeNetworking(BaseMaasAction):
machine.reset_network_config()
machine.refresh()
self.logger.debug(
"The variable, n.interfaces is : %s"
% (n.interfaces))
for i in n.interfaces:
self.logger.debug(
"The variable, name is : %s"
% (i.device_name))
# self.logger.debug(
# "The variable, i is : %s"
# % (i))
# rename only ens ones
# if "ens" in i.device_name:
machine.rename_interface(i.device_name)
if not i.network_link:
self.logger.debug(
"Interface %s has no network link, skipping configuration."

View File

@ -108,6 +108,43 @@ class Interface(model_base.ResourceBase):
return False
def update(self, **kwargs):
"""Update this interface.
{system_id} (string):Node/machine ID Required.
{id} (string):interface ID Required.
"""
if kwargs:
url = self.interpolate_url()
self.logger.debug("Updating interface %s:%s on system %s." %
(self.name, self.resource_id, self.system_id))
iface_params = dict()
# self.logger.debug("Setting interface parameters for interface %s on system %s." %
# (self.resource_id, self.system_id))
for k, v in kwargs.items():
iface_params[k] = v
iface_params["id"] = self.resource_id
resp = self.api_client.put(url, files=iface_params)
if not resp.ok:
self.logger.warning(
"Could not update interface, MaaS error: %s - %s" %
(resp.status_code, resp.text))
raise errors.DriverError(
"Could not update interface, MaaS error: %s - %s" %
(resp.status_code, resp.text))
else:
self.logger.warning(
"Could not update interface, no parameters supplied for update")
# resp = self.api_client.put(url, op='interfaces',
# files={"name": path_name, "id": interface_id})
def disconnect(self):
"""Disconnect this interface from subnets and VLANs."""
url = self.interpolate_url()

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,62 @@ class Machine(model_base.ResourceBase):
return i
return None
def get_commissioning_results(self):
"""Load the commissioning script results"""
self.resource_url = 'nodes/{resource_id}/results/'
url = self.interpolate_url()
options = {
'filters': "99-netiface-names.sh",
'include_output': "true",
}
resp = self.api_client.get(url, files=options)
# self.logger.debug("MaaS query URL : %s | Options: %s " % url % options)
# self.logger.debug("MaaS response: %s" % resp.text)
output_str = resp.decode('utf-8')
data_dict = json.loads(output_str)
# self.logger.debug("MaaS data_dict: %s" % data_dict)
if resp.status_code == 200:
self.results = data_dict
if not resp.ok:
brief_msg = ("Error getting commissioning script, 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 rename_interface(self, interface_name):
"""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))
iface = self.get_network_interface(interface_name)
if iface.name is not interface_name:
self.logger.info("Interface %s not the correct interface to rename."
% (iface.name))
return None
# maas_interface.update(name=path_name)
resp = self.api_client.put(url, op='interfaces',
params={"name": path_name, "id": iface.resource_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``.
@ -392,6 +449,7 @@ class Machine(model_base.ResourceBase):
def set_power_parameters(self, power_type, **kwargs):
"""Set power parameters for this node.
Only available after the node has been added to MAAS.
:param power_type: The type of power management for the node