Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3.6
- import sys, mysql.connector
- 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"
- 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"
- 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"
- query4 = "SELECT unit_no, atom FROM RackSpace WHERE object_id = %s"
- con = mysql.connector.connect( host="localhost", database="racktables", user="racktables", password="MY_SECRET_PASSWORD" )
- cur = con.cursor()
- # select all rows in the datacenter
- cur.execute( query1, [ sys.argv[1] ] )
- result1 = cur.fetchall()
- print(result1)
- if result1:
- print("1 ok")
- row_count = 0
- for ( row_name, row_id ) in result1:
- # select all racks in the row
- cur.execute( query2, [ row_id ] )
- result2 = cur.fetchall()
- if result2:
- print("2 ok")
- rack_count = 0
- for ( rack_name, rack_id ) in result2:
- # select all objects in the rack
- cur.execute( query3, [ rack_id ] )
- result3 = cur.fetchall()
- if result3:
- print("3 ok")
- for ( object_name, object_id, object_type ) in result3:
- # select all 3d "atoms" for the object
- cur.execute( query4, [ object_id ] )
- result4 = cur.fetchall()
- if result4:
- print("4 ok")
- # process all atoms to calculate the objects minimum and maximum unit and depth values
- depth_max=0
- depth_min=4
- unit_max=0
- unit_min=1000
- for ( atom_height, atom_depth ) in result4:
- if ( atom_height < unit_min ):
- unit_min = atom_height
- if ( atom_height > unit_max ):
- unit_max = atom_height
- if ( atom_depth == "front" ):
- atom_depth=0
- if ( atom_depth == "interior" ):
- atom_depth=1
- if ( atom_depth == "rear" ):
- atom_depth=2
- if ( atom_depth < depth_min ):
- depth_min = atom_depth
- if ( atom_depth > depth_max ):
- depth_max = atom_depth
- # set the color
- red = 128
- green = 128
- blue = 128
- if ( object_type == 4 ):
- red = 128
- green = 128
- blue = 255
- if ( object_type == 8 ):
- red = 128
- green = 200
- blue = 128
- # calculate xyz in millimeters
- if ( row_count % 2 == 0 ):
- x_min = (row_count* 2400 ) + 1200 - ( depth_max * 400 ) - 400
- x_max = (row_count* 2400 ) + 1200 - ( depth_min * 400 )
- else:
- x_min = (row_count* 2400 ) + ( depth_min * 400 )
- x_max = (row_count* 2400 ) + ( depth_max * 400 ) + 400
- y_min = (rack_count* 600 ) + 10
- y_max = (rack_count* 600 ) + 590
- z_min = ( unit_min * 50 )
- z_max = ( unit_max * 50 ) + 45
- print(object_name)
- print(object_id)
- print(object_type)
- print(x_min)
- print(x_max)
- print(y_min)
- print(y_max)
- print(z_min)
- print(z_max)
- print(red)
- print(blue)
- print(green)
- print()
- rack_count=rack_count+1
- row_count=row_count+1
- rack_count= 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement