blob: 1f7969d6b745998a4016c8580a4e258b09bf38d3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
// Copyright 2019 Nick White.
// Use of this source code is governed by the GPLv3
// license that can be found in the LICENSE file.
// spotme creates new spot instances for the book pipeline.
package main
import (
"flag"
"fmt"
"log"
"rescribe.xyz/bookpipeline"
)
const usage = `Usage: spotme [-n num]
Create new spot instances for the book pipeline.
`
type SpotPipeliner interface {
Init() error
StartInstances(n int) error
}
// NullWriter is used so non-verbose logging may be discarded
type NullWriter bool
func (w NullWriter) Write(p []byte) (n int, err error) {
return len(p), nil
}
func main() {
num := flag.Int("n", 1, "number of instances to start")
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), usage)
flag.PrintDefaults()
}
flag.Parse()
var verboselog *log.Logger
var n NullWriter
verboselog = log.New(n, "", 0)
var conn SpotPipeliner
conn = &bookpipeline.AwsConn{Region: "eu-west-2", Logger: verboselog}
err := conn.Init()
if err != nil {
log.Fatalln("Failed to set up cloud connection:", err)
}
log.Println("Starting spot instances")
err = conn.StartInstances(*num)
if err != nil {
log.Fatalln("Failed to start a spot instance:", err)
}
log.Println("Spot instance request sent successfully")
}
|