1
|
|
|
# Licensed to the StackStorm, Inc ('StackStorm') under one or more |
2
|
|
|
# contributor license agreements. See the NOTICE file distributed with |
3
|
|
|
# this work for additional information regarding copyright ownership. |
4
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0 |
5
|
|
|
# (the "License"); you may not use this file except in compliance with |
6
|
|
|
# the License. You may obtain a copy of the License at |
7
|
|
|
# |
8
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
9
|
|
|
# |
10
|
|
|
# Unless required by applicable law or agreed to in writing, software |
11
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
12
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13
|
|
|
# See the License for the specific language governing permissions and |
14
|
|
|
# limitations under the License. |
15
|
|
|
|
16
|
|
|
import os |
17
|
|
|
|
18
|
|
|
from st2common.runners.base_action import Action |
19
|
|
|
from st2common.util.virtualenvs import setup_pack_virtualenv |
20
|
|
|
|
21
|
|
|
__all__ = [ |
22
|
|
|
'SetupVirtualEnvironmentAction' |
23
|
|
|
] |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
class SetupVirtualEnvironmentAction(Action): |
27
|
|
|
""" |
28
|
|
|
Action which sets up virtual environment for the provided packs. |
29
|
|
|
|
30
|
|
|
Setup consists of the following step: |
31
|
|
|
|
32
|
|
|
1. Create virtual environment for the pack |
33
|
|
|
2. Install base requirements which are common to all the packs |
34
|
|
|
3. Install pack-specific requirements (if any) |
35
|
|
|
|
36
|
|
|
If the 'update' parameter is set to True, the setup skips the deletion and |
37
|
|
|
creation of the virtual environment and performs an update of the |
38
|
|
|
current dependencies as well as an installation of new dependencies |
39
|
|
|
""" |
40
|
|
|
def __init__(self, config=None, action_service=None): |
41
|
|
|
super(SetupVirtualEnvironmentAction, self).__init__( |
42
|
|
|
config=config, |
43
|
|
|
action_service=action_service) |
44
|
|
|
|
45
|
|
|
self.https_proxy = os.environ.get('https_proxy', self.config.get('https_proxy', None)) |
46
|
|
|
self.http_proxy = os.environ.get('http_proxy', self.config.get('http_proxy', None)) |
47
|
|
|
self.proxy_ca_bundle_path = os.environ.get( |
48
|
|
|
'proxy_ca_bundle_path', |
49
|
|
|
self.config.get('proxy_ca_bundle_path', None) |
50
|
|
|
) |
51
|
|
|
self.no_proxy = os.environ.get('no_proxy', self.config.get('no_proxy', None)) |
52
|
|
|
|
53
|
|
|
self.proxy_config = None |
54
|
|
|
|
55
|
|
|
if self.http_proxy or self.https_proxy: |
56
|
|
|
self.logger.debug('Using proxy %s', |
57
|
|
|
self.http_proxy if self.http_proxy else self.https_proxy) |
58
|
|
|
self.proxy_config = { |
59
|
|
|
'https_proxy': self.https_proxy, |
60
|
|
|
'http_proxy': self.http_proxy, |
61
|
|
|
'proxy_ca_bundle_path': self.proxy_ca_bundle_path, |
62
|
|
|
'no_proxy': self.no_proxy |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if self.https_proxy and not os.environ.get('https_proxy', None): |
66
|
|
|
os.environ['https_proxy'] = self.https_proxy |
67
|
|
|
|
68
|
|
|
if self.http_proxy and not os.environ.get('http_proxy', None): |
69
|
|
|
os.environ['http_proxy'] = self.http_proxy |
70
|
|
|
|
71
|
|
|
if self.no_proxy and not os.environ.get('no_proxy', None): |
72
|
|
|
os.environ['no_proxy'] = self.no_proxy |
73
|
|
|
|
74
|
|
|
if self.proxy_ca_bundle_path and not os.environ.get('proxy_ca_bundle_path', None): |
75
|
|
|
os.environ['no_proxy'] = self.no_proxy |
76
|
|
|
|
77
|
|
|
def run(self, packs, update=False): |
78
|
|
|
""" |
79
|
|
|
:param packs: A list of packs to create the environment for. |
80
|
|
|
:type: packs: ``list`` |
81
|
|
|
|
82
|
|
|
:param update: True to update dependencies inside the virtual environment. |
83
|
|
|
:type update: ``bool`` |
84
|
|
|
""" |
85
|
|
|
|
86
|
|
|
for pack_name in packs: |
87
|
|
|
setup_pack_virtualenv(pack_name=pack_name, update=update, logger=self.logger, |
88
|
|
|
proxy_config=self.proxy_config) |
89
|
|
|
|
90
|
|
|
message = ('Successfuly set up virtualenv for the following packs: %s' % |
91
|
|
|
(', '.join(packs))) |
92
|
|
|
return message |
93
|
|
|
|