2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-25 19:10:10 +00:00

Provide helpful error on bad user/password in delta pdu

This commit is contained in:
Jarrod Johnson 2022-09-21 16:19:13 -04:00
parent 25c66e163c
commit 0c08d8f6d3
2 changed files with 16 additions and 7 deletions

View File

@ -155,7 +155,9 @@ class PDUClient(object):
if not username or not passwd:
raise Exception('Missing username or password')
body = 'User={0}&Password={1}&B1=Login'.format(username, passwd)
self.wc.grab_response('/login.htm', body)
rsp = self.wc.grab_response('/login.htm', body)
if b'Incorrect User Name' in rsp[0]:
raise exc.TargetEndpointBadCredentials()
def logout(self):
@ -184,8 +186,12 @@ def retrieve(nodes, element, configmanager, inputdata):
yield msg.ConfluentResourceUnavailable(node, 'Not implemented')
return
for node in nodes:
gc = PDUClient(node, configmanager)
state = gc.get_outlet(element[-1])
try:
gc = PDUClient(node, configmanager)
state = gc.get_outlet(element[-1])
except exc.TargetEndpointBadCredentials:
yield msg.ConfluentTargetInvalidCredentials(node)
continue
yield msg.PowerState(node=node, state=state)
gc.logout()

View File

@ -39,10 +39,13 @@ def retrieve(nodes, element, configmanager, inputdata):
for pgroup in outlets[node]:
pdu = outlets[node][pgroup]['pdu']
outlet = outlets[node][pgroup]['outlet']
for rsp in core.handle_path(
'/nodes/{0}/power/outlets/{1}'.format(pdu, outlet),
'retrieve', configmanager):
yield msg.KeyValueData({pgroup: rsp.kvpairs['state']['value']}, node)
try:
for rsp in core.handle_path(
'/nodes/{0}/power/outlets/{1}'.format(pdu, outlet),
'retrieve', configmanager):
yield msg.KeyValueData({pgroup: rsp.kvpairs['state']['value']}, node)
except exc.TargetEndpointBadCredentials:
yield msg.ConfluentTargetInvalidCredentials(pdu)
def get_outlets(nodes, emebs, inletname):
outlets = {}