github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/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.MegabytesWithUnlimited `short:"i" description:"Maximum amount of memory a process can have (e.g. 1024M, 1G, 10G). (Default: unlimited)."` 16 TotalMemory flag.MegabytesWithUnlimited `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 TotalLogVolume flag.BytesWithUnlimited `short:"l" description:"Total log volume per second all processes can have, in bytes (e.g. 128B, 4K, 1M). -1 represents an unlimited amount. (Default: -1)."` 21 22 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] [-l LOG_VOLUME]"` 23 relatedCommands interface{} `related_commands:"create-space, space-quotas, set-space-quota"` 24 } 25 26 func (cmd CreateSpaceQuotaCommand) Execute([]string) error { 27 err := cmd.SharedActor.CheckTarget(true, false) 28 if err != nil { 29 return err 30 } 31 32 user, err := cmd.Actor.GetCurrentUser() 33 if err != nil { 34 return err 35 } 36 37 cmd.UI.DisplayTextWithFlavor("Creating space quota {{.SpaceQuota}} for org {{.CurrentOrg}} as {{.CurrentUser}}...", map[string]interface{}{ 38 "SpaceQuota": cmd.RequiredArgs.SpaceQuota, 39 "CurrentOrg": cmd.Config.TargetedOrganization().Name, 40 "CurrentUser": user.Name, 41 }) 42 43 warnings, err := cmd.Actor.CreateSpaceQuota( 44 cmd.RequiredArgs.SpaceQuota, 45 cmd.Config.TargetedOrganization().GUID, 46 v7action.QuotaLimits{ 47 TotalMemoryInMB: convertMegabytesFlagToNullInt(cmd.TotalMemory), 48 PerProcessMemoryInMB: convertMegabytesFlagToNullInt(cmd.PerProcessMemory), 49 TotalInstances: convertIntegerLimitFlagToNullInt(cmd.NumAppInstances), 50 PaidServicesAllowed: &cmd.PaidServicePlans, 51 TotalServiceInstances: convertIntegerLimitFlagToNullInt(cmd.TotalServiceInstances), 52 TotalRoutes: convertIntegerLimitFlagToNullInt(cmd.TotalRoutes), 53 TotalReservedPorts: convertIntegerLimitFlagToNullInt(cmd.TotalReservedPorts), 54 TotalLogVolume: convertBytesFlagToNullInt(cmd.TotalLogVolume), 55 }, 56 ) 57 58 cmd.UI.DisplayWarnings(warnings) 59 if err != nil { 60 switch err.(type) { 61 case ccerror.QuotaAlreadyExists: 62 cmd.UI.DisplayWarning(err.Error()) 63 default: 64 return err 65 } 66 } 67 68 cmd.UI.DisplayOK() 69 70 return nil 71 }