本文整理匯總了Golang中github.com/NetSys/quilt/db.Machine.Provider方法的典型用法代碼示例。如果您正苦於以下問題:Golang Machine.Provider方法的具體用法?Golang Machine.Provider怎麽用?Golang Machine.Provider使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/NetSys/quilt/db.Machine
的用法示例。
在下文中一共展示了Machine.Provider方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestDefaultRegion
func TestDefaultRegion(t *testing.T) {
exp := "foo"
m := db.Machine{Provider: "Amazon", Region: exp}
m = DefaultRegion(m)
if m.Region != exp {
t.Errorf("expected %s, found %s", exp, m.Region)
}
m.Region = ""
m = DefaultRegion(m)
exp = "us-west-1"
if m.Region != exp {
t.Errorf("expected %s, found %s", exp, m.Region)
}
m.Region = ""
m.Provider = "Google"
exp = "us-east1-b"
m = DefaultRegion(m)
if m.Region != exp {
t.Errorf("expected %s, found %s", exp, m.Region)
}
m.Region = ""
m.Provider = "Azure"
exp = "Central US"
m = DefaultRegion(m)
if m.Region != exp {
t.Errorf("expected %s, found %s", exp, m.Region)
}
m.Region = ""
m.Provider = "Vagrant"
exp = ""
m = DefaultRegion(m)
if m.Region != exp {
t.Errorf("expected %s, found %s", exp, m.Region)
}
m.Region = ""
m.Provider = "Panic"
defer func() {
if r := recover(); r == nil {
t.Error("Expected panic")
}
}()
m = DefaultRegion(m)
}
示例2: toDBMachine
// toDBMachine converts machines specified in the Stitch into db.Machines that can
// be compared against what's already in the db.
// Specifically, it sets the role of the db.Machine, the size (which may depend
// on RAM and CPU constraints), and the provider.
// Additionally, it skips machines with invalid roles, sizes or providers.
func toDBMachine(machines []stitch.Machine, maxPrice float64) []db.Machine {
var hasMaster, hasWorker bool
var dbMachines []db.Machine
for _, stitchm := range machines {
var m db.Machine
role, err := db.ParseRole(stitchm.Role)
if err != nil {
log.WithError(err).Error("Error parsing role.")
continue
}
m.Role = role
hasMaster = hasMaster || role == db.Master
hasWorker = hasWorker || role == db.Worker
p, err := db.ParseProvider(stitchm.Provider)
if err != nil {
log.WithError(err).Error("Error parsing provider.")
continue
}
m.Provider = p
m.Size = stitchm.Size
if m.Size == "" {
providerInst := provider.New(p)
m.Size = providerInst.ChooseSize(
stitchm.RAM, stitchm.CPU, maxPrice)
if m.Size == "" {
log.Errorf("No valid size for %v, skipping.", m)
continue
}
}
m.DiskSize = stitchm.DiskSize
if m.DiskSize == 0 {
m.DiskSize = defaultDiskSize
}
m.SSHKeys = stitchm.SSHKeys
m.Region = stitchm.Region
dbMachines = append(dbMachines, provider.DefaultRegion(m))
}
if !hasMaster && hasWorker {
log.Warning("A Master was specified but no workers.")
return nil
} else if hasMaster && !hasWorker {
log.Warning("A Worker was specified but no masters.")
return nil
}
return dbMachines
}