Patrik_Arlos

Identify components used by tenant

Nov 27th, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.89 KB | None | 0 0
  1. #!/bin/bash                                                                                                                                                                          
  2.  
  3. tenantString=$1
  4. myInstances=""
  5. myImages=""
  6. mySnapshots=""
  7. myVolumes=""
  8. myFloatingIPs=""
  9. myGroups=""
  10. myKeypairs=""
  11. myNetworks=""
  12. mySubnets=""
  13. myRouters=""
  14.  
  15.  
  16. ##Start checking Instances (NOVA)                                                                                                                                                    
  17. instances=`nova list --all-tenants | grep -v '\-\-' | awk 'BEGIN {FS = "|"}; { if (NR>1) { print $2;}}'| sort`
  18. echo "Checking Instances"
  19. for instance in $instances;
  20. do
  21.     echo -n "."
  22.     tenI=`nova show $instance | grep $tenantString`
  23.     if [[ ! -z $tenI ]]
  24.     then
  25.         myInstances+=" $instance"
  26.     fi
  27. done
  28. echo "Done."
  29. ##Start checking Images (NOVA)                                                                                                                                                        
  30. images=`nova image-list | grep -v '\-\-' | awk 'BEGIN {FS = "|"}; { if (NR>1) { print $2;}}'| sort`
  31. echo "Checking Images"
  32. for image in $images;
  33. do
  34.     echo -n "."
  35. #    echo -n "$image"                                                                                                                                                                
  36.     tenI=`nova image-show $image | grep $tenantString`
  37.     if [[ ! -z $tenI ]]
  38.     then
  39.         myImages+=" $image"
  40.     fi
  41. done
  42. echo "Done."
  43. ##Start checking Snapshots (CINDER)                                                                                                                                                  
  44. snapshots=`cinder snapshot-list --all-tenants | grep -v '\-\-' | awk 'BEGIN {FS = "|"}; { if (NR>1) { print $2;}}'| sort`
  45. echo "Checking Snapshots"
  46. for snapshot in $snapshots;
  47. do
  48.     echo -n "."
  49.     tenI=`cinder snapshot-show $snapshot | grep $tenantString`
  50.     if [[ ! -z $tenI ]]
  51.     then
  52.         mySnapshots+=" $snapshot"
  53.     fi
  54. done
  55. echo "Done."
  56. ##Start checking Volumes (CINDER)                                                                                                                                                    
  57. volumes=`cinder list --all-tenants | grep -v '\-\-' | awk 'BEGIN {FS = "|"}; { if (NR>1) { print $2;}}'| sort`
  58. echo "Checking Volumes"
  59. for volume in $volumes;
  60. do
  61.     echo -n "."
  62.     tenI=`cinder show $volume | grep $tenantString`
  63.     if [[ ! -z $tenI ]]
  64.     then
  65.         myVolumes+=" $volume"
  66.     fi
  67. done
  68. echo "Done."
  69. ##Check Sequrity: FloatingIPS                                                                                                                                                        
  70. ##Check Sequrity: Groups                                                                                                                                                              
  71. ##Check Sequrity: KeyPairs                                                                                                                                                            
  72. ##Check Quantum; networks                                                                                                                                                            
  73.  
  74. nets=` quantum net-list | grep -v '\-\-' | awk 'BEGIN {FS = "|"}; { if (NR>1) { print $2;}}'| sort`
  75. echo "Checking Networks."
  76. for net in $nets;
  77. do
  78.     echo -n "."
  79.     tenN=`quantum net-show $net | grep tenant_id | grep $tenantString`
  80.     if [[ ! -z $tenN ]]
  81.     then
  82.         myNetworks+=" $net"
  83.     fi
  84. done
  85. echo "Done."
  86.  
  87. ##Check Quantum; sub-nets                                                                                                                                                            
  88. snets=`quantum subnet-list | grep 'start' | awk 'BEGIN {FS = "|"}; {print $2}' | sort`
  89. echo "Checking sub-networks."
  90. for subnet in $snets;
  91. do
  92.     echo -n "."
  93.     tenSN=`quantum subnet-show $subnet | grep tenant_id | grep $tenantString`
  94.     if [[ ! -z $tenSN ]]
  95.     then
  96.         mySubnets+=" $subnet"
  97.     fi
  98. done
  99. echo "Done."
  100.  
  101. ##Check Quantum; Routers                                                                                                                                                              
  102. routers=` quantum router-list | grep -v '\-\-' | awk 'BEGIN {FS = "|"}; { if (NR>1) { print $2;}}'| sort`
  103. echo "Checking Routers."
  104. for router in $routers;
  105. do
  106.     echo -n "."
  107.     tenR=`quantum router-show $router | grep tenant_id | grep $tenantString`
  108.     if [[ ! -z $tenR ]]
  109.     then
  110.         myRouters+=" $router"
  111.     fi
  112. done
  113. echo "Done."
  114. echo "Identified; for $tenantString"
  115. echo "Instances: $myInstances"
  116. echo "Images   : $myImages"
  117. echo "Snapshots: $mySnapshots"
  118. echo "Volumes  : $myVolumes"
  119. echo "Networks : $myNetworks"
  120. echo "Subnets  : $mySubnets"
  121. echo "Routers  : $myRouters"
Advertisement
Add Comment
Please, Sign In to add comment