Skip to content

Commit

Permalink
Add destroy command
Browse files Browse the repository at this point in the history
  • Loading branch information
godofwharf committed Sep 5, 2018
1 parent dc54a2f commit a9e2752
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions babe
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,21 @@ def killInstance(appName, instance, grace, rangerOOR, lbOOR, scale):
else:
print("Kill api returned: [" + str(killResponse.status_code) + "] " + killResponse.text)

def destroyApp(appName):
r = requests.delete(url("/v2/apps/" + appName), auth=httpBasicCreds, verify=httpsVerify)
if 200 == r.status_code:
print("App " + appName + " destroyed")
def destroyApp(appName, force=False):
if not force:
prompt_response = raw_input("Do you really want to destroy the app {0} [y/n]? ".format(appName))
if force or prompt_response == 'y':
r = requests.delete(url("/v2/apps/" + appName), auth=httpBasicCreds, verify=httpsVerify)
if 200 == r.status_code:
print("App " + appName + " destroyed")
else:
printApiError(r)
else:
printApiError(r)
print("Not destroying app {0}".format(appName))

def destroyCommand(destroyAppOptionsParser):
appName = destroyAppOptionsParser.app
destroyApp(appName)

def waitForTargetScale(appName, targetScale):
while True:
Expand Down Expand Up @@ -313,7 +322,7 @@ def suspendCommand(suspendOptionsParser):
currentInstances = currentInstances - 1
waitForTargetScale(appName, 0)
if destroy:
destroyApp(appName)
destroyApp(appName, force=True)


def killSingleAppInstance(killSingleAppConfig):
Expand Down Expand Up @@ -405,6 +414,11 @@ if __name__ == "__main__":
killInstanceOptionsParser.add_argument('-r', '--ranger-oor', help='Whether to skip taking instance OOR in ranger', dest='rangeroor', action='store_false')
killInstanceOptionsParser.set_defaults(func=killSingleAppInstance)

#Destroy App
destroyAppOptionsParser = subparsers.add_parser('destroy', help='Destroy an app instance')
destroyAppOptionsParser.add_argument('app', help='App name')
destroyAppOptionsParser.set_defaults(func=destroyCommand)

parsed=parser.parse_args()
marathon=parsed.endpoint
useAuth = len(parsed.user) > 0
Expand Down

0 comments on commit a9e2752

Please sign in to comment.