本文整理匯總了Golang中github.com/NetSys/quilt/db.Database.InsertMachine方法的典型用法代碼示例。如果您正苦於以下問題:Golang Database.InsertMachine方法的具體用法?Golang Database.InsertMachine怎麽用?Golang Database.InsertMachine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/NetSys/quilt/db.Database
的用法示例。
在下文中一共展示了Database.InsertMachine方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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
}