From ff52ad4740a3cc1d9312d242ac63ae3ca254862a Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 28 Jul 2015 14:25:51 -0400 Subject: [PATCH] Implement read network configuration Read network configuration from the endpoint and present under the management_controller configuration. --- confluent_server/confluent/core.py | 4 +++ confluent_server/confluent/messages.py | 21 +++++++++++++++ .../plugins/hardwaremanagement/ipmi.py | 26 +++++++++++++++++-- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/confluent_server/confluent/core.py b/confluent_server/confluent/core.py index 7bd9850d..9a43d16d 100644 --- a/confluent_server/confluent/core.py +++ b/confluent_server/confluent/core.py @@ -131,6 +131,10 @@ noderesources = { 'pluginattrs': ['hardwaremanagement.method'], 'default': 'ipmi', }), + 'net_interfaces': PluginCollection({ + 'pluginattrs': ['hardwaremanagement.method'], + 'default': 'ipmi', + }), } }, '_console': { diff --git a/confluent_server/confluent/messages.py b/confluent_server/confluent/messages.py index 48520bdc..89a8f141 100644 --- a/confluent_server/confluent/messages.py +++ b/confluent_server/confluent/messages.py @@ -778,6 +778,27 @@ class KeyValueData(ConfluentMessage): else: self.kvpairs = {name: kvdata} + +class NetworkConfiguration(ConfluentMessage): + desc = 'Network configuration' + + def __init__(self, name=None, ipv4addr=None, ipv4gateway=None, + ipv4cfgmethod=None, hwaddr=None): + self.notnode = name is None + self.stripped = False + + kvpairs = { + 'ipv4_address': {'value': ipv4addr}, + 'ipv4_gateway': {'value': ipv4gateway}, + 'ipv4_configuration': {'value': ipv4cfgmethod}, + 'hw_addr': {'value': hwaddr}, + } + if self.notnode: + self.kvpairs = kvpairs + else: + self.kvpairs = {name: kvpairs} + + class HealthSummary(ConfluentMessage): readonly = True valid_values = valid_health_values diff --git a/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py b/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py index 4514d242..6028b538 100644 --- a/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py +++ b/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py @@ -372,10 +372,12 @@ class IpmiHandler(object): raise Exception('Not Implemented') def handle_configuration(self): - if self.element[1:3] == ['management_controller', 'alerts' ]: + if self.element[1:3] == ['management_controller', 'alerts']: return self.handle_alerts() - elif self.element[1:3] == ['management_controller', 'users' ]: + elif self.element[1:3] == ['management_controller', 'users']: return self.handle_users() + elif self.element[1:3] == ['management_controller', 'net_interfaces']: + return self.handle_nets() raise Exception('Not implemented') def decode_alert(self): @@ -426,6 +428,26 @@ class IpmiHandler(object): return raise Exception('Not implemented') + def handle_nets(self): + if len(self.element) == 3: + if self.op != 'read': + self.output.put( + msg.ConfluentNodeError(self.node, 'Unsupported operation')) + return + self.output.put(msg.ChildCollection('management')) + elif len(self.element) == 4 and self.element[-1] == 'management': + if self.op == 'read': + lancfg = self.ipmicmd.get_net_configuration() + self.output.put(msg.NetworkConfiguration( + self.node, ipv4addr=lancfg['ipv4_address'], + ipv4gateway=lancfg['ipv4_gateway'], + ipv4cfgmethod=lancfg['ipv4_configuration'], + hwaddr=lancfg['mac_address'] + )) + else: + self.output.put(msg.ConfluentNodeError(self.node, + 'Not yet implemented')) + def handle_users(self): # Create user if len(self.element) == 3: