Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. #!/bin/bash
  2. # attachiscsi.sh - Attach iSCSI devices attached to the instance to the operating system
  3. #
  4. # Author: Steven B. Nelson, Sr. Solutions Architect
  5. # Oracle Bare Metal Cloud Services
  6. #
  7. # 12 March 2017
  8. # Copyright Oracle, Inc. All rights reserved.
  9. # Make FIFO pipes for the two loops below
  10. mkfifo discpipe
  11. mkfifo sesspipe
  12.  
  13. # Find all the iSCSI Block Storage volumes attached to the instance but
  14. # not configured for use on the instance. Basically, get a list of the
  15. # volumes that the instance can see, the loop through the ones it has,
  16. # and add volumes not already configured on the instance.
  17. #
  18. # First get the list of volumes visible (attached) to the instance
  19. iscsiadm -m discovery -t st -p 169.254.0.2:3260 | grep -v uefi | awk '{print $2}' > discpipe &
  20.  
  21. # Loop through the list (via the named FIFO pipe below)
  22. while read target
  23. do
  24. # Get the list of the currently attached Block Storage volumes
  25. iscsiadm -m session -P 0 | grep -v uefi | awk '{print $4}' > sesspipe &
  26.  
  27. # Set a flag, and loop through the sessions (attached, but not configured)
  28. # and see if the volumes match. If so, skip to the next until we get
  29. # through the list. Session list is via the pipe.
  30. found="false"
  31. while read session
  32. do
  33. if [ ${target} = ${session} ]
  34. then
  35. found="true"
  36. break
  37. fi
  38. done < sesspipe
  39.  
  40. # If the volume is not found, configure it. Get the resulting device file.
  41. if [ ${found} = "false" ]
  42. then
  43. iscsiadm -m node -o new -T ${target} -p 169.254.0.2:3260
  44. iscsiadm -m node -o update -T ${target} -n node.startup -v automatic
  45. iscsiadm -m node -T ${target} -p 169.254.0.2:3260 -l
  46. sleep 5
  47. fi
  48. done < discpipe
  49.  
  50. # Remove the FIFOs
  51. find . -maxdepth 1 -type p -exec rm {} \;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement