예제 #1
0
func (c *cleaner) add(v interface{}) {
	var fn func()
	switch model := v.(type) {
	case *models.User:
		fn = func() {
			modelhelper.RemoveUser(model.Name)
		}
	case *models.Account:
		fn = func() {
			modelhelper.RemoveAccount(model.Id)
		}
	case *models.Group:
		fn = func() {
			modelhelper.RemoveGroup(model.Id)
		}
	case *models.Machine:
		fn = func() {
			modelhelper.DeleteMachine(model.ObjectId)
		}
	case *models.ComputeStack:
		fn = func() {
			modelhelper.DeleteComputeStack(model.Id.Hex())
		}
	default:
		panic(fmt.Errorf("cleaner for %T not implemented", v))
	}
	*c = append(*c, fn)
}
예제 #2
0
// * delete all jComputeStacks which "originId" does not exist in JAccount
// * delete alljComputeStacks which { group:koding }
func deleteComputeStacks(res interface{}) error {
	cs := res.(*models.ComputeStack)

	if cs.Group != "koding" && getAccountByID(cs.OriginId.Hex()) && getGroupBySlug(cs.Group) {
		return nil
	}

	fmt.Printf("deleting jComputeStack %q\n", cs.Id.Hex())
	if !*flagDry {
		return helper.DeleteComputeStack(cs.Id.Hex())
	}

	return nil
}
예제 #3
0
파일: mongo.go 프로젝트: koding/koding
// Destroy implements the Database interface.
func (db *mongoDatabase) Destroy(opts *DestroyOptions) error {
	if err := opts.Valid(); err != nil {
		return err
	}

	err := new(multierror.Error)

	for _, id := range opts.Stack.Machines {
		if e := modelhelper.DeleteMachine(id); e != nil {
			err = multierror.Append(err, e)
		}
	}

	if e := modelhelper.DeleteComputeStack(opts.Stack.Id.Hex()); e != nil {
		err = multierror.Append(err, e)
	}

	return err.ErrorOrNil()
}