object_lifecycles.rst 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. Object states and lifecycles
  2. ============================
  3. Overview
  4. --------
  5. Some objects, namely, Instances, Volumes, Snapshots and Images, have a specific
  6. life-cycle and a set of states they can be in. For example, an Instance may
  7. be in state RUNNING and a volume maybe in state AVAILABLE. These provider
  8. specific states are mapped to a common vocabulary of states in CloudBridge.
  9. In addition, it is common to want to wait for objects to reach a particular
  10. state. For example, wait for an instance to transition from PENDING->RUNNING.
  11. To facilitate this, all such objects in CloudBridge implement the
  12. :py:class:`ObjectLifeCycleMixin`. Each object with a lifecycle has a state
  13. property, a refresh method and a wait_for method.
  14. The state property will return the object's current state, and the refresh()
  15. method can be used to requery the server and update the object's state.
  16. The wait_for method can be used to wait for the object to transition to a
  17. desired state or set of states.
  18. There is also a convenience method named wait_till_ready(), which will wait
  19. for the object to reach a ready-to-use state. A ready-to-use state would mean
  20. that the object has been successfully created and can be interacted with, and
  21. is not in an error state. Since this can be tedious to get right, the
  22. wait_till_ready() method encapsulates this behaviour. For example - in the case
  23. of an Instance, wait_till_ready() will internally call the wait_for method as
  24. follows:
  25. .. code-block:: python
  26. self.wait_for(
  27. [InstanceState.RUNNING],
  28. terminal_states=[InstanceState.TERMINATED, InstanceState.ERROR],
  29. timeout=timeout,
  30. interval=interval)
  31. This would cause the wait_for method to repeatedly call refresh() till the
  32. object's state reaches RUNNING. It will raise a :class:`WaitStateException`
  33. if the timeout expires, or the object reaches a terminal state, such as
  34. TERMINATED or ERROR, in which case it is no longer reasonable to wait for the
  35. object to reach a running state.
  36. Informational states and actionable states
  37. ------------------------------------------
  38. As in the wait_for example above, some states are purely informational, and
  39. some states are actionable. Informational states are meant to provide
  40. information to the end-user, and should generally not be used by program logic
  41. to take actions. For example, it would be incorrect to write a wait_for
  42. function as follows:
  43. .. code-block:: python
  44. wait_for([InstanceState.PENDING], ...)
  45. This is because the PENDING state is fleeting and may occur too fast to be
  46. reliably detected by the client. In contrast, a state such as RUNNING is more
  47. stable and program logic can reasonably take actions based on such states. In
  48. the discussion that follows, we will specifically differentiate between
  49. informational and actionable states.
  50. Instance states and lifecycle
  51. -----------------------------
  52. The following states are defined for a CloudBridge Instance.
  53. =================== ============= ==================
  54. State Category Description
  55. =================== ============= ==================
  56. UNKNOWN actionable Instance state is unknown. This means that the instance does not exist or CloudBridge does not know how to map this state.
  57. PENDING informational Instance is pending
  58. CONFIGURING informational Instance is being reconfigured in some way and may not be usable.
  59. RUNNING actionable Instance is running.
  60. REBOOTING informational Instance is rebooting.
  61. TERMINATED actionable Instance is terminated. No further operations possible.
  62. STOPPED actionable Instance is stopped. Instance can be resumed.
  63. ERROR actionable Instance is in an error state. No further operations possible.
  64. =================== ============= ==================
  65. The lifecycle diagram is as follows:
  66. .. image:: ../images/lifecycle_instance.svg
  67. Actionable states are shown in blue and informational states in cyan.
  68. Note that any state could potentially transition into an ERROR state.
  69. An Instance may initially be in an UNKNOWN state and transition into
  70. a PENDING state on launch. Similarly, it may transition into an UNKNOWN
  71. state after TERMINATION and the object no longer exists. More rarely, an
  72. instance may transition into an UNKNOWN state if CloudBridge does not know
  73. how to map the state reported by the cloud provider. Therefore, when writing
  74. a wait_for method, these potential transitions should be taken into account.
  75. Volume states and lifecycle
  76. ---------------------------
  77. The following states are defined for a CloudBridge Volume.
  78. =================== ============= ==================
  79. State Category Description
  80. =================== ============= ==================
  81. UNKNOWN actionable Volume state is unknown. This means that the volume does not exist or CloudBridge does not know how to map this state.
  82. CREATING informational Volume is pending
  83. CONFIGURING informational Volume is being reconfigured in some way and may not be usable.
  84. AVAILABLE actionable Volume is unattached and available for use.
  85. IN_USE informational Volume is attached to an instance and in-use.
  86. DELETED actionable Volume has been deleted. No further operations possible.
  87. ERROR actionable Volume is in an error state. No further operations possible.
  88. =================== ============= ==================
  89. The lifecycle diagram is as follows:
  90. .. image:: ../images/lifecycle_volume.svg
  91. Actionable states are shown in blue and informational states in cyan.
  92. Note that any state could potentially transition into an ERROR state.
  93. A Volume may initially be in an UNKNOWN state and transition into
  94. a CREATING state when created anew. Similarly, it may transition into an UNKNOWN
  95. state after DELETED and the object no longer exists. More rarely, a
  96. volume may transition into an UNKNOWN state if CloudBridge does not know
  97. how to map the state reported by the cloud provider. A Volume will typically
  98. transition through a CONFIGURING stage before going to an IN_USE stage and vice
  99. versa.
  100. Snapshot states and lifecycle
  101. -----------------------------
  102. The following states are defined for a CloudBridge Snapshot.
  103. =================== ============= ==================
  104. State Category Description
  105. =================== ============= ==================
  106. UNKNOWN actionable Snapshot state is unknown. This means that the snapshot does not exist or CloudBridge does not know how to map this state.
  107. PENDING informational Snapshot is pending
  108. CONFIGURING informational Snapshot is being reconfigured in some way and may not be usable.
  109. AVAILABLE actionable Snapshot is ready.
  110. ERROR actionable Snapshot is in an error state. No further operations possible.
  111. =================== ============= ==================
  112. The lifecycle diagram is as follows:
  113. .. image:: ../images/lifecycle_snapshot.svg
  114. Actionable states are shown in blue and informational states in cyan.
  115. Note that any state could potentially transition into an ERROR state.
  116. A Snapshot may initially be in an UNKNOWN state and transition into
  117. a PENDING state when created anew. Similarly, it may transition into an UNKNOWN
  118. state after deleted and the object no longer exists. More rarely, a
  119. snapshot may transition into an UNKNOWN state if CloudBridge does not know
  120. how to map the state reported by the cloud provider.
  121. Image states and lifecycle
  122. --------------------------
  123. The following states are defined for a CloudBridge Image.
  124. =================== ============= ==================
  125. State Category Description
  126. =================== ============= ==================
  127. UNKNOWN actionable Image state is unknown. This means that the Image does not exist or CloudBridge does not know how to map this state.
  128. PENDING informational Image is pending
  129. AVAILABLE actionable Image is ready.
  130. ERROR actionable Image is in an error state. No further operations possible.
  131. =================== ============= ==================
  132. The lifecycle diagram is as follows:
  133. .. image:: ../images/lifecycle_image.svg
  134. Actionable states are shown in blue and informational states in cyan.
  135. Note that any state could potentially transition into an ERROR state.
  136. An Image may initially be in an UNKNOWN state and transition into
  137. a PENDING state when created anew. Similarly, it may transition into an UNKNOWN
  138. state after deleted and the image no longer exists. More rarely, an
  139. Image may transition into an UNKNOWN state if CloudBridge does not know
  140. how to map the state reported by the cloud provider.