예제 #1
0
func machineFromMongodb(db *mongodb.MongoDB) (*machines, error) {
	from, err := time.Parse(time.RFC3339, "2015-03-07T13:15:00Z")
	if err != nil {
		return nil, err
	}

	to, err := time.Parse(time.RFC3339, "2015-04-10T07:30:00Z")
	if err != nil {
		return nil, err
	}

	machines := newMachines()
	err = db.Run("jMachines", func(c *mgo.Collection) error {
		var m koding.Machine
		iter := c.Find(
			bson.M{
				"createdAt": bson.M{
					"$gte": from.UTC(),
					"$lt":  to.UTC(),
				},
				// "status.state": machinestate.Stopped.String(),
			},
		).Iter()

		for iter.Next(&m) {
			machines.docs = append(machines.docs, m)
		}

		return iter.Close()
	})

	return machines, err
}
예제 #2
0
파일: instances.go 프로젝트: koding/koding
func deleteDocument(i *ec2.Instance, db *mongodb.MongoDB) error {
	if i == nil {
		return errors.New("nil instance")
	}

	var id bson.ObjectId

	for _, tag := range i.Tags {
		key := strings.ToLower(aws.StringValue(tag.Key))
		value := strings.ToLower(aws.StringValue(tag.Value))

		if key != "koding-machineid" || value == "" {
			continue
		}

		id = bson.ObjectIdHex(value)
		break
	}

	if !id.Valid() {
		return errors.New("unable to find valid jMachine.ObjectId")
	}

	return db.Run(modelhelper.MachinesColl, func(c *mgo.Collection) error { return c.RemoveId(id) })
}
예제 #3
0
파일: iter.go 프로젝트: koding/koding
// Iter accepts mongo and iterOptions and runs the query
func Iter(mongo *mongodb.MongoDB, iterOptions *iterOptions) error {
	if iterOptions.CollectionName == "" {
		return errors.New("Collection name is not set")
	}

	if iterOptions.F == nil {
		return errors.New("Iteration function is not given")
	}
	if iterOptions.Result == nil {
		return errors.New("Datatype is not given")
	}

	return mongo.Run(iterOptions.CollectionName, createQuery(iterOptions))
}
예제 #4
0
파일: userdebug.go 프로젝트: koding/koding
func machinesFromInstanceId(db *mongodb.MongoDB, instanceId string) (*machines, error) {
	machines := newMachines()
	err := db.Run("jMachines", func(c *mgo.Collection) error {
		var m MachineDocument
		iter := c.Find(bson.M{"meta.instanceId": instanceId}).Iter()

		for iter.Next(&m) {
			machines.docs = append(machines.docs, m)
		}

		return iter.Close()
	})

	return machines, err
}
예제 #5
0
파일: userdebug.go 프로젝트: koding/koding
func machinesFromUsername(db *mongodb.MongoDB, username string) (*machines, error) {
	machines := newMachines()
	err := db.Run("jMachines", func(c *mgo.Collection) error {
		var m MachineDocument
		iter := c.Find(bson.M{"credential": username}).Iter()

		for iter.Next(&m) {
			machines.docs = append(machines.docs, m)
		}

		return iter.Close()
	})

	return machines, err
}