@@ -125,15 +125,18 @@ def convert_gb_to_mb(value):
125125
126126
127127def get_all_partitions (config , cookies , system_uuid ):
128- uri = f"/rest/api/uom/ManagedSystem/{ system_uuid } /LogicalPartition/quick/All"
129- url = "https://" + util .get_host_address (config ) + uri
130- headers = {"x-api-key" : util .get_session_key (config )}
131- response = requests .get (url , headers = headers ,
132- cookies = cookies , verify = False )
133- if response .status_code != 200 :
134- raise PartitionError (
135- f"failed to get partition list, error: { response .text } " )
136- return response .json ()
128+ try :
129+ uri = f"/rest/api/uom/ManagedSystem/{ system_uuid } /LogicalPartition/quick/All"
130+ url = "https://" + util .get_host_address (config ) + uri
131+ headers = {"x-api-key" : util .get_session_key (config )}
132+ response = requests .get (url , headers = headers ,
133+ cookies = cookies , verify = False )
134+ response .raise_for_status ()
135+ return response .json ()
136+ except requests .exceptions .RequestException as e :
137+ raise PartitionError (f"failed to get partition list, while making http request, error: { e } , response: { e .response .text } " )
138+ except Exception as e :
139+ raise PartitionError (f"failed to get partition list, error: { e } " )
137140
138141
139142# Checks if partition exists, returns exists and if partition is created by PIM
@@ -164,37 +167,43 @@ def check_partition_exists(config, cookies, system_uuid):
164167
165168
166169def create_partition (config , cookies , system_uuid ):
167- logger .debug (
168- f"Creating partition with name '{ util .get_partition_name (config )} '" )
169- uri = f"/rest/api/uom/ManagedSystem/{ system_uuid } /LogicalPartition"
170- url = "https://" + util .get_host_address (config ) + uri
171- payload = populate_payload (config )
172- headers = {"x-api-key" : util .get_session_key (config ),
173- "Content-Type" : CONTENT_TYPE }
174- response = requests .put (url , headers = headers ,
175- data = payload , cookies = cookies , verify = False )
176- if response .status_code != 200 :
177- raise PartitionError (
178- f"failed to create partition, error: { response .text } " )
179-
180- soup = BeautifulSoup (response .text , 'xml' )
181- partition_uuid = soup .find ("PartitionUUID" )
182- return partition_uuid .text
170+ try :
171+ logger .debug (
172+ f"Creating partition with name '{ util .get_partition_name (config )} '" )
173+ uri = f"/rest/api/uom/ManagedSystem/{ system_uuid } /LogicalPartition"
174+ url = "https://" + util .get_host_address (config ) + uri
175+ payload = populate_payload (config )
176+ headers = {"x-api-key" : util .get_session_key (config ),
177+ "Content-Type" : CONTENT_TYPE }
178+ response = requests .put (url , headers = headers ,
179+ data = payload , cookies = cookies , verify = False )
180+ response .raise_for_status ()
181+
182+ soup = BeautifulSoup (response .text , 'xml' )
183+ partition_uuid = soup .find ("PartitionUUID" )
184+ return partition_uuid .text
185+ except requests .exceptions .RequestException as e :
186+ raise PartitionError (f"failed to create partition, while making http request, error: { e } , response: { e .response .text } " )
187+ except Exception as e :
188+ raise PartitionError (f"failed to create partition, error: { e } " )
183189
184190
185191def get_partition_details (config , cookies , system_uuid , partition_uuid ):
186- uri = f"/rest/api/uom/ManagedSystem/{ system_uuid } /LogicalPartition/{ partition_uuid } "
187- url = "https://" + util .get_host_address (config ) + uri
188- headers = {"x-api-key" : util .get_session_key (config ),
189- "Content-Type" : "application/vnd.ibm.powervm.uom+xml; Type=LogicalPartition" }
190- response = requests .get (url , headers = headers ,
191- cookies = cookies , verify = False )
192- if response .status_code != 200 :
193- raise PartitionError (
194- f"failed to get partition details, error: { response .text } " )
195- soup = BeautifulSoup (response .text , 'xml' )
196- lpar = str (soup .find ('LogicalPartition' ))
197- return lpar
192+ try :
193+ uri = f"/rest/api/uom/ManagedSystem/{ system_uuid } /LogicalPartition/{ partition_uuid } "
194+ url = "https://" + util .get_host_address (config ) + uri
195+ headers = {"x-api-key" : util .get_session_key (config ),
196+ "Content-Type" : "application/vnd.ibm.powervm.uom+xml; Type=LogicalPartition" }
197+ response = requests .get (url , headers = headers ,
198+ cookies = cookies , verify = False )
199+ response .raise_for_status ()
200+ soup = BeautifulSoup (response .text , 'xml' )
201+ lpar = str (soup .find ('LogicalPartition' ))
202+ return lpar
203+ except requests .exceptions .RequestException as e :
204+ raise PartitionError (f"failed to get partition details, while making http request, error: { e } , response: { e .response .text } " )
205+ except Exception as e :
206+ raise PartitionError (f"failed to get partition details, error: { e } " )
198207
199208
200209def edit_lpar_compute (config , cookies , system_uuid , partition_uuid ):
@@ -215,30 +224,33 @@ def edit_lpar_compute(config, cookies, system_uuid, partition_uuid):
215224 "Content-Type" : "application/vnd.ibm.powervm.uom+xml; Type=LogicalPartition" }
216225 response = requests .post (url , headers = headers , cookies = cookies , data = str (
217226 updated_lpar_payload ), verify = False )
218- if response .status_code != 200 :
219- raise PartitionError (
220- f"failed to edit lpar compute, error: { response .text } " )
227+ response .raise_for_status ()
228+ except requests . exceptions . RequestException as e :
229+ raise PartitionError ( f"failed to edit lpar compute, while making http request, error: { e } , response: { e . response .text } " )
221230 except Exception as e :
222- raise e
231+ raise Exception ( f"failed to edit lpar compute, error: { e } " )
223232 logger .debug (
224233 f"Compute for partition: { partition_uuid } is updated successfully" )
225234 return
226235
227236
228237def set_partition_boot_string (config , cookies , system_uuid , partition_uuid , partition_payload , boot_string ):
229- uri = f"/rest/api/uom/ManagedSystem/{ system_uuid } /LogicalPartition/{ partition_uuid } "
230- url = "https://" + util .get_host_address (config ) + uri
231- headers = {"x-api-key" : util .get_session_key (config ),
232- "Content-Type" : "application/vnd.ibm.powervm.uom+xml; Type=LogicalPartition" }
233- payload = BeautifulSoup (partition_payload , 'xml' )
234- pending_boot = payload .find ("PendingBootString" )
235- pending_boot .append (boot_string )
236-
237- response = requests .post (url , headers = headers ,
238- cookies = cookies , data = str (payload ), verify = False )
239- if response .status_code != 200 :
240- raise PartitionError (
241- f"failed to update boot order for the partition: '{ partition_uuid } ', error: { response .text } " )
238+ try :
239+ uri = f"/rest/api/uom/ManagedSystem/{ system_uuid } /LogicalPartition/{ partition_uuid } "
240+ url = "https://" + util .get_host_address (config ) + uri
241+ headers = {"x-api-key" : util .get_session_key (config ),
242+ "Content-Type" : "application/vnd.ibm.powervm.uom+xml; Type=LogicalPartition" }
243+ payload = BeautifulSoup (partition_payload , 'xml' )
244+ pending_boot = payload .find ("PendingBootString" )
245+ pending_boot .append (boot_string )
246+
247+ response = requests .post (url , headers = headers ,
248+ cookies = cookies , data = str (payload ), verify = False )
249+ response .raise_for_status ()
250+ except requests .exceptions .RequestException as e :
251+ raise PartitionError (f"failed to update boot order for the partition: '{ partition_uuid } ' while making http request, error: { e } , response: { e .response .text } " )
252+ except Exception as e :
253+ raise Exception (f"failed to update boot order for the partition: '{ partition_uuid } ', error: { e } " )
242254 logger .debug (
243255 f"Updated the boot order for the partition: '{ partition_uuid } '" )
244256 return
0 commit comments