Merge "Refactor senlin node update logic"
This commit is contained in:
commit
b2ab0c20df
|
@ -11,7 +11,6 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from heat.common import exception
|
|
||||||
from heat.common.i18n import _
|
from heat.common.i18n import _
|
||||||
from heat.engine import attributes
|
from heat.engine import attributes
|
||||||
from heat.engine import constraints
|
from heat.engine import constraints
|
||||||
|
@ -43,12 +42,6 @@ class Node(resource.Resource):
|
||||||
'INIT', 'ACTIVE', 'CREATING',
|
'INIT', 'ACTIVE', 'CREATING',
|
||||||
)
|
)
|
||||||
|
|
||||||
_ACTION_STATUS = (
|
|
||||||
ACTION_SUCCEEDED, ACTION_FAILED,
|
|
||||||
) = (
|
|
||||||
'SUCCEEDED', 'FAILED',
|
|
||||||
)
|
|
||||||
|
|
||||||
ATTRIBUTES = (
|
ATTRIBUTES = (
|
||||||
ATTR_DETAILS, ATTR_CLUSTER,
|
ATTR_DETAILS, ATTR_CLUSTER,
|
||||||
) = (
|
) = (
|
||||||
|
@ -127,46 +120,20 @@ class Node(resource.Resource):
|
||||||
return node.to_dict()
|
return node.to_dict()
|
||||||
|
|
||||||
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
|
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
|
||||||
updaters = dict()
|
action_id = None
|
||||||
UPDATE_PROPS = [self.NAME, self.METADATA, self.PROFILE]
|
if prop_diff:
|
||||||
if any(p in prop_diff for p in UPDATE_PROPS):
|
if self.PROFILE in prop_diff:
|
||||||
params = dict((k, v) for k, v in prop_diff.items()
|
prop_diff['profile_id'] = prop_diff.pop(self.PROFILE)
|
||||||
if k in UPDATE_PROPS)
|
node = self.client().update_node(
|
||||||
if self.PROFILE in params:
|
self.resource_id, **prop_diff)
|
||||||
params['profile_id'] = params.pop(self.PROFILE)
|
action_id = node.location.split('/')[-1]
|
||||||
updaters['profile_update'] = {
|
|
||||||
'params': params,
|
|
||||||
'finished': False,
|
|
||||||
}
|
|
||||||
|
|
||||||
return updaters
|
return action_id
|
||||||
|
|
||||||
def check_update_complete(self, updaters):
|
def check_update_complete(self, action_id):
|
||||||
def check_action(updater, set_key):
|
if action_id is None:
|
||||||
action = self.client().get_action(updater['action'])
|
|
||||||
if action.status == self.ACTION_SUCCEEDED:
|
|
||||||
updater[set_key] = True
|
|
||||||
elif action.status == self.ACTION_FAILED:
|
|
||||||
raise exception.ResourceInError(
|
|
||||||
status_reason=action.status_reason,
|
|
||||||
resource_status=action.status,
|
|
||||||
)
|
|
||||||
|
|
||||||
if not updaters:
|
|
||||||
return True
|
return True
|
||||||
profile_update = updaters.get('profile_update')
|
return self.client_plugin().check_action_status(action_id)
|
||||||
if profile_update and not profile_update['finished']:
|
|
||||||
if 'action' not in profile_update:
|
|
||||||
resp = self.client().update_node(
|
|
||||||
self.resource_id, **profile_update['params'])
|
|
||||||
profile_update['action'] = resp.location.split('/')[-1]
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
check_action(profile_update, 'finished')
|
|
||||||
if not profile_update['finished']:
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def _resolve_attribute(self, name):
|
def _resolve_attribute(self, name):
|
||||||
node = self.client().get_node(self.resource_id,
|
node = self.client().get_node(self.resource_id,
|
||||||
|
|
Loading…
Reference in New Issue