當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Database.SelectFromMachine方法代碼示例

本文整理匯總了Golang中github.com/NetSys/quilt/db.Database.SelectFromMachine方法的典型用法代碼示例。如果您正苦於以下問題:Golang Database.SelectFromMachine方法的具體用法?Golang Database.SelectFromMachine怎麽用?Golang Database.SelectFromMachine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/NetSys/quilt/db.Database的用法示例。


在下文中一共展示了Database.SelectFromMachine方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: machineTxn

func machineTxn(view db.Database, stitch stitch.Stitch) error {
	// XXX: How best to deal with machines that don't specify enough information?
	maxPrice, _ := stitch.QueryFloat("MaxPrice")
	stitchMachines := toDBMachine(stitch.QueryMachines(), maxPrice)

	dbMachines := view.SelectFromMachine(nil)

	scoreFun := func(left, right interface{}) int {
		stitchMachine := left.(db.Machine)
		dbMachine := right.(db.Machine)

		switch {
		case dbMachine.Provider != stitchMachine.Provider:
			return -1
		case dbMachine.Region != stitchMachine.Region:
			return -1
		case dbMachine.Size != "" && stitchMachine.Size != dbMachine.Size:
			return -1
		case dbMachine.Role != db.None && dbMachine.Role != stitchMachine.Role:
			return -1
		case dbMachine.DiskSize != stitchMachine.DiskSize:
			return -1
		case dbMachine.PrivateIP == "":
			return 2
		case dbMachine.PublicIP == "":
			return 1
		default:
			return 0
		}
	}

	pairs, bootList, terminateList := join.Join(stitchMachines, dbMachines, scoreFun)

	for _, toTerminate := range terminateList {
		toTerminate := toTerminate.(db.Machine)
		view.Remove(toTerminate)
	}

	for _, bootSet := range bootList {
		bootSet := bootSet.(db.Machine)

		pairs = append(pairs, join.Pair{L: bootSet, R: view.InsertMachine()})
	}

	for _, pair := range pairs {
		stitchMachine := pair.L.(db.Machine)
		dbMachine := pair.R.(db.Machine)

		dbMachine.Role = stitchMachine.Role
		dbMachine.Size = stitchMachine.Size
		dbMachine.DiskSize = stitchMachine.DiskSize
		dbMachine.Provider = stitchMachine.Provider
		dbMachine.Region = stitchMachine.Region
		dbMachine.SSHKeys = stitchMachine.SSHKeys
		view.Commit(dbMachine)
	}

	return nil
}
開發者ID:yuenmeiwan,項目名稱:quilt,代碼行數:59,代碼來源:engine.go

示例2: aclTxn

func aclTxn(view db.Database, stitch stitch.Stitch) error {
	cluster, err := view.GetCluster()
	if err != nil {
		return err
	}

	machines := view.SelectFromMachine(func(m db.Machine) bool {
		return m.PublicIP != ""
	})
	acls := resolveACLs(stitch.QueryStrSlice("AdminACL"))

	for _, m := range machines {
		acls = append(acls, m.PublicIP+"/32")
	}

	sort.Strings(acls)
	cluster.ACLs = acls
	view.Commit(cluster)

	return nil
}
開發者ID:yuenmeiwan,項目名稱:quilt,代碼行數:21,代碼來源:engine.go


注:本文中的github.com/NetSys/quilt/db.Database.SelectFromMachine方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。