~cprov/tanuki-continuous-deployer/local-provider

« back to all changes in this revision

Viewing changes to list.py

  • Committer: Thomi Richards
  • Date: 2015-07-17 06:02:44 UTC
  • Revision ID: thomi.richards@canonical.com-20150717060244-jngqosrn11qcx8ns
RemoveĀ unusedĀ code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python3
2
 
#
3
 
# Copyright (C) 2015 Canonical
4
 
#
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.
9
 
#
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.
14
 
#
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/>.
17
 
#
18
 
"""CI Automation: script for listing auto-deployed services."""
19
 
 
20
 
import argparse
21
 
import datetime
22
 
import os
23
 
import sys
24
 
 
25
 
 
26
 
from ci_automation.nova import get_services_map
27
 
from ci_automation.utils import setup_logger
28
 
 
29
 
 
30
 
def main():
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()
39
 
 
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()
49
 
            float_ips = ""
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))
55
 
 
56
 
    return 0
57
 
 
58
 
 
59
 
if __name__ == "__main__":
60
 
    sys.exit(main())