@@ -69,16 +69,39 @@ def me(
6969 tree .add ("[bold]Username:[/bold] " + data .get ("username" ))
7070 tree .add ("[bold]Email:[/bold] " + data .get ("email" ))
7171
72+ # show projects info
7273 project_list = api_driver .get ("/openstack/projects/" + config .username ).json ()
7374 project_tree = tree .add (":open_file_folder: Projects" )
7475 for project in project_list :
7576 project_tree_item = project_tree .add (":computer: " + project .get ('name' ))
7677 project_tree_item .add ("[bold]Owner:[/bold] " + project .get ('owner' , '' ))
7778 project_tree_item .add ("Members: " + " " .join (project .get ('members' , [])))
79+
80+ # show quotas for project
81+ project_quota_list = api_driver .get (f"/quota/project/{ project .get ('name' )} /adjustements" )
82+ if project_quota_list .status_code >= 400 :
83+ project_tree_item .add (f":warning: Error fetching quotas for project { project .get ('name' )} " )
84+ continue
85+
86+ project_quota_tree = project_tree_item .add (":open_file_folder: Quotas for project" )
87+ quota_types = set ([quota .get ('type' ) for quota in project_quota_list .json ()])
88+ total_quotas = {quota_type : 0 for quota_type in quota_types }
89+ self_quotas = {quota_type : 0 for quota_type in quota_types }
90+ for quota in project_quota_list .json ():
91+ total_quotas [quota .get ('type' )] += quota .get ('quantity' )
92+ if quota .get ('username' ) == config .username :
93+ self_quotas [quota .get ('type' )] += quota .get ('quantity' )
94+
95+ for quota_type , quantity in total_quotas .items ():
96+ if quantity == 0 :
97+ continue
98+ project_quota_tree .add (f"{ quota_type } Total: { quantity } " )
99+ project_quota_tree .add (f"{ quota_type } You give: { self_quotas [quota_type ]} " )
100+
78101 if not project_list :
79102 project_tree .add (":warning: No projects found" )
80103
81- quota_tree = tree .add (":open_file_folder: Quotas" )
104+ quota_tree = tree .add (":open_file_folder: Quotas owned " )
82105 quota_list = api_driver .get (f"/quota/user/{ config .username } /total" ).json ()
83106 for quota in quota_list :
84107 quota_tree .add (f"Type: { quota .get ('type' )} / { quota .get ('quantity' )} " )
0 commit comments