openstack_client_400.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. Installs and configures an OpenStack Client
  16. """
  17. import os
  18. from packstack.installer import utils
  19. # ------------- OpenStack Client Packstack Plugin Initialization --------------
  20. PLUGIN_NAME = "OS-Client"
  21. PLUGIN_NAME_COLORED = utils.color_text(PLUGIN_NAME, 'blue')
  22. def initConfig(controller):
  23. group = {"GROUP_NAME": "NOVACLIENT",
  24. "DESCRIPTION": "NOVACLIENT Config parameters",
  25. "PRE_CONDITION": "CONFIG_CLIENT_INSTALL",
  26. "PRE_CONDITION_MATCH": "y",
  27. "POST_CONDITION": False,
  28. "POST_CONDITION_MATCH": True}
  29. controller.addGroup(group, [])
  30. def initSequences(controller):
  31. if controller.CONF['CONFIG_CLIENT_INSTALL'] != 'y':
  32. return
  33. osclientsteps = [
  34. {'title': 'Preparing OpenStack Client entries',
  35. 'functions': [create_manifest]}
  36. ]
  37. controller.addSequence("Installing OpenStack Client", [], [],
  38. osclientsteps)
  39. # -------------------------- step functions --------------------------
  40. def create_manifest(config, messages):
  41. client_host = config['CONFIG_CONTROLLER_HOST'].strip()
  42. server = utils.ScriptRunner(client_host)
  43. server.append('echo $HOME')
  44. rc, root_home = server.execute()
  45. root_home = root_home.strip()
  46. homedir = os.path.expanduser('~')
  47. config['HOME_DIR'] = homedir
  48. uname, gname = utils.get_current_username()
  49. config['NO_ROOT_USER'], config['NO_ROOT_GROUP'] = uname, gname
  50. no_root_allinone = (client_host == utils.get_localhost_ip() and
  51. root_home != homedir)
  52. config['NO_ROOT_USER_ALLINONE'] = no_root_allinone and True or False
  53. msg = ("File %s/keystonerc_admin has been created on OpenStack client host"
  54. " %s. To use the command line tools you need to source the file.")
  55. messages.append(msg % (root_home, client_host))
  56. if no_root_allinone:
  57. msg = ("Copy of keystonerc_admin file has been created for non-root "
  58. "user in %s.")
  59. messages.append(msg % homedir)