Skip to content

Commit

Permalink
Merge pull request #5951 from rook/mergify/bp/release-1.4/pr-5931
Browse files Browse the repository at this point in the history
ceph: Allowing ceph filesystem argument to be optional (bp #5931)
  • Loading branch information
mergify[bot] committed Aug 3, 2020
2 parents 2ef3b2e + 87a0538 commit 91b48b0
Showing 1 changed file with 73 additions and 41 deletions.
114 changes: 73 additions & 41 deletions cluster/examples/kubernetes/ceph/create-external-cluster-resources.py
Expand Up @@ -251,21 +251,16 @@ def create_cephCSIKeyring_RBDProvisioner(self):
def get_cephfs_data_pool_details(self):
cmd_json = {"prefix": "fs ls", "format": "json"}
ret_val, json_out, err_msg = self._common_cmd_json_gen(cmd_json)
# if there is an unsuccessful attempt,
if ret_val != 0 or len(json_out) == 0:
raise ExecutionFailureException(
"'fs ls' command failed.\nError: {}".format(
err_msg if ret_val != 0 else "No filesystem detected."))
# if there are multiple filesystems present, and
# no specific filesystem name and data-pool names are provided,
# then raise an exception
if len(json_out) > 1 and not self._arg_parser.cephfs_filesystem_name:
# if the arguments are not provided, generate an error message
raise ExecutionFailureException(
"More than ONE filesystems detected.\n" +
"{}\n\n".format(json_out) +
"Please manually provide the details for " +
"'--cephfs-filesystem-name'")
# if there is an unsuccessful attempt, report an error
if ret_val != 0:
# if fs and data_pool arguments are not set, silently return
if self._arg_parser.cephfs_filesystem_name == "" and self._arg_parser.cephfs_data_pool_name == "":
return
# if user has provided any of the
# '--cephfs-filesystem-name' or '--cephfs-data-pool-name' arguments,
# raise an exception as we are unable to verify the args
raise ExecutionFailureException("'fs ls' ceph call failed with error: {}".format(err_msg))

matching_json_out = {}
# if '--cephfs-filesystem-name' argument is provided,
# check whether the provided filesystem-name exists or not
Expand All @@ -281,29 +276,60 @@ def get_cephfs_data_pool_details(self):
self._arg_parser.cephfs_filesystem_name,
[str(x['name']) for x in json_out]))
matching_json_out = matching_json_out_list[0]
# if cephfs filesystem name is not provided,
# try to get a default fs name by doing the following
else:
self._arg_parser.cephfs_filesystem_name = str(json_out[0]['name'])
matching_json_out = json_out[0]
# a. check if there is only one filesystem is present
if len(json_out) == 1:
matching_json_out = json_out[0]
# b. or else, check if data_pool name is provided
elif self._arg_parser.cephfs_data_pool_name:
# and if present, check whether there exists a fs which has the data_pool
for eachJ in json_out:
if self._arg_parser.cephfs_data_pool_name in eachJ['data_pools']:
matching_json_out = eachJ
break
# if there is no matching fs exists, that means provided data_pool name is invalid
if not matching_json_out:
raise ExecutionFailureException(
"Provided data_pool name, {}, does not exists".format(
self._arg_parser.cephfs_data_pool_name))
# c. if nothing is set and couldn't find a default,
else:
# just return silently
return

if matching_json_out:
self._arg_parser.cephfs_filesystem_name = str(matching_json_out['name'])

if type(matching_json_out['data_pools']) == list:
if len(matching_json_out['data_pools']) == 0:
raise ExecutionFailureException("No 'data_pools' found.")
# if the user has already provided data-pool-name,
# through --cephfs-data-pool-name
if self._arg_parser.cephfs_data_pool_name:
# if the provided name is not matching with the one in the list
if self._arg_parser.cephfs_data_pool_name not in matching_json_out['data_pools']:
raise ExecutionFailureException(
("Provided 'data-pool-name': '{}', " +
"doesn't match from the data-pools' list: {}").format(
self._arg_parser.cephfs_data_pool_name,
[str(x) for x in matching_json_out['data_pools']]))
"{}: '{}', {}: {}".format(
"Provided data-pool-name",
self._arg_parser.cephfs_data_pool_name,
"doesn't match from the data-pools' list",
[str(x) for x in matching_json_out['data_pools']]))
# if data_pool name is not provided,
# then try to find a default data pool name
else:
# if no data_pools exist, silently return
if len(matching_json_out['data_pools']) == 0:
return
self._arg_parser.cephfs_data_pool_name = str(
matching_json_out['data_pools'][0])
# if there are more than one 'data_pools' exist,
# then warn the user that we are using the selected name
if len(matching_json_out['data_pools']) > 1:
print("WARNING: Multiple data pools detected.\n" +
"{}\n".format([str(x) for x in matching_json_out['data_pools']]) +
"Using the data-pool: {}\n".format(self._arg_parser.cephfs_data_pool_name))
print("{}: {}\n{}: '{}'\n".format(
"WARNING: Multiple data pools detected",
[str(x) for x in matching_json_out['data_pools']],
"Using the data-pool",
self._arg_parser.cephfs_data_pool_name))

def create_cephCSIKeyring_RBDNode(self):
cmd_json = {"prefix": "auth get-or-create",
Expand Down Expand Up @@ -455,21 +481,6 @@ def gen_json_out(self):
"pool": self.out_map['RBD_POOL_NAME']
}
},
{
"name": "cephfs",
"kind": "StorageClass",
"data": {
"fsName": self.out_map['CEPHFS_FS_NAME'],
"pool": self.out_map['CEPHFS_POOL_NAME']
}
},
{
"name": "ceph-rgw",
"kind": "StorageClass",
"data": {
"endpoint": self.out_map['RGW_ENDPOINT']
}
},
{
"name": "monitoring-endpoint",
"kind": "CephCluster",
Expand All @@ -479,6 +490,27 @@ def gen_json_out(self):
}
}
]
# if 'CEPHFS_FS_NAME' exists, then only add 'cephfs' StorageClass
if self.out_map['CEPHFS_FS_NAME']:
json_out.append(
{
"name": "cephfs",
"kind": "StorageClass",
"data": {
"fsName": self.out_map['CEPHFS_FS_NAME'],
"pool": self.out_map['CEPHFS_POOL_NAME']
}
})
# if 'RGW_ENDPOINT' exists, then only add 'ceph-rgw' StorageClass
if self.out_map['RGW_ENDPOINT']:
json_out.append(
{
"name": "ceph-rgw",
"kind": "StorageClass",
"data": {
"endpoint": self.out_map['RGW_ENDPOINT']
}
})
return json.dumps(json_out)+LINESEP

def main(self):
Expand Down

0 comments on commit 91b48b0

Please sign in to comment.