Skip to content

Commit 42a302f

Browse files
author
igor-feoktistov
committed
Fixed JSON ValueError issue
Added ValueError exception to all methods to provide better diagnostics while authentication issue or WAPI version mismatch
1 parent 47c7c77 commit 42a302f

File tree

1 file changed

+72
-24
lines changed

1 file changed

+72
-24
lines changed

infoblox.py

Lines changed: 72 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ def get_next_available_ip(self, network):
105105
raise InfobloxGeneralException(r_json['text'])
106106
else:
107107
r.raise_for_status()
108-
except Exception as e:
108+
except ValueError:
109+
raise Exception(r)
110+
except Exception:
109111
raise
110112

111113
def create_host_record(self, ip_v4, fqdn):
@@ -125,7 +127,9 @@ def create_host_record(self, ip_v4, fqdn):
125127
raise InfobloxGeneralException(r_json['text'])
126128
else:
127129
r.raise_for_status()
128-
except Exception as e:
130+
except ValueError:
131+
raise Exception(r)
132+
except Exception:
129133
raise
130134

131135
def delete_host_record(self, fqdn):
@@ -158,7 +162,9 @@ def delete_host_record(self, fqdn):
158162
raise InfobloxGeneralException(r_json['text'])
159163
else:
160164
r.raise_for_status()
161-
except Exception as e:
165+
except ValueError:
166+
raise Exception(r)
167+
except Exception:
162168
raise
163169

164170
def add_host_alias(self, host_fqdn, alias_fqdn):
@@ -198,7 +204,9 @@ def add_host_alias(self, host_fqdn, alias_fqdn):
198204
raise InfobloxGeneralException(r_json['text'])
199205
else:
200206
r.raise_for_status()
201-
except Exception as e:
207+
except ValueError:
208+
raise Exception(r)
209+
except Exception:
202210
raise
203211

204212
def delete_host_alias(self, host_fqdn, alias_fqdn):
@@ -238,7 +246,9 @@ def delete_host_alias(self, host_fqdn, alias_fqdn):
238246
raise InfobloxGeneralException(r_json['text'])
239247
else:
240248
r.raise_for_status()
241-
except Exception as e:
249+
except ValueError:
250+
raise Exception(r)
251+
except Exception:
242252
raise
243253

244254
def create_cname_record(self, canonical, name):
@@ -258,7 +268,9 @@ def create_cname_record(self, canonical, name):
258268
raise InfobloxGeneralException(r_json['text'])
259269
else:
260270
r.raise_for_status()
261-
except Exception as e:
271+
except ValueError:
272+
raise Exception(r)
273+
except Exception:
262274
raise
263275

264276
def delete_cname_record(self, fqdn):
@@ -291,7 +303,9 @@ def delete_cname_record(self, fqdn):
291303
raise InfobloxGeneralException(r_json['text'])
292304
else:
293305
r.raise_for_status()
294-
except Exception as e:
306+
except ValueError:
307+
raise Exception(r)
308+
except Exception:
295309
raise
296310

297311
def create_dhcp_range(self, start_ip_v4, end_ip_v4):
@@ -311,7 +325,9 @@ def create_dhcp_range(self, start_ip_v4, end_ip_v4):
311325
raise InfobloxGeneralException(r_json['text'])
312326
else:
313327
r.raise_for_status()
314-
except Exception as e:
328+
except ValueError:
329+
raise Exception(r)
330+
except Exception:
315331
raise
316332

317333
def delete_dhcp_range(self, start_ip_v4, end_ip_v4):
@@ -345,7 +361,9 @@ def delete_dhcp_range(self, start_ip_v4, end_ip_v4):
345361
raise InfobloxGeneralException(r_json['text'])
346362
else:
347363
r.raise_for_status()
348-
except Exception as e:
364+
except ValueError:
365+
raise Exception(r)
366+
except Exception:
349367
raise
350368

351369
def get_host(self, fqdn, fields=None):
@@ -371,7 +389,9 @@ def get_host(self, fqdn, fields=None):
371389
raise InfobloxNotFoundException(r_json['text'])
372390
else:
373391
r.raise_for_status()
374-
except Exception as e:
392+
except ValueError:
393+
raise Exception(r)
394+
except Exception:
375395
raise
376396

377397
def get_host_by_ip(self, ip_v4):
@@ -396,7 +416,9 @@ def get_host_by_ip(self, ip_v4):
396416
raise InfobloxGeneralException(r_json['text'])
397417
else:
398418
r.raise_for_status()
399-
except Exception as e:
419+
except ValueError:
420+
raise Exception(r)
421+
except Exception:
400422
raise
401423

