当前位置: 首页>>代码示例>>Golang>>正文


Golang plugin.CliConnection类代码示例

本文整理汇总了Golang中github.com/cloudfoundry/cli/plugin.CliConnection的典型用法代码示例。如果您正苦于以下问题:Golang CliConnection类的具体用法?Golang CliConnection怎么用?Golang CliConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CliConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: GetEnvs

func (a *AppEnv) GetEnvs(cli plugin.CliConnection, args []string) ([]string, error) {
	if loggedIn, _ := cli.IsLoggedIn(); loggedIn == false {
		return nil, errors.New("You must login first!")
	}

	if len(args) <= 1 {
		return nil, errors.New("You must specify an app name")
	}

	cliOut, err := a.GetAppEnvFromCli(cli, args[1])

	vcapServicesExport := a.GetJsonAndFormat("VCAP_SERVICES", cliOut)
	vcapAppExport := a.GetJsonAndFormat("VCAP_APPLICATION", cliOut)

	envvars := []string{}

	if vcapServicesExport != "" {
		envvars = append(envvars, vcapServicesExport)
	}

	if vcapAppExport != "" {
		envvars = append(envvars, vcapAppExport)
	}

	return envvars, err
}
开发者ID:Samze,项目名称:appenvs,代码行数:26,代码来源:appenv.go

示例2: startedApps

func startedApps(cliConnection plugin.CliConnection, url string) ([]StartedApp, error) {
	appsJson, err := cliConnection.CliCommandWithoutTerminalOutput("curl", url)
	if nil != err {
		return nil, err
	}
	data := strings.Join(appsJson, "\n")
	var appsData map[string]interface{}
	json.Unmarshal([]byte(data), &appsData)

	apps := []StartedApp{}
	for _, app := range appsData["resources"].([]interface{}) {
		entity := app.(map[string]interface{})["entity"].(map[string]interface{})
		state := entity["state"].(string)
		if state == "STARTED" {
			metadata := app.(map[string]interface{})["metadata"].(map[string]interface{})
			result := StartedApp{
				Name:     entity["name"].(string),
				Guid:     metadata["guid"].(string),
				SpaceUrl: entity["space_url"].(string),
				State:    state,
			}
			apps = append(apps, result)
		}
	}

	if nil != appsData["next_url"] {
		next, _ := startedApps(cliConnection, appsData["next_url"].(string))
		apps = append(apps, next...)
	}

	return apps, err
}
开发者ID:davidehringer,项目名称:cf-ip-query-plugin,代码行数:32,代码来源:api.go

示例3: Run

func (c *NozzlerCmd) Run(cliConnection plugin.CliConnection, args []string) {
	var debug bool
	if args[0] != "nozzle" {
		return
	}
	c.ui = terminal.NewUI(os.Stdin, terminal.NewTeePrinter())

	fc := flags.NewFlagContext(setupFlags())
	err := fc.Parse(args[1:]...)
	if err != nil {
		c.ui.Failed(err.Error())
	}
	if fc.IsSet("debug") {
		debug = fc.Bool("debug")
	}

	dopplerEndpoint, err := cliConnection.DopplerEndpoint()
	if err != nil {
		c.ui.Failed(err.Error())
	}

	authToken, err := cliConnection.AccessToken()
	if err != nil {
		c.ui.Failed(err.Error())
	}

	client := firehose.NewClient(authToken, dopplerEndpoint, debug, c.ui)
	client.Start()
}
开发者ID:jtuchscherer,项目名称:nozzle-plugin,代码行数:29,代码来源:main.go

示例4: runServiceOpen

