]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/ansible/output_wizards.py
2 ceph-mgr Output Wizards module
4 Output wizards are used to process results in different ways in
8 # pylint: disable=bad-continuation
13 from orchestrator
import InventoryDevice
, InventoryNode
15 from .ansible_runner_svc
import EVENT_DATA_URL
17 class OutputWizard(object):
18 """Base class for help to process output in completion objects
20 def __init__(self
, ar_client
, logger
):
21 """Make easy to work in output wizards using this attributes:
23 :param ars_client: Ansible Runner Service client
24 :param logger: log object
26 self
.ar_client
= ar_client
29 def process(self
, operation_id
, raw_result
):
30 """Make the magic here
32 :param operation_id: Allows to identify the Ansible Runner Service
33 operation whose result we wnat to process
34 :param raw_result: input for processing
36 raise NotImplementedError
38 class ProcessInventory(OutputWizard
):
39 """ Adapt the output of the playbook used in 'get_inventory'
40 to the Orchestrator expected output (list of InventoryNode)
43 def process(self
, operation_id
, raw_result
):
45 :param operation_id: Playbook uuid
46 :param raw_result: events dict with the results
50 {'37-100564f1-9fed-48c2-bd62-4ae8636dfcdb': {'host': '192.168.121.254',
51 'task': 'list storage inventory',
52 'event': 'runner_on_ok'},
53 '36-2016b900-e38f-7dcd-a2e7-00000000000e': {'host': '192.168.121.252'
54 'task': 'list storage inventory',
55 'event': 'runner_on_ok'}}
57 :return : list of InventoryNode
59 # Just making more readable the method
60 inventory_events
= raw_result
62 #Obtain the needed data for each result event
65 # Loop over the result events and request the event data
66 for event_key
, dummy_data
in inventory_events
.items():
68 event_response
= self
.ar_client
.http_get(EVENT_DATA_URL
%
69 (operation_id
, event_key
))
71 # self.pb_execution.play_uuid
73 # Process the data for each event
75 event_data
= json
.loads(event_response
.text
)["data"]["event_data"]
77 host
= event_data
["host"]
79 devices
= json
.loads(event_data
["res"]["stdout"])
81 for storage_device
in devices
:
82 dev
= InventoryDevice
.from_ceph_volume_inventory(storage_device
)
85 inventory_nodes
.append(InventoryNode(host
, devs
))
88 return inventory_nodes
90 class ProcessPlaybookResult(OutputWizard
):
91 """ Provides the result of a playbook execution as plain text
93 def process(self
, operation_id
, raw_result
):
95 :param operation_id: Playbook uuid
96 :param raw_result: events dict with the results
98 :return : String with the playbook execution event list
100 # Just making more readable the method
101 inventory_events
= raw_result
105 # Loop over the result events and request the data
106 for event_key
, dummy_data
in inventory_events
.items():
107 event_response
= self
.ar_client
.http_get(EVENT_DATA_URL
%
108 (operation_id
, event_key
))
110 result
+= event_response
.text
115 class ProcessHostsList(OutputWizard
):
116 """ Format the output of host ls call
118 def process(self
, operation_id
, raw_result
):
119 """ Format the output of host ls call
121 :param operation_id: Not used in this output wizard
122 :param raw_result: In this case is like the following json:
136 :return: list of InventoryNodes
138 # Just making more readable the method
139 host_ls_json
= raw_result
144 json_resp
= json
.loads(host_ls_json
)
146 for host
in json_resp
["data"]["hosts"]:
147 inventory_nodes
.append(InventoryNode(host
, []))
150 self
.log
.exception("Malformed json response")
152 self
.log
.exception("Unexpected content in Ansible Runner Service"
155 self
.log
.exception("Hosts data must be iterable in Ansible Runner "
158 return inventory_nodes