components/openstack/cinder/files/solaris/zfs.py
changeset 1912 b0c17ef05b75
parent 1760 353323c7bdc1
child 1944 56ac2df1785b
equal deleted inserted replaced
1911:17096cac036b 1912:b0c17ef05b75
    28 from cinder import flags
    28 from cinder import flags
    29 from cinder.image import image_utils
    29 from cinder.image import image_utils
    30 from cinder.openstack.common import log as logging
    30 from cinder.openstack.common import log as logging
    31 from cinder.volume import driver
    31 from cinder.volume import driver
    32 
    32 
       
    33 from solaris_install.target.size import Size
       
    34 
    33 FLAGS = flags.FLAGS
    35 FLAGS = flags.FLAGS
    34 LOG = logging.getLogger(__name__)
    36 LOG = logging.getLogger(__name__)
    35 
    37 
    36 solaris_zfs_opts = [
    38 solaris_zfs_opts = [
    37     cfg.StrOpt('zfs_volume_base',
    39     cfg.StrOpt('zfs_volume_base',
   205         image_utils.upload_volume(context,
   207         image_utils.upload_volume(context,
   206                                   image_service,
   208                                   image_service,
   207                                   image_meta,
   209                                   image_meta,
   208                                   self.local_path(volume))
   210                                   self.local_path(volume))
   209 
   211 
   210     def _get_zfs_property(self, prop, vol_snap):
   212     def _get_zfs_property(self, prop, dataset):
   211         """Get the value of property for the volume or snapshot."""
   213         """Get the value of property for the dataset."""
   212         (out, _err) = self._execute('/usr/sbin/zfs', 'get', '-H', '-o',
   214         (out, _err) = self._execute('/usr/sbin/zfs', 'get', '-H', '-o',
   213                                     'value', prop, vol_snap)
   215                                     'value', prop, dataset)
   214         return out.rstrip()
   216         return out.rstrip()
   215 
   217 
   216     def _get_zfs_snap_name(self, snapshot):
   218     def _get_zfs_snap_name(self, snapshot):
   217         """Get the snapshot path."""
   219         """Get the snapshot path."""
   218         return "%s/%s@%s" % (self.configuration.zfs_volume_base,
   220         return "%s/%s@%s" % (self.configuration.zfs_volume_base,
   220 
   222 
   221     def _get_zfs_volume_name(self, volume):
   223     def _get_zfs_volume_name(self, volume):
   222         """Add the pool name to get the ZFS volume."""
   224         """Add the pool name to get the ZFS volume."""
   223         return "%s/%s" % (self.configuration.zfs_volume_base,
   225         return "%s/%s" % (self.configuration.zfs_volume_base,
   224                           volume['name'])
   226                           volume['name'])
   225 
       
   226     def _get_zpool_property(self, prop):
       
   227         """Get the value of property from the zpool."""
       
   228         zpool = self.configuration.zfs_volume_base.split('/')[0]
       
   229         try:
       
   230             value = None
       
   231             (out, _err) = self._execute('/usr/sbin/zpool', 'get', prop, zpool)
       
   232         except exception.ProcessExecutionError as err:
       
   233             LOG.error(_("Failed to get property '%s': %s")
       
   234                       % (prop, err.stderr))
       
   235             return value
       
   236 
       
   237         zpool_prop = out.splitlines()[1].split()
       
   238         if zpool_prop[1] == prop:
       
   239             value = zpool_prop[2]
       
   240 
       
   241         return value
       
   242 
   227 
   243     def _get_zvol_path(self, volume):
   228     def _get_zvol_path(self, volume):
   244         """Get the ZFS volume path."""
   229         """Get the ZFS volume path."""
   245         return "/dev/zvol/rdsk/%s" % self._get_zfs_volume_name(volume)
   230         return "/dev/zvol/rdsk/%s" % self._get_zfs_volume_name(volume)
   246 
   231 
   254         stats["storage_protocol"] = self.protocol
   239         stats["storage_protocol"] = self.protocol
   255         stats["driver_version"] = '1.0'
   240         stats["driver_version"] = '1.0'
   256         stats["vendor_name"] = 'Oracle'
   241         stats["vendor_name"] = 'Oracle'
   257         stats['QoS_support'] = False
   242         stats['QoS_support'] = False
   258 
   243 
   259         total = self._get_zpool_property("size")
   244         dataset = self.configuration.zfs_volume_base
   260         free = self._get_zpool_property("free")
   245         used_size = self._get_zfs_property('used', dataset)
   261         if total is not None:
   246         avail_size = self._get_zfs_property('avail', dataset)
   262             stats['total_capacity_gb'] = float(total.split('G')[0])
   247         stats['total_capacity_gb'] = \
   263         else:
   248             (Size(used_size) + Size(avail_size)).get(Size.gb_units)
   264             stats['total_capacity_gb'] = 0
   249         stats['free_capacity_gb'] = Size(avail_size).get(Size.gb_units)
   265         if free is not None:
       
   266             stats['free_capacity_gb'] = float(free.split('G')[0])
       
   267         else:
       
   268             stats['free_capacity_gb'] = 0
       
   269         stats['reserved_percentage'] = self.configuration.reserved_percentage
   250         stats['reserved_percentage'] = self.configuration.reserved_percentage
   270 
   251 
   271         self._stats = stats
   252         self._stats = stats
   272 
   253 
   273 
   254