Skip to content

Commit

Permalink
ceph-volume: adds sys_info constant to hold system information
Browse files Browse the repository at this point in the history
This is only currently used to hold information about devices
from /sys/block in the util.Device class in the sys_api property.

Signed-off-by: Andrew Schoen <aschoen@redhat.com>
(cherry picked from commit 035f1a4)
  • Loading branch information
andrewschoen committed Aug 29, 2018
1 parent ed3ea93 commit 7b5b3f0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/ceph-volume/ceph_volume/__init__.py
@@ -1,6 +1,10 @@
from collections import namedtuple


sys_info = namedtuple('sys_info', ['devices'])
sys_info.devices = dict()


class UnloadedConfig(object):
"""
This class is used as the default value for conf.ceph so that if
Expand Down
14 changes: 8 additions & 6 deletions src/ceph-volume/ceph_volume/util/device.py
@@ -1,4 +1,5 @@
import os
from ceph_volume import sys_info
from ceph_volume.api import lvm
from ceph_volume.util import disk

Expand All @@ -12,6 +13,7 @@ def __init__(self, path):
self.lv_api = None
self.pvs_api = []
self.disk_api = {}
self.sys_api = {}
self._exists = None
self._is_lvm_member = None
self._parse()
Expand All @@ -30,6 +32,10 @@ def _parse(self):
if device_type in ['part', 'disk']:
self._set_lvm_membership()

if not sys_info.devices:
sys_info.devices = disk.get_devices()
self.sys_api = sys_info.devices.get(self.abspath, {})

def __repr__(self):
prefix = 'Unknown'
if self.is_lv:
Expand Down Expand Up @@ -63,9 +69,7 @@ def _set_lvm_membership(self):

@property
def exists(self):
if self._exists is None:
self._exists = os.path.exists(self.abspath)
return self._exists
return os.path.exists(self.abspath)

@property
def is_lvm_member(self):
Expand All @@ -75,9 +79,7 @@ def is_lvm_member(self):

@property
def is_mapper(self):
if self._is_mapper is None:
self._is_mapper = self.path.startswith('/dev/mapper')
return self._is_mapper
return self.path.startswith('/dev/mapper')

@property
def is_lv(self):
Expand Down

0 comments on commit 7b5b3f0

Please sign in to comment.