Skip to content

Commit

Permalink
Fix for new tmate server names (alphanum)
Browse files Browse the repository at this point in the history
  • Loading branch information
danhigham committed Jul 23, 2015
1 parent 6789d95 commit ed3a952
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
Binary file modified bin/linux64/cf-plugin-console
Binary file not shown.
Binary file modified bin/osx/cf-plugin-console
Binary file not shown.
47 changes: 39 additions & 8 deletions console.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ type AppSearchEntity struct {
DetectedBuildpack string `json:"detected_buildpack"`
}

type AppSummary struct {
Guid string `json:"guid"`
Name string `json:"name"`
Diego bool `json:"diego"`
}

func fatalIf(err error) {
if err != nil {
fmt.Fprintln(os.Stdout, "error:", err)
Expand All @@ -58,15 +64,25 @@ func (plugin ConsolePlugin) Run(cliConnection plugin.CliConnection, args []strin
appName := args[1]
guid, entity := plugin.FindAppGuid(cliConnection, appName)

// Update the app to start tmate
plugin.UpdateForTmate(cliConnection, guid, "sleep 3600")
// Is it running diego
summary := plugin.Summary(cliConnection, guid)

instances := entity.Instances

if summary.Diego == false {

// Update the app to start tmate
plugin.UpdateForTmate(cliConnection, guid, "sleep 3600")

// Kill the first instance
// plugin.KillInstanceZero(cliConnection, guid)
// Add Instance
instances = entity.Instances + 1
plugin.ChangeInstanceCount(cliConnection, guid, instances)

// Add Instance
instances := entity.Instances + 1
plugin.ChangeInstanceCount(cliConnection, guid, instances)
} else {



}

lastDate := plugin.GetLatestLogDate(cliConnection, appName)

Expand Down Expand Up @@ -102,7 +118,7 @@ func (plugin ConsolePlugin) WaitAndConnect(cliConnection plugin.CliConnection, a
plugin.Log("Waiting for SSH endpoint.\n", false)

// Regex for tmate log line
exp := fmt.Sprintf("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{2}-\\d{4}\\s\\[App\\/%v\\]\\s{3}[^\\n]+\\s([^\\s]+\\@[a-z]+\\.tmate\\.io)", instances-1)
exp := fmt.Sprintf("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{2}-\\d{4}\\s\\[App\\/%v\\]\\s{6}[^\\n]+\\s([^\\s]+\\@[a-z1-9]+\\.tmate\\.io)", instances-1)
reDate := regexp.MustCompile(`(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{2}-\d{4})\s`)

re := regexp.MustCompile(exp)
Expand Down Expand Up @@ -226,6 +242,21 @@ func (plugin ConsolePlugin) FindAppGuid(cliConnection plugin.CliConnection, appN
return res.Resources[0].Metadata.Guid, res.Resources[0].Entity
}

func (plugin ConsolePlugin) Summary(cliConnection plugin.CliConnection, guid string) (AppSummary) {

appQuery := fmt.Sprintf("/v2/apps/%v/summary", guid)
cmd := []string{"curl", appQuery}

output, _ := cliConnection.CliCommandWithoutTerminalOutput(cmd...)
res := AppSummary{}
json.Unmarshal([]byte(strings.Join(output, "")), &res)

plugin.Log(fmt.Sprintf("%v \n", res), true)

return res
}


func (ConsolePlugin) Log(text string, skipChevron bool) {
if skipChevron {
fmt.Printf("%v", colorstring.Color("[light_gray]" + text))
Expand Down

0 comments on commit ed3a952

Please sign in to comment.