rename interface
Change-Id: I413e3d1770401e58cbf5b801892b46378d7840b0
This commit is contained in:
parent
375abedb8a
commit
0704445892
|
@ -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."
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
"""Model representing MAAS node/machine resource."""
|
||||
import logging
|
||||
import base64
|
||||
import json
|
||||
|
||||
from threading import Lock, Condition
|
||||
|
||||
|
@ -82,6 +83,39 @@ 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() # extract the appropriate name for the specific interface
|
||||
|
||||
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``.
|
||||
|
||||
|
|
Loading…
Reference in New Issue