mirror of
https://opendev.org/x/pyghmi
synced 2025-01-27 19:37:44 +00:00
Merge "Implement IMM remote media mount"
This commit is contained in:
commit
563b15decf
@ -761,7 +761,10 @@ class OEMHandler(generic.OEMHandler):
|
||||
data=(1, 1))
|
||||
|
||||
def attach_remote_media(self, url, username, password):
|
||||
if self.has_megarac:
|
||||
if self.has_imm:
|
||||
imm.attach_remote_media(self.ipmicmd, self._certverify, url,
|
||||
username, password)
|
||||
elif self.has_megarac:
|
||||
proto, host, path = util.urlsplit(url)
|
||||
if proto == 'smb':
|
||||
proto = 'cifs'
|
||||
@ -783,7 +786,9 @@ class OEMHandler(generic.OEMHandler):
|
||||
raise
|
||||
|
||||
def detach_remote_media(self):
|
||||
if self.has_megarac:
|
||||
if self.has_imm:
|
||||
imm.detach_remote_media(self.ipmicmd, self._certverify)
|
||||
elif self.has_megarac:
|
||||
self.ipmicmd.xraw_command(
|
||||
netfn=0x32, command=0x9f, data=(8, 10, 0, 0))
|
||||
self.ipmicmd.xraw_command(netfn=0x32, command=0x9f, data=(8, 11))
|
||||
|
@ -107,6 +107,38 @@ def get_web_session(ipmicmd, certverify, wc):
|
||||
return wc
|
||||
|
||||
|
||||
def attach_remote_media(ipmicmd, certverify, url, user, password):
|
||||
wc = get_web_session(ipmicmd, certverify, None)
|
||||
url = url.replace(':', '\:')
|
||||
params = urllib.urlencode({
|
||||
'RP_VmAllocateMountUrl({0},{1},1,,)'.format(
|
||||
ipmicmd.ipmi_session.userid, url): ''
|
||||
})
|
||||
result = wc.grab_json_response('/data?set', params)
|
||||
if result['return'] != 'Success':
|
||||
raise Exception(result['reason'])
|
||||
wc.grab_json_response('/data/logout')
|
||||
|
||||
|
||||
def detach_remote_media(ipmicmd, certverify):
|
||||
wc = get_web_session(ipmicmd, certverify, None)
|
||||
mnt = wc.grab_json_response('/designs/imm/dataproviders/imm_rp_images.php')
|
||||
removeurls = []
|
||||
for item in mnt['items']:
|
||||
if 'urls' in item:
|
||||
for url in item['urls']:
|
||||
removeurls.append(url['url'])
|
||||
for url in removeurls:
|
||||
url = url.replace(':', '\:')
|
||||
params = urllib.urlencode({
|
||||
'RP_VmAllocateUnMountUrl({0},{1},0,)'.format(
|
||||
ipmicmd.ipmi_session.userid, url): ''})
|
||||
result = wc.grab_json_response('/data?set', params)
|
||||
if result['return'] != 'Success':
|
||||
raise Exception(result['reason'])
|
||||
wc.grab_json_response('/data/logout')
|
||||
|
||||
|
||||
def fetch_agentless_firmware(ipmicmd, certverify):
|
||||
wc = None
|
||||
adapterdata = get_cached_data(ipmicmd, 'lenovo_cached_adapters')
|
||||
@ -174,7 +206,7 @@ def fetch_agentless_firmware(ipmicmd, certverify):
|
||||
'versionStr']
|
||||
yield (diskname, bdata)
|
||||
if wc:
|
||||
wc.request('GET', '/data/logout')
|
||||
wc.grab_json_response('/data/logout')
|
||||
|
||||
|
||||
def get_hw_inventory(ipmicmd, certverify):
|
||||
@ -253,6 +285,8 @@ def hardware_inventory_map(ipmicmd, certverify):
|
||||
if not skipadapter:
|
||||
hwmap[aname] = bdata
|
||||
ipmicmd.ipmi_session.lenovo_cached_hwmap = (hwmap, _monotonic_time())
|
||||
if wc:
|
||||
wc.grab_json_response('/data/logout')
|
||||
return hwmap
|
||||
|
||||
|
||||
|
@ -62,8 +62,11 @@ class SecureHTTPConnection(httplib.HTTPConnection, object):
|
||||
self.cookies[k] = c[k].value
|
||||
return rsp
|
||||
|
||||
def grab_json_response(self, url):
|
||||
self.request('GET', url)
|
||||
def grab_json_response(self, url, data=None):
|
||||
if data:
|
||||
self.request('POST', url, data)
|
||||
else:
|
||||
self.request('GET', url)
|
||||
rsp = self.getresponse()
|
||||
if rsp.status == 200:
|
||||
return json.loads(rsp.read())
|
||||
|
Loading…
x
Reference in New Issue
Block a user