Debian Codegraph @

ansible_collections/infoblox/nios_modules/plugins/modules/nios_restartservices.py

raw symbols SCIP
1 #!/usr/bin/python
2 # Copyright (c) 2018-2019 Red Hat, Inc.
3 # Copyright (c) 2020 Infoblox, Inc.
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import absolute_import, division, print_function
7 __metaclass__ = type
8
9 DOCUMENTATION = '''
10 ---
11 module: nios_restartservices
12 author: "Mauricio Teixeira (@badnetmask)"
13 short_description: Restart grid services.
14 version_added: "1.1.0"
15 description:
16 - Restart grid services.
17 - When invoked without any options, will restart ALL services on the
18 default restart group IF NEEDED.
19 requirements:
20 - infoblox-client
21 extends_documentation_fragment: infoblox.nios_modules.nios
22 notes:
23 - This module supports C(check_mode).
24 options:
25 groups:
26 description:
27 - The list of the Service Restart Groups to restart.
28 required: false
29 type: list
30 elements: str
31 members:
32 description:
33 - The list of the Grid Members to restart.
34 required: false
35 type: list
36 elements: str
37 mode:
38 description:
39 - The restart method in case of grid restart.
40 required: false
41 type: str
42 choices:
43 - GROUPED
44 - SEQUENTIAL
45 - SIMULTANEOUS
46 restart_option:
47 description:
48 - Controls whether services are restarted unconditionally or when needed
49 required: false
50 type: str
51 default: RESTART_IF_NEEDED
52 choices:
53 - RESTART_IF_NEEDED
54 - FORCE_RESTART
55 services:
56 description:
57 - The list of services the restart applicable to.
58 required: false
59 type: list
60 elements: str
61 default: ALL
62 choices:
63 - ALL
64 - DNS
65 - DHCP
66 - DHCPV4
67 - DHCPV6
68 '''
69
70 EXAMPLES = '''
71 - name: Restart all grid services if needed.
72 infoblox.nios_modules.nios_restartservices:
73 provider:
74 host: "{{ inventory_hostname_short }}"
75 username: admin
76 password: admin
77 connection: local
78
79 - name: Restart DNS service if needed.
80 infoblox.nios_modules.nios_restartservices:
81 services:
82 - DNS
83 provider:
84 host: "{{ inventory_hostname_short }}"
85 username: admin
86 password: admin
87 connection: local
88 '''
89
90 RETURN = ''' # '''
91
92 from ansible.module_utils.basic import AnsibleModule
93 from ..module_utils.api import WapiModule
94 from ..module_utils.api import normalize_ib_spec
95
96
97 def main():
98 ''' Main entry point for module execution
99 '''
100
101 ib_spec = dict(
102 groups=dict(type='list', elements='str'),
103 members=dict(type='list', elements='str'),
104 mode=dict(type='str', choices=['GROUPED', 'SEQUENTIAL',
105 'SIMULTANEOUS']),
106 restart_option=dict(type='str', default='RESTART_IF_NEEDED',
107 choices=['RESTART_IF_NEEDED', 'FORCE_RESTART']),
108 services=dict(type='list', elements='str', default=['ALL'],
109 choices=['ALL', 'DNS', 'DHCP', 'DHCPV4', 'DHCPV6'])
110 )
111
112 argument_spec = dict(
113 provider=dict(required=True)
114 )
115
116 argument_spec.update(normalize_ib_spec(ib_spec))
117 argument_spec.update(WapiModule.provider_spec)
118
119 module = AnsibleModule(argument_spec=argument_spec,
120 supports_check_mode=True)
121
122 wapi = WapiModule(module)
123
124 # restart is a grid function, so we need to properly format
125 # the arguments before sending the command
126 restart_params = module.params
127 del restart_params['provider']
128 if restart_params['groups'] is None:
129 del restart_params['groups']
130 if restart_params['members'] is None:
131 del restart_params['members']
132 if restart_params['mode'] is None:
133 del restart_params['mode']
134 grid_obj = wapi.get_object('grid')
135 if grid_obj is None:
136 module.fail_json(msg='Failed to get NIOS grid information.')
137 result = wapi.call_func('restartservices', grid_obj[0]['_ref'], restart_params)
138
139 module.exit_json(**result)
140
141
142 if __name__ == '__main__':
143 main()