~andrewjbeach/juju-ci-tools/make-local-patcher

« back to all changes in this revision

Viewing changes to clean_maas.py

  • Committer: Curtis Hovey
  • Date: 2016-09-21 17:54:26 UTC
  • mto: This revision was merged to the branch mainline in revision 1612.
  • Revision ID: curtis@canonical.com-20160921175426-hmk3wlxrl1vpfuwr
Poll for the token, whcih might be None.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
"""Delete all machines from given MAAS environment."""
 
3
 
 
4
from __future__ import print_function
 
5
 
 
6
import argparse
 
7
import sys
 
8
 
 
9
import jujuconfig
 
10
import substrate
 
11
 
 
12
 
 
13
def main(argv):
 
14
    parser = argparse.ArgumentParser(description="Delete all machines in MAAS")
 
15
    parser.add_argument("name", help="Name of the MAAS in juju config.")
 
16
    args = parser.parse_args(argv[1:])
 
17
    environments = jujuconfig.get_environments()
 
18
    if args.name not in environments:
 
19
        parser.error("No maas '{}' found in juju config".format(args.name))
 
20
    config = environments[args.name]
 
21
    with substrate.maas_account_from_config(config) as manager:
 
22
        machines = manager.get_allocated_nodes()
 
23
        print("Found {} machines: {}".format(len(machines), machines.keys()))
 
24
        manager.terminate_instances(machine["resource_uri"]
 
25
                                    for machine in machines.values())
 
26
        print("Released.")
 
27
    return 0
 
28
 
 
29
 
 
30
if __name__ == "__main__":
 
31
    sys.exit(main(sys.argv))