2222# THE SOFTWARE.
2323###
2424
25- from hpOneView import *
25+ from hpOneView .oneview_client import OneViewClient
26+ from base64 import b64encode
2627from functools import partial
28+ from pprint import pprint
29+
2730import amqp
2831import amqp .spec
32+ import datetime
33+ import http
2934import json
3035import ssl
31- import datetime
32- from pprint import pprint
33- from base64 import b64encode
36+ import time
3437
3538smhost = None
3639smhead = None
37- act = None
3840
3941
4042def sm_do_http (method , path , body ):
@@ -101,23 +103,32 @@ def new_incident(desc, sev):
101103
102104
103105def print_alert (uri ):
104- alerts = act . get_alerts ()
106+ alerts = oneview_client . alerts . get_all ()
105107 for alert in alerts :
106108 if alert ['uri' ] == uri :
107109 pprint (alert )
108110
109111
110112def update_alert (uri , smid ):
111- alerts = act . get_alerts ()
113+ alerts = oneview_client . alerts . get_all ()
112114 notes = 'Case automatically loged in HPE Service Manager with ID: ' + smid
113115 for alert in alerts :
114116 if alert ['uri' ] == uri :
115- amap = common .make_alertMap_dict (notes , alert ['eTag' ])
116- act .update_alert (alert , amap )
117+ oneview_client .alerts .update (create_alert_map (notes , alert ['eTag' ]), alert ['uris' ])
117118 return True
118119 return False
119120
120121
122+ def create_alert_map (notes , etag ):
123+ return {
124+ 'alertState' : 'Active' ,
125+ 'assignedToUser' : 'None' ,
126+ 'alertUrgency' : 'None' ,
127+ 'notes' : notes ,
128+ 'eTag' : etag
129+ }
130+
131+
121132def get_incidents ():
122133 body = sm_get ('/SM/9/rest/incidents?&view=expand' )
123134 pprint (body )
@@ -222,38 +233,34 @@ def recv(host, route):
222233 conn .close ()
223234
224235
225- def login (con , credential ):
226- # Login with givin credentials
227- try :
228- con .login (credential )
229- except :
230- print ('Login failed' )
231-
232-
233- def acceptEULA (con ):
236+ def acceptEULA (oneview_client ):
234237 # See if we need to accept the EULA before we try to log in
235- con .get_eula_status ()
238+ eula_status = oneview_client . connection .get_eula_status ()
236239 try :
237- if con . get_eula_status () is True :
238- con .set_eula ('no' )
240+ if eula_status is True :
241+ oneview_client . connection .set_eula ('no' )
239242 except Exception as e :
240243 print ('EXCEPTION:' )
241244 print (e )
242245
243246
244- def getCertCa (sec ):
245- cert = sec . get_cert_ca ()
247+ def getCertCa (oneview_client ):
248+ cert = oneview_client . certificate_authority . get ()
246249 ca = open ('caroot.pem' , 'w+' )
247250 ca .write (cert )
248251 ca .close ()
249252
250253
251- def genRabbitCa (sec ):
252- sec .gen_rabbitmq_ca ()
254+ def genRabbitCa (oneview_client ):
255+ certificate_ca_signed_client = {
256+ "commonName" : "default" ,
257+ "type" : "RabbitMqClientCertV2"
258+ }
259+ oneview_client .certificate_rabbitmq .generate (certificate_ca_signed_client )
253260
254261
255- def getRabbitKp (sec ):
256- cert = sec . get_rabbitmq_kp ( )
262+ def getRabbitKp (oneview_client ):
263+ cert = oneview_client . certificate_rabbitmq . get_key_pair ( 'default' )
257264 ca = open ('client.pem' , 'w+' )
258265 ca .write (cert ['base64SSLCertData' ])
259266 ca .close ()
@@ -263,7 +270,7 @@ def getRabbitKp(sec):
263270
264271
265272def main ():
266- global smhost , smhead , act
273+ global smhost , smhead , oneview_client
267274
268275 if amqp .VERSION < (2 , 1 , 4 ):
269276 print ("WARNING: This script has been tested only with amqp 2.1.4, "
@@ -294,7 +301,6 @@ def main():
294301 action = 'store_true' ,
295302 help = 'List all Service Manager incidents and exit' )
296303 args = parser .parse_args ()
297- credential = {'userName' : args .user , 'password' : args .passwd }
298304 smcred = args .id + ':' + args .spass
299305 userAndPass = b64encode (str .encode (smcred )).decode ('ascii' )
300306 smhead = {'Content-Type' : 'application/json;charset=utf-8' ,
@@ -305,21 +311,25 @@ def main():
305311 get_incidents ()
306312 sys .exit ()
307313
308- con = connection (args .host )
309- sec = security (con )
310- act = activity (con )
314+ config = {
315+ "ip" : args .host ,
316+ "credentials" : {
317+ "userName" : args .user ,
318+ "password" : args .passwd
319+ }
320+ }
311321
312- login ( con , credential )
313- acceptEULA (con )
322+ oneview_client = OneViewClient ( config )
323+ acceptEULA (oneview_client )
314324
315325 # Generate the RabbitMQ keypair (only needs to be done one time)
316326 if args .gen :
317- genRabbitCa (sec )
327+ genRabbitCa (oneview_client )
318328 sys .exit ()
319329
320330 if args .down :
321- getCertCa (sec )
322- getRabbitKp (sec )
331+ getCertCa (oneview_client )
332+ getRabbitKp (oneview_client )
323333 sys .exit ()
324334
325335 recv (args .host , args .route )
0 commit comments