-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathceph_osd_flag.py
130 lines (113 loc) · 3.66 KB
/
ceph_osd_flag.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Copyright 2020, Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import, division, print_function
__metaclass__ = type
from ansible.module_utils.basic import AnsibleModule
try:
from ansible.module_utils.ca_common import exit_module, \
generate_cmd, \
is_containerized
except ImportError:
from module_utils.ca_common import exit_module, \
generate_cmd, \
is_containerized
import datetime
ANSIBLE_METADATA = {
'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'
}
DOCUMENTATION = '''
---
module: ceph_osd_flag
short_description: Manage Ceph OSD flag
version_added: "2.8"
description:
- Manage Ceph OSD flag
options:
name:
description:
- name of the ceph OSD flag.
required: true
choices: ['noup', 'nodown', 'noout', 'nobackfill', 'norebalance',
'norecover', 'noscrub', 'nodeep-scrub']
cluster:
description:
- The ceph cluster name.
required: false
default: ceph
state:
description:
- If 'present' is used, the module sets the OSD flag.
If 'absent' is used, the module will unset the OSD flag.
required: false
choices: ['present', 'absent']
default: present
author:
- Dimitri Savineau <[email protected]>
'''
EXAMPLES = '''
- name: set noup OSD flag
ceph_osd_flag:
name: noup
- name: unset multiple OSD flags
ceph_osd_flag:
name: '{{ item }}'
state: absent
loop:
- 'noup'
- 'norebalance'
'''
RETURN = '''# '''
def main():
module = AnsibleModule(
argument_spec=dict(
name=dict(type='str', required=True, choices=['noup', 'nodown', 'noout', 'nobackfill', 'norebalance', 'norecover', 'noscrub', 'nodeep-scrub']), # noqa: E501
cluster=dict(type='str', required=False, default='ceph'),
state=dict(type='str', required=False, default='present', choices=['present', 'absent']), # noqa: E501
),
supports_check_mode=True,
)
name = module.params.get('name')
cluster = module.params.get('cluster')
state = module.params.get('state')
startd = datetime.datetime.now()
container_image = is_containerized()
if state == 'present':
cmd = generate_cmd(sub_cmd=['osd', 'set'], args=[name], cluster=cluster, container_image=container_image) # noqa: E501
else:
cmd = generate_cmd(sub_cmd=['osd', 'unset'], args=[name], cluster=cluster, container_image=container_image) # noqa: E501
if module.check_mode:
exit_module(
module=module,
out='',
rc=0,
cmd=cmd,
err='',
startd=startd,
changed=False
)
else:
rc, out, err = module.run_command(cmd)
exit_module(
module=module,
out=out,
rc=rc,
cmd=cmd,
err=err,
startd=startd,
changed=True
)
if __name__ == '__main__':
main()