-
Notifications
You must be signed in to change notification settings - Fork 29
/
status.go
70 lines (65 loc) · 2.2 KB
/
status.go
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
59
60
61
62
63
64
65
66
67
68
69
70
package commands
import (
"log"
"os"
"strings"
fc "github.com/Skarlso/go-furnace/furnace-gcp/config"
"github.com/Skarlso/go-furnace/handle"
"github.com/Yitsushi/go-commander"
"golang.org/x/net/context"
"golang.org/x/oauth2/google"
dm "google.golang.org/api/deploymentmanager/v2"
"google.golang.org/api/googleapi"
)
// Status commands for google Deployment Manager
type Status struct {
}
// Execute runs the create command
func (s *Status) Execute(opts *commander.CommandHelper) {
configName := opts.Arg(0)
if len(configName) > 0 {
dir, _ := os.Getwd()
if err := fc.LoadConfigFileIfExists(dir, configName); err != nil {
handle.Fatal(configName, err)
}
}
log.Println("Looking for Deployment under project name: .", keyName(fc.Config.Main.ProjectName))
deploymentName := fc.Config.Gcp.StackName
log.Println("Deployment name is: ", keyName(deploymentName))
ctx := context.Background()
client, err := google.DefaultClient(ctx, dm.NdevCloudmanScope)
handle.Error(err)
d, _ := dm.New(client)
project := d.Deployments.Get(fc.Config.Main.ProjectName, deploymentName)
p, err := project.Do()
if err != nil {
if err.(*googleapi.Error).Code != 404 {
handle.Fatal("error while getting deployment: ", err)
} else {
handle.Fatal("Stack not found!", nil)
}
}
manifestID := p.Manifest[strings.LastIndex(p.Manifest, "/")+1 : len(p.Manifest)]
manifest := d.Manifests.Get(fc.Config.Main.ProjectName, deploymentName, manifestID)
m, err := manifest.Do()
handle.Error(err)
log.Println("Description: ", p.Description)
log.Println("Name: ", p.Name)
log.Println("Labels: ", p.Labels)
log.Println("Selflink: ", p.SelfLink)
log.Println("Layout: \n", m.Layout)
// Consider getting every resource status?
}
// NewStatus Creates a new status command
func NewStatus(appName string) *commander.CommandWrapper {
return &commander.CommandWrapper{
Handler: &Status{},
Help: &commander.CommandDescriptor{
Name: "status",
ShortDescription: "Get the status of an existing Deployment Management group.",
LongDescription: `Get the status of an existing Deployment Management group.`,
Arguments: "[--config=configFile]",
Examples: []string{"status [--config=configFile]"},
},
}
}