예제 #1
0
func ListContainers(w http.ResponseWriter, r *http.Request) {
	containers := db.GetContainers()
	out, err := json.MarshalIndent(containers, "", "  ")
	if err != nil {
		log.Println(err)
	}
	fmt.Fprintf(w, string(out)+"\n")
}
예제 #2
0
func ManageContainers(w http.ResponseWriter, r *http.Request) {
	containers := db.GetContainers()
	t, _ := template.New("index").Parse(`
   <html>
      <h1>Swarm Manager</h1>
      <h2>Launch a container</h2>
      <form action="/api/spawn/" method="POST">
         Image: <input type="text" name="image" value="ipython/scipystack"/><br>
         User: <input type="text" name="user" value="odewahn"/><br>
         <input type="submit"/>
      </form>
      <h2>Active Containers</h2>
      <table>
        {{ range .}}
				{{ if .IsActive }}
         <tr>
            <td>
               <a target=_blank href="http://{{.Url}}">{{.Url}}</a>
            </td>
            <td>
               {{.Image}}
            </td>
            <td>
               {{.User}}
            </td>
						<td>
               {{.Status}}
            </td>
            <td>
               {{.StartTime}}
            </td>
            <td>
               <a href="/api/container/{{.Hostname}}/kill">Kill</a>
            </td>
          </tr>
					{{ end }}
         {{end}}
      </table>
  </html>
  `)
	t.Execute(w, containers)
}