本文整理汇总了Golang中code/cloudfoundry/org/cli/plugin.CliConnection.CliCommandWithoutTerminalOutput方法的典型用法代码示例。如果您正苦于以下问题:Golang CliConnection.CliCommandWithoutTerminalOutput方法的具体用法?Golang CliConnection.CliCommandWithoutTerminalOutput怎么用?Golang CliConnection.CliCommandWithoutTerminalOutput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类code/cloudfoundry/org/cli/plugin.CliConnection
的用法示例。
在下文中一共展示了CliConnection.CliCommandWithoutTerminalOutput方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Delete
func Delete(cliConnection plugin.CliConnection, args []string) {
appName := args[1]
urlValues := url.Values{}
urlValues.Add("names", args[1])
fmt.Printf("Deleting app %s...\n", appName)
rawOutput, _ := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps?%s", urlValues.Encode()))
apps := V3AppsModel{}
output := strings.Join(rawOutput, "")
json.Unmarshal([]byte(output), &apps)
if len(apps.Apps) == 0 {
fmt.Printf("App %s not found\n", appName)
return
}
if _, err := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps/%s", apps.Apps[0].Guid), "-X", "DELETE"); err != nil {
fmt.Printf("Failed to delete app %s\n", appName)
return
}
fmt.Println("OK")
}
示例2: Poll
func Poll(cliConnection plugin.CliConnection, endpoint string, desired string, timeout time.Duration, timeoutMessage string) {
timeElapsed := 0 * time.Second
for timeElapsed < timeout {
rawOutput, err := cliConnection.CliCommandWithoutTerminalOutput("curl", endpoint, "-X", "GET")
FreakOut(err)
output := strings.Join(rawOutput, "")
if strings.Contains(output, desired) {
return
}
timeElapsed = timeElapsed + 1*time.Second
time.Sleep(1 * time.Second)
}
FreakOut(errors.New(timeoutMessage))
}
示例3: RunTask
func RunTask(cliConnection plugin.CliConnection, args []string) {
appName := args[1]
taskName := args[2]
taskCommand := args[3]
fmt.Println("OK\n")
fmt.Printf("Running task %s on app %s...\n\n", taskName, appName)
go Logs(cliConnection, args)
time.Sleep(2 * time.Second) // b/c sharing the cliConnection makes things break
rawOutput, _ := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps?names=%s", appName))
output := strings.Join(rawOutput, "")
apps := models.V3AppsModel{}
json.Unmarshal([]byte(output), &apps)
if len(apps.Apps) == 0 {
fmt.Printf("App %s not found\n", appName)
return
}
appGuid := apps.Apps[0].Guid
body := fmt.Sprintf(`{
"name": "%s",
"command": "%s"
}`, taskName, taskCommand)
rawOutput, err := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps/%s/tasks", appGuid), "-X", "POST", "-d", body)
if err != nil {
fmt.Printf("Failed to run task %s\n", taskName)
return
}
output = strings.Join(rawOutput, "")
task := models.V3TaskModel{}
err = json.Unmarshal([]byte(output), &task)
util.FreakOut(err)
if task.Guid == "" {
fmt.Printf("Failed to run task %s:\n%s\n", taskName, output)
return
}
util.Poll(cliConnection, fmt.Sprintf("/v3/tasks/%s", task.Guid), "SUCCEEDED", 1*time.Minute, "Task failed to run")
fmt.Printf("Task %s successfully completed.\n", task.Guid)
}
示例4: BindService
func BindService(cliConnection plugin.CliConnection, args []string) {
customParameters := "{}"
fc := flags.New()
fc.NewStringFlag("parameters", "c", "Valid JSON object containing service-specific configuration parameters, provided either in-line or in a file. For a list of supported configuration parameters, see documentation for the particular service offering.")
fc.Parse(args...)
if fc.IsSet("c") {
customParameters = fc.String("c")
}
appName := fc.Args()[1]
serviceInstanceName := fc.Args()[2]
rawOutput, _ := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps?names=%s", appName))
apps := V3AppsModel{}
output := strings.Join(rawOutput, "")
json.Unmarshal([]byte(output), &apps)
if len(apps.Apps) == 0 {
fmt.Printf("App %s not found\n", appName)
return
}
appGuid := apps.Apps[0].Guid
serviceInstance, err := cliConnection.GetService(serviceInstanceName)
FreakOut(err)
serviceInstanceGuid := serviceInstance.Guid
body := fmt.Sprintf(`{
"type": "app",
"relationships": {
"app": {"guid" : "%s"},
"service_instance": {"guid": "%s"}
},
"data": {
"parameters": %s
}
}`, appGuid, serviceInstanceGuid, customParameters)
if _, err := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/service_bindings"), "-X", "POST", "-d", body); err != nil {
fmt.Printf("Failed to bind app %s to service instance %s\n", appName, serviceInstanceName)
return
}
fmt.Println("OK")
}
示例5: Processes
func Processes(cliConnection plugin.CliConnection, args []string) {
mySpace, err := cliConnection.GetCurrentSpace()
FreakOut(err)
rawOutput, err := cliConnection.CliCommandWithoutTerminalOutput("curl", "v3/processes?per_page=5000", "-X", "GET")
FreakOut(err)
output := strings.Join(rawOutput, "")
processes := V3ProcessesModel{}
err = json.Unmarshal([]byte(output), &processes)
FreakOut(err)
rawOutput, err = cliConnection.CliCommandWithoutTerminalOutput("curl", "v3/apps?per_page=5000", "-X", "GET")
FreakOut(err)
output = strings.Join(rawOutput, "")
apps := V3AppsModel{}
err = json.Unmarshal([]byte(output), &apps)
FreakOut(err)
appsMap := make(map[string]V3AppModel)
for _, app := range apps.Apps {
appsMap[app.Guid] = app
}
if len(processes.Processes) > 0 {
processesTable := NewTable([]string{("app"), ("type"), ("instances"), ("memory in MB"), ("disk in MB")})
for _, v := range processes.Processes {
if strings.Contains(v.Links.Space.Href, mySpace.Guid) {
appName := "N/A"
if v.Links.App.Href != "/v3/apps/" {
appGuid := strings.Split(v.Links.App.Href, "/v3/apps/")[1]
appName = appsMap[appGuid].Name
}
processesTable.Add(
appName,
v.Type,
strconv.Itoa(v.Instances),
strconv.Itoa(v.Memory)+"MB",
strconv.Itoa(v.Disk)+"MB",
)
}
}
processesTable.Print()
} else {
fmt.Println("No v3 processes found.")
}
}
示例6: Tasks
func Tasks(cliConnection plugin.CliConnection, args []string) {
appName := args[1]
fmt.Printf("Listing tasks for app %s...\n", appName)
rawOutput, _ := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps?names=%s", appName))
output := strings.Join(rawOutput, "")
apps := V3AppsModel{}
json.Unmarshal([]byte(output), &apps)
if len(apps.Apps) == 0 {
fmt.Printf("App %s not found\n", appName)
return
}
appGuid := apps.Apps[0].Guid
rawOutput, err := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps/%s/tasks", appGuid), "-X", "GET")
FreakOut(err)
output = strings.Join(rawOutput, "")
tasks := V3TasksModel{}
err = json.Unmarshal([]byte(output), &tasks)
FreakOut(err)
if len(tasks.Tasks) > 0 {
tasksTable := NewTable([]string{("id"), ("state"), ("start time"), ("name"), ("command")})
for _, v := range tasks.Tasks {
tasksTable.Add(
strconv.Itoa(v.Id),
v.State,
v.CreatedAt.Format("Jan 2, 15:04:05 MST"),
v.Name,
v.Command,
)
}
tasksTable.Print()
} else {
fmt.Println("No v3 tasks found.")
}
}
示例7: Apps
func Apps(cliConnection plugin.CliConnection, args []string) {
mySpace, err := cliConnection.GetCurrentSpace()
util.FreakOut(err)
rawOutput, err := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("v3/apps?space_guids=%s", mySpace.Guid), "-X", "GET")
output := strings.Join(rawOutput, "")
util.FreakOut(err)
apps := V3AppsModel{}
err = json.Unmarshal([]byte(output), &apps)
util.FreakOut(err)
if len(apps.Apps) > 0 {
appsTable := util.NewTable([]string{("name"), ("total_desired_instances")})
for _, v := range apps.Apps {
appsTable.Add(
v.Name,
strconv.Itoa(v.Instances),
)
}
appsTable.Print()
} else {
fmt.Println("No v3 apps found.")
}
}
示例8: getAllApps
func getAllApps(cliConnection plugin.CliConnection) (AppsModel, error) {
nextURL := "v2/apps"
allApps := AppsModel{}
for nextURL != "" {
output, err := cliConnection.CliCommandWithoutTerminalOutput("curl", nextURL)
if err != nil {
return AppsModel{}, err
}
apps := AppsModel{}
err = json.Unmarshal([]byte(output[0]), &apps)
if err != nil {
return AppsModel{}, err
}
allApps.Resources = append(allApps.Resources, apps.Resources...)
nextURL = apps.NextURL
}
return allApps, nil
}
示例9: Run
func (c *CoreCmd) Run(cliConnection plugin.CliConnection, args []string) {
if args[0] == "core-command" {
output, err := cliConnection.CliCommand(args[1:]...)
if err != nil {
fmt.Println("PLUGIN ERROR: Error from CliCommand: ", err)
}
dumpOutput(output)
} else if args[0] == "core-command-quiet" {
output, err := cliConnection.CliCommandWithoutTerminalOutput(args[1:]...)
if err != nil {
fmt.Println("PLUGIN ERROR: Error from CliCommand: ", err)
}
dumpOutput(output)
} else if args[0] == "awesomeness" {
cliConnection.CliCommand("plugins")
} else if len(args) == 2 && args[0] == "awesomeness" && args[1] == "easter_egg" {
fmt.Println(`
ZZZZ$Z$$$ZZ$$$$$77$777777777777777777777I77II7I?III?IIII???????+++????????++++++=++++++++++++++++++=++======+======+++++
ZZZZZZZZ$$ZZ$77777777777III777777I7777IIIIIIIII??IIIIII???????++++???????++++++++++++?????++++++++++========+===~+=+++++
ZZZZZZ$$$$$$77777$$77I77777777III77IIIIII7IIIII????II????I7$ZZZ$$7I???????++?+++++++++++++++++++++++==+=============++++
$ZZ77$7$$$$$777777777777I7777IIII77I777III?III??????IDNNMNNNNNDDDNNNDDO7????+++++=++=++++++++=++++====+========~~===++++
ZZ$$$7777$$$$$777777777777IIIIIIII7IIIIIIIIII?I??+IZNND8NNNMMMMNNNDDDNND8?+??+?++++++++++++++==+=+===++=======~~~====+++
$$$$$$$$Z$$$$7777777777I7I?II??IIIIII?III???????$DMNN8O8NNNNNNNNMMMMND8DNMD$+++?++==++++++++=======~===========~~======+
$$$$Z$$$$$$$7777I777IIIIII?IIIIIIIII?????+????ZNND8DDZZDDDDDDDNNNNNNMMMMNNNNNZ?++=====+++++++=====~~==~===~==~=~=~======
$$$7$$$7$777III777IIIIIIIIIII??III??III???++?$MNNDDD8$O88DDDNMNNNNNNMMMMMMDNMMN7+=====+++++==========~~~~~~~~~~=~======+
77777777777777IIIII7IIIII????????II?????++++$DN8Z7?+++=++???I$ODNNNMMMMMNNNNNMMM+=+===~==========~==~~~~~~~~~~~~=~======
$$77777777777I77IIIIIIII????II?III?????++++I8N$I?+======++???I$O8DDNNNMMNNNMNMNMZ+=+==~===~~====~==~~~~~~~~~~~~~~~======
$$77777777III77IIIIIIII??????I?I????+++++?I8NOI?=~~~~~~~~~==+?I7$ZDNNNNMMMMNNNMNMO+===~~===~~~~~~~~~~~~~~~~~~::~~=======
$$$$$$77II77IIIIIIIIIII?????????????+++++7NM87+=~:~~:~~~~~~==++I7$8DNNNMNMMMMMNMNMO=~=======~~~~~~~:~~~~~~:::::::~~=====
77777$$7IIII?II??II??????????++++??++===$NMNZI+=~~~~~~~~~~~==+?I7$OO8DNMNNNMNNMMNMM$==+++===~===~~~~~~~~:::::::::~~~====
7II?I7I77III???+????++???????++????+==~+$DMD$I+=======~=====+???I7$ZO8DDNNMMNNMMMMMD???+++++++==~=~~~~=~~~~~:::::~~~==+=
777I777$7II???????++++??????+++???++==+IONM8$I+============+++??II7$ZZODNNNMMMMMMMMM7?I??????+=====~~~~~~~~~~::::~~~===+
$7777$$ZZ7I7I??++?I?++?++???+++++++===7$DNNO7I++===~~=======++++++?I7$Z8NNNNNMNMNMMM8I7IIII7I+=====~+=~~::::~~~::~~~===+
ZZZOOZ8OO$7III?II77I?+++++++++=====+=?78DMMZI?=+===~=~=~==++=+++???II7Z8NMMMMMMMNMNMD7$$$I77I????+++?=~~~~~~~::::::~==++
O8888ZZZ88Z$$$$7777$7?I7?++=+=++====+7$8NMMOI?????+=+===?7$7IIIII77$ZZODNNMMMMMMNNMNN$OZ$7IIII?I??++?+?+=~~:~~:::::===++
O8DD8OOOOOOOZ$$$$$Z$$$Z$7I++++++====?$Z8MMM87?I77$I++++?$ZOZZZZOZ$OOOOO8NNMMMMMMNNNMMOZ$ZZ$$777I??+??+?+=~~:~~~::::~====
DDDD88OOOZZZZOOOZZOOOOZ$ZZ7+?+=++=++IOO8DNMDDDI777$ZI+?ZDDZ7$OOO8DMNO$ZODMMMNNNNMMMNMDOZZZZZ$III?I7$7I??=~~~~~~~:~==++++
888888888OOOO8OZO8OOOZO$7$Z+?+=+++??IZDNNMMOZDIZNDO7I=I8O$I?IOZZZZ???I7O8MMNNMMMMMMMMNOOZZZZZ7$$$77$77I++~:::::~:~====+?
DD8D8O8OOO888OOOZ8D8O88ZZ8+???IZO$???ONNMMMZIIII$Z7?+=7ZZ7??I77$7I++?I7ODMMMMMMMMNNNMMO8OOOZ$7$$$77$777I?=~~~~~~~===+++?
8D88OO88OOO8888OODD888OOO8OZ7$OO$8Z7ZO8NMMN7?+=====+?+I77I?=~~~~~=??I7Z8DMMMMNMMMMMNNMZZZZZ$$777$$$Z$$$7I+==~==~=====++?
8DDDO88888888DDD8DD88DD8O888OZOZ$DO$OO8NMMM$?+====++++?II?+==~~~==?I7$Z8NMMMMNMMMMNNNMZZZZZZ$$Z$$$$ZZZ$7I?==========++??
DD888D8OO8DDD8ODNDD88DDD8D8D8O8OODOO88DNNMM8I+=~==+++=?II?++====++I7$ZODNMMMNMMNMMNNNM77777I??I???????????++++++???????I
NMMNNNNNDDDND8D88DD8DDDDDD8DD8D8D8DNNNNNNMMD7+++==++++II7I?++==++?7$ZO8NNMMMNNNMMMMMNN88OOOOO$$$$$$$7I??I???++??III7$$7I
NMMNDDNNNDDDD88O88888D8DN8DDDDDDNNNMMNNNMMMMZ7++??I?=?777ZI++=+??I$ZOODNNMMMMMMMMMMMMNDD8O8OOOZZZZZZZ$ZZ$7I7777I7I7$$ZZZ
NNNNNDDNNDDDNDNDD888DD88DDDDDDDDDNNNNNMMMMMMD$II?++?$8NMND7++??II7ZO88DNMMMMMMMMMMMMMMNDDD888OOOOOO8OZ$Z$$$ZZZ$$$$$$$$ZZ
MMNMNDDNNNDDNDDDNDD8DD888D88DDDDNNNMNNNMMMMMNZ7II?==?NNN8ZI??III7$$ZO8DNMMMMMMMMMMMMMMN8OOOOOOOOZOOOZOZZZZOZZZZ$$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NNNNNNMNND88D8$?IIII777$$Z$$$Z$$$
NNNNNNMNNDDDNDDD8O8O8DDNMNNNNMMMMNNNMMMMMMMNNN7I?+++========++========++??I$8OO88O8DNMNNNNMDDNNMNDDDOO$I$7I??II??I777777
NNNMNNNND8DDD8DDO8D8DNDNDDNNDDNMNNNMMMMMMMNNNOI+++++=~~=====+====~=====+?I$$8DO88O8NNMNNNDD88DDDNNNN8OO8Z$77Z7?7O777$O$$
NDNNNDNNND8888O8OO8O8DDDNNDDDNNDNNMMMMMMNDDDO$?+==============~====+++++?I$8O888888MMMNN8ZZZ88DDNMMNND8Z$$IIIIII?IIII???
NNNMNDMMNM8Z8$ZOOO8OODDDDD888DNNMMMMMMMM8OZZO7++======~~~=======~~==++?+?I$ZOO8D88DND888OZOZ7ZZZO8DNMMMND88888Z77777I?I?
NNNNNDMMNMDDN$ZOZZOOZO88DN888DMMMMMMMMMMOZZ$$?=+===========~=====~===+++?I$ZOO8DDD8OOZ$$$7$$$8DDDDNMNNMMMD8O88OZ$$$OO77$
NNNNNNMMNNNDNMN8OZZO88O8D88DNMMMMMMMMMMNZ7II?+==========~======~=~===++??7ZOO888O$7$$$$I?IIII$O8DNMMMMMMMMNDD8ODD88888DO
DDNNDDNDDNNNNNNDNDOOOOOOO88MMMMMMMMMMMN8$III+===~=========~~=~~~==~==++?I$$ZZZZOOOZ7I?7$O888DNNNNNNMMMMMMMMNNDD88DNNDO$I
NNNNDDDNNNDNNNNNN88DDD8OZ$MMMMMMMMMMMMND7?++=======+===~~~~~~~~=~~~~~=+??7$$ZOO$7$ZO8DDNNNMMMMMMMMMMMMMMMMMMMD88DDD8888D
DNNNNNNNDDDDDNDDDDD888OZ$8MMMMMMMMMMMNDD87?++=~~=++++=~~~~~~~:~~~~~~===+?7ZZ$ZZODNNMNNDDNNNNMMMMMMMMMMMMMMMMMNMD8888DND8
DNNNNNNNNND88D8888OZ$ZZZ8NMMMMMMMMMMNNDDDO$I?+===+?++==~~~~~~~~~~~~====?7$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MMMNMMNNNMNNNNNNNNN
//.........这里部分代码省略.........
示例10: CancelTask
func CancelTask(cliConnection plugin.CliConnection, args []string) {
appName := args[1]
taskName := args[2]
rawOutput, err := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps?names=%s", appName))
util.FreakOut(err)
output := strings.Join(rawOutput, "")
apps := models.V3AppsModel{}
json.Unmarshal([]byte(output), &apps)
if len(apps.Apps) == 0 {
fmt.Printf("App %s not found\n", appName)
return
}
appGuid := apps.Apps[0].Guid
rawTasksJson, err := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps/%s/tasks", appGuid))
util.FreakOut(err)
tasksJson := strings.Join(rawTasksJson, "")
tasks := models.V3TasksModel{}
err = json.Unmarshal([]byte(tasksJson), &tasks)
util.FreakOut(err)
var runningTasks []runningTask
for _, task := range tasks.Tasks {
if taskName == task.Name && task.State == "RUNNING" {
runningTasks = append(runningTasks, runningTask{task.Guid, task.Command, task.State, task.UpdatedAt})
}
}
if len(runningTasks) == 0 {
fmt.Println("No running task found. Task name:", taskName)
return
} else if len(runningTasks) == 1 {
rawOutput, err = cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/tasks/%s/cancel", runningTasks[0].guid), "-X", "PUT", "-d", "{}")
util.FreakOut(err)
output := strings.Join(rawOutput, "")
fmt.Println(output)
return
} else {
fmt.Printf("Please select which task to cancel: \n\n")
tasksTable := util.NewTable([]string{"#", "Task Name", "Command", "State", "Time"})
for i, task := range runningTasks {
tasksTable.Add(
strconv.Itoa(i+1),
taskName,
task.command,
task.state,
fmt.Sprintf("%s", task.time.Format("Jan 2, 15:04:05 MST")),
)
}
tasksTable.Print()
var i int64 = -1
var str string
for i <= 0 || i > int64(len(runningTasks)) {
fmt.Printf("\nSelect from above > ")
fmt.Scanf("%s", &str)
i, _ = strconv.ParseInt(str, 10, 32)
}
rawOutput, err = cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/tasks/%s/cancel", runningTasks[i-1].guid), "-X", "PUT", "-d", "{}")
util.FreakOut(err)
output := strings.Join(rawOutput, "")
fmt.Println(output)
}
}
示例11: Logs
func Logs(cliConnection plugin.CliConnection, args []string) {
appName := args[1]
rawOutput, _ := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps?names=%s", appName))
apps := V3AppsModel{}
output := strings.Join(rawOutput, "")
json.Unmarshal([]byte(output), &apps)
if len(apps.Apps) == 0 {
fmt.Printf("App %s not found\n", appName)
return
}
app := apps.Apps[0]
messageQueue := logs.NewNoaaMessageQueue()
bufferTime := 25 * time.Millisecond
ticker := time.NewTicker(bufferTime)
logChan := make(chan logs.Loggable)
errChan := make(chan error)
dopplerEndpoint, err := cliConnection.DopplerEndpoint()
FreakOut(err)
ssl, err := cliConnection.IsSSLDisabled()
FreakOut(err)
tlsConfig := net.NewTLSConfig([]tls.Certificate{}, ssl)
noaaConsumer := consumer.New(dopplerEndpoint, tlsConfig, http.ProxyFromEnvironment)
defer func() {
noaaConsumer.Close()
flushMessages(logChan, messageQueue)
}()
onConnect := func() {
fmt.Printf("Tailing logs for app %s...\r\n\r\n", appName)
}
noaaConsumer.SetOnConnectCallback(onConnect)
accessToken, err := cliConnection.AccessToken()
FreakOut(err)
c, e := noaaConsumer.TailingLogs(app.Guid, accessToken)
go func() {
for {
select {
case msg, ok := <-c:
if !ok {
ticker.Stop()
flushMessages(logChan, messageQueue)
close(logChan)
close(errChan)
return
}
messageQueue.PushMessage(msg)
case err := <-e:
if err != nil {
errChan <- err
ticker.Stop()
close(logChan)
close(errChan)
return
}
}
}
}()
go func() {
for range ticker.C {
flushMessages(logChan, messageQueue)
}
}()
for {
select {
case msg := <-logChan:
fmt.Printf("%s\r\n", logMessageOutput(msg, time.Local))
case err, ok := <-errChan:
if !ok {
FreakOut(err)
}
}
}
}
示例12: Push
func Push(cliConnection plugin.CliConnection, args []string) {
appDir := "."
buildpack := "null"
dockerImage := ""
fc := flags.New()
fc.NewStringFlag("filepath", "p", "path to app dir or zip to upload")
fc.NewStringFlag("buildpack", "b", "the buildpack to use")
fc.NewStringFlag("docker-image", "di", "the docker image to use")
fc.Parse(args...)
if fc.IsSet("p") {
appDir = fc.String("p")
}
if fc.IsSet("b") {
buildpack = fmt.Sprintf(`"%s"`, fc.String("b"))
}
if fc.IsSet("di") {
dockerImage = fmt.Sprintf(`"%s"`, fc.String("di"))
}
mySpace, _ := cliConnection.GetCurrentSpace()
lifecycle := ""
if dockerImage != "" {
lifecycle = `"lifecycle": { "type": "docker", "data": {} }`
} else {
lifecycle = fmt.Sprintf(`"lifecycle": { "type": "buildpack", "data": { "buildpack": %s } }`, buildpack)
}
//create the app
rawOutput, err := cliConnection.CliCommandWithoutTerminalOutput("curl", "/v3/apps", "-X", "POST", "-d",
fmt.Sprintf(`{"name":"%s", "relationships": { "space": {"guid":"%s"}}, %s}`, fc.Args()[1], mySpace.Guid, lifecycle))
FreakOut(err)
output := strings.Join(rawOutput, "")
app := V3AppModel{}
err = json.Unmarshal([]byte(output), &app)
FreakOut(err)
if app.Error_Code != "" {
FreakOut(errors.New("Error creating v3 app: " + app.Error_Code))
}
time.Sleep(2 * time.Second) // wait for app to settle before kicking off the log streamer
go Logs(cliConnection, args)
time.Sleep(2 * time.Second) // b/c sharing the cliConnection makes things break
//create package
pack := V3PackageModel{}
if dockerImage != "" {
request := fmt.Sprintf(`{"type": "docker", "data": {"image": %s}}`, dockerImage)
rawOutput, err = cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps/%s/packages", app.Guid), "-X", "POST", "-d", request)
FreakOut(err)
output = strings.Join(rawOutput, "")
err = json.Unmarshal([]byte(output), &pack)
if err != nil {
FreakOut(errors.New("Error creating v3 app package: " + app.Error_Code))
}
} else {
//create the empty package to upload the app bits to
rawOutput, err = cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps/%s/packages", app.Guid), "-X", "POST", "-d", "{\"type\": \"bits\"}")
FreakOut(err)
output = strings.Join(rawOutput, "")
err = json.Unmarshal([]byte(output), &pack)
if err != nil {
FreakOut(errors.New("Error creating v3 app package: " + app.Error_Code))
}
token, err := cliConnection.AccessToken()
FreakOut(err)
api, apiErr := cliConnection.ApiEndpoint()
FreakOut(apiErr)
apiString := fmt.Sprintf("%s", api)
if strings.Index(apiString, "s") == 4 {
apiString = apiString[:4] + apiString[5:]
}
//gather files
zipper := appfiles.ApplicationZipper{}
fileutils.TempFile("uploads", func(zipFile *os.File, err error) {
zipper.Zip(appDir, zipFile)
_, upload := exec.Command("curl", fmt.Sprintf("%s/v3/packages/%s/upload", apiString, pack.Guid), "-F", fmt.Sprintf("[email protected]%s", zipFile.Name()), "-H", fmt.Sprintf("Authorization: %s", token), "-H", "Expect:").Output()
FreakOut(upload)
})
//waiting for cc to pour bits into blobstore
Poll(cliConnection, fmt.Sprintf("/v3/packages/%s", pack.Guid), "READY", 5*time.Minute, "Package failed to upload")
}
rawOutput, err = cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/packages/%s/droplets", pack.Guid), "-X", "POST", "-d", "{}")
FreakOut(err)
output = strings.Join(rawOutput, "")
droplet := V3DropletModel{}
err = json.Unmarshal([]byte(output), &droplet)
if err != nil {
FreakOut(errors.New("error marshaling the v3 droplet: " + err.Error()))
}
//wait for the droplet to be ready
Poll(cliConnection, fmt.Sprintf("/v3/droplets/%s", droplet.Guid), "STAGED", 10*time.Minute, "Droplet failed to stage")
//assign droplet to the app
//.........这里部分代码省略.........