2
0

block_storage.rst 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. Working with block storage
  2. ==========================
  3. To add persistent storage to your cloud environments, you would use block
  4. storage devices, namely volumes and volume snapshots. A volume is attached to
  5. an instance and mounted as a file system for use by an application. A volume
  6. snapshot is a point-in-time snapshot of a volume that can be shared with other
  7. cloud users. Before a snapshot can be used, it is necessary to create a volume
  8. from it.
  9. Volume storage
  10. --------------
  11. Operations, such as creating a new volume and listing the existing ones, are
  12. performed via the :class:`.VolumeService`. To start, let's create a 1GB volume.
  13. .. code-block:: python
  14. vol = provider.storage.volumes.create('cloudbridge-vol', 1, 'us-east-1e')
  15. vol.wait_till_ready()
  16. provider.storage.volumes.list()
  17. Next, let's attach the volume to a running instance as device ``/dev/sdh``:
  18. vol.attach('i-dbf37022', '/dev/sdh')
  19. vol.refresh()
  20. vol.state
  21. # 'in-use'
  22. Once attached, from within the instance, it is necessary to create a file
  23. system on the new volume and mount it.
  24. Once you wish to detach a volume from an instance, it is necessary to unmount
  25. the file system from within the instance and detach it. The volume can then be
  26. attached to a different instance with all the data on it preserved.
  27. .. code-block:: python
  28. vol.detach()
  29. vol.refresh()
  30. vol.state
  31. # 'available'
  32. Snapshot storage
  33. ----------------
  34. A volume snapshot it created from an existing volume. Note that it may take a
  35. long time for a snapshot to become ready, particularly on AWS.
  36. .. code-block:: python
  37. snap = vol.create_snapshot('cloudbridge-snap',
  38. 'A demo snapshot created via CloudBridge.')
  39. snap.wait_till_ready()
  40. snap.state
  41. # 'available'
  42. In order to make use of a snapshot, it is necessary to create a volume from it::
  43. vol = provider.storage.volumes.create(
  44. 'cloudbridge-snap-vol', 1, 'us-east-1e', snapshot=snap)
  45. The newly created volume behaves just like any other volume and can be attached
  46. to an instance for use.