github.com/lukasheimann/cloudfoundrycli@v7.1.0+incompatible/cf/models/space_quota.go (about)

     1  package models
     2  
     3  import (
     4  	"encoding/json"
     5  	"strconv"
     6  
     7  	"code.cloudfoundry.org/cli/cf/formatters"
     8  	. "code.cloudfoundry.org/cli/cf/i18n"
     9  )
    10  
    11  type SpaceQuota struct {
    12  	GUID                    string      `json:"guid,omitempty"`
    13  	Name                    string      `json:"name"`
    14  	MemoryLimit             int64       `json:"memory_limit"`          // in Megabytes
    15  	InstanceMemoryLimit     int64       `json:"instance_memory_limit"` // in Megabytes
    16  	RoutesLimit             int         `json:"total_routes"`
    17  	ServicesLimit           int         `json:"total_services"`
    18  	NonBasicServicesAllowed bool        `json:"non_basic_services_allowed"`
    19  	OrgGUID                 string      `json:"organization_guid"`
    20  	AppInstanceLimit        int         `json:"app_instance_limit"`
    21  	ReservedRoutePortsLimit json.Number `json:"total_reserved_route_ports,omitempty"`
    22  }
    23  
    24  const UnlimitedDisplay = "unlimited"
    25  
    26  func (q SpaceQuota) FormattedMemoryLimit() string {
    27  	return formatters.ByteSize(q.MemoryLimit * formatters.MEGABYTE)
    28  }
    29  
    30  func (q SpaceQuota) FormattedInstanceMemoryLimit() string {
    31  	if q.InstanceMemoryLimit == -1 {
    32  		return T(UnlimitedDisplay)
    33  	}
    34  	return formatters.ByteSize(q.InstanceMemoryLimit * formatters.MEGABYTE)
    35  }
    36  
    37  func (q SpaceQuota) FormattedAppInstanceLimit() string {
    38  	appInstanceLimit := T(UnlimitedDisplay)
    39  	if q.AppInstanceLimit != -1 { //TODO - figure out how to use resources.UnlimitedAppInstances
    40  		appInstanceLimit = strconv.Itoa(q.AppInstanceLimit)
    41  	}
    42  
    43  	return appInstanceLimit
    44  }
    45  
    46  func (q SpaceQuota) FormattedServicesLimit() string {
    47  	servicesLimit := T(UnlimitedDisplay)
    48  	if q.ServicesLimit != -1 {
    49  		servicesLimit = strconv.Itoa(q.ServicesLimit)
    50  	}
    51  
    52  	return servicesLimit
    53  }
    54  
    55  func (q SpaceQuota) FormattedRoutePortsLimit() string {
    56  	reservedRoutePortsLimit := T(UnlimitedDisplay)
    57  	if q.ReservedRoutePortsLimit != "-1" {
    58  		reservedRoutePortsLimit = string(q.ReservedRoutePortsLimit)
    59  	}
    60  
    61  	return reservedRoutePortsLimit
    62  }
    63  
    64  type SpaceQuotaResponse struct {
    65  	GUID                    string      `json:"guid,omitempty"`
    66  	Name                    string      `json:"name"`
    67  	MemoryLimit             int64       `json:"memory_limit"`          // in Megabytes
    68  	InstanceMemoryLimit     int64       `json:"instance_memory_limit"` // in Megabytes
    69  	RoutesLimit             int         `json:"total_routes"`
    70  	ServicesLimit           int         `json:"total_services"`
    71  	NonBasicServicesAllowed bool        `json:"non_basic_services_allowed"`
    72  	OrgGUID                 string      `json:"organization_guid"`
    73  	AppInstanceLimit        json.Number `json:"app_instance_limit"`
    74  	ReservedRoutePortsLimit json.Number `json:"total_reserved_route_ports"`
    75  }