Skip to content

Commit edcaec2

Browse files
committed
Added get-dependencies option to install_pack.py
1 parent b9aec99 commit edcaec2

File tree

2 files changed

+53
-14
lines changed

2 files changed

+53
-14
lines changed

CHANGELOG.rst

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Added
2828
* Expose environment variable ST2_ACTION_DEBUG to all StackStorm actions.
2929
Contributed by @maxfactor1
3030

31+
* Added get-dependencies option to install_pack.py #5994
3132

3233
3.8.0 - November 18, 2022
3334
-------------------------

st2common/st2common/cmd/install_pack.py

+52-14
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,19 @@
1414
# limitations under the License.
1515

1616
import sys
17+
from os import listdir
1718

1819
from oslo_config import cfg
1920

2021
from st2common import config
2122
from st2common import log as logging
2223
from st2common.config import do_register_cli_opts
2324
from st2common.script_setup import setup as common_setup
25+
from st2common.util.pack import get_pack_metadata
2426
from st2common.util.pack_management import download_pack
2527
from st2common.util.pack_management import get_and_set_proxy_config
2628
from st2common.util.virtualenvs import setup_pack_virtualenv
29+
from st2common.content.utils import get_pack_base_path
2730

2831
__all__ = ["main"]
2932

@@ -53,28 +56,37 @@ def _register_cli_opts():
5356
help="True to force pack installation and ignore install "
5457
"lock file if it exists.",
5558
),
59+
cfg.BoolOpt(
60+
"get-dependencies",
61+
default=False,
62+
help="True to install pack dependencies",
63+
),
5664
]
5765
do_register_cli_opts(cli_opts)
5866

5967

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)
6270

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))
7082

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()
7683

84+
def download_packs(packs, verify_ssl, force, dependencies, proxy_config):
7785
for pack in packs:
86+
if pack in listdir("/opt/stackstorm/packs"):
87+
LOG.info('Pack already installed "%s"' % (pack))
88+
continue
89+
7890
# 1. Download the pack
7991
LOG.info('Installing pack "%s"' % (pack))
8092
result = download_pack(
@@ -107,4 +119,30 @@ def main(argv):
107119
)
108120
LOG.info('Successfully set up virtualenv for pack "%s"' % (pack_name))
109121

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+
110148
return 0

0 commit comments

Comments
 (0)