object_lifecycles.rst 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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.DELETED, 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. DELETED 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
  57. that the instance does not exist or
  58. CloudBridge does not know how to map this
  59. state.
  60. PENDING informational Instance is pending
  61. CONFIGURING informational Instance is being reconfigured in some
  62. way and may not be usable.
  63. RUNNING actionable Instance is running.
  64. REBOOTING informational Instance is rebooting.
  65. DELETED actionable Instance is deleted. No further
  66. operations possible.
  67. STOPPED actionable Instance is stopped. Instance can be
  68. resumed.
  69. ERROR actionable Instance is in an error state. No further
  70. operations possible.
  71. =================== ============= ==================
  72. The lifecycle diagram is as follows:
  73. .. image:: ../images/lifecycle_instance.svg
  74. Actionable states are shown in blue and informational states in cyan.
  75. Note that any state could potentially transition into an ERROR state.
  76. An Instance may initially be in an UNKNOWN state and transition into
  77. a PENDING state on launch. Similarly, it may transition into an UNKNOWN
  78. state after TERMINATION and the object no longer exists. More rarely, an
  79. instance may transition into an UNKNOWN state if CloudBridge does not know
  80. how to map the state reported by the cloud provider. Therefore, when writing
  81. a wait_for method, these potential transitions should be taken into account.
  82. Volume states and lifecycle
  83. ---------------------------
  84. The following states are defined for a CloudBridge Volume.
  85. =================== ============= ==================
  86. State Category Description
  87. =================== ============= ==================
  88. UNKNOWN actionable Volume state is unknown. This means that
  89. the volume does not exist or CloudBridge
  90. does not know how to map this state.
  91. CREATING informational Volume is pending
  92. CONFIGURING informational Volume is being reconfigured in some way
  93. and may not be usable.
  94. AVAILABLE actionable Volume is unattached and available for use.
  95. IN_USE informational Volume is attached to an instance and in-use.
  96. DELETED actionable Volume has been deleted. No further
  97. operations possible.
  98. ERROR actionable Volume is in an error state. No further
  99. operations possible.
  100. =================== ============= ==================
  101. The lifecycle diagram is as follows:
  102. .. image:: ../images/lifecycle_volume.svg
  103. Actionable states are shown in blue and informational states in cyan.
  104. Note that any state could potentially transition into an ERROR state.
  105. A Volume may initially be in an UNKNOWN state and transition into
  106. a CREATING state when created anew. Similarly, it may transition into an UNKNOWN
  107. state after DELETED and the object no longer exists. More rarely, a
  108. volume may transition into an UNKNOWN state if CloudBridge does not know
  109. how to map the state reported by the cloud provider. A Volume will typically
  110. transition through a CONFIGURING stage before going to an IN_USE stage and vice
  111. versa.
  112. Snapshot states and lifecycle
  113. -----------------------------
  114. The following states are defined for a CloudBridge Snapshot.
  115. =================== ============= ==================
  116. State Category Description
  117. =================== ============= ==================
  118. UNKNOWN actionable Snapshot state is unknown. This means
  119. that the snapshot does not exist or
  120. CloudBridge does not know how to map this
  121. state.
  122. PENDING informational Snapshot is pending
  123. CONFIGURING informational Snapshot is being reconfigured in some
  124. way and may not be usable.
  125. AVAILABLE actionable Snapshot is ready.
  126. ERROR actionable Snapshot is in an error state. No further
  127. operations possible.
  128. =================== ============= ==================
  129. The lifecycle diagram is as follows:
  130. .. image:: ../images/lifecycle_snapshot.svg
  131. Actionable states are shown in blue and informational states in cyan.
  132. Note that any state could potentially transition into an ERROR state.
  133. A Snapshot may initially be in an UNKNOWN state and transition into
  134. a PENDING state when created anew. Similarly, it may transition into an UNKNOWN
  135. state after deleted and the object no longer exists. More rarely, a
  136. snapshot may transition into an UNKNOWN state if CloudBridge does not know
  137. how to map the state reported by the cloud provider.
  138. Image states and lifecycle
  139. --------------------------
  140. The following states are defined for a CloudBridge Image.
  141. =================== ============= ==================
  142. State Category Description
  143. =================== ============= ==================
  144. UNKNOWN actionable Image state is unknown. This means that
  145. the Image does not exist or CloudBridge
  146. does not know how to map this state.
  147. PENDING informational Image is pending
  148. AVAILABLE actionable Image is ready.
  149. ERROR actionable Image is in an error state. No further
  150. operations possible.
  151. =================== ============= ==================
  152. The lifecycle diagram is as follows:
  153. .. image:: ../images/lifecycle_image.svg
  154. Actionable states are shown in blue and informational states in cyan.
  155. Note that any state could potentially transition into an ERROR state.
  156. An Image may initially be in an UNKNOWN state and transition into
  157. a PENDING state when created anew. Similarly, it may transition into an UNKNOWN
  158. state after deleted and the image no longer exists. More rarely, an
  159. Image may transition into an UNKNOWN state if CloudBridge does not know
  160. how to map the state reported by the cloud provider.