Esempio n. 1
0
func serviceDomainDetach(serviceID, domain string, args domainStruct) {
	// Split namespace and service
	host, app, service, tag, err := internal.ParseResourceName(serviceID)
	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 service name. Please see sail service domain detach --help\n")
		os.Exit(1)
	}

	body, err := json.Marshal(args)
	internal.Check(err)

	// Sanity checks
	err = internal.CheckName(domain)
	internal.Check(err)

	path := fmt.Sprintf("/applications/%s/services/%s/attached-routes/%s", app, service, domain)
	data := internal.DeleteBodyWantJSON(path, body)

	internal.FormatOutput(data, func(data []byte) {
		fmt.Fprintf(os.Stderr, "Detached route %s %s%s from service %s/%s\n", args.Method, domain, args.Pattern, app, service)
	})
}
Esempio 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)
}
Esempio n. 3
0
File: logs.go Progetto: Alkorin/sail
func cmdLogs(cmd *cobra.Command, args []string) {
	usage := "usage: sail containers logs [<applicationName>/]<containerId>"

	if len(args) != 1 {
		fmt.Fprintln(os.Stderr, usage)
		os.Exit(1)
	}

	// Split namespace and container
	host, app, container, tag, err := internal.ParseResourceName(args[0])
	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 container name. Please see sail container logs --help\n")
		os.Exit(1)
	}

	// Get args
	logsBody.Application = app
	logsBody.Container = container
	containerLogs(logsBody)
}
Esempio n. 4
0
func cmdAdd(cmd *cobra.Command, args []string) {
	cmdAddBody.ContainerNetwork = make(map[string]map[string][]string)
	cmdAddBody.Links = make(map[string]string)
	cmdAddBody.ContainerPorts = make(map[string][]PortConfig)
	cmdAddBody.ContainerCommand = make([]string, 0)

	if len(args) < 2 {
		fmt.Fprintln(os.Stderr, cmdAddUsage)
		os.Exit(1)
	}

	// Split namespace and repository
	host, app, repo, tag, err := internal.ParseResourceName(args[0])
	internal.Check(err)
	cmdAddBody.Application = app
	cmdAddBody.Repository = repo
	cmdAddBody.RepositoryTag = tag

	if !internal.CheckHostConsistent(host) {
		fmt.Fprintf(os.Stderr, "Error: Invalid Host %s for endpoint %s\n", host, internal.Host)
		os.Exit(1)
	}

	// Service name
	if len(args) >= 2 {
		cmdAddBody.Service = args[1]
	} else {
		cmdAddBody.Service = cmdAddBody.Repository
	}

	serviceAdd(cmdAddBody)
}
Esempio n. 5
0
func serviceAttach(serviceID string) {
	// Split namespace and service
	host, app, service, _, err := internal.ParseResourceName(serviceID)
	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)
	}

	internal.StreamPrint("GET", fmt.Sprintf("/applications/%s/services/%s/attach", app, service), nil)
	internal.ExitAfterCtrlC()
}
Esempio n. 6
0
func containerAttach(containerID string) {
	// Split namespace and container
	host, _, container, tag, err := internal.ParseResourceName(containerID)
	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 container name. Please see sail container attach --help\n")
		os.Exit(1)
	}

	internal.StreamPrint("GET", fmt.Sprintf("/containers/%s/attach", container), nil)
	internal.ExitAfterCtrlC()
}
Esempio n. 7
0
func cmdScale(cmd *cobra.Command, args []string) {
	if len(args) != 1 {
		fmt.Fprintln(os.Stderr, scaleUsage)
		os.Exit(1)
	}

	// Split namespace and service
	host, app, service, _, err := internal.ParseResourceName(args[0])
	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)
	}

	serviceScale(app, service, scaleNumber, scaleDestroy, scaleBatch)
}
Esempio n. 8
0
func networkRangeAdd(networkID, ipFrom, ipTo 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)
	}

	path := fmt.Sprintf("/applications/%s/networks/%s/ranges/%s-%s", app, net, ipFrom, ipTo)
	internal.FormatOutputDef(internal.PostWantJSON(path))

}
Esempio n. 9
0
func cmdServiceDelete(cmd *cobra.Command, args []string) {
	usage := "Invalid usage. sail service delete [<applicationName>/]<serviceId>"
	if len(args) != 1 {
		fmt.Fprintln(os.Stderr, usage)
		return
	}

	// Split namespace and service
	host, app, service, _, err := internal.ParseResourceName(args[0])
	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)
	}

	serviceDelete(app, service)
}
Esempio n. 10
0
File: add.go Progetto: runabove/sail
func networkAdd(networkID string, args networkAddStruct) {
	// 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 add --help\n")
		os.Exit(1)
	}

	body, err := json.Marshal(args)
	internal.Check(err)

	path := fmt.Sprintf("/applications/%s/networks/%s", app, net)
	internal.FormatOutputDef(internal.PostBodyWantJSON(path, body))

}
Esempio n. 11
0
File: add.go Progetto: runabove/sail
func repositoryAdd(repositoryName string, args repositoryAddStruct) {
	// Split namespace and repository
	host, app, repo, tag, err := internal.ParseResourceName(repositoryName)
	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 repository name. Please see sail repository add --help\n")
		os.Exit(1)
	}

	body, err := json.Marshal(args)
	internal.Check(err)

	path := fmt.Sprintf("/repositories/%s/%s", app, repo)
	internal.FormatOutputDef(internal.PostBodyWantJSON(path, body))

}
Esempio n. 12
0
func repositoryRemove(repositoryID string) {
	// Split namespace and repository
	host, app, repo, tag, err := internal.ParseResourceName(repositoryID)
	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 repository name. Please see sail repository delete --help\n")
		os.Exit(1)
	}

	path := fmt.Sprintf("/repositories/%s/%s", app, repo)
	data := internal.DeleteWantJSON(path)

	internal.FormatOutput(data, func(data []byte) {
		fmt.Fprintf(os.Stderr, "Deleted repository %s/%s\n", app, repo)
	})
}
Esempio n. 13
0
func cmdLogs(cmd *cobra.Command, args []string) {
	usage := "Invalid usage. sail service logs [<applicationName>/]<serviceId>. Please see sail service logs --help\n"
	if len(args) != 1 {
		fmt.Fprintf(os.Stderr, usage)
		return
	}

	// Split namespace and service
	host, app, service, _, err := internal.ParseResourceName(args[0])
	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)
	}

	// Get args
	logsBody.Application = app
	logsBody.Service = service
	serviceLogs(logsBody)
}
Esempio n. 14
0
func cmdRedeploy(cmd *cobra.Command, args []string) {
	usage := "Invalid usage. sail service redeploy <applicationName>/<serviceId>. Please see sail service redeploy --help\n"
	if len(args) != 1 {
		fmt.Fprintf(os.Stderr, usage)
		return
	}

	// Split namespace and repository
	host, app, service, _, err := internal.ParseResourceName(args[0])
	internal.Check(err)
	redeployBody.Application = app
	redeployBody.Service = service

	if !internal.CheckHostConsistent(host) {
		fmt.Fprintf(os.Stderr, "Error: Invalid Host %s for endpoint %s\n", host, internal.Host)
		os.Exit(1)
	}

	// Redeploy
	serviceRedeploy(redeployBody)
}