本文整理匯總了Golang中github.com/cloudfoundry/cli/cf/models.QuotaFields.MemoryLimit方法的典型用法代碼示例。如果您正苦於以下問題:Golang QuotaFields.MemoryLimit方法的具體用法?Golang QuotaFields.MemoryLimit怎麽用?Golang QuotaFields.MemoryLimit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/cli/cf/models.QuotaFields
的用法示例。
在下文中一共展示了QuotaFields.MemoryLimit方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Execute
func (cmd *CreateQuota) Execute(context flags.FlagContext) {
name := context.Args()[0]
cmd.ui.Say(T("Creating quota {{.QuotaName}} as {{.Username}}...", map[string]interface{}{
"QuotaName": terminal.EntityNameColor(name),
"Username": terminal.EntityNameColor(cmd.config.Username()),
}))
quota := models.QuotaFields{
Name: name,
}
memoryLimit := context.String("m")
if memoryLimit != "" {
parsedMemory, err := formatters.ToMegabytes(memoryLimit)
if err != nil {
cmd.ui.Failed(T("Invalid memory limit: {{.MemoryLimit}}\n{{.Err}}", map[string]interface{}{"MemoryLimit": memoryLimit, "Err": err}))
}
quota.MemoryLimit = parsedMemory
}
instanceMemoryLimit := context.String("i")
if instanceMemoryLimit == "-1" || instanceMemoryLimit == "" {
quota.InstanceMemoryLimit = -1
} else {
parsedMemory, errr := formatters.ToMegabytes(instanceMemoryLimit)
if errr != nil {
cmd.ui.Failed(T("Invalid instance memory limit: {{.MemoryLimit}}\n{{.Err}}", map[string]interface{}{"MemoryLimit": instanceMemoryLimit, "Err": errr}))
}
quota.InstanceMemoryLimit = parsedMemory
}
if context.IsSet("r") {
quota.RoutesLimit = context.Int("r")
}
if context.IsSet("s") {
quota.ServicesLimit = context.Int("s")
}
if context.IsSet("allow-paid-service-plans") {
quota.NonBasicServicesAllowed = true
}
err := cmd.quotaRepo.Create(quota)
httpErr, ok := err.(errors.HttpError)
if ok && httpErr.ErrorCode() == errors.QUOTA_EXISTS {
cmd.ui.Ok()
cmd.ui.Warn(T("Quota Definition {{.QuotaName}} already exists", map[string]interface{}{"QuotaName": quota.Name}))
return
}
if err != nil {
cmd.ui.Failed(err.Error())
}
cmd.ui.Ok()
}