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: script for listing auto-deployed services."""
26
from ci_automation.nova import get_services_map
27
from ci_automation.utils import setup_logger
31
parser = argparse.ArgumentParser(
32
description="Check the number of deployments for a service")
33
parser.add_argument('--base-dir', '-b',
34
default=os.path.expanduser("~/ci-cd-identifiers"),
35
help="The directory where identifiers are stored "
36
" (eg. ~/ci-cd-identifiers)")
37
args = parser.parse_args()
38
logger = setup_logger()
40
services = get_services_map(args.base_dir)
41
sorted_services = sorted(services.items(), key=lambda s: s[0])
42
for srv, deployments in sorted_services:
43
print('* {}:'.format(srv))
44
sorted_deployments = sorted(
45
deployments.items(), key=lambda d: d[1]['epoch'], reverse=True)
46
for ident, contents in sorted_deployments:
47
date_created = datetime.datetime.utcfromtimestamp(
48
contents['epoch']).ctime()
50
if contents['floating_ips']:
51
float_ips = "=> {}".format(', '.join(
52
contents['floating_ips']))
53
print('\t{}: {} ({} units) {}'.format(
54
ident, date_created, len(contents['units']), float_ips))
59
if __name__ == "__main__":