Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Logfiles support
Browse files Browse the repository at this point in the history
  • Loading branch information
Dj Walker-Morgan committed Sep 24, 2018
1 parent ef12bc2 commit 89a1c62
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Available Commands:
details Show details for a deployment
help Help about any command
list List deployments attached to account
logfiles Commands for logfiles
recipe Show details of a recipe
recipes Show Recipes related to deployment
scale Show scale information for a deployment
Expand Down Expand Up @@ -68,6 +69,10 @@ bach backups [command]
restore Restore a deployment
start Start backups for a deployment
bach logfiles [command]
get Show Logfile details for deployment
list Show Logfiles for deployment
bach user [command]
add Add user
del Delete user
Expand Down
75 changes: 75 additions & 0 deletions cmd/logfileget.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright © 2017 Compose, an IBM Company
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"fmt"
"log"

"github.com/spf13/cobra"
)

var downloadLogfileNow bool

// logfilegetCmd represents the logfiles get command
var logfilegetCmd = &cobra.Command{
Use: "get [deployment id] logfile id/name]",
Short: "Show Logfile details for deployment",
Long: `Show the Logfile details for a deployment's Logfile`,
Run: func(cmd *cobra.Command, args []string) {
c := getComposeAPI()
if len(args) != 2 {
log.Fatal("Need a deployment id/name and a logfile id")
}
depid, err := resolveDepID(c, args[0])
if err != nil {
log.Fatal(err)
}
logfileid := args[1]
if outputRaw {
text, errs := c.GetLogfileDetailsForDeploymentJSON(depid, logfileid)
bailOnErrs(errs)
fmt.Println(text)
} else {
logfile, errs := c.GetLogfileDetailsForDeployment(depid, logfileid)
bailOnErrs(errs)

if !outputJSON {
fmt.Printf("%15s: %s\n", "Logfile ID", logfile.ID)
fmt.Printf("%15s: %s\n", "Deployment ID", logfile.Deploymentid)
fmt.Printf("%15s: %s\n", "Capsule ID", logfile.Capsuleid)
fmt.Printf("%15s: %s\n", "Logfile Name", logfile.Name)
fmt.Printf("%15s: %s\n", "Status", logfile.Status)
fmt.Printf("%15s: %s\n", "Download Link", logfile.DownloadLink)

if downloadLogfileNow {
err := DownloadFile(logfile.Name, logfile.DownloadLink)
if err != nil {
fmt.Printf("Error downloading: %s\n", err)
} else {
fmt.Printf("Downloaded: %s\n", logfile.Name)
}
}
} else {
printAsJSON(logfile)
}
}
},
}

func init() {
logfilesCmd.AddCommand(logfilegetCmd)
logfilegetCmd.Flags().BoolVarP(&downloadLogfileNow, "download", "d", false, "Download the selected logfile")
}
64 changes: 64 additions & 0 deletions cmd/logfilelist.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright © 2017 Compose, an IBM Company
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"fmt"
"log"

"github.com/spf13/cobra"
)

// logfilesListCmd represents the logfiles list command
var logfilesListCmd = &cobra.Command{
Use: "list [deployment id/name]",
Short: "Show Logfiles for deployment",
Long: `Show the Logfiles for a deployment`,
Run: func(cmd *cobra.Command, args []string) {
c := getComposeAPI()
if len(args) == 0 {
log.Fatal("Need a deployment id/name")
}
depid, err := resolveDepID(c, args[0])
if err != nil {
log.Fatal(err)
}
if outputRaw {
text, errs := c.GetLogfilesForDeploymentJSON(depid)
bailOnErrs(errs)
fmt.Println(text)
} else {
logfiles, errs := c.GetLogfilesForDeployment(depid)
bailOnErrs(errs)

if !outputJSON {
for _, logfile := range *logfiles {
fmt.Printf("%15s: %s\n", "Logfile ID", logfile.ID)
fmt.Printf("%15s: %s\n", "Deployment ID", logfile.Deploymentid)
fmt.Printf("%15s: %s\n", "Capsule ID", logfile.Capsuleid)
fmt.Printf("%15s: %s\n", "Logfile Name", logfile.Name)
fmt.Printf("%15s: %s\n", "Status", logfile.Status)
fmt.Println()
}
} else {
printAsJSON(logfiles)
}
}
},
}

func init() {
logfilesCmd.AddCommand(logfilesListCmd)
}
29 changes: 29 additions & 0 deletions cmd/logfiles.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright © 2017 Compose, an IBM Company
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"github.com/spf13/cobra"
)

// RootCmd represents the backups subcommand
var logfilesCmd = &cobra.Command{
Use: "logfiles",
Short: "Commands for Logfiles",
Long: `A selection of subcommands are available for listing and retrieving Logfiles `,
}

func init() {
RootCmd.AddCommand(logfilesCmd)
}

0 comments on commit 89a1c62

Please sign in to comment.