@@ -47,9 +47,11 @@ class HpcRestClient(object):
47
47
NODE_STATUS_NODE_HEALTH_UNAPPROVED_VALUE = "Unapproved"
48
48
NODE_STATUS_NODE_GROUP_KEY = "Groups"
49
49
50
- def __init__ (self , hostname = "localhost" ):
50
+ def __init__ (self , pem , hostname = "localhost" ):
51
+ # type: (str) -> None
51
52
self .hostname = hostname
52
53
self .logger = logging_aux .init_logger_aux ("hpcframework.restclient" , 'hpcframework.restclient.log' )
54
+ self ._pem = pem
53
55
54
56
def _log_error (self , function_name , res ):
55
57
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):
61
63
def _get (self , function_name , function_route , params ):
62
64
headers = {"Content-Type" : "application/json" }
63
65
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 )
65
67
try :
66
68
res .raise_for_status ()
67
69
self ._log_info (function_name , res )
@@ -73,7 +75,7 @@ def _get(self, function_name, function_route, params):
73
75
def _post (self , function_name , function_route , data ):
74
76
headers = {"Content-Type" : "application/json" }
75
77
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 )
77
79
try :
78
80
res .raise_for_status ()
79
81
self ._log_info (function_name , res )
@@ -85,7 +87,7 @@ def _post(self, function_name, function_route, data):
85
87
# Starts auto-scale api
86
88
def get_grow_decision (self , node_group_name = "" ):
87
89
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 )
89
91
if res .ok :
90
92
self .logger .info (res .content )
91
93
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=""):
100
102
self .logger .error ("status_code:{} content:{}" .format (res .status_code , res .content ))
101
103
102
104
def check_nodes_idle (self , nodes ):
105
+ # type: (list[str]) -> list[IdleNode]
103
106
data = json .dumps (nodes )
104
107
res = self ._post (self .check_nodes_idle .__name__ , self .CHECK_NODES_IDLE_ROUTE , data )
105
108
jobjs = json .loads (res .content )
@@ -155,10 +158,10 @@ def add_node_to_node_group(self, group_name, node_names):
155
158
156
159
157
160
if __name__ == '__main__' :
158
- client = HpcRestClient ()
161
+ client = HpcRestClient (r"E:\Certs\testhpcfull.pem" )
159
162
ans = client .get_grow_decision ()
160
163
print ans .cores_to_grow
161
- print client .check_nodes_idle (json . dumps ( ['mesoswinjd' ]) )
164
+ print client .check_nodes_idle (['mesoswinjd' ])
162
165
163
166
print client .list_node_groups ("MESOS" )
164
167
print client .add_node_group ("Mesos" , "Node Group for Compute nodes from Mesos" )
0 commit comments