blob: 77c1654bef77d6b499145ae6b39c6a338638d676 [file] [log] [blame]
Alex Savatieievc9055712019-03-01 14:43:56 -06001from cfg_checker.helpers import args_utils
Alexd9fd85e2019-05-16 16:58:24 -05002from cfg_checker.modules.packages.repos import RepoManager
Alex Savatieievc9055712019-03-01 14:43:56 -06003
Alex3ebc5632019-04-18 16:47:18 -05004import checker
5
Alexbab1efe2019-04-23 18:51:23 -05006command_help = "Package versions check (Candidate vs Installed)"
7
8
9def init_parser(_parser):
10 # packages subparser
11 pkg_subparsers = _parser.add_subparsers(dest='type')
12
13 pkg_report_parser = pkg_subparsers.add_parser(
14 'report',
15 help="Report package versions to HTML file"
16 )
17 pkg_report_parser.add_argument(
18 '--full',
19 action="store_true", default=False,
20 help="HTML report will have all of the packages, not just errors"
21 )
22 pkg_report_parser.add_argument(
23 '--html',
24 metavar='packages_html_filename',
25 help="HTML filename to save report"
26 )
27 pkg_report_parser.add_argument(
28 '--csv',
29 metavar='packages_csv_filename',
30 help="CSV filename to save report"
31 )
32
Alexd9fd85e2019-05-16 16:58:24 -050033 pkg_repos = pkg_subparsers.add_parser(
34 'versions',
35 help="Parse versions at given URL and create local map"
36 )
37 pkg_repos.add_argument(
38 '--list-tags',
39 action="store_true", default=False,
40 help="Just list tags available in mirror"
41 )
42 pkg_repos.add_argument(
43 '--url',
44 metavar='repo_url', default="http://mirror.mirantis.com",
45 help="URL for repos, default: http://mirror.mirantis.com"
46 )
47 pkg_repos.add_argument(
48 '--tag',
49 metavar='repo_tag', default=None,
50 help="Repository tag to process packages from. Default: "
51 "All url's root folder tags"
52 )
53 pkg_repos.add_argument(
54 '--build-repos',
55 action="store_true", default=False,
56 help="Conduct build stage before working with tags"
57 )
58 pkg_repos.add_argument(
59 '--gen-desc',
60 action="store_true", default=False,
61 help="Save pkg descriptions while parsing"
62 )
Alex74dc1352019-05-17 13:18:24 -050063 pkg_show = pkg_subparsers.add_parser(
64 'show',
65 help="Show package history from the map"
66 )
67 pkg_show.add_argument(
68 'args',
69 nargs='+',
70 help="Package names separated by space"
71 )
72
Alexbab1efe2019-04-23 18:51:23 -050073 return _parser
74
Alex Savatieievc9055712019-03-01 14:43:56 -060075
76def do_report(args):
Alex41485522019-04-12 17:26:18 -050077 """Create package versions report, HTML
Alex Savatieievc9055712019-03-01 14:43:56 -060078
79 :args: - parser arguments
80 :return: - no return value
81 """
Alexbab1efe2019-04-23 18:51:23 -050082 _type, _filename = args_utils.get_package_report_type_and_filename(args)
Alex Savatieievc9055712019-03-01 14:43:56 -060083
84 # init connection to salt and collect minion data
85 pChecker = checker.CloudPackageChecker()
86 # collect data on installed packages
87 pChecker.collect_installed_packages()
88 # diff installed and candidates
Alex Savatieiev3db12a72019-03-22 16:32:31 -050089 pChecker.collect_packages()
Alex Savatieievc9055712019-03-01 14:43:56 -060090 # report it
Alex41485522019-04-12 17:26:18 -050091 pChecker.create_report(_filename, rtype=_type, full=args.full)
Alexd9fd85e2019-05-16 16:58:24 -050092
93
94def do_versions(args):
95 """Builds tagged repo structure and parses Packages.gz files
96
97 :args: - parser arguments
98 :return: - no return value
99 """
100 # Get the list of tags for the url
101 r = RepoManager()
Alex74dc1352019-05-17 13:18:24 -0500102 if args.list_tags:
103 r.action_for_tag(args.url, args.tag, action="list")
104 return
Alexd9fd85e2019-05-16 16:58:24 -0500105 if args.build_repos:
106 # if tag is supplied, use it
107 if args.tag:
108 r.action_for_tag(args.url, args.tag, action="build")
109 else:
110 r.build_repos(args.url)
111
Alexd9fd85e2019-05-16 16:58:24 -0500112 if args.tag:
113 # Process only this tag
114 r.action_for_tag(
115 args.url,
116 args.tag,
117 action="fetch",
118 descriptions=args.gen_desc
119 )
120 else:
121 # All of them
122 r.parse_repos()
Alex74dc1352019-05-17 13:18:24 -0500123
124
125def do_show(args):
126 """Shows package (or multiple) history across parsed tags
127 """
128 # Init manager
129 r = RepoManager()
130 # show packages
131 for p in args.args:
132 r.show_package(p)