func (plugin OpenPlugin) runServiceOpen(cliConnection plugin.CliConnection, args []string) {
	output, err := cliConnection.CliCommandWithoutTerminalOutput("service", args[1], "--guid")
	if err != nil {
		fmt.Fprintln(os.Stdout, "error: service does not exist")
		os.Exit(1)
	}
	serviceInstanceGUID := strings.TrimSpace(output[0])

	output, err = cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v2/service_instances/%s", serviceInstanceGUID))
	if err != nil {
		fmt.Fprintln(os.Stdout, "error: service does not exist")
		os.Exit(1)
	}
	jsonStr := ""
	for _, line := range output {
		jsonStr += line + "\n"
	}

	response := serviceInstanceResponse{}
	json.Unmarshal([]byte(jsonStr), &response)

	url := response.Entity.DashboardURL
	if url == "" {
		fmt.Println("No dashboard available")
	} else {
		open.Run(url)
	}
}
开发者ID:whitfiea,项目名称:cf-plugin-open,代码行数:28,代码来源:open.go

示例5: Curl

func Curl(cli plugin.CliConnection, result interface{}, args ...string) error {
	output, err := cli.CliCommandWithoutTerminalOutput(append([]string{"curl"}, args...)...)
	if err != nil {
		return err
	}

	buf := []byte(strings.Join(output, "\n"))

	var errorResponse curlError
	err = json.Unmarshal(buf, &errorResponse)
	if err != nil {
		return err
	}

	if errorResponse.Code != 0 {
		return errors.New(errorResponse.Description)
	}

	if result != nil {
		err = json.Unmarshal(buf, result)
		if err != nil {
			return err
		}
	}

	return nil
}
开发者ID:sykesm,项目名称:diego-ssh,代码行数:27,代码来源:curl.go

示例6: Run

func (s *FirehoseStatsCmd) Run(cliConnection plugin.CliConnection, args []string) {

	if args[0] != "firehose-stats" {
		return
	}

	s.cfUI = terminal.NewUI(os.Stdin, terminal.NewTeePrinter())

	dopplerEndpoint, err := cliConnection.DopplerEndpoint()
	if err != nil {
		s.cfUI.Failed(err.Error())
	}

	authToken, err := cliConnection.AccessToken()
	if err != nil {
		s.cfUI.Failed(err.Error())
	}
	firehoseChan := make(chan *events.Envelope)
	client := firehose.NewClient(authToken, dopplerEndpoint, s.cfUI, firehoseChan)
	client.Start()

	statsUI := stats.New(client, s.cfUI, cliConnection)
	statsUI.Start()

}
开发者ID:wfernandes,项目名称:firehose-stats,代码行数:25,代码来源:main.go

示例7: getAppGuid

func getAppGuid(cliConnection plugin.CliConnection, appName string) string {
	repo := core_config.NewRepositoryFromFilepath(config_helpers.DefaultFilePath(), func(err error) {
		if err != nil {
			fmt.Println("\nERROR:", err)
			os.Exit(1)
		}
	})
	spaceGuid := repo.SpaceFields().Guid

	cmd := []string{"curl", fmt.Sprintf("/v2/spaces/%v/apps?q=name:%v&inline-relations-depth=1", spaceGuid, appName)}
	output, err := cliConnection.CliCommandWithoutTerminalOutput(cmd...)
	if err != nil {
		for _, e := range output {
			fmt.Println(e)
		}
		os.Exit(1)
	}

	search := &Search{}
	if err := json.Unmarshal([]byte(strings.Join(output, "")), &search); err != nil {
		fmt.Println("\nERROR:", err)
		os.Exit(1)
	}

	return search.Resources[0].Metadata.Guid
}
开发者ID:swisscom,项目名称:cf-statistics-plugin,代码行数:26,代码来源:plugin_hook.go

示例8: Run

