本文整理汇总了Golang中github.com/tsuru/tsuru/cmd.Context.RawOutput方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.RawOutput方法的具体用法?Golang Context.RawOutput怎么用?Golang Context.RawOutput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/tsuru/tsuru/cmd.Context
的用法示例。
在下文中一共展示了Context.RawOutput方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Run
func (c *moveContainerCmd) Run(context *cmd.Context, client *cmd.Client) error {
context.RawOutput()
url, err := cmd.GetURL(fmt.Sprintf("/docker/container/%s/move", context.Args[0]))
if err != nil {
return err
}
params := map[string]string{
"to": context.Args[1],
}
b, err := json.Marshal(params)
if err != nil {
return err
}
buffer := bytes.NewBuffer(b)
request, err := http.NewRequest("POST", url, buffer)
if err != nil {
return err
}
request.Header.Set("Content-Type", "application/json")
response, err := client.Do(request)
if err != nil {
return err
}
w := tsuruIo.NewStreamWriter(context.Stdout, nil)
for n := int64(1); n > 0 && err == nil; n, err = io.Copy(w, response.Body) {
}
if err != nil {
return err
}
unparsed := w.Remaining()
if len(unparsed) > 0 {
return fmt.Errorf("unparsed message error: %s", string(unparsed))
}
return nil
}
示例2: Run
func (c *rebalanceContainersCmd) Run(context *cmd.Context, client *cmd.Client) error {
context.RawOutput()
if !c.dry && !c.Confirm(context, "Are you sure you want to rebalance containers?") {
return nil
}
u, err := cmd.GetURL("/docker/containers/rebalance")
if err != nil {
return err
}
opts := rebalanceOptions{
Dry: c.dry,
}
if len(c.metadataFilter) > 0 {
opts.MetadataFilter = c.metadataFilter
}
if len(c.appFilter) > 0 {
opts.AppFilter = c.appFilter
}
v, err := form.EncodeToValues(&opts)
if err != nil {
return err
}
request, err := http.NewRequest("POST", u, bytes.NewBufferString(v.Encode()))
if err != nil {
return err
}
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
response, err := client.Do(request)
if err != nil {
return err
}
return cmd.StreamJSONResponse(context.Stdout, response)
}
示例3: Run
func (c *appRestart) Run(context *cmd.Context, client *cmd.Client) error {
context.RawOutput()
appName, err := c.Guess()
if err != nil {
return err
}
url, err := cmd.GetURL(fmt.Sprintf("/apps/%s/restart?process=%s", appName, c.process))
if err != nil {
return err
}
request, err := http.NewRequest("POST", url, nil)
if err != nil {
return err
}
response, err := client.Do(request)
if err != nil {
return err
}
defer response.Body.Close()
w := tsuruIo.NewStreamWriter(context.Stdout, nil)
for n := int64(1); n > 0 && err == nil; n, err = io.Copy(w, response.Body) {
}
if err != nil {
return err
}
unparsed := w.Remaining()
if len(unparsed) > 0 {
return fmt.Errorf("unparsed message error: %s", string(unparsed))
}
return nil
}
示例4: Run
func (c *appRun) Run(context *cmd.Context, client *cmd.Client) error {
context.RawOutput()
appName, err := c.Guess()
if err != nil {
return err
}
url, err := cmd.GetURL(fmt.Sprintf("/apps/%s/run?once=%t", appName, c.once))
if err != nil {
return err
}
b := strings.NewReader(strings.Join(context.Args, " "))
request, err := http.NewRequest("POST", url, b)
if err != nil {
return err
}
r, err := client.Do(request)
if err != nil {
return err
}
defer r.Body.Close()
w := tsuruIo.NewStreamWriter(context.Stdout, nil)
for n := int64(1); n > 0 && err == nil; n, err = io.Copy(w, r.Body) {
}
if err != nil {
return err
}
unparsed := w.Remaining()
if len(unparsed) > 0 {
return fmt.Errorf("unparsed message error: %s", string(unparsed))
}
return nil
}
示例5: Run
func (c *appPlanChange) Run(context *cmd.Context, client *cmd.Client) error {
context.RawOutput()
appName, err := c.Guess()
if err != nil {
return err
}
plan := tsuruapp.Plan{Name: context.Args[0]}
question := fmt.Sprintf("Are you sure you want to change the plan of the application %q to %q?", appName, plan.Name)
if !c.Confirm(context, question) {
return nil
}
url, err := cmd.GetURL(fmt.Sprintf("/apps/%s/plan", appName))
if err != nil {
return err
}
b, err := json.Marshal(plan)
if err != nil {
return err
}
request, err := http.NewRequest("POST", url, bytes.NewReader(b))
if err != nil {
return err
}
response, err := client.Do(request)
if err != nil {
return err
}
return cmd.StreamJSONResponse(context.Stdout, response)
}
示例6: Run
func (c *rebalanceContainersCmd) Run(context *cmd.Context, client *cmd.Client) error {
context.RawOutput()
if !c.dry && !c.Confirm(context, "Are you sure you want to rebalance containers?") {
return nil
}
url, err := cmd.GetURL("/docker/containers/rebalance")
if err != nil {
return err
}
params := map[string]interface{}{
"dry": fmt.Sprintf("%t", c.dry),
}
if len(c.metadataFilter) > 0 {
params["metadataFilter"] = c.metadataFilter
}
if len(c.appFilter) > 0 {
params["appFilter"] = c.appFilter
}
b, err := json.Marshal(params)
if err != nil {
return err
}
buffer := bytes.NewBuffer(b)
request, err := http.NewRequest("POST", url, buffer)
if err != nil {
return err
}
request.Header.Set("Content-Type", "application/json")
response, err := client.Do(request)
if err != nil {
return err
}
return cmd.StreamJSONResponse(context.Stdout, response)
}
示例7: Run
func (c *unitAdd) Run(context *cmd.Context, client *cmd.Client) error {
context.RawOutput()
appName, err := c.Guess()
if err != nil {
return err
}
u, err := cmd.GetURL(fmt.Sprintf("/apps/%s/units", appName))
if err != nil {
return err
}
val := url.Values{}
val.Add("units", context.Args[0])
val.Add("process", c.process)
request, err := http.NewRequest("PUT", u, bytes.NewBufferString(val.Encode()))
if err != nil {
return err
}
request.Header.Add("Content-Type", "application/x-www-form-urlencoded")
response, err := client.Do(request)
if err != nil {
return err
}
defer response.Body.Close()
return cmd.StreamJSONResponse(context.Stdout, response)
}
示例8: Run
func (c *autoScaleRunCmd) Run(context *cmd.Context, client *cmd.Client) error {
context.RawOutput()
if !c.Confirm(context, "Are you sure you want to run auto scaling checks?") {
return nil
}
u, err := cmd.GetURL("/docker/autoscale/run")
if err != nil {
return err
}
request, err := http.NewRequest("POST", u, nil)
if err != nil {
return err
}
response, err := client.Do(request)
if err != nil {
return err
}
w := tsuruIo.NewStreamWriter(context.Stdout, nil)
for n := int64(1); n > 0 && err == nil; n, err = io.Copy(w, response.Body) {
}
if err != nil {
return err
}
unparsed := w.Remaining()
if len(unparsed) > 0 {
return errors.Errorf("unparsed message error: %s", string(unparsed))
}
return nil
}
示例9: Run
func (c *envUnset) Run(context *cmd.Context, client *cmd.Client) error {
context.RawOutput()
appName, err := c.Guess()
if err != nil {
return err
}
url, err := cmd.GetURL(fmt.Sprintf("/apps/%s/env", appName))
if err != nil {
return err
}
var buf bytes.Buffer
json.NewEncoder(&buf).Encode(context.Args)
request, err := http.NewRequest("DELETE", url, &buf)
if err != nil {
return err
}
response, err := client.Do(request)
if err != nil {
return err
}
w := tsuruIo.NewStreamWriter(context.Stdout, nil)
for n := int64(1); n > 0 && err == nil; n, err = io.Copy(w, response.Body) {
}
if err != nil {
return err
}
unparsed := w.Remaining()
if len(unparsed) > 0 {
return fmt.Errorf("unparsed message error: %s", string(unparsed))
}
return nil
}
示例10: Run
func (su *serviceUnbind) Run(ctx *cmd.Context, client *cmd.Client) error {
ctx.RawOutput()
appName, err := su.Guess()
if err != nil {
return err
}
instanceName := ctx.Args[0]
url, err := cmd.GetURL("/services/instances/" + instanceName + "/" + appName)
if err != nil {
return err
}
request, err := http.NewRequest("DELETE", url, nil)
if err != nil {
return err
}
resp, err := client.Do(request)
if err != nil {
return err
}
defer resp.Body.Close()
w := tsuruIo.NewStreamWriter(ctx.Stdout, nil)
for n := int64(1); n > 0 && err == nil; n, err = io.Copy(w, resp.Body) {
}
if err != nil {
return err
}
unparsed := w.Remaining()
if len(unparsed) > 0 {
return fmt.Errorf("unparsed message error: %s", string(unparsed))
}
return nil
}
示例11: Run
func (p *platformUpdate) Run(context *cmd.Context, client *cmd.Client) error {
context.RawOutput()
name := context.Args[0]
if p.disable && p.enable {
return errors.New("Conflicting options: --enable and --disable\n")
}
if !p.disable && !p.enable && p.dockerfile == "" {
return errors.New("Flag is required")
}
disable := ""
if p.enable {
disable = "false"
}
if p.disable {
disable = "true"
}
body := fmt.Sprintf("a=1&dockerfile=%s", p.dockerfile)
url, err := cmd.GetURL(fmt.Sprintf("/platforms/%s?disabled=%s", name, disable))
request, err := http.NewRequest("PUT", url, strings.NewReader(body))
if err != nil {
return err
}
request.Header.Add("Content-Type", "application/x-www-form-urlencoded")
response, err := client.Do(request)
if err != nil {
return err
}
return cmd.StreamJSONResponse(context.Stdout, response)
}
示例12: Run
func (c *plugin) Run(context *cmd.Context, client *cmd.Client) error {
context.RawOutput()
pluginName := context.Args[0]
pluginPath := cmd.JoinWithUserDir(".tsuru", "plugins", pluginName)
target, err := cmd.GetURL("/")
if err != nil {
return err
}
token, err := cmd.ReadToken()
if err != nil {
return err
}
envs := os.Environ()
tsuruEnvs := []string{
"TSURU_TARGET=" + target,
"TSURU_TOKEN=" + token,
"TSURU_PLUGIN_NAME=" + pluginName,
}
envs = append(envs, tsuruEnvs...)
opts := exec.ExecuteOptions{
Cmd: pluginPath,
Args: context.Args[1:],
Stdout: context.Stdout,
Stderr: context.Stderr,
Stdin: context.Stdin,
Envs: envs,
}
return executor().Execute(opts)
}
示例13: Run
func (c *dockerLogUpdate) Run(context *cmd.Context, client *cmd.Client) error {
context.RawOutput()
if c.restart {
extra := ""
if c.pool != "" {
extra = fmt.Sprintf(" running on pool %s", c.pool)
}
msg := fmt.Sprintf("Are you sure you want to restart all apps%s?", extra)
if !c.Confirm(context, msg) {
return nil
}
}
url, err := cmd.GetURL("/docker/logs")
if err != nil {
return err
}
envList := []provision.Entry{
{Name: "log-driver", Value: c.logDriver},
}
for name, value := range c.logOpts {
envList = append(envList, provision.Entry{Name: name, Value: value})
}
conf := provision.ScopedConfig{}
if c.pool == "" {
conf.Envs = envList
} else {
conf.Pools = []provision.PoolEntry{{
Name: c.pool,
Envs: envList,
}}
}
b, err := json.Marshal(logsSetData{
Restart: c.restart,
Config: conf,
})
if err != nil {
return err
}
buffer := bytes.NewBuffer(b)
request, err := http.NewRequest("POST", url, buffer)
if err != nil {
return err
}
request.Header.Set("Content-Type", "application/json")
response, err := client.Do(request)
if err != nil {
return err
}
defer response.Body.Close()
return cmd.StreamJSONResponse(context.Stdout, response)
}
示例14: Run
func (createRootUserCmd) Run(context *cmd.Context, client *cmd.Client) error {
context.RawOutput()
scheme, err := config.GetString("auth:scheme")
if err != nil {
scheme = "native"
}
app.AuthScheme, err = auth.GetScheme(scheme)
if err != nil {
return err
}
email := context.Args[0]
user, err := auth.GetUserByEmail(email)
if err == nil {
err = addSuperRole(user)
if err != nil {
return err
}
fmt.Fprintln(context.Stdout, "Root user successfully updated.")
}
var confirm, password string
if scheme == "native" {
fmt.Fprint(context.Stdout, "Password: ")
password, err = cmd.PasswordFromReader(context.Stdin)
if err != nil {
return err
}
fmt.Fprint(context.Stdout, "\nConfirm: ")
confirm, err = cmd.PasswordFromReader(context.Stdin)
if err != nil {
return err
}
fmt.Fprintln(context.Stdout)
if password != confirm {
return errors.New("Passwords didn't match.")
}
}
user, err = app.AuthScheme.Create(&auth.User{
Email: email,
Password: password,
})
if err != nil {
return err
}
err = addSuperRole(user)
if err != nil {
return err
}
fmt.Fprintln(context.Stdout, "Root user successfully created.")
return nil
}
示例15: Run
func (c *UpgradeCmd) Run(context *cmd.Context, client *cmd.Client) error {
context.RawOutput()
url, err := cmd.GetURL("/docker/bs/upgrade")
if err != nil {
return err
}
request, err := http.NewRequest("POST", url, nil)
if err != nil {
return err
}
response, err := client.Do(request)
if err != nil {
return err
}
defer response.Body.Close()
return cmd.StreamJSONResponse(context.Stdout, response)
}