Skip to content

Commit 258a3ed

Browse files
committed
Merge branch 'client-auth'
# Conflicts: # .idea/inspectionProfiles/Project_Default.xml
2 parents dea14af + bc505be commit 258a3ed

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

.idea/inspectionProfiles/Project_Default.xml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hpcframework.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def run(self):
4040
except KeyboardInterrupt:
4141
print('Stop requested by user, stopping framework....')
4242

43-
def __init__(self, script_path="", setup_path="", headnode="", ssl_thumbprint="", framework_uri="", node_group=""):
43+
def __init__(self, script_path, setup_path, headnode, ssl_thumbprint, client_cert, framework_uri, node_group=""):
4444
logging.basicConfig()
4545
self.logger = logging_aux.init_logger_aux("hpcframework", "hpcframework.log")
4646
# signal.signal(signal.SIGINT, signal.SIG_IGN)
@@ -52,7 +52,7 @@ def __init__(self, script_path="", setup_path="", headnode="", ssl_thumbprint=""
5252
self.ssl_thumbprint = ssl_thumbprint
5353
self.framework_uri = framework_uri
5454
self.node_group = node_group
55-
self.hpc_client = HpcRestClient()
55+
self.hpc_client = HpcRestClient(client_cert)
5656
self.heartbeat_table = hpc_cluster_manager.HpcClusterManager(self.hpc_client, node_group=self.node_group)
5757
self.heartbeat_table.subscribe_node_closed_callback(lambda l: map(self._kill_task_by_hostname, l))
5858
self.heartbeat_table.start()
@@ -216,8 +216,9 @@ def _kill_task_by_hostname(self, hostname):
216216
parser.add_argument("setup_path", help="Path of HPC Pack setup executable (e.g. setup.exe)")
217217
parser.add_argument("headnode", help="Hostname of HPC Pack cluster head node")
218218
parser.add_argument("ssl_thumbprint",
219-
help="Thumbprint of certificate which will be used in installtion and communication with HPC "
219+
help="Thumbprint of certificate which will be used in installation and communication with HPC "
220220
"Pack cluster")
221+
parser.add_argument("client_cert", help=".pem file of client cert used for HPC Management REST API authentication")
221222
parser.add_argument("heartbeat_uri", help="Base URI of heart beat server of HPC Pack Mesos framework")
222223
args = parser.parse_args()
223224

restclient.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ class HpcRestClient(object):
4747
NODE_STATUS_NODE_HEALTH_UNAPPROVED_VALUE = "Unapproved"
4848
NODE_STATUS_NODE_GROUP_KEY = "Groups"
4949

50-
def __init__(self, hostname="localhost"):
50+
def __init__(self, pem, hostname="localhost"):
51+
# type: (str) -> None
5152
self.hostname = hostname
5253
self.logger = logging_aux.init_logger_aux("hpcframework.restclient", 'hpcframework.restclient.log')
54+
self._pem = pem
5355

5456
def _log_error(self, function_name, res):
5557
self.logger.error("{}: status_code:{} content:{}".format(function_name, res.status_code, res.content))
@@ -61,7 +63,7 @@ def _log_info(self, function_name, res):
6163
def _get(self, function_name, function_route, params):
6264
headers = {"Content-Type": "application/json"}
6365
url = function_route.format(self.hostname)
64-
res = requests.get(url, headers=headers, verify=False, params=params)
66+
res = requests.get(url, headers=headers, verify=False, params=params, cert=self._pem)
6567
try:
6668
res.raise_for_status()
6769
self._log_info(function_name, res)
@@ -73,7 +75,7 @@ def _get(self, function_name, function_route, params):
7375
def _post(self, function_name, function_route, data):
7476
headers = {"Content-Type": "application/json"}
7577
url = function_route.format(self.hostname)
76-
res = requests.post(url, data=data, headers=headers, verify=False)
78+
res = requests.post(url, data=data, headers=headers, verify=False, cert=self._pem)
7779
try:
7880
res.raise_for_status()
7981
self._log_info(function_name, res)
@@ -85,7 +87,7 @@ def _post(self, function_name, function_route, data):
8587
# Starts auto-scale api
8688
def get_grow_decision(self, node_group_name=""):
8789
url = self.GROW_DECISION_API_ROUTE.format(self.hostname)
88-
res = requests.post(url, verify=False)
90+
res = requests.post(url, verify=False, cert=self._pem, timeout=15)
8991
if res.ok:
9092
self.logger.info(res.content)
9193
grow_decision_dict = {k.upper(): v for k, v in json.loads(res.content).items()}
@@ -100,6 +102,7 @@ def get_grow_decision(self, node_group_name=""):
100102
self.logger.error("status_code:{} content:{}".format(res.status_code, res.content))
101103

102104
def check_nodes_idle(self, nodes):
105+
# type: (list[str]) -> list[IdleNode]
103106
data = json.dumps(nodes)
104107
res = self._post(self.check_nodes_idle.__name__, self.CHECK_NODES_IDLE_ROUTE, data)
105108
jobjs = json.loads(res.content)
@@ -155,10 +158,10 @@ def add_node_to_node_group(self, group_name, node_names):
155158

156159

157160
if __name__ == '__main__':
158-
client = HpcRestClient()
161+
client = HpcRestClient(r"E:\Certs\testhpcfull.pem")
159162
ans = client.get_grow_decision()
160163
print ans.cores_to_grow
161-
print client.check_nodes_idle(json.dumps(['mesoswinjd']))
164+
print client.check_nodes_idle(['mesoswinjd'])
162165

163166
print client.list_node_groups("MESOS")
164167
print client.add_node_group("Mesos", "Node Group for Compute nodes from Mesos")

0 commit comments

Comments
 (0)