Buckets:
| from oslo_log import log as logging | |
| from oslo_utils import importutils | |
| from nova import exception | |
| libosinfo = None | |
| LOG = logging.getLogger(__name__) | |
| class _OsInfoDatabase(object, ): | |
| _instance = None | |
| def __init__(self): | |
| global libosinfo | |
| try: | |
| if (libosinfo is None): | |
| libosinfo = importutils.import_module('gi.repository.Libosinfo') | |
| except ImportError as exp: | |
| LOG.info('Cannot load Libosinfo: (%s)', exp) | |
| else: | |
| self.loader = libosinfo.Loader() | |
| self.loader.process_default_path() | |
| self.db = self.loader.get_db() | |
| self.oslist = self.db.get_os_list() | |
| def get_instance(cls): | |
| 'Get libosinfo connection\n ' | |
| if (cls._instance is None): | |
| cls._instance = _OsInfoDatabase() | |
| return cls._instance | |
| def get_os(self, os_name): | |
| "Retrieve OS object based on id, unique URI identifier of the OS\n :param os_name: id - the unique operating systemidentifier\n e.g. http://fedoraproject.org/fedora/21,\n http://microsoft.com/win/xp,\n or a\n short-id - the short name of the OS\n e.g. fedora21, winxp\n :returns: The operation system object Libosinfo.Os\n :raise exception.OsInfoNotFound: If os hasn't been found\n " | |
| if (libosinfo is None): | |
| return | |
| if (not os_name): | |
| raise exception.OsInfoNotFound(os_name='Empty') | |
| fltr = libosinfo.Filter.new() | |
| flt_field = ('id' if os_name.startswith('http') else 'short-id') | |
| fltr.add_constraint(flt_field, os_name) | |
| filtered = self.oslist.new_filtered(fltr) | |
| list_len = filtered.get_length() | |
| if (not list_len): | |
| raise exception.OsInfoNotFound(os_name=os_name) | |
| return filtered.get_nth(0) | |
| class OsInfo(object, ): | |
| 'OS Information Structure\n ' | |
| def __init__(self, os_name): | |
| self._os_obj = self._get_os_obj(os_name) | |
| def _get_os_obj(self, os_name): | |
| if (os_name is not None): | |
| try: | |
| return _OsInfoDatabase.get_instance().get_os(os_name) | |
| except exception.NovaException as e: | |
| LOG.warning('Cannot find OS information - Reason: (%s)', e) | |
| def network_model(self): | |
| if (self._os_obj is not None): | |
| fltr = libosinfo.Filter() | |
| fltr.add_constraint('class', 'net') | |
| devs = self._os_obj.get_all_devices(fltr) | |
| if devs.get_length(): | |
| return devs.get_nth(0).get_name() | |
| def disk_model(self): | |
| if (self._os_obj is not None): | |
| fltr = libosinfo.Filter() | |
| fltr.add_constraint('class', 'block') | |
| devs = self._os_obj.get_all_devices(fltr) | |
| if devs.get_length(): | |
| return devs.get_nth(0).get_name() | |
| class HardwareProperties(object, ): | |
| def __init__(self, image_meta): | |
| ':param image_meta: ImageMeta object\n ' | |
| self.img_props = image_meta.properties | |
| os_key = self.img_props.get('os_distro') | |
| self.os_info_obj = OsInfo(os_key) | |
| def network_model(self): | |
| model = self.img_props.get('hw_vif_model', self.os_info_obj.network_model) | |
| return ('virtio' if (model == 'virtio-net') else model) | |
| def disk_model(self): | |
| model = self.img_props.get('hw_disk_bus', self.os_info_obj.disk_model) | |
| return ('virtio' if (model == 'virtio-block') else model) | |
Xet Storage Details
- Size:
- 3.66 kB
- Xet hash:
- f9809965e472867110921ba2da537064b142e9458ecc9fea9a2a9d37045fbedb
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.