basedefs.py 3.4 KB

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