3
# Copyright (C) 2015 Canonical
5
# This program is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation, either version 3 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
"""CI Automation: Destroys an environment upon given its SHA1 value."""
26
from ci_automation import (
34
parser = argparse.ArgumentParser(
35
description=('Destroys the juju environment of a given identifier')
37
parser.add_argument('--project', default='mojo-stg-ue-ci-engineering')
38
parser.add_argument('--base',
39
default=os.path.expanduser('~/juju-environments/'))
40
parser.add_argument('identifier', metavar='IDENTIFIER')
41
args = parser.parse_args()
43
glob_pattern = os.path.join(args.base, '*{}'.format(args.identifier))
44
matching = glob.glob(glob_pattern)
46
print("Nothing to do - no files matching pattern %r" % glob_pattern)
47
# We are happy if it's already destroyed.
53
print('Environments collision ? %r', matching)
56
name = os.path.basename(env_dir)
57
if juju.deployment_has_floating_ips(name, args.base):
59
Cowardly refusing to reap that, since it has floating IP addresses assigned.
61
Don't do what Thomi did and destroy in-use production services!
62
Assign all floating IP addresses to a new deployment, then call reaper.py
67
juju.destroy_all_services(name, args.base)
68
print('Services destroyed')
69
juju.destroy_environment(name, args.base)
70
print('Environment {} destroyed'.format(name))
71
control_bucket = "juju-{}".format(name)
72
swift.delete(control_bucket)
73
print('Swift control bucket {} deleted'.format(control_bucket))
74
mojo.workspace_destroy(args.project, name)
75
print('Mojo Workspace {}/{} destroyed'.format(args.project, name))
80
if __name__ == '__main__':