Ejemplo n.º 1
0
func repositoryList(apps []string) {
	w := tabwriter.NewWriter(os.Stdout, 30, 1, 3, ' ', 0)
	titles := []string{"NAME", "TAG", "TYPE", "PRIVACY", "SOURCE"}
	fmt.Fprintln(w, strings.Join(titles, "\t"))

	repositories := []string{}
	var repository map[string]interface{}
	for _, app := range apps {
		b := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/repositories/%s", app), nil)
		internal.Check(json.Unmarshal(b, &repositories))
		for _, repositoryID := range repositories {
			b := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/repositories/%s/%s", app, repositoryID), nil)
			internal.Check(json.Unmarshal(b, &repository))

			tags := repository["tags"]
			if tags == "" {
				tags = "-"
			}
			source := repository["source"]
			if source == nil || source == "" {
				source = "-"
			}
			fmt.Fprintf(w, "%s/%s\t%s\t%s\t%s\t%s\n", app, repository["name"], tags, repository["type"], repository["privacy"], source)
			w.Flush()
		}
	}
}
Ejemplo n.º 2
0
func networkShow(networkID string) {
	// Split namespace and repository
	host, app, net, tag, err := internal.ParseResourceName(networkID)
	internal.Check(err)

	if !internal.CheckHostConsistent(host) {
		fmt.Fprintf(os.Stderr, "Error: Invalid Host %s for endpoint %s\n", host, internal.Host)
		os.Exit(1)
	} else if len(tag) > 0 {
		fmt.Fprintf(os.Stderr, "Error: Invalid network name. Please see sail network show --help\n")
		os.Exit(1)
	}

	var network map[string]interface{}
	var ranges []string

	b := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/applications/%s/networks/%s", app, net), nil)
	internal.Check(json.Unmarshal(b, &network))

	brange := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/applications/%s/networks/%s/ranges", app, net), nil)
	internal.Check(json.Unmarshal(brange, &ranges))

	network["range"] = ranges
	n, err := json.Marshal(network)
	internal.Check(err)

	internal.FormatOutputDef(n)
}
Ejemplo n.º 3
0
Archivo: list.go Proyecto: bewiwi/sail
func serviceList(apps []string) {
	w := tabwriter.NewWriter(os.Stdout, 27, 1, 2, ' ', 0)
	titles := []string{"NAME", "REPOSITORY", "IMAGE ID", "STATE", "CONTAINERS", "CREATED", "NETWORK"}
	fmt.Fprintln(w, strings.Join(titles, "\t"))

	services := []string{}
	var service map[string]interface{}
	for _, app := range apps {
		b := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/applications/%s/services", app), nil)
		internal.Check(json.Unmarshal(b, &services))
		for _, serviceID := range services {
			b := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/applications/%s/services/%s", app, serviceID), nil)
			internal.Check(json.Unmarshal(b, &service))

			ips := []string{}
			for _, container := range service["containers"].(map[string]interface{}) {
				for name, network := range container.(map[string]interface{})["network"].(map[string]interface{}) {
					ips = append(ips, fmt.Sprintf("%s:%s", name, network.(map[string]interface{})["ip"]))
				}
			}

			fmt.Fprintf(w, "%s/%s\t%s@%s\t%s\t%s\t%d\t%s\t%s\n",
				app, service["name"],
				service["repository"],
				service["repository_tag"],
				service["image"].(string)[:12],
				strings.ToUpper(service["state"].(string)),
				int(service["container_number"].(float64)),
				service["creation_date"].(string)[:19],
				strings.Join(ips, ","))

			w.Flush()
		}
	}
}
Ejemplo n.º 4
0
func sshKeyList() {

	type keyStruct struct {
		Name        string `json:"name"`
		Fingerprint string `json:"fingerprint"`
		PublicKey   string `json:"public_key"`
	}

	b := internal.ReqWant("GET", http.StatusOK, "/user/keys", nil)
	var keys []keyStruct

	err := json.Unmarshal(b, &keys)
	internal.Check(err)

	w := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
	titles := []string{"NAME", "FINGERPRINT"}
	fmt.Fprintln(w, strings.Join(titles, "\t"))

	for _, key := range keys {
		fmt.Fprintf(w, "%s\t%s\n",
			key.Name,
			key.Fingerprint,
		)
	}
	w.Flush()
}
Ejemplo n.º 5
0
func serviceDelete(namespace string, name string) {
	path := fmt.Sprintf("/applications/%s/services/%s?force=%t", namespace, name, deleteForce)
	data := internal.ReqWant("DELETE", http.StatusOK, path, nil)

	internal.FormatOutput(data, func(data []byte) {
		fmt.Fprintf(os.Stderr, "Deleted service %s/%s\n", namespace, name)
	})
}
Ejemplo n.º 6
0
func containerList(apps []string) {
	w := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0)
	titles := []string{"APPLICATION", "SERVICE", "CONTAINER", "STATE", "DEPLOYED"}
	fmt.Fprintln(w, strings.Join(titles, "\t"))

	containers := []string{}
	var container map[string]interface{}
	for _, app := range apps {
		b := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/applications/%s/containers", app), nil)
		internal.Check(json.Unmarshal(b, &containers))
		for _, containerID := range containers {
			b := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/applications/%s/containers/%s", app, containerID), nil)
			internal.Check(json.Unmarshal(b, &container))
			fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t\n", app, container["service"], container["name"], strings.ToUpper(container["state"].(string)), container["deployment_date"])
			w.Flush()
		}
	}
}
Ejemplo n.º 7
0
Archivo: show.go Proyecto: bewiwi/sail
func networkShow(networkID string) {
	t := strings.Split(networkID, "/")
	if len(t) != 2 {
		fmt.Fprintln(os.Stderr, "Invalid usage. sail network show <applicationName>/<networkId>. Please see sail network show --help")
	} else {

		var network map[string]interface{}
		var ranges []string

		b := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/applications/%s/networks/%s", t[0], t[1]), nil)
		internal.Check(json.Unmarshal(b, &network))

		brange := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/applications/%s/networks/%s/ranges", t[0], t[1]), nil)
		internal.Check(json.Unmarshal(brange, &ranges))

		network["range"] = ranges
		n, err := json.Marshal(network)
		internal.Check(err)
		internal.FormatOutputDef(n)
	}
}
Ejemplo n.º 8
0
Archivo: list.go Proyecto: bewiwi/sail
func domainListNamespace(namespace, service string) {
	var services []string

	// TODO: rewrite whithout the m(n+1)+1... (needs API)
	if len(service) > 0 {
		services = append(services, service)
	} else {
		b := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/applications/%s/services", namespace), nil)
		internal.Check(json.Unmarshal(b, &services))
	}

	for _, service := range services {
		domainListService(namespace, service)
	}
}
Ejemplo n.º 9
0
func networkList(apps []string) {
	w := tabwriter.NewWriter(os.Stdout, 30, 1, 3, ' ', 0)
	titles := []string{"NAME", "SUBNET"}
	fmt.Fprintln(w, strings.Join(titles, "\t"))

	networks := []string{}
	var network map[string]interface{}
	for _, app := range apps {
		b := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/applications/%s/networks", app), nil)
		internal.Check(json.Unmarshal(b, &networks))
		for _, networkID := range networks {
			b := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/applications/%s/networks/%s", app, networkID), nil)
			internal.Check(json.Unmarshal(b, &network))

			subnet := network["subnet"]
			if network["subnet"] == nil || network["subnet"] == "" {
				subnet = "-"
			}

			fmt.Fprintf(w, "%s\t%s\n", network["name"], subnet)
			w.Flush()
		}
	}
}
Ejemplo n.º 10
0
Archivo: list.go Proyecto: bewiwi/sail
func domainListService(namespace, service string) {
	b := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/applications/%s/services/%s/attached-routes", namespace, service), nil)
	internal.FormatOutput(b, domainListFormatter)
}
Ejemplo n.º 11
0
func domainListApplication(app string) {
	b := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/applications/%s/attached-domains", app), nil)
	internal.FormatOutput(b, domainListFormatter)
}
Ejemplo n.º 12
0
func serviceDelete(namespace string, name string) {
	path := fmt.Sprintf("/applications/%s/services/%s", namespace, name)
	data := internal.ReqWant("DELETE", http.StatusOK, path, nil)
	// TODO Check for json error here
	internal.FormatOutputDef(data)
}