Revision 845b7ed1 lib/storage/gluster.py

b/lib/storage/gluster.py
33 33
from ganeti import errors
34 34
from ganeti import netutils
35 35
from ganeti import constants
36
from ganeti import ssconf
36 37

  
37 38
from ganeti.utils import io
38 39
from ganeti.storage import base
......
277 278
class GlusterStorage(base.BlockDev):
278 279
  """File device using the Gluster backend.
279 280

  
280
  This class represents a file storage backend device stored on Gluster. The
281
  system administrator must mount the Gluster device himself at boot time before
282
  Ganeti is run.
281
  This class represents a file storage backend device stored on Gluster. Ganeti
282
  mounts and unmounts the Gluster devices automatically.
283 283

  
284 284
  The unique_id for the file device is a (file_driver, file_path) tuple.
285 285

  
......
290 290
    """
291 291
    if children:
292 292
      base.ThrowError("Invalid setup for file device")
293
    super(GlusterStorage, self).__init__(unique_id, children, size, params,
294
                                         dyn_params)
295
    if not isinstance(unique_id, (tuple, list)) or len(unique_id) != 2:
296
      raise ValueError("Invalid configuration data %s" % str(unique_id))
297
    self.driver = unique_id[0]
298
    self.dev_path = unique_id[1]
299 293

  
300
    self.file = FileDeviceHelper(self.dev_path)
294
    try:
295
      driver, path = unique_id
296
    except ValueError: # wrong number of arguments
297
      raise ValueError("Invalid configuration data %s" % repr(unique_id))
298

  
299
    server_addr = params[constants.GLUSTER_HOST]
300
    port = params[constants.GLUSTER_PORT]
301
    volume = params[constants.GLUSTER_VOLUME]
302

  
303
    self.volume = GlusterVolume(server_addr, port, volume)
304
    self.path = path
305
    self.driver = driver
306
    self.full_path = io.PathJoin(self.volume.mount_point, self.path)
307
    self.file = None
308

  
309
    super(GlusterStorage, self).__init__(unique_id, children, size,
310
                                         params, dyn_params)
301 311

  
302 312
    self.Attach()
303 313

  
......
341 351
    @return: True if the removal was successful
342 352

  
343 353
    """
344
    return self.file.Remove()
354
    with self.volume.Mount():
355
      self.file = FileDeviceHelper(self.full_path)
356
      if self.file.Remove():
357
        self.file = None
358
        return True
359
      else:
360
        return False
345 361

  
346 362
  def Rename(self, new_id):
347 363
    """Renames the file.
......
367 383
    @return: True if file exists
368 384

  
369 385
    """
386
    try:
387
      self.volume.Mount()
388
      self.file = FileDeviceHelper(self.full_path)
389
      self.dev_path = self.full_path
390
    except Exception as err:
391
      self.volume.Unmount()
392
      raise err
393

  
370 394
    self.attached = self.file.Exists()
371 395
    return self.attached
372 396

  
......
395 419
    if not isinstance(unique_id, (tuple, list)) or len(unique_id) != 2:
396 420
      raise ValueError("Invalid configuration data %s" % str(unique_id))
397 421

  
398
    dev_path = unique_id[1]
422
    full_path = unique_id[1]
423

  
424
    server_addr = params[constants.GLUSTER_HOST]
425
    port = params[constants.GLUSTER_PORT]
426
    volume = params[constants.GLUSTER_VOLUME]
427

  
428
    volume_obj = GlusterVolume(server_addr, port, volume)
429
    full_path = io.PathJoin(volume_obj.mount_point, full_path)
430

  
431
    # Possible optimization: defer actual creation to first Attach, rather
432
    # than mounting and unmounting here, then remounting immediately after.
433
    with volume_obj.Mount():
434
      FileDeviceHelper.CreateFile(full_path, size, create_folders=True)
399 435

  
400
    FileDeviceHelper.Create(dev_path, size)
401 436
    return GlusterStorage(unique_id, children, size, params, dyn_params)

Also available in: Unified diff