Skip to content

Commit

Permalink
Merge branch 'topic/okurth/fix-virtio' into 'poi-container'
Browse files Browse the repository at this point in the history
use a blacklist instead of whitelist for disk devices, and refactor refresh_devices() method

See merge request core-build/photon-os-installer!30
  • Loading branch information
oliverkurth committed Nov 27, 2023
2 parents 7875612 + 4d3eea7 commit 8b5257e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion photon_installer/custompartition.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, maxy, maxx, install_config):
Device.refresh_devices()

def initialize_devices(self):
self.devices = Device.refresh_devices_bytes()
self.devices = Device.refresh_devices(bytes=True)

# Subtract BIOS&ESP SIZE from the disk_size since this much is hardcoded for bios
# and efi partition in installer.py
Expand Down
30 changes: 16 additions & 14 deletions photon_installer/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,33 @@
# * Copyright © 2020 VMware, Inc.
# * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-only
# */
#
#
# Author: Mahmoud Bassiouny <[email protected]>


import subprocess
import os


# see https://www.kernel.org/doc/Documentation/admin-guide/devices.txt
LSBLK_EXCLUDE = "2,9,11,15,16,17,18,19,20,23,24,25,26,27,28,29,30,32,35,37,46,103,113,144,145,146"


class Device(object):
def __init__(self, model, path, size):
self.model = model
self.path = path
self.size = size

@staticmethod
def refresh_devices():
devices_list = subprocess.check_output(['lsblk', '-d', '-I', '7,8,179,202,254,259', '-n',
'--output', 'NAME,SIZE,MODEL'],
stderr=open(os.devnull, 'w'))
return Device.wrap_devices_from_list(devices_list)

@staticmethod
def refresh_devices_bytes():
devices_list = subprocess.check_output(['lsblk', '-d', '--bytes', '-I',
'7,8,179,202,254,259', '-n', '--output', 'NAME,SIZE,MODEL'],
stderr=open(os.devnull, 'w'))
def refresh_devices(bytes=False):
args = ["lsblk",
"-d",
"-e", LSBLK_EXCLUDE,
"-n",
"--output", "NAME,SIZE,MODEL"]
if bytes:
args.append("--bytes")
devices_list = subprocess.check_output(args,
stderr=subprocess.DEVNULL)
return Device.wrap_devices_from_list(devices_list)

@staticmethod
Expand Down

0 comments on commit 8b5257e

Please sign in to comment.