File tree Expand file tree Collapse file tree 4 files changed +96
-0
lines changed
Expand file tree Collapse file tree 4 files changed +96
-0
lines changed Original file line number Diff line number Diff line change 1+ from cloudshell .helpers .scripts .cloudshell_scripts_helpers import get_reservation_context_details , get_api_session , \
2+ get_resource_context_details
3+ from purge_ixia_db import purge_ixia_db_flow
4+
5+ # get resource details from context
6+ api = get_api_session ()
7+ sb_details = get_reservation_context_details ()
8+ sb_id = sb_details .id
9+ resource_details = get_resource_context_details ()
10+
11+ # put interesting data into variables
12+ model = resource_details .model
13+ name = resource_details .name
14+ ip = resource_details .address
15+
16+ # extract data from attributes
17+ attrs = resource_details .attributes
18+ user = attrs [f"{ model } .User" ]
19+ encrypted_password = attrs [f"{ model } .Password" ]
20+
21+ # stored password needs to be decrypted
22+ decrypted_password = api .DecryptPassword (encryptedString = encrypted_password ).Value
23+
24+ # start flow
25+ api .WriteMessageToReservationOutput (reservationId = sb_id ,
26+ message = f"starting purge flow" )
27+
28+ purge_ixia_db_flow (ip , user , decrypted_password )
29+
30+ # printing to std_out will be the return value of resource scripts
31+ print (f"Ixia Purge DB flow completed for '{ name } '" )
Original file line number Diff line number Diff line change 1+ from bps_restpy .bps import BPS
2+ from bps_restpy .bps_restpy_v1 .bpsAdminRest import BPS_Storrage
3+
4+
5+ class IxiaCleanupException (Exception ):
6+ pass
7+
8+
9+ def validate_result (result : bool , action = "" ):
10+ if not result :
11+ msg = "Issue during Ixia action"
12+ if action :
13+ msg += f": '{ action } '"
14+ raise IxiaCleanupException (msg )
15+
16+
17+ def purge_ixia_db_flow (ip , user , password ):
18+ """
19+ instantiate api session, purge and compact reports in ixia
20+ :param str ip:
21+ :param str user:
22+ :param str password:
23+ :return:
24+ """
25+ # Login to BPS box
26+ bps = BPS (ip , user , password )
27+
28+ # get storage controller
29+ bps_storage = BPS_Storrage (bps )
30+
31+ # login
32+ bps_storage .login ()
33+
34+ # purge reports
35+ purge_result = bps_storage .purgeReports (versionId = None )
36+ validate_result (purge_result , action = "PURGE DB" )
37+
38+ # compact storage
39+ compact_result = bps_storage .compactStorage (versionId = None )
40+ validate_result (compact_result , action = "COMPACT DB" )
41+
42+
43+ if __name__ == "__main__" :
44+ # bps system info
45+ bps_system = '<BPS_BOX_IP/HOSTNAME>'
46+ bpsuser = 'bps user'
47+ bpspass = 'bps pass'
48+
49+ purge_ixia_db_flow (bps_system , bpsuser , bpspass )
Original file line number Diff line number Diff line change 1+ from cloudshell .helpers .scripts .cloudshell_scripts_helpers import get_reservation_context_details , get_api_session , \
2+ get_resource_context_details
3+
4+ api = get_api_session ()
5+ sb_details = get_reservation_context_details ()
6+ sb_id = sb_details .id
7+
8+ resource_details = get_resource_context_details ()
9+ name = resource_details .name
10+ ip = resource_details .address
11+
12+ api .WriteMessageToReservationOutput (reservationId = sb_id ,
13+ message = f"Resource name: { name } , IP: { ip } " )
14+
15+ raise Exception (f"Resource { name } exploded during operation!!!" )
Original file line number Diff line number Diff line change 1+ cloudshell-automation-api
You can’t perform that action at this time.
0 commit comments