Skip to content

Commit 3e9fa3c

Browse files
asm0deuzguits
authored andcommitted
Fix module_utils issues
Modified paths to ceph_common in modules Move ca_common functions -> ceph_common Signed-off-by: Teoman ONAY <tonay@ibm.com>
1 parent 29d6ae6 commit 3e9fa3c

20 files changed

+109
-169
lines changed

plugins/module_utils/ca_common.py

Lines changed: 0 additions & 151 deletions
This file was deleted.

plugins/module_utils/ceph_common.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,97 @@
1010

1111
ExceptionType = TypeVar('ExceptionType', bound=BaseException)
1212

13+
def generate_cmd(cmd='ceph',
14+
sub_cmd=None,
15+
args=None,
16+
user_key=None,
17+
cluster='ceph',
18+
user='client.admin',
19+
container_image=None,
20+
interactive=False):
21+
'''
22+
Generate 'ceph' command line to execute
23+
'''
24+
25+
if user_key is None:
26+
user_key = '/etc/ceph/{}.{}.keyring'.format(cluster, user)
27+
28+
cmd = pre_generate_cmd(cmd, container_image=container_image, interactive=interactive) # noqa: E501
29+
30+
base_cmd = [
31+
'-n',
32+
user,
33+
'-k',
34+
user_key,
35+
'--cluster',
36+
cluster
37+
]
38+
39+
if sub_cmd is not None:
40+
base_cmd.extend(sub_cmd)
41+
42+
cmd.extend(base_cmd) if args is None else cmd.extend(base_cmd + args)
43+
44+
return cmd
45+
46+
47+
def container_exec(binary, container_image, interactive=False):
48+
'''
49+
Build the docker CLI to run a command inside a container
50+
'''
51+
52+
container_binary = os.getenv('CEPH_CONTAINER_BINARY')
53+
command_exec = [container_binary, 'run']
54+
55+
if interactive:
56+
command_exec.extend(['--interactive'])
57+
58+
command_exec.extend(['--rm',
59+
'--net=host',
60+
'-v', '/etc/ceph:/etc/ceph:z',
61+
'-v', '/var/lib/ceph/:/var/lib/ceph/:z',
62+
'-v', '/var/log/ceph/:/var/log/ceph/:z',
63+
'--entrypoint=' + binary, container_image])
64+
return command_exec
65+
66+
67+
def is_containerized():
68+
'''
69+
Check if we are running on a containerized cluster
70+
'''
71+
72+
if 'CEPH_CONTAINER_IMAGE' in os.environ:
73+
container_image = os.getenv('CEPH_CONTAINER_IMAGE')
74+
else:
75+
container_image = None
76+
77+
return container_image
78+
79+
80+
def pre_generate_cmd(cmd, container_image=None, interactive=False):
81+
'''
82+
Generate ceph prefix command
83+
'''
84+
if container_image:
85+
cmd = container_exec(cmd, container_image, interactive=interactive)
86+
else:
87+
cmd = [cmd]
88+
89+
return cmd
90+
91+
92+
def exec_command(module, cmd, stdin=None, check_rc=False):
93+
'''
94+
Execute command(s)
95+
'''
96+
97+
binary_data = False
98+
if stdin:
99+
binary_data = True
100+
rc, out, err = module.run_command(cmd, data=stdin, binary_data=binary_data, check_rc=check_rc) # noqa: E501
101+
102+
return rc, cmd, out, err
103+
13104

14105
def retry(exceptions: Type[ExceptionType], module: "AnsibleModule", retries: int = 20, delay: int = 1) -> Callable:
15106
def decorator(f: Callable) -> Callable:

plugins/modules/ceph_authtool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from ansible.module_utils.basic import AnsibleModule
55
try:
6-
from ansible.module_utils.ca_common import container_exec, \
6+
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import container_exec, \
77
is_containerized
88
except ImportError:
99
from module_utils.ca_common import container_exec, \

plugins/modules/ceph_crush.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from ansible.module_utils.basic import AnsibleModule
1111
try:
12-
from ansible.module_utils.ca_common import fatal
12+
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import fatal
1313
except ImportError:
1414
from module_utils.ca_common import fatal
1515
import datetime

plugins/modules/ceph_crush_rule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from ansible.module_utils.basic import AnsibleModule
1919
try:
20-
from ansible.module_utils.ca_common import exit_module, \
20+
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module, \
2121
generate_cmd, \
2222
is_containerized, \
2323
exec_command

plugins/modules/ceph_dashboard_user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from ansible.module_utils.basic import AnsibleModule
1919
try:
20-
from ansible.module_utils.ca_common import generate_cmd, \
20+
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import generate_cmd, \
2121
is_containerized, \
2222
exec_command, \
2323
exit_module, \

plugins/modules/ceph_ec_profile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from ansible.module_utils.basic import AnsibleModule
1919
try:
20-
from ansible.module_utils.ca_common import is_containerized, \
20+
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import is_containerized, \
2121
generate_cmd, \
2222
exec_command, \
2323
exit_module

plugins/modules/ceph_fs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from ansible.module_utils.basic import AnsibleModule
1919
try:
20-
from ansible.module_utils.ca_common import is_containerized, \
20+
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import is_containerized, \
2121
exec_command, \
2222
generate_cmd, \
2323
exit_module

plugins/modules/ceph_key.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from ansible.module_utils.basic import AnsibleModule
1919
try:
20-
from ansible.module_utils.ca_common import generate_cmd, \
20+
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import generate_cmd, \
2121
is_containerized, \
2222
container_exec, \
2323
fatal

plugins/modules/ceph_mgr_module.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from ansible.module_utils.basic import AnsibleModule
1919
try:
20-
from ansible.module_utils.ca_common import exit_module, \
20+
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module, \
2121
generate_cmd, \
2222
is_containerized
2323
except ImportError:

0 commit comments

Comments
 (0)