marcoverl

CESNET-create-VM.sh

Jul 14th, 2016
224
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2. export OCCIAPI=https://carach5.ics.muni.cz:11443/
  3. case "$1" in
  4. del)
  5. VMID=$(occi --endpoint $OCCIAPI --auth x509 --voms --action list --resource compute)
  6. occi --endpoint $OCCIAPI --auth x509 --voms --action delete --resource $VMID
  7. echo VM $VMID has been destroyed
  8. ;;
  9. list)
  10. occi --endpoint $OCCIAPI --auth x509 --voms --action list --resource compute
  11. ;;
  12. images)
  13. occi --endpoint $OCCIAPI --auth x509 --voms --action describe --resource os_tpl
  14. ;;
  15. flavors)
  16. occi --endpoint $OCCIAPI --auth x509 --voms --action describe --resource resource_tpl
  17. ;;
  18. create)
  19. OS=$2
  20. [ -z "$2" ] && echo "Usage : $0 create centos7/ubuntu" && exit
  21. [ $OS == "centos7" ] && export OST=os_tpl#uuid_enmr_gpgpu_centos_7_cerit_sc_185
  22. [ $OS == "ubuntu" ] && export OST=os_tpl#uuid_enmr_gpgpu_egi_ubuntu_server_14_04_lts_cerit_sc_168
  23. occi --endpoint $OCCIAPI --auth x509 --voms --action create -r compute -M $OST --context user_data="file://$PWD/ansible_user_data_$OS" --attribute occi.core.title="GPU-VM"
  24. echo sleeping 10...
  25. sleep 10
  26. VMID=$(occi --endpoint $OCCIAPI --auth x509 --voms --action list --resource compute)
  27. NET=($(occi --endpoint $OCCIAPI --auth x509 --voms --action describe --resource compute | grep occi.networkinterface.address | awk '{print $3}'))
  28. echo connect via:
  29. echo ssh \$SSH_OPT -i yoursshkey $OS@${NET[@]}
  30. ;;
  31. ssh)
  32. NET=($(occi --endpoint $OCCIAPI --auth x509 --voms --action describe --resource compute | grep occi.networkinterface.address | awk '{print $3}'))
  33. echo connect via:
  34. echo ssh \$SSH_OPT -i yoursshkey $2@${NET[@]}
  35. ;;
  36. *)
  37. echo this option does not exist!
  38. echo "Usage : $0 create|del|list|ssh|flavors|images"
  39. esac
RAW Paste Data