Skip to content

Commit a7e1969

Browse files
authored
Merge pull request #37 from schubergphilis/improve-error-handling
Exit when specified parameters are non-unique
2 parents 105e007 + baf5d9d commit a7e1969

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

cloudstackops/cloudstackops.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ def checkCloudStackName(self, args):
334334
if listAll == 'true':
335335
apicall.listAll = "true"
336336

337+
found_counter = 0
337338
try:
338339
data = self.cloudstack.marvin_request(apicall)
339340
if (data is None or len(data) == 0) and self.DEBUG == 1:
@@ -348,17 +349,22 @@ def checkCloudStackName(self, args):
348349
for d in data:
349350
# And make sure it's the correct one
350351
if csname == d.name or csname == d.instancename:
352+
found_counter += 1
351353
if self.DEBUG == 1:
352-
print "Found in loop " + str(d.name)
354+
print "Found in loop " + str(d.name) + " counter = " + str(found_counter)
353355

354356
csnameID = d.id
355-
break
356357
elif self.DEBUG == 1:
357-
print "Not found in loop " + str(d.name)
358+
print "Not found in loop " + str(d.name) + " counter = " + str(found_counter)
358359

359360
if len(csnameID) < 1:
360-
print "Warning: '%s' could not be located in CloudStack database using '%s' or is not unique -- Exit." % (csname, csApiCall)
361+
print "Warning: '%s' could not be located in CloudStack database using '%s' -- Exit." % (csname, csApiCall)
361362
sys.exit(1)
363+
364+
if found_counter >1:
365+
print "Error: '%s' could not be located in CloudStack database using '%s' because it is not unique -- Exit." % (csname, csApiCall)
366+
sys.exit(1)
367+
362368
else:
363369
print "Error: '%s' could not be located in CloudStack database using '%s' -- exit!" % (csname, csApiCall)
364370
# Exit if not found

0 commit comments

Comments
 (0)