Skip to content

Commit 88b9cbe

Browse files
authored
Merge branch 'master' into console-status
2 parents 2be2bac + acc29ff commit 88b9cbe

20 files changed

+471
-12
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Civo CLI is a tool to manage your [Civo.com](https://www.civo.com) account from
3232
- [Teams](#teams)
3333
- [Permissions](#permissions)
3434
- [Region](#region)
35+
- [Resource Snapshots](#resource-snapshots)
3536
- [Enabling shell autocompletion](#enabling-shell-autocompletion)
3637
- [Contributing](#contributing)
3738
- [License](#license)
@@ -2284,6 +2285,35 @@ $ civo permissions ls
22842285
22852286
## Region
22862287
2288+
## Resource Snapshots
2289+
2290+
Resource snapshots allow you to manage snapshots of your resources. You can list, show details, update, delete, and restore snapshots using the following commands:
2291+
2292+
```sh
2293+
# List all resource snapshots
2294+
civo resource-snapshot list
2295+
2296+
# Show details of a specific snapshot
2297+
civo resource-snapshot show SNAPSHOT_ID/NAME
2298+
2299+
# Update a snapshot
2300+
civo resource-snapshot update SNAPSHOT_ID/NAME
2301+
2302+
# Delete a snapshot
2303+
civo resource-snapshot delete SNAPSHOT_ID/NAME
2304+
2305+
# Restore a snapshot
2306+
civo resource-snapshot restore SNAPSHOT_ID/NAME
2307+
```
2308+
2309+
The available fields for custom output format when listing snapshots are:
2310+
- id
2311+
- name
2312+
- description
2313+
- resource_type
2314+
- created_at
2315+
2316+
22872317
As Civo grows, more regions for your instances will become available. You can run `civo region ls` to list the regions available. Block storage (Volumes) is region-specific, so if you configure an instance in one region, any volumes you wish to attach to that instance would have to be in the same region.
22882318
22892319
#### List all region

cmd/instance/instance_create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ If you wish to use a custom format, the available fields are:
330330
}
331331
}
332332

333-
if common.OutputFormat == "human" {
333+
if common.OutputFormat == common.OutputFormatHuman {
334334
if executionTime != "" {
335335
fmt.Printf("The instance %s %s has been created in %s\n", utility.Green(instance.Hostname), publicIP, executionTime)
336336
} else {

cmd/instance/instance_firewall.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ If you wish to use a custom format, the available fields are:
7878
os.Exit(1)
7979
}
8080

81-
if common.OutputFormat == "human" {
82-
fmt.Printf("Set the firewall for the instance %s (%s) to %s (%s)\n", utility.Green(instance.Hostname), instance.ID, utility.Green(firewall.Name), firewall.ID)
81+
if common.OutputFormat == common.OutputFormatHuman {
82+
fmt.Printf("The instance %s (%s) has been assigned to firewall %s (%s)\n", utility.Green(instance.Hostname), instance.ID, utility.Green(firewall.Name), firewall.ID)
8383
} else {
8484
ow := utility.NewOutputWriter()
8585
ow.StartLine()

cmd/instance/instance_move_ip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ If you wish to use a custom format, the available fields are:
7070
os.Exit(1)
7171
}
7272

73-
if common.OutputFormat == "human" {
73+
if common.OutputFormat == common.OutputFormatHuman {
7474
fmt.Printf("Moved the IP %s to the instance %s (%s)\n", utility.Green(args[1]), utility.Green(instance.Hostname), instance.ID)
7575
} else {
7676
ow := utility.NewOutputWriter()

cmd/instance/instance_password.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ If you wish to use a custom format, the available fields are:
4141
os.Exit(1)
4242
}
4343

44-
if common.OutputFormat == "human" {
44+
if common.OutputFormat == common.OutputFormatHuman {
4545
fmt.Printf("The instance %s (%s) has the password %s (and user %s)\n", utility.Green(instance.Hostname), instance.ID, utility.Green(instance.InitialPassword), utility.Green(instance.InitialUser))
4646
} else {
4747
ow := utility.NewOutputWriter()

cmd/instance/instance_reboot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ If you wish to use a custom format, the available fields are:
4545
os.Exit(1)
4646
}
4747

48-
if common.OutputFormat == "human" {
48+
if common.OutputFormat == common.OutputFormatHuman {
4949
fmt.Printf("The instance %s (%s) is being rebooted\n", utility.Green(instance.Hostname), instance.ID)
5050
} else {
5151
ow := utility.NewOutputWriter()

cmd/instance/instance_soft_reboot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ If you wish to use a custom format, the available fields are:
4545
os.Exit(1)
4646
}
4747

48-
if common.OutputFormat == "human" {
48+
if common.OutputFormat == common.OutputFormatHuman {
4949
fmt.Printf("The instance %s (%s) is being soft-rebooted\n", utility.Green(instance.Hostname), instance.ID)
5050
} else {
5151
ow := utility.NewOutputWriter()

cmd/instance/instance_start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ If you wish to use a custom format, the available fields are:
4646
os.Exit(1)
4747
}
4848

49-
if common.OutputFormat == "human" {
49+
if common.OutputFormat == common.OutputFormatHuman {
5050
fmt.Printf("The instance %s (%s) is being started\n", utility.Green(instance.Hostname), instance.ID)
5151
} else {
5252
ow := utility.NewOutputWriter()

cmd/instance/instance_stop.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ If you wish to use a custom format, the available fields are:
7070
}
7171
}
7272

73-
if common.OutputFormat == "human" {
73+
if common.OutputFormat == common.OutputFormatHuman {
7474
fmt.Printf("The instance %s (%s) is being stopped\n", utility.Green(instance.Hostname), instance.ID)
7575
} else {
7676
ow := utility.NewOutputWriter()

cmd/instance/instance_tag.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ If you wish to use a custom format, the available fields are:
5151
os.Exit(1)
5252
}
5353

54-
if common.OutputFormat == "human" {
54+
if common.OutputFormat == common.OutputFormatHuman {
5555
fmt.Printf("The instance %s (%s) has been tagged with '%s'\n", utility.Green(instance.Hostname), instance.ID, utility.Green(tags))
5656
} else {
5757
ow := utility.NewOutputWriter()

cmd/instance/instance_update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ If you wish to use a custom format, the available fields are:
6060
os.Exit(1)
6161
}
6262

63-
if common.OutputFormat == "human" {
63+
if common.OutputFormat == common.OutputFormatHuman {
6464
fmt.Printf("The instance %s (%s) has been updated\n", utility.Green(instance.Hostname), instance.ID)
6565
} else {
6666
ow := utility.NewOutputWriter()

cmd/instance/instance_upgrade.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ If you wish to use a custom format, the available fields are:
7272
os.Exit(1)
7373
}
7474

75-
if common.OutputFormat == "human" {
75+
if common.OutputFormat == common.OutputFormatHuman {
7676
fmt.Printf("The instance %s (%s) is being upgraded to %s\n", utility.Green(instance.Hostname), instance.ID, utility.Green(args[1]))
7777
} else {
7878
ow := utility.NewOutputWriter()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package resourcesnapshot
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
)
6+
7+
// ResourceSnapshotCmd represents the resource-snapshot command
8+
var ResourceSnapshotCmd = &cobra.Command{
9+
Use: "resource-snapshot",
10+
Aliases: []string{"resourcesnapshot", "resource-snapshots", "resourcesnapshots"},
11+
Short: "Manage resource snapshots",
12+
Long: `List, update and delete resource snapshots`,
13+
}
14+
15+
func init() {
16+
ResourceSnapshotCmd.AddCommand(resourceSnapshotListCmd)
17+
ResourceSnapshotCmd.AddCommand(resourceSnapshotShowCmd)
18+
ResourceSnapshotCmd.AddCommand(resourceSnapshotUpdateCmd)
19+
ResourceSnapshotCmd.AddCommand(resourceSnapshotDeleteCmd)
20+
ResourceSnapshotCmd.AddCommand(resourceSnapshotRestoreCmd)
21+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package resourcesnapshot
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/civo/cli/common"
8+
"github.com/civo/cli/config"
9+
"github.com/civo/cli/utility"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
var resourceSnapshotDeleteCmd = &cobra.Command{
14+
Use: "delete ID/NAME",
15+
Args: cobra.MinimumNArgs(1),
16+
Aliases: []string{"rm", "remove"},
17+
Short: "Delete a resource snapshot",
18+
Long: `Delete a resource snapshot by ID or name.`,
19+
Run: func(cmd *cobra.Command, args []string) {
20+
utility.EnsureCurrentRegion()
21+
22+
client, err := config.CivoAPIClient()
23+
if common.RegionSet != "" {
24+
client.Region = common.RegionSet
25+
}
26+
if err != nil {
27+
utility.Error("Creating the connection to Civo's API failed with %s", err)
28+
os.Exit(1)
29+
}
30+
31+
// Get the snapshot first to verify it exists and to show the name in output
32+
snapshot, err := client.GetResourceSnapshot(args[0])
33+
if err != nil {
34+
utility.Error("Error retrieving resource snapshot: %s", err)
35+
os.Exit(1)
36+
}
37+
38+
// Delete the snapshot
39+
_, err = client.DeleteResourceSnapshot(snapshot.ID)
40+
if err != nil {
41+
utility.Error("Error deleting resource snapshot: %s", err)
42+
os.Exit(1)
43+
}
44+
45+
if common.OutputFormat == common.OutputFormatHuman {
46+
fmt.Printf("The resource snapshot %s (%s) has been deleted\n", utility.Green(snapshot.Name), snapshot.ID)
47+
} else {
48+
ow := utility.NewOutputWriter()
49+
ow.StartLine()
50+
ow.AppendDataWithLabel("id", snapshot.ID, "ID")
51+
ow.AppendDataWithLabel("name", snapshot.Name, "Name")
52+
if common.OutputFormat == "json" {
53+
ow.WriteSingleObjectJSON(common.PrettySet)
54+
} else {
55+
ow.WriteCustomOutput(common.OutputFields)
56+
}
57+
}
58+
},
59+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package resourcesnapshot
2+
3+
import (
4+
"os"
5+
"time"
6+
7+
"github.com/civo/cli/common"
8+
"github.com/civo/cli/config"
9+
"github.com/civo/cli/utility"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
var resourceSnapshotListCmd = &cobra.Command{
14+
Use: "list",
15+
Aliases: []string{"ls"},
16+
Short: "List all resource snapshots",
17+
Long: `List all resource snapshots currently available in your account.
18+
If you wish to use a custom format, the available fields are:
19+
20+
* id
21+
* name
22+
* description
23+
* resource_type
24+
* created_at`,
25+
Run: func(cmd *cobra.Command, args []string) {
26+
utility.EnsureCurrentRegion()
27+
28+
client, err := config.CivoAPIClient()
29+
if common.RegionSet != "" {
30+
client.Region = common.RegionSet
31+
}
32+
if err != nil {
33+
utility.Error("Creating the connection to Civo's API failed with %s", err)
34+
os.Exit(1)
35+
}
36+
37+
snapshots, err := client.ListResourceSnapshots()
38+
if err != nil {
39+
utility.Error("Error listing resource snapshots: %s", err)
40+
os.Exit(1)
41+
}
42+
43+
ow := utility.NewOutputWriter()
44+
45+
for _, snapshot := range snapshots {
46+
ow.StartLine()
47+
48+
ow.AppendDataWithLabel("id", snapshot.ID, "ID")
49+
ow.AppendDataWithLabel("name", snapshot.Name, "Name")
50+
ow.AppendDataWithLabel("description", snapshot.Description, "Description")
51+
ow.AppendDataWithLabel("resource_type", snapshot.ResourceType, "Resource Type")
52+
ow.AppendDataWithLabel("created_at", snapshot.CreatedAt.Format(time.RFC1123), "Created At")
53+
}
54+
55+
switch common.OutputFormat {
56+
case common.OutputFormatJSON:
57+
ow.WriteMultipleObjectsJSON(common.PrettySet)
58+
case common.OutputFormatCustom:
59+
ow.WriteCustomOutput(common.OutputFields)
60+
case common.OutputFormatHuman:
61+
ow.WriteTable()
62+
default:
63+
ow.WriteTable()
64+
}
65+
},
66+
}

0 commit comments

Comments
 (0)