From 68c7ab4c9098e4b5dbc178ff531791c72c1510e9 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 23 Aug 2017 15:41:16 -0400 Subject: [PATCH] Add ability to group discovery by uuid API adds 'by-uuid', which helps group BMC and PXE together to make relationship clear. --- confluent_server/confluent/discovery/core.py | 17 ++++++++++++++++- .../confluent/discovery/handlers/imm.py | 2 +- .../confluent/discovery/protocols/pxe.py | 2 +- .../confluent/discovery/protocols/slp.py | 2 +- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/confluent_server/confluent/discovery/core.py b/confluent_server/confluent/discovery/core.py index 784a7de1..f6e54257 100644 --- a/confluent_server/confluent/discovery/core.py +++ b/confluent_server/confluent/discovery/core.py @@ -165,6 +165,7 @@ def _info_matches(info, criteria): node = criteria.get('by-node', None) serial = criteria.get('by-serial', None) status = criteria.get('by-state', None) + uuid = criteria.get('by-uuid', None) if model and info.get('modelnumber', None) != model: return False if devtype and devtype not in info.get('services', []): @@ -175,6 +176,8 @@ def _info_matches(info, criteria): return False if status and info.get('discostatus', None) != status: return False + if uuid and info.get('uuid') != uuid: + return False return True @@ -196,6 +199,18 @@ def list_matching_serials(criteria): if _info_matches(info, criteria): yield msg.ChildCollection(serial + '/') +def list_matching_uuids(criteria): + uuids = [] + for mac in known_info: + info = known_info[mac] + uuid = info.get('uuid', None) + if not uuid: + continue + if _info_matches(info, criteria): + uuids.append(uuid) + for uuid in uuids: + yield msg.ChildCollection(uuid + '/') + def list_matching_states(criteria): return [msg.ChildCollection(x) for x in ('discovered/', 'identified/', @@ -247,12 +262,12 @@ multi_selectors = set([ 'by-type', 'by-model', 'by-state', + 'by-uuid', ]) node_selectors = set([ 'by-node', - #'by-uuid', 'by-serial', ]) diff --git a/confluent_server/confluent/discovery/handlers/imm.py b/confluent_server/confluent/discovery/handlers/imm.py index 983eb94e..dfd80813 100644 --- a/confluent_server/confluent/discovery/handlers/imm.py +++ b/confluent_server/confluent/discovery/handlers/imm.py @@ -62,7 +62,7 @@ class NodeHandler(bmchandler.NodeHandler): ipmicmd = self._get_ipmicmd() guiddata = ipmicmd.xraw_command(netfn=6, command=8) self.info['uuid'] = pygutil.decode_wireformat_uuid( - guiddata['data']) + guiddata['data']).lower() ipmicmd.oem_init() bayid = ipmicmd._oem.immhandler.get_property( '/v2/cmm/sp/7') diff --git a/confluent_server/confluent/discovery/protocols/pxe.py b/confluent_server/confluent/discovery/protocols/pxe.py index cbb1f87a..0d596415 100644 --- a/confluent_server/confluent/discovery/protocols/pxe.py +++ b/confluent_server/confluent/discovery/protocols/pxe.py @@ -37,7 +37,7 @@ def decode_uuid(rawguid): lebytes = struct.unpack_from('HHI', buffer(rawguid[8:])) return '{0:08X}-{1:04X}-{2:04X}-{3:04X}-{4:04X}{5:08X}'.format( - lebytes[0], lebytes[1], lebytes[2], bebytes[0], bebytes[1], bebytes[2]) + lebytes[0], lebytes[1], lebytes[2], bebytes[0], bebytes[1], bebytes[2]).lower() def find_info_in_options(rq, optidx): diff --git a/confluent_server/confluent/discovery/protocols/slp.py b/confluent_server/confluent/discovery/protocols/slp.py index f66975b2..024bc983 100644 --- a/confluent_server/confluent/discovery/protocols/slp.py +++ b/confluent_server/confluent/discovery/protocols/slp.py @@ -272,7 +272,7 @@ def _parse_attrlist(attrstr): '{4:04X}{5:08X}'.format( lebytes[0], lebytes[1], lebytes[2], bebytes[0], bebytes[1], bebytes[2] - ) + ).lower() attribs[attrname].append(val) attrstr = attrstr[attrstr.index(')'):] elif attrstr[0] == ',':