~ubuntu-branches/ubuntu/trusty/cinder/trusty

« back to all changes in this revision

Viewing changes to cinder/volume/drivers/nfs.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-03-25 08:30:42 UTC
  • mfrom: (10.1.1 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20130325083042-4c9f80w7t98klicf
Tags: 1:2013.1~rc2-0ubuntu2
debian/rules: Fix FTBFS, we want '-v' and not '-V'. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
from oslo.config import cfg
23
23
 
24
24
from cinder import exception
25
 
from cinder import flags
26
25
from cinder.openstack.common import log as logging
27
26
from cinder.volume import driver
28
27
 
49
48
                    'of the nfs man page for details'),
50
49
]
51
50
 
52
 
FLAGS = flags.FLAGS
53
 
FLAGS.register_opts(volume_opts)
54
 
 
55
51
 
56
52
class RemoteFsDriver(driver.VolumeDriver):
57
53
    """Common base for drivers that work like NFS."""
66
62
    def delete_volume(self, volume):
67
63
        raise NotImplementedError()
68
64
 
 
65
    def delete_snapshot(self, snapshot):
 
66
        """Do nothing for this driver, but allow manager to handle deletion
 
67
           of snapshot in error state."""
 
68
        pass
 
69
 
69
70
    def ensure_export(self, ctx, volume):
70
71
        raise NotImplementedError()
71
72
 
263
264
        greatest_share = None
264
265
 
265
266
        for nfs_share in self._mounted_shares:
266
 
            capacity = self._get_available_capacity(nfs_share)
 
267
            capacity = self._get_available_capacity(nfs_share)[0]
267
268
            if capacity > greatest_size:
268
269
                greatest_share = nfs_share
269
270
                greatest_size = capacity
292
293
 
293
294
        available = 0
294
295
 
 
296
        size = int(out.split()[1])
295
297
        if self.configuration.nfs_disk_util == 'df':
296
298
            available = int(out.split()[3])
297
299
        else:
298
 
            size = int(out.split()[1])
299
300
            out, _ = self._execute('du', '-sb', '--apparent-size',
300
301
                                   '--exclude', '*snapshot*', mount_point,
301
302
                                   run_as_root=True)
302
303
            used = int(out.split()[0])
303
304
            available = size - used
304
305
 
305
 
        return available
 
306
        return available, size
306
307
 
307
308
    def _mount_nfs(self, nfs_share, mount_path, ensure=False):
308
309
        """Mount NFS share to mount path"""
311
312
 
312
313
        # Construct the NFS mount command.
313
314
        nfs_cmd = ['mount', '-t', 'nfs']
314
 
        if FLAGS.nfs_mount_options is not None:
315
 
            nfs_cmd.extend(['-o', FLAGS.nfs_mount_options])
 
315
        if cfg.CONF.nfs_mount_options is not None:
 
316
            nfs_cmd.extend(['-o', cfg.CONF.nfs_mount_options])
316
317
        nfs_cmd.extend([nfs_share, mount_path])
317
318
 
318
319
        try:
322
323
                LOG.warn(_("%s is already mounted"), nfs_share)
323
324
            else:
324
325
                raise
 
326
 
 
327
    def get_volume_stats(self, refresh=False):
 
328
        """Get volume status.
 
329
 
 
330
        If 'refresh' is True, run update the stats first."""
 
331
        if refresh or not self._stats:
 
332
            self._update_volume_status()
 
333
 
 
334
        return self._stats
 
335
 
 
336
    def _update_volume_status(self):
 
337
        """Retrieve status info from volume group."""
 
338
 
 
339
        LOG.debug(_("Updating volume status"))
 
340
        data = {}
 
341
        backend_name = self.configuration.safe_get('volume_backend_name')
 
342
        data["volume_backend_name"] = backend_name or 'Generic_NFS'
 
343
        data["vendor_name"] = 'Open Source'
 
344
        data["driver_version"] = '1.0'
 
345
        data["storage_protocol"] = 'nfs'
 
346
 
 
347
        self._ensure_shares_mounted()
 
348
 
 
349
        global_capacity = 0
 
350
        global_free = 0
 
351
        for nfs_share in self._mounted_shares:
 
352
            free, capacity = self._get_available_capacity(nfs_share)
 
353
            global_capacity += capacity
 
354
            global_free += free
 
355
 
 
356
        data['total_capacity_gb'] = global_capacity / 1024.0 ** 3
 
357
        data['free_capacity_gb'] = global_free / 1024.0 ** 3
 
358
        data['reserved_percentage'] = 0
 
359
        data['QoS_support'] = False
 
360
        self._stats = data