-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #204 from jameshcorbett/rabbit-mapping
Dws: use static rabbit layout mapping for JGF
- Loading branch information
Showing
8 changed files
with
170 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
dist_fluxcmd_SCRIPTS = \ | ||
flux-dws2jgf.py | ||
flux-dws2jgf.py \ | ||
flux-rabbitmapping.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import sys | ||
import json | ||
import subprocess | ||
|
||
import flux | ||
from flux.hostlist import Hostlist | ||
|
||
import kubernetes as k8s | ||
from kubernetes.client.rest import ApiException | ||
|
||
|
||
def get_storage(config_file): | ||
k8s_client = k8s.config.new_client_from_config(config_file=config_file) | ||
try: | ||
api_instance = k8s.client.CustomObjectsApi(k8s_client) | ||
except ApiException as rest_exception: | ||
if rest_exception.status == 403: | ||
raise Exception( | ||
"You must be logged in to the K8s or OpenShift cluster to continue" | ||
) | ||
raise | ||
|
||
group = "dataworkflowservices.github.io" | ||
version = "v1alpha2" | ||
plural = "storages" | ||
return api_instance.list_cluster_custom_object(group, version, plural) | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser( | ||
formatter_class=flux.util.help_formatter(), | ||
description=("Create a mapping between compute nodes and rabbit nodes"), | ||
) | ||
parser.add_argument( | ||
"--kubeconfig", | ||
"-k", | ||
default=None, | ||
metavar="FILE", | ||
help="Path to kubeconfig file to use", | ||
) | ||
parser.add_argument( | ||
"--indent", | ||
"-i", | ||
default=None, | ||
type=int, | ||
metavar="N", | ||
help="Number of spaces to indent output JSON document", | ||
) | ||
parser.add_argument( | ||
"--nosort", | ||
action="store_false", | ||
help="Do not sort keys in output JSON document", | ||
) | ||
args = parser.parse_args() | ||
rabbit_mapping = {"computes": {}, "rabbits": {}} | ||
for nnf in get_storage(args.kubeconfig)["items"]: | ||
hlist = Hostlist() | ||
nnf_name = nnf["metadata"]["name"] | ||
for compute in nnf["status"]["access"].get("computes", []): | ||
hlist.append(compute["name"]) | ||
rabbit_mapping["computes"][compute["name"]] = nnf_name | ||
rabbit_mapping["rabbits"][nnf_name] = {} | ||
rabbit_mapping["rabbits"][nnf_name]["hostlist"] = hlist.uniq().encode() | ||
rabbit_mapping["rabbits"][nnf_name]["capacity"] = nnf["status"]["capacity"] | ||
json.dump(rabbit_mapping, sys.stdout, indent=args.indent, sort_keys=args.nosort) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"computes": { | ||
"compute-01": "kind-worker2", | ||
"compute-02": "kind-worker2", | ||
"compute-03": "kind-worker2", | ||
"compute-04": "kind-worker3" | ||
}, | ||
"rabbits": { | ||
"kind-worker2": { | ||
"capacity": 39582418599936, | ||
"hostlist": "compute-[01-03]" | ||
}, | ||
"kind-worker3": { | ||
"capacity": 39582418599936, | ||
"hostlist": "compute-04" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.