func (c *DemoCmd) Run(cliConnection plugin.CliConnection, args []string) {
	switch args[0] {
	case "list-apps":
		fc, err := parseArguments(args)
		if err != nil {
			exit1(err.Error())
		}

		endpoint, err := cliConnection.ApiEndpoint()
		if err != nil {
			exit1("Error getting targeted endpoint: " + err.Error())
		}
		fmt.Printf("Listing apps @ endpoint %s/v2/apps...\n\n", endpoint)

		allApps, err := getAllApps(cliConnection)
		if err != nil {
			exit1("Error curling v2/apps: " + err.Error())
		}

		for _, app := range allApps.Resources {
			if (fc.IsSet("started") && app.Entity.State == "STARTED") ||
				(fc.IsSet("stopped") && app.Entity.State == "STOPPED") ||
				(!fc.IsSet("stopped") && !fc.IsSet("started")) {
				fmt.Println(app.Entity.Name)
			}
		}

	case "CLI-MESSAGE-UNINSTALL":
		fmt.Println("Thanks for using this demo")
	}
}
开发者ID:Reejoshi,项目名称:cli,代码行数:31,代码来源:test_rpc_server_example.go

示例9: CheckUpApps

// CheckUpApps performs checkup on applications and adds the result to triage map
func (c *DoctorPlugin) CheckUpApps(cliConnection plugin.CliConnection, triage []string, listOfRunningApps []plugin_models.GetAppsModel, listOfStoppedApps []plugin_models.GetAppsModel) []string {
	const alarmCPU float64 = 85.0

	for _, i := range listOfRunningApps {
		app, err := cliConnection.GetApp(i.Name)
		if err != nil {
			c.ui.Failed(err.Error())
		}

		if len(app.StagingFailedReason) > 0 {
			triage = append(triage, i.Name+" ___ StagingFailedReason: "+app.StagingFailedReason)
		}

		insts := app.Instances

		for _, ins := range insts {
			if ins.CpuUsage > alarmCPU {
				triage = append(triage, i.Name+" ___ CPU usage over %85 percent!")
			}

			if float64(ins.DiskUsage) > float64(ins.DiskQuota)*0.80 {
				triage = append(triage, i.Name+" ___ DiskUsage over %80 percent of DiskQuota")
			}

			if float64(ins.MemUsage) > float64(ins.MemQuota)*0.80 {
				triage = append(triage, i.Name+" ___ MemUsage over %80 percent of MemQuota")
			}

			if float64(ins.MemUsage) < float64(ins.MemQuota)*0.15 {
				triage = append(triage, i.Name+" ___ MemUsage lower than %15 percent of MemQuota, scaledown is an option.")
			}

			if len(insts) > 1 && float64(ins.MemUsage) < float64(ins.MemQuota)*0.15 && ins.CpuUsage < 10.0 {
				triage = append(triage, i.Name+" ___ app has more than one instance running with very low resource consumption. candidate for scaling down.")
			}

		}

		routes := app.Routes

		if len(routes) == 0 {
			triage = append(triage, i.Name+" ___ You have a running application that does not have a route!")
		}
	}

	for _, y := range listOfStoppedApps {
		app, err := cliConnection.GetApp(y.Name)
		if err != nil {
			c.ui.Failed(err.Error())
		}

		if len(app.StagingFailedReason) > 0 {
			triage = append(triage, y.Name+" ___ StagingFailedReason: "+app.StagingFailedReason)
		}
	}

	return triage

}
开发者ID:afeld,项目名称:cf-doctor-plugin,代码行数:60,代码来源:main.go

示例10: GetAllApps

func GetAllApps(cliConnection plugin.CliConnection) ([]AppModel, error) {
	response, err := cliConnection.CliCommandWithoutTerminalOutput("curl", "v2/apps")

	apps := AppsModel{}
	err = json.Unmarshal([]byte(response[0]), &apps)

	return apps.Resources, err
}
开发者ID:simonleung8,项目名称:cli-plugin-examples,代码行数:8,代码来源:apps_repository.go

示例11: UnmapContextRoute

func UnmapContextRoute(cliConnection plugin.CliConnection, args []string) {
	app := args[1]
	domain := args[2]
	host := args[3]
	path := args[4]

	mySpace, _ := cliConnection.GetCurrentSpace()

	output, err := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("v2/apps?q=name:%s&q=space_guid:%s", app, mySpace.Guid))
	FreakOut(err)
	apps := AppsModel{}
	err = json.Unmarshal([]byte(output[0]), &apps)
	FreakOut(err)
	if len(apps.Resources) == 0 {
		fmt.Printf("App %s not found", app)
		return
	}
	appGuid := apps.Resources[0].Metadata.Guid

	output, err = cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("v2/domains?q=name:%s", domain))
	FreakOut(err)
	domains := DomainsModel{}
	err = json.Unmarshal([]byte(output[0]), &domains)
	FreakOut(err)
	if len(domains.Resources) == 0 {
		fmt.Printf("Domain %s not found", domain)
		return
	}
	domainGuid := domains.Resources[0].Metadata.Guid

	output, err = cliConnection.CliCommandWithoutTerminalOutput("curl",
		fmt.Sprintf("v2/routes?q=domain_guid:%s&q=host:%s&q=path:%s", domainGuid, host, path))
	FreakOut(err)
	routes := RoutesModel{}
	err = json.Unmarshal([]byte(output[0]), &routes)
	FreakOut(err)
	if len(routes.Resources) == 0 {
		fmt.Printf("Route not found host: %s, path: %s", host, path)
		return
	}
	routeGuid := routes.Resources[0].Metadata.Guid

	output, err = cliConnection.CliCommandWithoutTerminalOutput("curl",
		fmt.Sprintf("v2/apps/%s/routes/%s", appGuid, routeGuid), "-X", "DELETE")
	FreakOut(err)
	mappedApp := AppModel{}
	err = json.Unmarshal([]byte(output[0]), &mappedApp)
	FreakOut(err)
	if mappedApp.Metadata.Guid == "" {
		error := ErrorModel{}
		err = json.Unmarshal([]byte(output[0]), &error)
		FreakOut(err)
		fmt.Printf("Failed to map route: %s", error.Description)
		return
	}

	fmt.Printf("Route successfully unmapped.")
}
开发者ID:zrob,项目名称:context-route-plugin,代码行数:58,代码来源:unmap_context_route.go

示例12: Curl

// Curl calls cf curl  and return the resulting json. This method will panic if
// the api is depricated
func Curl(cli plugin.CliConnection, path string) (map[string]interface{}, error) {
	output, err := cli.CliCommandWithoutTerminalOutput("curl", path)

	if nil != err {
		return nil, err
	}

	return parseOutput(output)
}
开发者ID:krujos,项目名称:cfcurl,代码行数:11,代码来源:cfcurl.go

示例13: scaleUp

func (app *AppStatus) scaleUp(cliConnection plugin.CliConnection) {
	// If not already started, start it
	if app.state != "started" {
		cliConnection.CliCommandWithoutTerminalOutput("start", app.name)
		app.state = "started"
	}
	app.countRequested++
	cliConnection.CliCommandWithoutTerminalOutput("scale", "-i", strconv.Itoa(app.countRequested), app.name)
}
开发者ID:TomG713,项目名称:scaleover-plugin,代码行数:9,代码来源:scaleover_plugin.go

示例14: setServiceCreds

func setServiceCreds(conn plugin.CliConnection, name string, creds map[string]interface{}) error {
	marshaled, err := json.Marshal(creds)
	if err != nil {
		return err
	}

	_, err = conn.CliCommandWithoutTerminalOutput("uups", name, "-p", string(marshaled[:]))
	return err
}
开发者ID:jmcarp,项目名称:cf-mups,代码行数:9,代码来源:main.go

示例15: KillInstanceZero

func (plugin ConsolePlugin) KillInstanceZero(cliConnection plugin.CliConnection, appGuid string) {

	plugin.Log("Killing instance 0.\n", false)

	// Kill the first instance and wait for it to come back up
	appURL := fmt.Sprintf("/v2/apps/%v/instances/0", appGuid)
	cmd := []string{"curl", appURL, "-X", "DELETE"}

	cliConnection.CliCommandWithoutTerminalOutput(cmd...)
}
开发者ID:tianhonglouis,项目名称:cf-console,代码行数:10,代码来源:console.go


注:本文中的github.com/cloudfoundry/cli/plugin.CliConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。