Skip to content

Commit

Permalink
Fix module_utils issues
Browse files Browse the repository at this point in the history
Modified paths to ceph_common in modules
Move ca_common functions -> ceph_common

Signed-off-by: Teoman ONAY <[email protected]>
  • Loading branch information
asm0deuz committed Jul 25, 2024
1 parent 1513a33 commit 015ac5d
Show file tree
Hide file tree
Showing 20 changed files with 109 additions and 169 deletions.
151 changes: 0 additions & 151 deletions plugins/module_utils/ca_common.py

This file was deleted.

91 changes: 91 additions & 0 deletions plugins/module_utils/ceph_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,97 @@

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

def generate_cmd(cmd='ceph',
sub_cmd=None,
args=None,
user_key=None,
cluster='ceph',
user='client.admin',
container_image=None,
interactive=False):
'''
Generate 'ceph' command line to execute
'''

if user_key is None:
user_key = '/etc/ceph/{}.{}.keyring'.format(cluster, user)

cmd = pre_generate_cmd(cmd, container_image=container_image, interactive=interactive) # noqa: E501

base_cmd = [
'-n',
user,
'-k',
user_key,
'--cluster',
cluster
]

if sub_cmd is not None:
base_cmd.extend(sub_cmd)

cmd.extend(base_cmd) if args is None else cmd.extend(base_cmd + args)

return cmd


def container_exec(binary, container_image, interactive=False):
'''
Build the docker CLI to run a command inside a container
'''

container_binary = os.getenv('CEPH_CONTAINER_BINARY')
command_exec = [container_binary, 'run']

if interactive:
command_exec.extend(['--interactive'])

command_exec.extend(['--rm',
'--net=host',
'-v', '/etc/ceph:/etc/ceph:z',
'-v', '/var/lib/ceph/:/var/lib/ceph/:z',
'-v', '/var/log/ceph/:/var/log/ceph/:z',
'--entrypoint=' + binary, container_image])
return command_exec


def is_containerized():
'''
Check if we are running on a containerized cluster
'''

if 'CEPH_CONTAINER_IMAGE' in os.environ:
container_image = os.getenv('CEPH_CONTAINER_IMAGE')
else:
container_image = None

return container_image


def pre_generate_cmd(cmd, container_image=None, interactive=False):
'''
Generate ceph prefix command
'''
if container_image:
cmd = container_exec(cmd, container_image, interactive=interactive)
else:
cmd = [cmd]

return cmd


def exec_command(module, cmd, stdin=None, check_rc=False):
'''
Execute command(s)
'''

binary_data = False
if stdin:
binary_data = True
rc, out, err = module.run_command(cmd, data=stdin, binary_data=binary_data, check_rc=check_rc) # noqa: E501

return rc, cmd, out, err


def retry(exceptions: Type[ExceptionType], module: "AnsibleModule", retries: int = 20, delay: int = 1) -> Callable:
def decorator(f: Callable) -> Callable:
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/ceph_authtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from ansible.module_utils.basic import AnsibleModule
try:
from ansible.module_utils.ca_common import container_exec, \
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import container_exec, \
is_containerized
except ImportError:
from module_utils.ca_common import container_exec, \
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/ceph_crush.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from ansible.module_utils.basic import AnsibleModule
try:
from ansible.module_utils.ca_common import fatal
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import fatal
except ImportError:
from module_utils.ca_common import fatal
import datetime
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/ceph_crush_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from ansible.module_utils.basic import AnsibleModule
try:
from ansible.module_utils.ca_common import exit_module, \
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module, \
generate_cmd, \
is_containerized, \
exec_command
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/ceph_dashboard_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from ansible.module_utils.basic import AnsibleModule
try:
from ansible.module_utils.ca_common import generate_cmd, \
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import generate_cmd, \
is_containerized, \
exec_command, \
exit_module, \
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/ceph_ec_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from ansible.module_utils.basic import AnsibleModule
try:
from ansible.module_utils.ca_common import is_containerized, \
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import is_containerized, \
generate_cmd, \
exec_command, \
exit_module
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/ceph_fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from ansible.module_utils.basic import AnsibleModule
try:
from ansible.module_utils.ca_common import is_containerized, \
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import is_containerized, \
exec_command, \
generate_cmd, \
exit_module
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/ceph_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from ansible.module_utils.basic import AnsibleModule
try:
from ansible.module_utils.ca_common import generate_cmd, \
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import generate_cmd, \
is_containerized, \
container_exec, \
fatal
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/ceph_mgr_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from ansible.module_utils.basic import AnsibleModule
try:
from ansible.module_utils.ca_common import exit_module, \
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module, \
generate_cmd, \
is_containerized
except ImportError:
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/ceph_osd.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from ansible.module_utils.basic import AnsibleModule
try:
from ansible.module_utils.ca_common import exit_module, generate_cmd, is_containerized # noqa: E501
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module, generate_cmd, is_containerized # noqa: E501
except ImportError:
from module_utils.ca_common import exit_module, generate_cmd, is_containerized # noqa: E501
import datetime
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/ceph_osd_flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from ansible.module_utils.basic import AnsibleModule
try:
from ansible.module_utils.ca_common import exit_module, \
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module, \
generate_cmd, \
is_containerized
except ImportError:
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/ceph_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from ansible.module_utils.basic import AnsibleModule
try:
from ansible.module_utils.ca_common import generate_cmd, \
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import generate_cmd, \
pre_generate_cmd, \
is_containerized, \
exec_command, \
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/ceph_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from ansible.module_utils.basic import AnsibleModule
try:
from ansible.module_utils.ca_common import exec_command, \
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exec_command, \
is_containerized, \
fatal
except ImportError:
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/ceph_volume_simple_activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from ansible.module_utils.basic import AnsibleModule
try:
from ansible.module_utils.ca_common import exit_module
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module
except ImportError:
from module_utils.ca_common import exit_module
import datetime
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/ceph_volume_simple_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from ansible.module_utils.basic import AnsibleModule
try:
from ansible.module_utils.ca_common import exit_module
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module
except ImportError:
from module_utils.ca_common import exit_module
import datetime
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/cephadm_adopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from ansible.module_utils.basic import AnsibleModule
try:
from ansible.module_utils.ca_common import exit_module
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import exit_module
except ImportError:
from module_utils.ca_common import exit_module
import datetime
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/radosgw_caps.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from ansible.module_utils.basic import AnsibleModule

try:
from ansible.module_utils.ca_common import (
from ansible_collections.ceph.automation.plugins.module_utils.ceph_common import (
exit_module,
exec_command,
is_containerized,
Expand Down
Loading

0 comments on commit 015ac5d

Please sign in to comment.