rename interface
Change-Id: I413e3d1770401e58cbf5b801892b46378d7840b0
This commit is contained in:
parent
375abedb8a
commit
b488ab8dd4
|
@ -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."
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
"""Model representing MAAS node/machine resource."""
|
||||
import logging
|
||||
import base64
|
||||
import json
|
||||
|
||||
from threading import Lock, Condition
|
||||
|
||||
|
@ -23,6 +24,7 @@ import drydock_provisioner.drivers.node.maasdriver.models.interface as maas_inte
|
|||
import drydock_provisioner.drivers.node.maasdriver.models.blockdev as maas_blockdev
|
||||
import drydock_provisioner.drivers.node.maasdriver.models.volumegroup as maas_vg
|
||||
import drydock_provisioner.drivers.node.maasdriver.models.node_results as maas_nr
|
||||
import drydock_provisioner.drivers.node.maasdriver.models.results as maas_results
|
||||
|
||||
from bson import BSON
|
||||
|
||||
|
@ -51,6 +53,13 @@ class Machine(model_base.ResourceBase):
|
|||
self.interfaces = maas_interface.Interfaces(
|
||||
api_client, system_id=self.resource_id)
|
||||
self.interfaces.refresh()
|
||||
try:
|
||||
self.results = maas_results.Result(
|
||||
api_client, system_id=self.resource_id)
|
||||
self.results.refresh()
|
||||
except Exception:
|
||||
self.logger.warning("Failed loading node %s node results." %
|
||||
(self.resource_id))
|
||||
try:
|
||||
self.block_devices = maas_blockdev.BlockDevices(
|
||||
api_client, system_id=self.resource_id)
|
||||
|
@ -82,6 +91,47 @@ 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}/'
|
||||
|
||||
# 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):
|
||||
"""rename interface"""
|
||||
url = self.interpolate_url()
|
||||
|
||||
int_names = self.results.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
|
||||
self.interfaces.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 +442,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
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
# Copyright 2018 AT&T Intellectual Property. All other rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""Model for MaaS Node Script Result resources."""
|
||||
import logging
|
||||
import json
|
||||
|
||||
import drydock_provisioner.drivers.node.maasdriver.models.base as model_base
|
||||
|
||||
|
||||
class Result(model_base.ResourceBase):
|
||||
|
||||
resource_url = 'nodes/{system_id}/results/'
|
||||
fields = [
|
||||
'resource_id',
|
||||
'system_id',
|
||||
'name',
|
||||
]
|
||||
json_fields = []
|
||||
|
||||
def __init__(self, api_client, **kwargs):
|
||||
super(Result, self).__init__(api_client, **kwargs)
|
||||
self.logger = logging.getLogger('drydock.nodedriver.maasdriver')
|
||||
|
||||
def get_commissioning_results(self):
|
||||
"""Load the commissioning script results"""
|
||||
|
||||
url = self.interpolate_url()
|
||||
|
||||
resp = self.api_client.get(url, 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
|
||||
|
||||
class Results(model_base.ResourceCollectionBase):
|
||||
|
||||
collection_url = 'node-script-result/'
|
||||
collection_resource = Result
|
||||
|
||||
def __init__(self, api_client, system_id_list=None, result_type=None):
|
||||
super().__init__(api_client)
|
||||
|
||||
self.system_id_list = system_id_list
|
||||
self.result_type = result_type
|
||||
'''
|
||||
def refresh(self):
|
||||
params = dict()
|
||||
if self.system_id_list:
|
||||
params['system_id'] = self.system_id_list
|
||||
if self.result_type and self.result_type != 'all':
|
||||
params['result_type'] = Result.type_map.get(self.result_type)
|
||||
|
||||
url = self.interpolate_url()
|
||||
|
||||
if params:
|
||||
resp = self.api_client.get(url, files=params)
|
||||
else:
|
||||
resp = self.api_client.get(url)
|
||||
|
||||
if resp.status_code in [200]:
|
||||
json_list = resp.json()
|
||||
self.resource = dict()
|
||||
|
||||
for o in json_list:
|
||||
if isinstance(o, dict):
|
||||
i = self.collection_resource.from_dict(self.api_client, o)
|
||||
self.resources[i.resource_id] = i
|
||||
|
||||
return
|
||||
'''
|
Loading…
Reference in New Issue