Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.50 KB | None | 0 0
  1. write-admin-file() {
  2. [[ -f ~/admin-openrc.sh ]] && rm ~/admin-openrc.sh
  3. export NO_WRITE_RC=false
  4. #Clear Openstack variables
  5. for var in $(set -o posix; set|/bin/grep -oE '^OS_[^=]+');do unset ${var};done
  6. #Assuming Keystone API 3
  7. unset OS_TENANT_ID
  8. unset OS_TENANT_NAME
  9. export OS_INTERFACE=public
  10. export OS_IDENTITY_API_VERSION=3
  11. printf "\e[2GFetching IP for Keystone\n"
  12. [[ $(juju config keystone vip) ]] && export OS_AUTH_URL="http://$(juju config keystone vip):5000/v3" || export OS_AUTH_URL="http://$(juju run --unit keystone/0 'unit-get public-address'):5000/v3"
  13. export OS_PROJECT_NAME=$(juju 2>/dev/null config keystone admin-user)
  14. export OS_USER_DOMAIN_NAME="$(juju 2>/dev/null config keystone admin-user)_domain"
  15. printf "\e[2GFetching default admin-user name from Juju\n"
  16. export OS_USERNAME=$(juju 2>/dev/null config keystone admin-user)
  17. printf "\e[2GFetching password for ${OS_USERNAME} from Juju\n"
  18. export OS_PASSWORD=$(juju 2>/dev/null config keystone admin-password)
  19. printf "\e[2GFetching Openstack Region name from Juju\n"
  20. export OS_REGION_NAME=$(juju 2>/dev/null config keystone region)
  21. printf "\e[2GFetching Domain ID for ${OS_USERNAME}_domain from Juju\n"
  22. export OS_PROJECT_DOMAIN_ID=$(openstack domain list --os-project-domain-name ${OS_USER_DOMAIN_NAME} --os-username ${OS_USERNAME} --os-password=${OS_PASSWORD}|awk '/'${OS_USER_DOMAIN_NAME}'/{print $2}')
  23. printf "\e[2GFetching Project ID for ${OS_USERNAME} project from Juju\n"
  24. export OS_PROJECT_ID=$(openstack project list --long --os-project-domain-name ${OS_USER_DOMAIN_NAME} --os-username ${OS_USERNAME} --os-password=${OS_PASSWORD}|awk '/'${OS_PROJECT_DOMAIN_ID}'/&&/'${OS_USERNAME}'/{print $2}')
  25.  
  26. #Check to make sure we have populated variables
  27. printf "\e[2GValidating that all OS_ variables are present\n"
  28. for var in $(set -o posix; set|/bin/grep -oE '^OS_[^=]+');do
  29. if [[ -z $(eval "echo \$$var") ]];then
  30. export NO_WRITE_RC=true
  31. printf "\e[4GCannot determine value for $var\n"
  32. fi
  33. done
  34.  
  35. #Write the RC File
  36. if [[ ${NO_WRITE_RC} = false ]];then
  37. printf "\e[2GCreating Openstack RC file...\n"
  38. { set|/bin/grep -oE '^OS_[^$]+'|sed 's/^.*$/export &/g;1s/^/#!\/usr\/bin\/env bash\n/;/HYPERVISORS/d'|tee 1>/dev/null ~/admin-openrc.sh; }
  39. [[ $? -eq 0 && -f ~/admin-openrc.sh ]] && { printf "\e[4GSourcing Openstack RC file...\n";source ~/admin-openrc.sh; }
  40. RC_FILE_SOURCED=true
  41. else
  42. printf "\e[2GCould not write the RC file.  Please ensure you are both the user and on the system where Juju deployed Openstack from.\n\n"
  43. RC_FILE_SOURCED=false
  44. return 1
  45. fi
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement