github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/command/v7/update_org_quota_command.go (about)

     1  package v7
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/actor/v7action"
     5  	"code.cloudfoundry.org/cli/command/flag"
     6  	"code.cloudfoundry.org/cli/command/translatableerror"
     7  )
     8  
     9  type UpdateOrgQuotaCommand struct {
    10  	BaseCommand
    11  
    12  	RequiredArgs          flag.OrganizationQuota      `positional-args:"Yes"`
    13  	NumAppInstances       flag.IntegerLimit           `short:"a" description:"Total number of application instances. -1 represents an unlimited amount."`
    14  	PaidServicePlans      bool                        `long:"allow-paid-service-plans" description:"Allow provisioning instances of paid service plans."`
    15  	NoPaidServicePlans    bool                        `long:"disallow-paid-service-plans" description:"Disallow provisioning instances of paid service plans."`
    16  	PerProcessMemory      flag.MegabytesWithUnlimited `short:"i" description:"Maximum amount of memory a process can have (e.g. 1024M, 1G, 10G). -1 represents an unlimited amount."`
    17  	TotalMemory           flag.MegabytesWithUnlimited `short:"m" description:"Total amount of memory all processes can have (e.g. 1024M, 1G, 10G).  -1 represents an unlimited amount."`
    18  	NewName               string                      `short:"n" description:"New name"`
    19  	TotalRoutes           flag.IntegerLimit           `short:"r" description:"Total number of routes. -1 represents an unlimited amount."`
    20  	TotalReservedPorts    flag.IntegerLimit           `long:"reserved-route-ports" description:"Maximum number of routes that may be created with ports. -1 represents an unlimited amount."`
    21  	TotalServiceInstances flag.IntegerLimit           `short:"s" description:"Total number of service instances. -1 represents an unlimited amount."`
    22  	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."`
    23  
    24  	usage           interface{} `usage:"CF_NAME update-org-quota QUOTA [-m TOTAL_MEMORY] [-i INSTANCE_MEMORY] [-n NEW_NAME] [-r ROUTES] [-s SERVICE_INSTANCES] [-a APP_INSTANCES] [--allow-paid-service-plans | --disallow-paid-service-plans] [--reserved-route-ports RESERVED_ROUTE_PORTS] [-l LOG_VOLUME]"`
    25  	relatedCommands interface{} `related_commands:"org, org-quota"`
    26  }
    27  
    28  func (cmd UpdateOrgQuotaCommand) Execute(args []string) error {
    29  	if cmd.PaidServicePlans && cmd.NoPaidServicePlans {
    30  		return translatableerror.ArgumentCombinationError{
    31  			Args: []string{"--allow-paid-service-plans", "--disallow-paid-service-plans"},
    32  		}
    33  	}
    34  
    35  	err := cmd.SharedActor.CheckTarget(false, false)
    36  	if err != nil {
    37  		return err
    38  	}
    39  
    40  	user, err := cmd.Actor.GetCurrentUser()
    41  	if err != nil {
    42  		return err
    43  	}
    44  
    45  	oldQuotaName := cmd.RequiredArgs.OrganizationQuotaName
    46  
    47  	cmd.UI.DisplayTextWithFlavor("Updating org quota {{.OrganizationQuotaName}} as {{.User}}...",
    48  		map[string]interface{}{
    49  			"OrganizationQuotaName": oldQuotaName,
    50  			"User":                  user.Name,
    51  		})
    52  
    53  	var paidServicesAllowed *bool
    54  	if cmd.PaidServicePlans || cmd.NoPaidServicePlans {
    55  		paidServicesAllowed = &cmd.PaidServicePlans
    56  	}
    57  
    58  	updatedQuotaLimits := v7action.QuotaLimits{
    59  		TotalMemoryInMB:       convertMegabytesFlagToNullInt(cmd.TotalMemory),
    60  		PerProcessMemoryInMB:  convertMegabytesFlagToNullInt(cmd.PerProcessMemory),
    61  		TotalInstances:        convertIntegerLimitFlagToNullInt(cmd.NumAppInstances),
    62  		PaidServicesAllowed:   paidServicesAllowed,
    63  		TotalServiceInstances: convertIntegerLimitFlagToNullInt(cmd.TotalServiceInstances),
    64  		TotalRoutes:           convertIntegerLimitFlagToNullInt(cmd.TotalRoutes),
    65  		TotalReservedPorts:    convertIntegerLimitFlagToNullInt(cmd.TotalReservedPorts),
    66  		TotalLogVolume:        convertBytesFlagToNullInt(cmd.TotalLogVolume),
    67  	}
    68  
    69  	warnings, err := cmd.Actor.UpdateOrganizationQuota(oldQuotaName, cmd.NewName, updatedQuotaLimits)
    70  	cmd.UI.DisplayWarnings(warnings)
    71  	if err != nil {
    72  		return err
    73  	}
    74  
    75  	cmd.UI.DisplayOK()
    76  
    77  	return nil
    78  }