~ubuntu-branches/ubuntu/vivid/ironic/vivid-updates

« back to all changes in this revision

Viewing changes to ironic/common/states.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-01-05 12:21:37 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20150105122137-171bqrdpcxqipunk
Tags: 2015.1~b1-0ubuntu1
* New upstream beta release:
  - d/control: Align version requirements with upstream release.
* d/watch: Update uversionmangle to deal with kilo beta versioning
  changes.
* d/control: Bumped Standards-Version to 3.9.6, no changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
maintenance mode in this case.
29
29
"""
30
30
 
 
31
from ironic.common import fsm
 
32
from ironic.openstack.common import log as logging
 
33
 
 
34
LOG = logging.getLogger(__name__)
31
35
 
32
36
#####################
33
37
# Provisioning states
85
89
"""
86
90
 
87
91
REBUILD = 'rebuild'
88
 
""" Node is currently being rebuilt. """
 
92
""" Node is to be rebuilt.
 
93
 
 
94
This is not used as a state, but rather as a "verb" when changing the node's
 
95
provision_state via the REST API.
 
96
"""
89
97
 
90
98
 
91
99
##############
100
108
 
101
109
REBOOT = 'rebooting'
102
110
""" Node is rebooting. """
 
111
 
 
112
 
 
113
#####################
 
114
# State machine model
 
115
#####################
 
116
def on_exit(old_state, event):
 
117
    """Used to log when a state is exited."""
 
118
    LOG.debug("Exiting old state '%s' in response to event '%s'",
 
119
        old_state, event)
 
120
 
 
121
 
 
122
def on_enter(new_state, event):
 
123
    """Used to log when entering a state."""
 
124
    LOG.debug("Entering new state '%s' in response to event '%s'",
 
125
              new_state, event)
 
126
 
 
127
watchers = {}
 
128
watchers['on_exit'] = on_exit
 
129
watchers['on_enter'] = on_enter
 
130
 
 
131
machine = fsm.FSM()
 
132
 
 
133
# Add stable states
 
134
machine.add_state(NOSTATE, **watchers)
 
135
machine.add_state(ACTIVE, **watchers)
 
136
machine.add_state(ERROR, **watchers)
 
137
 
 
138
# Add deploy* states
 
139
machine.add_state(DEPLOYDONE, target=ACTIVE, **watchers)
 
140
machine.add_state(DEPLOYING, target=DEPLOYDONE, **watchers)
 
141
machine.add_state(DEPLOYWAIT, **watchers)
 
142
machine.add_state(DEPLOYFAIL, **watchers)
 
143
 
 
144
# Add delete* states
 
145
machine.add_state(DELETED, target=NOSTATE, **watchers)
 
146
machine.add_state(DELETING, target=DELETED, **watchers)
 
147
 
 
148
 
 
149
# From NOSTATE, a deployment may be started
 
150
machine.add_transition(NOSTATE, DEPLOYING, 'deploy')
 
151
 
 
152
# A deployment may fail
 
153
machine.add_transition(DEPLOYING, DEPLOYFAIL, 'fail')
 
154
 
 
155
# A failed deployment may be retried
 
156
# ironic/conductor/manager.py:do_node_deploy()
 
157
machine.add_transition(DEPLOYFAIL, DEPLOYING, 'rebuild')
 
158
 
 
159
# A deployment may also wait on external callbacks
 
160
machine.add_transition(DEPLOYING, DEPLOYWAIT, 'wait')
 
161
machine.add_transition(DEPLOYWAIT, DEPLOYING, 'resume')
 
162
 
 
163
# A deployment waiting on callback may time out
 
164
machine.add_transition(DEPLOYWAIT, DEPLOYFAIL, 'fail')
 
165
 
 
166
# A deployment may complete
 
167
machine.add_transition(DEPLOYING, ACTIVE, 'done')
 
168
 
 
169
# An active instance may be re-deployed
 
170
# ironic/conductor/manager.py:do_node_deploy()
 
171
machine.add_transition(ACTIVE, DEPLOYING, 'rebuild')
 
172
 
 
173
# An active instance may be deleted
 
174
# ironic/conductor/manager.py:do_node_tear_down()
 
175
machine.add_transition(ACTIVE, DELETING, 'delete')
 
176
 
 
177
# While a deployment is waiting, it may be deleted
 
178
# ironic/conductor/manager.py:do_node_tear_down()
 
179
machine.add_transition(DEPLOYWAIT, DELETING, 'delete')
 
180
 
 
181
# A failed deployment may also be deleted
 
182
# ironic/conductor/manager.py:do_node_tear_down()
 
183
machine.add_transition(DEPLOYFAIL, DELETING, 'delete')
 
184
 
 
185
# A delete may complete
 
186
machine.add_transition(DELETING, NOSTATE, 'done')
 
187
 
 
188
# These states can also transition to error
 
189
machine.add_transition(NOSTATE, ERROR, 'error')
 
190
machine.add_transition(DEPLOYING, ERROR, 'error')
 
191
machine.add_transition(ACTIVE, ERROR, 'error')
 
192
machine.add_transition(DELETING, ERROR, 'error')
 
193
 
 
194
# An errored instance can be rebuilt
 
195
# ironic/conductor/manager.py:do_node_deploy()
 
196
machine.add_transition(ERROR, DEPLOYING, 'rebuild')
 
197
# or deleted
 
198
# ironic/conductor/manager.py:do_node_tear_down()
 
199
machine.add_transition(ERROR, DELETING, 'delete')