python utility to manage a tripleo based cloud
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.4KB

  1. # Copyright 2016 Red Hat, Inc.
  2. # All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  5. # not use this file except in compliance with the License. You may obtain
  6. # a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. # License for the specific language governing permissions and limitations
  14. # under the License.
  15. from __future__ import print_function
  16. from tripleo_common.actions import scale
  17. from tripleoclient import exceptions
  18. from tripleoclient import utils
  19. from tripleoclient.workflows import base
  20. def ansible_tear_down(clients, **workflow_input):
  21. workflow_client = clients.workflow_engine
  22. tripleoclients = clients.tripleoclient
  23. workflow_input['playbook_name'] = 'scale_playbook.yaml'
  24. with tripleoclients.messaging_websocket() as ws:
  25. execution = base.start_workflow(
  26. workflow_client,
  27. 'tripleo.deployment.v1.config_download_deploy',
  28. workflow_input=workflow_input
  29. )
  30. for payload in base.wait_for_messages(workflow_client, ws, execution):
  31. print(payload['message'])
  32. if payload['status'] == 'SUCCESS':
  33. print("Scale-down configuration completed.")
  34. else:
  35. raise exceptions.DeploymentError("Scale-down configuration failed.")
  36. def scale_down(clients, plan_name, nodes, timeout=None):
  37. """Unprovision and deletes overcloud nodes from a heat stack.
  38. :param clients: Application client object.
  39. :type clients: Object
  40. :param timeout: Timeout to use when deleting nodes. If timeout is None
  41. it will be set to 240.
  42. :type timeout: Integer
  43. :param plan: Plan name.
  44. :type plan: String
  45. :param nodes: List of nodes to delete.
  46. :type nodes: List
  47. """
  48. workflow_input = {
  49. "plan_name": plan_name,
  50. "nodes": nodes,
  51. }
  52. ansible_tear_down(clients, **workflow_input)
  53. if not timeout:
  54. timeout = 240
  55. context = clients.tripleoclient.create_mistral_context()
  56. scale_down_action = scale.ScaleDownAction(nodes=nodes, timeout=timeout)
  57. scale_down_action.run(context=context)
  58. utils.wait_for_stack_ready(
  59. orchestration_client=clients.orchestration,
  60. stack_name=plan_name,
  61. action='UPDATE'
  62. )