forked from redhat-openstack/packstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasedefs.py
More file actions
102 lines (85 loc) · 3.26 KB
/
Copy pathbasedefs.py
File metadata and controls
102 lines (85 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# -*- coding: utf-8 -*-
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
This module provides all the predefined variables.
"""
import datetime
import os
import pkg_resources
import sys
import tempfile
from .utils import get_current_user
APP_NAME = "Packstack"
FILE_YUM_VERSION_LOCK = "/etc/yum/pluginconf.d/versionlock.list"
PACKSTACK_SRC_DOC = pkg_resources.resource_filename(
pkg_resources.Requirement.parse('packstack'), 'docs/packstack.rst'
)
if os.path.exists(PACKSTACK_SRC_DOC):
PACKSTACK_DOC = PACKSTACK_SRC_DOC
else:
PACKSTACK_DOC = '/usr/share/packstack/packstack.rst'
PACKSTACK_VAR_DIR = '/var/tmp/packstack'
try:
os.mkdir(PACKSTACK_VAR_DIR, 0o700)
except OSError:
# directory is already created, check ownership
stat = os.stat(PACKSTACK_VAR_DIR)
if stat.st_uid == 0 and os.getuid() != stat.st_uid:
print ('%s is already created and owned by root. Please change '
'ownership and try again.' % PACKSTACK_VAR_DIR)
sys.exit(1)
finally:
uid, gid = get_current_user()
if uid != 0 and os.getuid() == 0:
try:
os.chown(PACKSTACK_VAR_DIR, uid, gid)
except Exception as ex:
print ('Unable to change owner of %s. Please fix ownership '
'manually and try again.' % PACKSTACK_VAR_DIR)
sys.exit(1)
_tmpdirprefix = datetime.datetime.now().strftime('%Y%m%d-%H%M%S-')
VAR_DIR = tempfile.mkdtemp(prefix=_tmpdirprefix, dir=PACKSTACK_VAR_DIR)
DIR_LOG = VAR_DIR
FILE_LOG = 'openstack-setup.log'
PUPPET_MANIFEST_RELATIVE = "manifests"
PUPPET_MANIFEST_DIR = os.path.join(VAR_DIR, PUPPET_MANIFEST_RELATIVE)
HIERADATA_FILE_RELATIVE = "hieradata"
HIERADATA_DIR = os.path.join(VAR_DIR, HIERADATA_FILE_RELATIVE)
LATEST_LOG_DIR = '%s/latest' % PACKSTACK_VAR_DIR
if os.path.exists(LATEST_LOG_DIR):
try:
os.unlink(LATEST_LOG_DIR)
except OSError:
print ('Unable to delete symbol link for log dir %s.' % LATEST_LOG_DIR)
try:
# Extract folder name at /var/tmp/packstack/<VAR_DIR> and do a relative
# symlink to /var/tmp/packstack/latest
os.symlink(os.path.basename(VAR_DIR),
os.path.join(PACKSTACK_VAR_DIR, 'latest'))
except OSError:
print ('Unable to create symbol link for log dir %s.' % LATEST_LOG_DIR)
PUPPET_DEPENDENCIES = ['puppet', 'hiera', 'openssh-clients', 'tar', 'nc']
PUPPET_MODULES_DEPS = ['rubygem-json']
FILE_INSTALLER_LOG = "setup.log"
DIR_PROJECT_DIR = os.environ.get('INSTALLER_PROJECT_DIR', os.path.join(os.getcwd(), 'packstack'))
DIR_PLUGINS = os.path.join(DIR_PROJECT_DIR, "plugins")
DIR_MODULES = os.path.join(DIR_PROJECT_DIR, "modules")
EXEC_RPM = "rpm"
EXEC_SEMANAGE = "semanage"
EXEC_NSLOOKUP = "nslookup"
EXEC_CHKCONFIG = "chkconfig"
EXEC_SERVICE = "service"
EXEC_IP = "ip"
# space len size for color print
SPACE_LEN = 70