1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
12 "git.curoverse.com/arvados.git/lib/cloud"
13 "git.curoverse.com/arvados.git/sdk/go/arvados"
14 "golang.org/x/crypto/ssh"
17 // LameInstanceSet creates instances that boot but can't run
19 type LameInstanceSet struct {
20 Hold chan bool // set to make(chan bool) to hold operations until Release is called
23 instances map[*lameInstance]bool
26 // Create returns a new instance.
27 func (p *LameInstanceSet) Create(instType arvados.InstanceType, imageID cloud.ImageID, tags cloud.InstanceTags, pubkey ssh.PublicKey) (cloud.Instance, error) {
28 inst := &lameInstance{
30 id: cloud.InstanceID(fmt.Sprintf("lame-%x", rand.Uint64())),
31 providerType: instType.ProviderType,
39 if p.instances == nil {
40 p.instances = map[*lameInstance]bool{}
42 p.instances[inst] = true
46 // Instances returns the instances that haven't been destroyed.
47 func (p *LameInstanceSet) Instances(cloud.InstanceTags) ([]cloud.Instance, error) {
50 var instances []cloud.Instance
51 for i := range p.instances {
52 instances = append(instances, i)
57 // Stop is a no-op, but exists to satisfy cloud.InstanceSet.
58 func (p *LameInstanceSet) Stop() {
61 // Release n held calls. Blocks if n calls aren't already
62 // waiting. Blocks forever if Hold is nil.
63 func (p *LameInstanceSet) Release(n int) {
64 for i := 0; i < n; i++ {
69 type lameInstance struct {
73 tags cloud.InstanceTags
76 func (inst *lameInstance) ID() cloud.InstanceID {
80 func (inst *lameInstance) String() string {
81 return fmt.Sprint(inst.id)
84 func (inst *lameInstance) ProviderType() string {
85 return inst.providerType
88 func (inst *lameInstance) Address() string {
92 func (inst *lameInstance) SetTags(tags cloud.InstanceTags) error {
94 defer inst.p.mtx.Unlock()
95 inst.tags = cloud.InstanceTags{}
96 for k, v := range tags {
102 func (inst *lameInstance) Destroy() error {
103 if inst.p.Hold != nil {
107 defer inst.p.mtx.Unlock()
108 delete(inst.p.instances, inst)
112 func (inst *lameInstance) Tags() cloud.InstanceTags {
116 func (inst *lameInstance) VerifyHostKey(ssh.PublicKey, *ssh.Client) error {