|
14 | 14 | # limitations under the License.
|
15 | 15 |
|
16 | 16 | import sys
|
| 17 | +from os import listdir |
17 | 18 |
|
18 | 19 | from oslo_config import cfg
|
19 | 20 |
|
20 | 21 | from st2common import config
|
21 | 22 | from st2common import log as logging
|
22 | 23 | from st2common.config import do_register_cli_opts
|
23 | 24 | from st2common.script_setup import setup as common_setup
|
| 25 | +from st2common.util.pack import get_pack_metadata |
24 | 26 | from st2common.util.pack_management import download_pack
|
25 | 27 | from st2common.util.pack_management import get_and_set_proxy_config
|
26 | 28 | from st2common.util.virtualenvs import setup_pack_virtualenv
|
| 29 | +from st2common.content.utils import get_pack_base_path |
27 | 30 |
|
28 | 31 | __all__ = ["main"]
|
29 | 32 |
|
@@ -53,28 +56,37 @@ def _register_cli_opts():
|
53 | 56 | help="True to force pack installation and ignore install "
|
54 | 57 | "lock file if it exists.",
|
55 | 58 | ),
|
| 59 | + cfg.BoolOpt( |
| 60 | + "get-dependencies", |
| 61 | + default=False, |
| 62 | + help="True to install pack dependencies", |
| 63 | + ), |
56 | 64 | ]
|
57 | 65 | do_register_cli_opts(cli_opts)
|
58 | 66 |
|
59 | 67 |
|
60 |
| -def main(argv): |
61 |
| - _register_cli_opts() |
| 68 | +def get_pack_dependencies(pack, verify_ssl, force, dependencies, proxy_config): |
| 69 | + pack_path = get_pack_base_path(pack) |
62 | 70 |
|
63 |
| - # Parse CLI args, set up logging |
64 |
| - common_setup( |
65 |
| - config=config, |
66 |
| - setup_db=False, |
67 |
| - register_mq_exchanges=False, |
68 |
| - register_internal_trigger_types=False, |
69 |
| - ) |
| 71 | + try: |
| 72 | + pack_metadata = get_pack_metadata(pack_dir=pack_path) |
| 73 | + result = pack_metadata.get("dependencies", None) |
| 74 | + except Exception: |
| 75 | + LOG.error("Could not open pack.yaml at location %s" % pack_path) |
| 76 | + result = None |
| 77 | + finally: |
| 78 | + if result: |
| 79 | + LOG.info('Getting pack dependencies for pack "%s"' % (pack)) |
| 80 | + download_packs(result, verify_ssl, force, dependencies, proxy_config) |
| 81 | + LOG.info('Successfully got pack dependencies for pack "%s"' % (pack)) |
70 | 82 |
|
71 |
| - packs = cfg.CONF.pack |
72 |
| - verify_ssl = cfg.CONF.verify_ssl |
73 |
| - force = cfg.CONF.force |
74 |
| - |
75 |
| - proxy_config = get_and_set_proxy_config() |
76 | 83 |
|
| 84 | +def download_packs(packs, verify_ssl, force, dependencies, proxy_config): |
77 | 85 | for pack in packs:
|
| 86 | + if pack in listdir("/opt/stackstorm/packs"): |
| 87 | + LOG.info('Pack already installed "%s"' % (pack)) |
| 88 | + continue |
| 89 | + |
78 | 90 | # 1. Download the pack
|
79 | 91 | LOG.info('Installing pack "%s"' % (pack))
|
80 | 92 | result = download_pack(
|
@@ -107,4 +119,30 @@ def main(argv):
|
107 | 119 | )
|
108 | 120 | LOG.info('Successfully set up virtualenv for pack "%s"' % (pack_name))
|
109 | 121 |
|
| 122 | + if dependencies: |
| 123 | + get_pack_dependencies( |
| 124 | + pack_name, verify_ssl, force, dependencies, proxy_config |
| 125 | + ) |
| 126 | + |
| 127 | + |
| 128 | +def main(argv): |
| 129 | + _register_cli_opts() |
| 130 | + |
| 131 | + # Parse CLI args, set up logging |
| 132 | + common_setup( |
| 133 | + config=config, |
| 134 | + setup_db=False, |
| 135 | + register_mq_exchanges=False, |
| 136 | + register_internal_trigger_types=False, |
| 137 | + ) |
| 138 | + |
| 139 | + packs = cfg.CONF.pack |
| 140 | + verify_ssl = cfg.CONF.verify_ssl |
| 141 | + force = cfg.CONF.force |
| 142 | + dependencies = cfg.CONF.get_dependencies |
| 143 | + |
| 144 | + proxy_config = get_and_set_proxy_config() |
| 145 | + |
| 146 | + download_packs(packs, verify_ssl, force, dependencies, proxy_config) |
| 147 | + |
110 | 148 | return 0
|
0 commit comments