github.com/loafoe/cli@v7.1.0+incompatible/command/v7/create_space_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 ) 8 9 type CreateSpaceQuotaCommand struct { 10 BaseCommand 11 12 RequiredArgs flag.SpaceQuota `positional-args:"yes"` 13 NumAppInstances flag.IntegerLimit `short:"a" description:"Total number of application instances. (Default: unlimited)."` 14 PaidServicePlans bool `long:"allow-paid-service-plans" description:"Allow provisioning instances of paid service plans. (Default: disallowed)."` 15 PerProcessMemory flag.MemoryWithUnlimited `short:"i" description:"Maximum amount of memory a process can have (e.g. 1024M, 1G, 10G). (Default: unlimited)."` 16 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)."` 17 TotalRoutes flag.IntegerLimit `short:"r" description:"Total number of routes. -1 represents an unlimited amount. (Default: 0)."` 18 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)."` 19 TotalServiceInstances flag.IntegerLimit `short:"s" description:"Total number of service instances. -1 represents an unlimited amount. (Default: 0)."` 20 usage interface{} `usage:"CF_NAME create-space-quota 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]"` 21 relatedCommands interface{} `related_commands:"create-space, space-quotas, set-space-quota"` 22 } 23 24 func (cmd CreateSpaceQuotaCommand) Execute([]string) error { 25 err := cmd.SharedActor.CheckTarget(true, false) 26 if err != nil { 27 return err 28 } 29 30 user, err := cmd.Config.CurrentUser() 31 if err != nil { 32 return err 33 } 34 35 cmd.UI.DisplayTextWithFlavor("Creating space quota {{.SpaceQuota}} for org {{.CurrentOrg}} as {{.CurrentUser}}...", map[string]interface{}{ 36 "SpaceQuota": cmd.RequiredArgs.SpaceQuota, 37 "CurrentOrg": cmd.Config.TargetedOrganization().Name, 38 "CurrentUser": user.Name, 39 }) 40 41 warnings, err := cmd.Actor.CreateSpaceQuota( 42 cmd.RequiredArgs.SpaceQuota, 43 cmd.Config.TargetedOrganization().GUID, 44 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 ) 54 55 cmd.UI.DisplayWarnings(warnings) 56 if err != nil { 57 switch err.(type) { 58 case ccerror.QuotaAlreadyExists: 59 cmd.UI.DisplayWarning(err.Error()) 60 default: 61 return err 62 } 63 } 64 65 cmd.UI.DisplayOK() 66 67 return nil 68 }