Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.71 KB | None | 0 0
  1. #!/usr/bin/python3.6
  2. import sys, mysql.connector
  3.  
  4. query1 = "SELECT row.name, row.id FROM Object AS row INNER JOIN EntityLink AS e ON row.id = e.child_entity_id WHERE e.parent_entity_id = %s ORDER BY row.name"
  5. query2 = "SELECT rack.name, rack.id FROM Object AS rack JOIN EntityLink AS e ON rack.id = e.child_entity_id WHERE e.parent_entity_id = %s"
  6. query3 = "SELECT DISTINCT o.name, o.id, o.objtype_id FROM Object AS o INNER JOIN RackSpace AS r ON o.id = r.object_id WHERE r.rack_id= %s"
  7. query4 = "SELECT unit_no, atom FROM RackSpace WHERE object_id = %s"
  8.  
  9. con = mysql.connector.connect( host="localhost", database="racktables", user="racktables", password="MY_SECRET_PASSWORD" )
  10. cur = con.cursor()
  11.  
  12. # select all rows in the datacenter
  13. cur.execute( query1, [ sys.argv[1] ] )
  14. result1 = cur.fetchall()
  15. print(result1)
  16. if result1:
  17. print("1 ok")
  18. row_count = 0
  19. for ( row_name, row_id ) in result1:
  20. # select all racks in the row
  21. cur.execute( query2, [ row_id ] )
  22. result2 = cur.fetchall()
  23. if result2:
  24. print("2 ok")
  25. rack_count = 0
  26. for ( rack_name, rack_id ) in result2:
  27. # select all objects in the rack
  28. cur.execute( query3, [ rack_id ] )
  29. result3 = cur.fetchall()
  30. if result3:
  31. print("3 ok")
  32. for ( object_name, object_id, object_type ) in result3:
  33. # select all 3d "atoms" for the object
  34. cur.execute( query4, [ object_id ] )
  35. result4 = cur.fetchall()
  36. if result4:
  37. print("4 ok")
  38. # process all atoms to calculate the objects minimum and maximum unit and depth values
  39. depth_max=0
  40. depth_min=4
  41. unit_max=0
  42. unit_min=1000
  43. for ( atom_height, atom_depth ) in result4:
  44. if ( atom_height < unit_min ):
  45. unit_min = atom_height
  46. if ( atom_height > unit_max ):
  47. unit_max = atom_height
  48. if ( atom_depth == "front" ):
  49. atom_depth=0
  50. if ( atom_depth == "interior" ):
  51. atom_depth=1
  52. if ( atom_depth == "rear" ):
  53. atom_depth=2
  54. if ( atom_depth < depth_min ):
  55. depth_min = atom_depth
  56. if ( atom_depth > depth_max ):
  57. depth_max = atom_depth
  58. # set the color
  59. red = 128
  60. green = 128
  61. blue = 128
  62. if ( object_type == 4 ):
  63. red = 128
  64. green = 128
  65. blue = 255
  66. if ( object_type == 8 ):
  67. red = 128
  68. green = 200
  69. blue = 128
  70. # calculate xyz in millimeters
  71. if ( row_count % 2 == 0 ):
  72. x_min = (row_count* 2400 ) + 1200 - ( depth_max * 400 ) - 400
  73. x_max = (row_count* 2400 ) + 1200 - ( depth_min * 400 )
  74. else:
  75. x_min = (row_count* 2400 ) + ( depth_min * 400 )
  76. x_max = (row_count* 2400 ) + ( depth_max * 400 ) + 400
  77. y_min = (rack_count* 600 ) + 10
  78. y_max = (rack_count* 600 ) + 590
  79. z_min = ( unit_min * 50 )
  80. z_max = ( unit_max * 50 ) + 45
  81. print(object_name)
  82. print(object_id)
  83. print(object_type)
  84. print(x_min)
  85. print(x_max)
  86. print(y_min)
  87. print(y_max)
  88. print(z_min)
  89. print(z_max)
  90. print(red)
  91. print(blue)
  92. print(green)
  93. print()
  94. rack_count=rack_count+1
  95. row_count=row_count+1
  96. rack_count= 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement