func (cmd CreateSpaceQuota) Run(context *cli.Context) { 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") if instanceMemoryLimit != "" { var parsedMemory int64 var err error if instanceMemoryLimit == "-1" { 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() }
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) }) Context("when the space has a space quota", func() { It("shows information about the given space", func() { runCommand("whose-space-is-it-anyway")