Skip to content

Instantly share code, notes, and snippets.

@aravindavk
Last active May 29, 2018 09:30
Show Gist options
  • Save aravindavk/672146cd5b5d050309a78c948f79dc5c to your computer and use it in GitHub Desktop.
Save aravindavk/672146cd5b5d050309a78c948f79dc5c to your computer and use it in GitHub Desktop.
import sys
defines = {
"VKEY_DIAG_LAT_MEASUREMENT" : "diagnostics.latency-measurement",
"VKEY_DIAG_CNT_FOP_HITS" : "diagnostics.count-fop-hits",
"AUTH_ALLOW_MAP_KEY" : "auth.allow",
"AUTH_REJECT_MAP_KEY" : "auth.reject",
"SSL_OWN_CERT_OPT" : "ssl.own-cert",
"SSL_PRIVATE_KEY_OPT" : "ssl.private-key",
"SSL_CA_LIST_OPT" : "ssl.ca-list",
"SSL_CRL_PATH_OPT" : "ssl.crl-path",
"SSL_CERT_DEPTH_OPT" : "ssl.certificate-depth",
"SSL_CIPHER_LIST_OPT" : "ssl.cipher-list",
"SSL_DH_PARAM_OPT" : "ssl.dh-param",
"SSL_EC_CURVE_OPT" : "ssl.ec-curve",
"VKEY_FEATURES_LIMIT_USAGE" : "features.limit-usage",
"VKEY_MARKER_XTIME" : "geo-replication.indexing",
"VKEY_MARKER_XTIME_FORCE" : "geo-replication.ignore-pid-check",
"VKEY_MARKER_XTIME" : "geo-replication.indexing",
"VKEY_MARKER_XTIME_FORCE" : "geo-replication.ignore-pid-check",
"VKEY_MARKER_XTIME_FORCE" : "geo-replication.ignore-pid-check",
"VKEY_MARKER_XTIME_FORCE" : "geo-replication.ignore-pid-check",
"VKEY_FEATURES_QUOTA" : "features.quota",
"VKEY_FEATURES_INODE_QUOTA" : "features.inode-quota",
"VKEY_FEATURES_BITROT" : "features.bitrot",
"NFS_DISABLE_MAP_KEY" : "nfs.disable",
"VKEY_CONFIG_GFPROXY" : "config.gfproxyd",
"GLUSTERD_QUORUM_TYPE_KEY" : "cluster.server-quorum-type",
"GLUSTERD_QUORUM_RATIO_KEY" : "cluster.server-quorum-ratio",
"GLUSTERD_GLOBAL_OP_VERSION_KEY" : "cluster.op-version",
"GLUSTERD_MAX_OP_VERSION_KEY" : "cluster.max-op-version",
"GLUSTERD_SHARED_STORAGE_KEY" : "cluster.enable-shared-storage",
"VKEY_FEATURES_SELINUX" : "features.selinux",
"GLUSTERD_BRICK_MULTIPLEX_KEY" : "cluster.brick-multiplex",
"GLUSTERD_BRICKMUX_LIMIT_KEY" : "cluster.max-bricks-per-process",
"GLUSTERD_LOCALTIME_LOGGING_KEY" : "cluster.localtime-logging"
}
def value_from_defines(val):
if val.strip('"') == val and val != "NULL":
return defines[val]
return val.strip('"')
def main(args):
options = {}
with open(args[1]) as f:
started = False
block_started = False
current_key = ""
for line in f:
if line.strip() == "struct volopt_map_entry glusterd_volopt_map[] = {":
started = True
continue
if started and line.strip().startswith("{"):
block_started = True
opt = {}
if block_started:
if ".key" in line:
opt["key"] =value_from_defines(line.split("=")[-1].strip(" \n,"))
if ".voltype" in line:
opt["voltype"] = value_from_defines(line.split("=")[-1].strip(" \n,"))
if ".option" in line:
opt["option"] = value_from_defines(line.split("=")[-1].strip(" \n,"))
if "}" in line:
block_started = False
if options.get(opt["key"], None) is None:
options[opt["key"]] = [opt]
else:
options[opt["key"]].append(opt)
print("package cmd\n")
print("var legacyVolumeOptions = map[string][]string {")
for key, opts in options.items():
old_name = key
if old_name == "NULL":
continue
optsvalue = ""
for opt in opts:
new = opt["voltype"].split("/")[-1]
target_name = old_name.split(".")[-1]
if opt.get("option", None) is not None:
target_name = opt["option"]
# TODO: Handle opt name starts with !
if target_name.startswith("!"):
print("\t// TODO: Target option name starts with ! in glusterd1")
target_name = target_name[1:]
new_name = new + "." + target_name
if old_name != new_name:
optsvalue += "\"" + new_name + "\", "
if optsvalue:
print('\t"%s": []string{%s},' % (old_name, optsvalue))
print("}")
if __name__ == "__main__":
main(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment