mirror of
https://opendev.org/x/pyghmi
synced 2025-01-27 19:37:44 +00:00
Extend TSM remote media to redfish mode
Refactor TSM core as needed to support OEM list of media. Change-Id: I2be297af57a9d02950cc8c081523fcc004c5fee2
This commit is contained in:
parent
2adaf00bd2
commit
68e45b919f
@ -28,7 +28,6 @@ import struct
|
||||
import time
|
||||
import pyghmi.exceptions as exc
|
||||
import pyghmi.constants as const
|
||||
import pyghmi.media as media
|
||||
import pyghmi.util.webclient as webclient
|
||||
from pyghmi.util.parse import parse_time
|
||||
import pyghmi.redfish.oem.lookup as oem
|
||||
@ -721,7 +720,6 @@ class Command(object):
|
||||
return self._varbmcnicurl
|
||||
|
||||
def list_network_interface_names(self):
|
||||
bmcinfo = self._do_web_request(self._bmcurl)
|
||||
nicurl = bmcinfo.get('EthernetInterfaces', {}).get('@odata.id',
|
||||
None)
|
||||
if not nicurl:
|
||||
@ -1522,19 +1520,7 @@ class Command(object):
|
||||
unavailable=unavail)
|
||||
|
||||
def list_media(self):
|
||||
bmcinfo = self._do_web_request(self._bmcurl)
|
||||
vmcoll = bmcinfo.get('VirtualMedia', {}).get('@odata.id', None)
|
||||
if vmcoll:
|
||||
vmlist = self._do_web_request(vmcoll)
|
||||
vmurls = [x['@odata.id'] for x in vmlist.get('Members', [])]
|
||||
for vminfo in self._do_bulk_requests(vmurls):
|
||||
vminfo = vminfo[0]
|
||||
if vminfo['Image']:
|
||||
imageurl = vminfo['Image'].replace('/' + vminfo['ImageName'], '')
|
||||
yield media.Media(vminfo['ImageName'], imageurl)
|
||||
elif vminfo['Inserted'] and vminfo['ImageName']:
|
||||
yield media.Media(vminfo['ImageName'])
|
||||
|
||||
return self.oem.list_media(self)
|
||||
|
||||
def get_storage_configuration(self):
|
||||
""""Get storage configuration data
|
||||
@ -1602,6 +1588,10 @@ class Command(object):
|
||||
def detach_remote_media(self):
|
||||
bmcinfo = self._do_web_request(self._bmcurl)
|
||||
vmcoll = bmcinfo.get('VirtualMedia', {}).get('@odata.id', None)
|
||||
try:
|
||||
self.oem.detach_remote_media()
|
||||
except exc.BypassGenericBehavior:
|
||||
return
|
||||
if vmcoll:
|
||||
vmlist = self._do_web_request(vmcoll)
|
||||
vmurls = [x['@odata.id'] for x in vmlist.get('Members', [])]
|
||||
|
@ -15,6 +15,7 @@
|
||||
import json
|
||||
import os
|
||||
import pyghmi.exceptions as exc
|
||||
import pyghmi.media as media
|
||||
|
||||
|
||||
class OEMHandler(object):
|
||||
@ -46,6 +47,20 @@ class OEMHandler(object):
|
||||
self.username = username
|
||||
self.password = password
|
||||
|
||||
def list_media(self, fishclient):
|
||||
bmcinfo = fishclient._do_web_request(fishclient._bmcurl)
|
||||
vmcoll = bmcinfo.get('VirtualMedia', {}).get('@odata.id', None)
|
||||
if vmcoll:
|
||||
vmlist = fishclient._do_web_request(vmcoll)
|
||||
vmurls = [x['@odata.id'] for x in vmlist.get('Members', [])]
|
||||
for vminfo in fishclient._do_bulk_requests(vmurls):
|
||||
vminfo = vminfo[0]
|
||||
if vminfo['Image']:
|
||||
imageurl = vminfo['Image'].replace('/' + vminfo['ImageName'], '')
|
||||
yield media.Media(vminfo['ImageName'], imageurl)
|
||||
elif vminfo['Inserted'] and vminfo['ImageName']:
|
||||
yield media.Media(vminfo['ImageName'])
|
||||
|
||||
def get_storage_configuration(self):
|
||||
raise exc.UnsupportedFunctionality(
|
||||
'Remote storage configuration not supported on this platform')
|
||||
|
@ -79,6 +79,7 @@ class TsmHandler(generic.OEMHandler):
|
||||
self.username = None
|
||||
self.password = None
|
||||
self.csrftok = None
|
||||
self.isipmi = bool(fish)
|
||||
self.fish = fish
|
||||
super(TsmHandler, self).__init__(sysinfo, sysurl, webclient, cache)
|
||||
self.tsm = webclient.thehost
|
||||
@ -363,6 +364,8 @@ class TsmHandler(generic.OEMHandler):
|
||||
wc = self.wc
|
||||
slots = wc.grab_json_response('/api/settings/media/remote/configurations')
|
||||
self._detach_all_media(wc, slots)
|
||||
if not self.isipmi:
|
||||
raise exc.BypassGenericBehavior()
|
||||
|
||||
def _allocate_slot(self, slots, filetype, wc, server, path):
|
||||
currhdds = []
|
||||
@ -463,7 +466,7 @@ class TsmHandler(generic.OEMHandler):
|
||||
raise exc.UnsupportedFunctionality(
|
||||
'Remote media upload not supported on this system')
|
||||
|
||||
def list_media(self):
|
||||
def list_media(self, fishclient):
|
||||
wc = self.wc
|
||||
rsp = wc.grab_json_response('/api/settings/media/general')
|
||||
cds = rsp['cd_remote_server_address']
|
||||
@ -482,13 +485,13 @@ class TsmHandler(generic.OEMHandler):
|
||||
if slot['redirection_status'] == 1:
|
||||
url = None
|
||||
if slot['media_type'] == 1:
|
||||
url = '{0}://{1}{2}/{3}'.format(
|
||||
cdproto, cds, cdpath, slot['image_name'])
|
||||
url = '{0}://{1}{2}'.format(
|
||||
cdproto, cds, cdpath)
|
||||
elif slot['media_type'] == 4:
|
||||
url = '{0}://{1}{2}/{3}'.format(
|
||||
hdproto, hds, hdpath, slot['image_name'])
|
||||
url = '{0}://{1}{2}'.format(
|
||||
hdproto, hds, hdpath)
|
||||
if url:
|
||||
yield media.Media(url)
|
||||
yield media.Media(slot['image_name'], url)
|
||||
|
||||
def attach_remote_media(self, url, user, password, vmurls):
|
||||
if not url.startswith('nfs://'):
|
||||
@ -533,4 +536,6 @@ class TsmHandler(generic.OEMHandler):
|
||||
else:
|
||||
self._allocate_slot(mountslots, filetype, wc, server, path)
|
||||
images = wc.grab_json_response('/api/settings/media/remote/images')
|
||||
self._exec_mount(filename, images, wc)
|
||||
self._exec_mount(filename, images, wc)
|
||||
if not self.isipmi:
|
||||
raise exc.BypassGenericBehavior()
|
Loading…
x
Reference in New Issue
Block a user