Skip to content

Instantly share code, notes, and snippets.

@nottrobin
Created November 25, 2015 23:20
Show Gist options
  • Select an option

  • Save nottrobin/1f64c29ff7aa170a1a21 to your computer and use it in GitHub Desktop.

Select an option

Save nottrobin/1f64c29ff7aa170a1a21 to your computer and use it in GitHub Desktop.
Destroy all machines and services in a juju environment, without destroying the environment
#!/usr/bin/env python
import yaml
import subprocess
status_command = "juju status"
status_output = subprocess.check_output(status_command.split())
status = yaml.load(status_output)
machines = status['machines'].keys()
machines.remove('0')
services = status['services'].keys() or []
if machines:
print "Destroying machines: " + ', '.join(machines)
try:
destroy_machines = 'juju destroy-machine --force ' + ' '.join(machines)
except:
pass
print subprocess.check_output(destroy_machines.split())
for service in services:
print "Destroying service: " + service
destroy_service = 'juju destroy-service ' + service
print subprocess.check_output(destroy_service.split())
print "Done resetting"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment