本文整理汇总了Golang中github.com/cloudfoundry/cli/cf/models.SpaceQuota类的典型用法代码示例。如果您正苦于以下问题:Golang SpaceQuota类的具体用法?Golang SpaceQuota怎么用?Golang SpaceQuota使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SpaceQuota类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1:
services := []models.ServiceInstanceFields{serviceInstance}
securityGroup1 := models.SecurityGroupFields{Name: "Nacho Security"}
securityGroup2 := models.SecurityGroupFields{Name: "Nacho Prime"}
securityGroups := []models.SecurityGroupFields{securityGroup1, securityGroup2}
space := models.Space{}
space.Name = "whose-space-is-it-anyway"
space.Organization = org
space.Applications = apps
space.Domains = domains
space.ServiceInstances = services
space.SecurityGroups = securityGroups
space.SpaceQuotaGuid = "runaway-guid"
quota := models.SpaceQuota{}
quota.Guid = "runaway-guid"
quota.Name = "runaway"
quota.MemoryLimit = 102400
quota.InstanceMemoryLimit = -1
quota.RoutesLimit = 111
quota.ServicesLimit = 222
quota.NonBasicServicesAllowed = false
requirementsFactory.LoginSuccess = true
requirementsFactory.TargetedOrgSuccess = true
requirementsFactory.Space = space
quotaRepo.FindByGuidReturns(quota, nil)
})
开发者ID:matanzit,项目名称:cli,代码行数:30,代码来源:space_test.go
示例2: Execute
func (cmd *CreateSpaceQuota) Execute(context flags.FlagContext) {
name := context.Args()[0]
org := cmd.config.OrganizationFields()
cmd.ui.Say(T("Creating space quota {{.QuotaName}} for org {{.OrgName}} as {{.Username}}...", map[string]interface{}{
"QuotaName": terminal.EntityNameColor(name),
"OrgName": terminal.EntityNameColor(org.Name),
"Username": terminal.EntityNameColor(cmd.config.Username()),
}))
quota := models.SpaceQuota{
Name: name,
OrgGuid: org.Guid,
}
memoryLimit := context.String("m")
if memoryLimit != "" {
parsedMemory, errr := formatters.ToMegabytes(memoryLimit)
if errr != nil {
cmd.ui.Failed(T("Invalid memory limit: {{.MemoryLimit}}\n{{.Err}}", map[string]interface{}{"MemoryLimit": memoryLimit, "Err": errr}))
}
quota.MemoryLimit = parsedMemory
}
instanceMemoryLimit := context.String("i")
var parsedMemory int64
var err error
if instanceMemoryLimit == "-1" || instanceMemoryLimit == "" {
parsedMemory = -1
} else {
parsedMemory, err = formatters.ToMegabytes(instanceMemoryLimit)
if err != nil {
cmd.ui.Failed(T("Invalid instance memory limit: {{.MemoryLimit}}\n{{.Err}}", map[string]interface{}{"MemoryLimit": instanceMemoryLimit, "Err": err}))
}
}
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("Space Quota Definition {{.QuotaName}} already exists", map[string]interface{}{"QuotaName": quota.Name}))
return
}
if err != nil {
cmd.ui.Failed(err.Error())
}
cmd.ui.Ok()
}
开发者ID:Doebe,项目名称:workplace,代码行数:66,代码来源:create_quota.go
示例3:
It("fails requirements when called without a quota name", func() {
runCommand()
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Incorrect Usage", "Requires an argument"},
))
})
It("fails requirements when an org is not targeted", func() {
requirementsFactory.TargetedOrgSuccess = false
Expect(runCommand()).To(BeFalse())
})
Context("When the quota provided exists", func() {
BeforeEach(func() {
quota := models.SpaceQuota{}
quota.Name = "my-quota"
quota.GUID = "my-quota-guid"
quota.OrgGUID = "my-org-guid"
quotaRepo.FindByNameReturns(quota, nil)
})
It("deletes a quota with a given name when the user confirms", func() {
ui.Inputs = []string{"y"}
runCommand("my-quota")
Expect(quotaRepo.DeleteArgsForCall(0)).To(Equal("my-quota-guid"))
Expect(ui.Prompts).To(ContainSubstrings(
[]string{"Really delete the quota", "my-quota"},
))
开发者ID:yingkitw,项目名称:cli,代码行数:30,代码来源:delete_space_quota_test.go
示例4: Execute
func (cmd *CreateSpaceQuota) Execute(context flags.FlagContext) error {
name := context.Args()[0]
org := cmd.config.OrganizationFields()
cmd.ui.Say(T("Creating space quota {{.QuotaName}} for org {{.OrgName}} as {{.Username}}...", map[string]interface{}{
"QuotaName": terminal.EntityNameColor(name),
"OrgName": terminal.EntityNameColor(org.Name),
"Username": terminal.EntityNameColor(cmd.config.Username()),
}))
quota := models.SpaceQuota{
Name: name,
OrgGUID: org.GUID,
}
memoryLimit := context.String("m")
if memoryLimit != "" {
parsedMemory, errr := formatters.ToMegabytes(memoryLimit)
if errr != nil {
return errors.New(T("Invalid memory limit: {{.MemoryLimit}}\n{{.Err}}", map[string]interface{}{"MemoryLimit": memoryLimit, "Err": errr}))
}
quota.MemoryLimit = parsedMemory
}
instanceMemoryLimit := context.String("i")
var parsedMemory int64
var err error
if instanceMemoryLimit == "-1" || instanceMemoryLimit == "" {
parsedMemory = -1
} else {
parsedMemory, err = formatters.ToMegabytes(instanceMemoryLimit)
if err != nil {
return errors.New(T("Invalid instance memory limit: {{.MemoryLimit}}\n{{.Err}}", map[string]interface{}{"MemoryLimit": instanceMemoryLimit, "Err": err}))
}
}
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
}
if context.IsSet("a") {
quota.AppInstanceLimit = context.Int("a")
} else {
quota.AppInstanceLimit = resources.UnlimitedAppInstances
}
if context.IsSet("reserved-route-ports") {
quota.ReservedRoutePortsLimit = json.Number(strconv.Itoa(context.Int("reserved-route-ports")))
}
err = cmd.quotaRepo.Create(quota)
httpErr, ok := err.(errors.HTTPError)
if ok && httpErr.ErrorCode() == errors.QuotaDefinitionNameTaken {
cmd.ui.Ok()
cmd.ui.Warn(T("Space Quota Definition {{.QuotaName}} already exists", map[string]interface{}{"QuotaName": quota.Name}))
return nil
}
if err != nil {
return err
}
cmd.ui.Ok()
return nil
}
开发者ID:jasonkeene,项目名称:cli,代码行数:77,代码来源:create_space_quota.go
示例5:
requirementsFactory.LoginSuccess = true
})
It("fails requirements when called without a quota name", func() {
runCommand()
Expect(ui.FailedWithUsage).To(BeTrue())
})
It("fails requirements when an org is not targeted", func() {
requirementsFactory.TargetedOrgSuccess = false
Expect(runCommand()).To(BeFalse())
})
Context("When the quota provided exists", func() {
BeforeEach(func() {
quota := models.SpaceQuota{}
quota.Name = "my-quota"
quota.Guid = "my-quota-guid"
quota.OrgGuid = "my-org-guid"
quotaRepo.FindByNameReturns(quota, nil)
})
It("deletes a quota with a given name when the user confirms", func() {
ui.Inputs = []string{"y"}
runCommand("my-quota")
Expect(quotaRepo.DeleteArgsForCall(0)).To(Equal("my-quota-guid"))
Expect(ui.Prompts).To(ContainSubstrings(
[]string{"Really delete the quota", "my-quota"},
))
开发者ID:tools-alexuser01,项目名称:cli,代码行数:31,代码来源:delete_quota_test.go
注:本文中的github.com/cloudfoundry/cli/cf/models.SpaceQuota类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论