Adds fetch quota command (#24)

This commit is contained in:
lenhattan86 2021-09-16 18:36:42 -07:00 committed by GitHub
parent 8ae23aad30
commit 23e9c904d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -103,6 +103,9 @@ func init() {
// Fetch Status
fetchCmd.AddCommand(fetchStatusCmd)
// fetch quota
fetchCmd.AddCommand(fetchQuotaCmd)
}
var fetchCmd = &cobra.Command{
@ -173,6 +176,13 @@ var fetchStatusCmd = &cobra.Command{
Run: fetchHostStatus,
}
var fetchQuotaCmd = &cobra.Command{
Use: "quota",
Short: "Fetch the quotas of given roles",
Long: `This command will print list of resource quotas with the aggregated resources for the given roles`,
Run: fetchQuota,
}
func fetchTasksConfig(cmd *cobra.Command, args []string) {
log.Infof("Fetching job configuration for [%s/%s/%s] \n", *env, *role, *name)
@ -381,3 +391,28 @@ func fetchJobs(cmd *cobra.Command, args []string) {
}
}
}
//fetchQuota gets quotas for roles in args
func fetchQuota(cmd *cobra.Command, args []string) {
for _, role := range args {
log.Infof("Fetching quota for role: %s \n", role)
result, err := client.GetQuota(role)
if err != nil {
log.Fatalf("error: %+v\n", err)
}
if toJson {
fmt.Println(internal.ToJSON(result))
} else {
fmt.Printf(" Quota: %v\n", internal.ToJSON(result.Quota.GetResources()))
fmt.Printf(" Aggregated Resources: \n")
fmt.Printf(" ProdSharedConsumption: %v\n", internal.ToJSON(result.ProdSharedConsumption.GetResources()))
fmt.Printf(" NonProdSharedConsumption: %v\n",
internal.ToJSON(result.NonProdSharedConsumption.GetResources()))
fmt.Printf(" ProdDedicatedConsumption: %v\n",
internal.ToJSON(result.ProdDedicatedConsumption.GetResources()))
fmt.Printf(" NonProdDedicatedConsumption: %v\n",
internal.ToJSON(result.NonProdDedicatedConsumption.GetResources()))
}
}
}