github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/actor/v7action/organization_quota.go (about) 1 package v7action 2 3 import ( 4 "code.cloudfoundry.org/cli/actor/actionerror" 5 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" 6 "code.cloudfoundry.org/cli/types" 7 ) 8 9 type OrganizationQuota struct { 10 // GUID is the unique ID of the organization quota. 11 GUID string 12 // Name is the name of the organization quota 13 Name string 14 15 //the various limits that are associated with applications 16 TotalMemory types.NullInt 17 InstanceMemory types.NullInt 18 TotalAppInstances types.NullInt 19 20 //the various limits that are associated with services 21 TotalServiceInstances types.NullInt 22 PaidServicePlans bool 23 24 //the various limits that are associated with routes 25 TotalRoutes types.NullInt 26 TotalRoutePorts types.NullInt 27 } 28 29 func (actor Actor) GetOrganizationQuotas() ([]OrganizationQuota, Warnings, error) { 30 ccv3OrgQuotas, warnings, err := actor.CloudControllerClient.GetOrganizationQuotas() 31 if err != nil { 32 return []OrganizationQuota{}, Warnings(warnings), err 33 } 34 35 var orgQuotas []OrganizationQuota 36 for _, quota := range ccv3OrgQuotas { 37 orgQuotas = append(orgQuotas, convertToOrganizationQuota(quota)) 38 } 39 40 return orgQuotas, Warnings(warnings), nil 41 } 42 43 func (actor Actor) GetOrganizationQuotaByName(orgQuotaName string) (OrganizationQuota, Warnings, error) { 44 ccv3OrgQuotas, warnings, err := actor.CloudControllerClient.GetOrganizationQuotas( 45 ccv3.Query{ 46 Key: ccv3.NameFilter, 47 Values: []string{orgQuotaName}, 48 }, 49 ) 50 if err != nil { 51 return OrganizationQuota{}, Warnings(warnings), err 52 53 } 54 55 if len(ccv3OrgQuotas) == 0 { 56 return OrganizationQuota{}, Warnings(warnings), actionerror.OrganizationQuotaNotFoundForNameError{Name: orgQuotaName} 57 } 58 orgQuota := convertToOrganizationQuota(ccv3OrgQuotas[0]) 59 60 return orgQuota, Warnings(warnings), nil 61 } 62 63 func convertToOrganizationQuota(ccv3OrgQuota ccv3.OrgQuota) OrganizationQuota { 64 orgQuota := OrganizationQuota{ 65 GUID: ccv3OrgQuota.GUID, 66 Name: ccv3OrgQuota.Name, 67 TotalMemory: ccv3OrgQuota.Apps.TotalMemory, 68 InstanceMemory: ccv3OrgQuota.Apps.InstanceMemory, 69 TotalAppInstances: ccv3OrgQuota.Apps.TotalAppInstances, 70 TotalServiceInstances: ccv3OrgQuota.Services.TotalServiceInstances, 71 PaidServicePlans: ccv3OrgQuota.Services.PaidServicePlans, 72 TotalRoutes: ccv3OrgQuota.Routes.TotalRoutes, 73 TotalRoutePorts: ccv3OrgQuota.Routes.TotalRoutePorts, 74 } 75 return orgQuota 76 }