X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/6d87ae37bbc00cbb6fffb47ade3ec824b501b3df..40e378c88c2ae8e90b0785f3983ca320827e4cdf:/lib/dispatchcloud/driver.go diff --git a/lib/dispatchcloud/driver.go b/lib/dispatchcloud/driver.go index 49437e3187..5fcc0903f5 100644 --- a/lib/dispatchcloud/driver.go +++ b/lib/dispatchcloud/driver.go @@ -8,15 +8,18 @@ import ( "fmt" "time" - "git.curoverse.com/arvados.git/lib/cloud" - "git.curoverse.com/arvados.git/lib/cloud/azure" - "git.curoverse.com/arvados.git/lib/cloud/ec2" - "git.curoverse.com/arvados.git/sdk/go/arvados" + "git.arvados.org/arvados.git/lib/cloud" + "git.arvados.org/arvados.git/lib/cloud/azure" + "git.arvados.org/arvados.git/lib/cloud/ec2" + "git.arvados.org/arvados.git/sdk/go/arvados" "github.com/prometheus/client_golang/prometheus" "github.com/sirupsen/logrus" "golang.org/x/crypto/ssh" ) +// Drivers is a map of available cloud drivers. +// Clusters.*.Containers.CloudVMs.Driver configuration values +// correspond to keys in this map. var Drivers = map[string]cloud.Driver{ "azure": azure.Driver, "ec2": ec2.Driver, @@ -52,6 +55,15 @@ type rateLimitedInstanceSet struct { ticker *time.Ticker } +func (is rateLimitedInstanceSet) Instances(tags cloud.InstanceTags) ([]cloud.Instance, error) { + <-is.ticker.C + insts, err := is.InstanceSet.Instances(tags) + for i, inst := range insts { + insts[i] = &rateLimitedInstance{inst, is.ticker} + } + return insts, err +} + func (is rateLimitedInstanceSet) Create(it arvados.InstanceType, image cloud.ImageID, tags cloud.InstanceTags, init cloud.InitCommand, pk ssh.PublicKey) (cloud.Instance, error) { <-is.ticker.C inst, err := is.InstanceSet.Create(it, image, tags, init, pk) @@ -68,6 +80,11 @@ func (inst *rateLimitedInstance) Destroy() error { return inst.Instance.Destroy() } +func (inst *rateLimitedInstance) SetTags(tags cloud.InstanceTags) error { + <-inst.ticker.C + return inst.Instance.SetTags(tags) +} + // Adds the specified defaultTags to every Create() call. type defaultTaggingInstanceSet struct { cloud.InstanceSet @@ -150,7 +167,11 @@ func (is instrumentedInstanceSet) Create(it arvados.InstanceType, image cloud.Im func (is instrumentedInstanceSet) Instances(tags cloud.InstanceTags) ([]cloud.Instance, error) { instances, err := is.InstanceSet.Instances(tags) is.cv.WithLabelValues("List", boolLabelValue(err != nil)).Inc() - return instances, err + var instrumented []cloud.Instance + for _, i := range instances { + instrumented = append(instrumented, instrumentedInstance{i, is.cv}) + } + return instrumented, err } type instrumentedInstance struct { @@ -173,7 +194,6 @@ func (inst instrumentedInstance) SetTags(tags cloud.InstanceTags) error { func boolLabelValue(v bool) string { if v { return "1" - } else { - return "0" } + return "0" }