github.com/loafoe/cli@v7.1.0+incompatible/command/v7/create_org_quota_command.go (about) 1 package v7 2 3 import ( 4 "code.cloudfoundry.org/cli/actor/v7action" 5 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 6 "code.cloudfoundry.org/cli/command/flag" 7 "code.cloudfoundry.org/cli/types" 8 ) 9 10 type CreateOrgQuotaCommand struct { 11 BaseCommand 12 13 RequiredArgs flag.OrganizationQuota `positional-args:"yes"` 14 NumAppInstances flag.IntegerLimit `short:"a" description:"Total number of application instances. (Default: unlimited)."` 15 PaidServicePlans bool `long:"allow-paid-service-plans" description:"Allow provisioning instances of paid service plans. (Default: disallowed)."` 16 PerProcessMemory flag.MemoryWithUnlimited `short:"i" description:"Maximum amount of memory a process can have (e.g. 1024M, 1G, 10G). (Default: unlimited)."` 17 TotalMemory flag.MemoryWithUnlimited `short:"m" description:"Total amount of memory all processes can have (e.g. 1024M, 1G, 10G). -1 represents an unlimited amount. (Default: 0)."` 18 TotalRoutes flag.IntegerLimit `short:"r" description:"Total number of routes. -1 represents an unlimited amount. (Default: 0)."` 19 TotalReservedPorts flag.IntegerLimit `long:"reserved-route-ports" description:"Maximum number of routes that may be created with ports. -1 represents an unlimited amount. (Default: 0)."` 20 TotalServiceInstances flag.IntegerLimit `short:"s" description:"Total number of service instances. -1 represents an unlimited amount. (Default: 0)."` 21 usage interface{} `usage:"CF_NAME create-org-quota ORG_QUOTA [-m TOTAL_MEMORY] [-i INSTANCE_MEMORY] [-r ROUTES] [-s SERVICE_INSTANCES] [-a APP_INSTANCES] [--allow-paid-service-plans] [--reserved-route-ports RESERVED_ROUTE_PORTS]"` 22 relatedCommands interface{} `related_commands:"create-org, org-quotas, set-org-quota"` 23 } 24 25 func (cmd CreateOrgQuotaCommand) Execute(args []string) error { 26 err := cmd.SharedActor.CheckTarget(false, false) 27 if err != nil { 28 return err 29 } 30 31 user, err := cmd.Config.CurrentUser() 32 if err != nil { 33 return err 34 } 35 36 orgQuotaName := cmd.RequiredArgs.OrganizationQuotaName 37 38 cmd.UI.DisplayTextWithFlavor("Creating org quota {{.OrganizationQuotaName}} as {{.User}}...", 39 map[string]interface{}{ 40 "User": user.Name, 41 "OrganizationQuotaName": orgQuotaName, 42 }) 43 44 warnings, err := cmd.Actor.CreateOrganizationQuota(orgQuotaName, v7action.QuotaLimits{ 45 TotalMemoryInMB: convertMegabytesFlagToNullInt(cmd.TotalMemory), 46 PerProcessMemoryInMB: convertMegabytesFlagToNullInt(cmd.PerProcessMemory), 47 TotalInstances: convertIntegerLimitFlagToNullInt(cmd.NumAppInstances), 48 PaidServicesAllowed: &cmd.PaidServicePlans, 49 TotalServiceInstances: convertIntegerLimitFlagToNullInt(cmd.TotalServiceInstances), 50 TotalRoutes: convertIntegerLimitFlagToNullInt(cmd.TotalRoutes), 51 TotalReservedPorts: convertIntegerLimitFlagToNullInt(cmd.TotalReservedPorts), 52 }) 53 cmd.UI.DisplayWarnings(warnings) 54 55 if _, ok := err.(ccerror.QuotaAlreadyExists); ok { 56 cmd.UI.DisplayWarning(err.Error()) 57 cmd.UI.DisplayOK() 58 return nil 59 } 60 61 if err != nil { 62 return err 63 } 64 cmd.UI.DisplayOK() 65 66 return nil 67 } 68 69 func convertMegabytesFlagToNullInt(flag flag.MemoryWithUnlimited) *types.NullInt { 70 if !flag.IsSet { 71 return nil 72 } 73 74 return &types.NullInt{IsSet: true, Value: flag.Value} 75 } 76 77 func convertIntegerLimitFlagToNullInt(flag flag.IntegerLimit) *types.NullInt { 78 if !flag.IsSet { 79 return nil 80 } 81 82 return &types.NullInt{IsSet: true, Value: flag.Value} 83 }