402424
def get_ip_by_host(self, fqdn):
@@ -424,7 +446,9 @@ def get_ip_by_host(self, fqdn):
424446
raise InfobloxGeneralException(r_json['text'])
425447
else:
426448
r.raise_for_status()
427-
except Exception as e:
449+
except ValueError:
450+
raise Exception(r)
451+
except Exception:
428452
raise
429453

430454
def get_host_extattrs(self, fqdn, attributes=None):
@@ -456,7 +480,9 @@ def get_host_extattrs(self, fqdn, attributes=None):
456480
raise InfobloxNotFoundException(r_json['text'])
457481
else:
458482
r.raise_for_status()
459-
except Exception as e:
483+
except ValueError:
484+
raise Exception(r)
485+
except Exception:
460486
raise
461487

462488
def get_network(self, network, fields=None):
@@ -482,7 +508,9 @@ def get_network(self, network, fields=None):
482508
raise InfobloxNotFoundException(r_json['text'])
483509
else:
484510
r.raise_for_status()
485-
except Exception as e:
511+
except ValueError:
512+
raise Exception(r)
513+
except Exception:
486514
raise
487515

488516
def get_network_by_ip(self, ip_v4):
@@ -507,7 +535,9 @@ def get_network_by_ip(self, ip_v4):
507535
raise InfobloxNotFoundException(r_json['text'])
508536
else:
509537
r.raise_for_status()
510-
except Exception as e:
538+
except ValueError:
539+
raise Exception(r)
540+
except Exception:
511541
raise
512542

513543
def get_network_by_extattrs(self, attributes):
@@ -539,7 +569,9 @@ def get_network_by_extattrs(self, attributes):
539569
raise InfobloxGeneralException(r_json['text'])
540570
else:
541571
r.raise_for_status()
542-
except Exception as e:
572+
except ValueError:
573+
raise Exception(r)
574+
except Exception:
543575
raise
544576

545577
def get_host_by_extattrs(self, attributes):
@@ -571,7 +603,9 @@ def get_host_by_extattrs(self, attributes):
571603
raise InfobloxNotFoundException(r_json['text'])
572604
else:
573605
r.raise_for_status()
574-
except Exception as e:
606+
except ValueError:
607+
raise Exception(r)
608+
except Exception:
575609
raise
576610

577611
def get_network_extattrs(self, network, attributes=None):
@@ -603,7 +637,9 @@ def get_network_extattrs(self, network, attributes=None):
603637
raise InfobloxNotFoundException(r_json['text'])
604638
else:
605639
r.raise_for_status()
606-
except Exception as e:
640+
except ValueError:
641+
raise Exception(r)
642+
except Exception:
607643
raise
608644

609645
def update_network_extattrs(self, network, attributes):
@@ -642,7 +678,9 @@ def update_network_extattrs(self, network, attributes):
642678
raise InfobloxGeneralException(r_json['text'])
643679
else:
644680
r.raise_for_status()
645-
except Exception as e:
681+
except ValueError:
682+
raise Exception(r)
683+
except Exception:
646684
raise
647685

648686
def delete_network_extattrs(self, network, attributes):
@@ -681,7 +719,9 @@ def delete_network_extattrs(self, network, attributes):
681719
raise InfobloxGeneralException(r_json['text'])
682720
else:
683721
r.raise_for_status()
684-
except Exception as e:
722+
except ValueError:
723+
raise Exception(r)
724+
except Exception:
685725
raise
686726

687727
def create_network(self, network):
@@ -700,7 +740,9 @@ def create_network(self, network):
700740
raise InfobloxGeneralException(r_json['text'])
701741
else:
702742
r.raise_for_status()
703-
except Exception as e:
743+
except ValueError:
744+
raise Exception(r)
745+
except Exception:
704746
raise
705747

706748
def delete_network(self, network):
@@ -733,7 +775,9 @@ def delete_network(self, network):
733775
raise InfobloxGeneralException(r_json['text'])
734776
else:
735777
r.raise_for_status()
736-
except Exception as e:
778+
except ValueError:
779+
raise Exception(r)
780+
except Exception:
737781
raise
738782

739783
def create_networkcontainer(self, networkcontainer):
@@ -752,7 +796,9 @@ def create_networkcontainer(self, networkcontainer):
752796
raise InfobloxGeneralException(r_json['text'])
753797
else:
754798
r.raise_for_status()
755-
except Exception as e:
799+
except ValueError:
800+
raise Exception(r)
801+
except Exception:
756802
raise
757803

758804
def delete_networkcontainer(self, networkcontainer):
@@ -785,5 +831,7 @@ def delete_networkcontainer(self, networkcontainer):
785831
raise InfobloxGeneralException(r_json['text'])
786832
else:
787833
r.raise_for_status()
788-
except Exception as e:
834+
except ValueError:
835+
raise Exception(r)
836+
except Exception:
789837
raise

0 commit comments

Comments
 (0)