@@ -83,8 +83,54 @@ def projects_testing_project_zones_australia_southeast1_a_instances_000000001_ge
8383 return render_template ('route_14_template.json' ), 200 , {'Content-Type' : 'application/json' }
8484
8585@app .route ('/projects/testing-project/zones/australia-southeast1-a/machineTypes' , methods = ['GET' ])
86- def projects_testing_project_zones_australia_southeast1_a_machineTypes ():
87- return render_template ('route_15_template.json' ), 200 , {'Content-Type' : 'application/json' }
86+ def machine_types ():
87+ import math
88+
89+ # The full list of machine type names
90+ machine_type_names = [
91+ f"p{ page } -c2-standard-{ vcpus } "
92+ for page in range (1 , 21 ) # Pages 1 through 20
93+ for vcpus in [8 , 60 , 4 , 30 , 16 ]
94+ ]
95+
96+ # Pagination parameters
97+ items_per_page = 10 # Adjust as needed
98+ current_page = int (request .args .get ('pageToken' , 1 )) # Default to page 1
99+ total_pages = math .ceil (len (machine_type_names ) / items_per_page )
100+
101+ # Determine start and end indices for the current page
102+ start_idx = (current_page - 1 ) * items_per_page
103+ end_idx = start_idx + items_per_page
104+
105+ # Slice the list for the current page
106+ page_items = machine_type_names [start_idx :end_idx ]
107+
108+ # Prepare the response
109+ response = {
110+ "kind" : "compute#machineTypeList" ,
111+ "id" : "projects/testing-project/zones/australia-southeast1-a/machineTypes" ,
112+ "items" : [
113+ {
114+ "kind" : "compute#machineType" ,
115+ "id" : f"8010{ page_items .index (name )} " ,
116+ "name" : name ,
117+ "description" : f"{ name } description" ,
118+ "guestCpus" : int (name .split ('-' )[- 1 ]),
119+ "memoryMb" : int (name .split ('-' )[- 1 ]) * 4096 , # Example calculation
120+ "zone" : "australia-southeast1-a" ,
121+ "selfLink" : f"https://www.googleapis.com/compute/v1/projects/testing-project/zones/australia-southeast1-a/machineTypes/{ name } " ,
122+ }
123+ for name in page_items
124+ ],
125+ "selfLink" : "https://www.googleapis.com/compute/v1/projects/testing-project/zones/australia-southeast1-a/machineTypes"
126+ }
127+
128+ # Add nextPageToken if applicable
129+ if current_page < total_pages :
130+ response ["nextPageToken" ] = str (current_page + 1 )
131+
132+ return jsonify (response )
133+
88134
89135
90136## TODO: geet rid once all else stable
0 commit comments