Switch key list over to using key names
This commit is contained in:
parent
d57884e2d7
commit
10a959e9f3
@ -7,7 +7,10 @@
|
||||
"InitialSize": "4gb",
|
||||
"Size": "4gb",
|
||||
"Region": "nyc1",
|
||||
"SshKeys": [513314, 1667247],
|
||||
"SshKeys": [
|
||||
"Key1",
|
||||
"gtalent2@gmail.com"
|
||||
],
|
||||
"UsePersistentImage": false,
|
||||
"ImageSlug": "ubuntu-16-04-x64",
|
||||
"Volumes": ["volume-nyc1-01"],
|
||||
|
@ -28,22 +28,6 @@ func (t *tokenSource) Token() (*oauth2.Token, error) {
|
||||
return token, nil
|
||||
}
|
||||
|
||||
func sshKeys(ids []int) []godo.DropletCreateSSHKey {
|
||||
var out []godo.DropletCreateSSHKey
|
||||
for _, id := range ids {
|
||||
out = append(out, godo.DropletCreateSSHKey{ID: id})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func volumes(names []string) []godo.DropletCreateVolume {
|
||||
var out []godo.DropletCreateVolume
|
||||
for _, name := range names {
|
||||
out = append(out, godo.DropletCreateVolume{Name: name})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
type DropletHandler struct {
|
||||
client *godo.Client
|
||||
settings Settings
|
||||
@ -103,8 +87,8 @@ func (me *DropletHandler) Spinup(name string) (string, error) {
|
||||
Region: vd.Region,
|
||||
Size: size,
|
||||
PrivateNetworking: true,
|
||||
SSHKeys: sshKeys(vd.SshKeys),
|
||||
Volumes: volumes(vd.Volumes),
|
||||
SSHKeys: me.sshKeys(vd.SshKeys),
|
||||
Volumes: me.volumes(vd.Volumes),
|
||||
UserData: vd.UserData,
|
||||
Image: image,
|
||||
}
|
||||
@ -321,3 +305,46 @@ func (me *DropletHandler) actionWait(actionId int) bool {
|
||||
time.Sleep(1000 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
func (me *DropletHandler) sshKeys(keyNames []string) []godo.DropletCreateSSHKey {
|
||||
// build key map
|
||||
page := 0
|
||||
perPage := 200
|
||||
keyMap := make(map[string]string)
|
||||
for {
|
||||
page++
|
||||
opt := &godo.ListOptions{
|
||||
Page: page,
|
||||
PerPage: perPage,
|
||||
}
|
||||
keys, _, err := me.client.Keys.List(opt)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
|
||||
for _, v := range keys {
|
||||
keyMap[v.Name] = v.Fingerprint
|
||||
}
|
||||
|
||||
// check next page?
|
||||
if len(keys) < perPage {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// build output key list
|
||||
var out []godo.DropletCreateSSHKey
|
||||
for _, kn := range keyNames {
|
||||
fp := keyMap[kn]
|
||||
out = append(out, godo.DropletCreateSSHKey{Fingerprint: fp})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (me *DropletHandler) volumes(names []string) []godo.DropletCreateVolume {
|
||||
var out []godo.DropletCreateVolume
|
||||
for _, name := range names {
|
||||
out = append(out, godo.DropletCreateVolume{Name: name})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
@ -74,7 +74,6 @@ func (me *ServerManager) Serve() {
|
||||
running = me.serveAction(action)
|
||||
case <-ticker.C:
|
||||
if time.Since(me.lastKeepAliveTime) > activityTimeout {
|
||||
log.Println("ServerManager: Activity timeout for", me.name, " - killing server")
|
||||
running = me.serveAction(serverManagerEvent{eventType: SERVERMANAGER_SPINDOWN})
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ type Server struct {
|
||||
UsePersistentImage bool
|
||||
ImageSlug string
|
||||
UserData string
|
||||
SshKeys []int
|
||||
SshKeys []string
|
||||
Volumes []string
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user