Skip to content

Commit fcabec2

Browse files
author
Dilshat
authored
Merge pull request #989 from subutai-io/dev
Dev -> Master
2 parents ef6c8a5 + ae9b9e6 commit fcabec2

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/fs/zfs.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
"strconv"
1717
"github.com/pkg/errors"
1818
"github.com/subutai-io/agent/config"
19+
"time"
20+
"fmt"
1921
)
2022

2123
var zfsRootDataset string
@@ -83,7 +85,7 @@ func CreateDataset(dataset string) error {
8385
// Lists snapshots for dataset
8486
// Returns output of `zfs list -t snapshot -r {root}/{dataset}` command
8587
func ListSnapshots(dataset string) (string, error) {
86-
out, err := exec.Execute("zfs", "list", "-t", "snapshot", "-o", "name,creation", "-r", path.Join(zfsRootDataset, dataset))
88+
out, err := exec.Execute("zfs", "list", "-t", "snapshot", "-o", "name,:created", "-r", path.Join(zfsRootDataset, dataset))
8789
if err != nil {
8890
return "", errors.Errorf("Error listing snapshots for %s: %s %s", dataset, out, err.Error())
8991
}
@@ -117,7 +119,7 @@ func RollbackToSnapshot(snapshot string, forceRollback bool) error {
117119
// Creates snapshot
118120
// e.g. CreateSnapshot("foo/rootfs@now")
119121
func CreateSnapshot(snapshot string, recursive bool) error {
120-
args := []string{"snapshot"}
122+
args := []string{"snapshot", "-o", ":created=" + getTimestamp()}
121123
if recursive {
122124
args = append(args, "-r")
123125
}
@@ -273,3 +275,11 @@ func ConvertToBytes(input string) (int, error) {
273275
res := float64(multiplier) * num
274276
return int(res), err
275277
}
278+
279+
func getTimestamp() string {
280+
t := time.Now()
281+
umillisec := t.Nanosecond() / 1000000
282+
return fmt.Sprintf("%d-%02d-%02dT%02d:%02d:%02d.%d",
283+
t.Year(), t.Month(), t.Day(),
284+
t.Hour(), t.Minute(), t.Second(), umillisec)
285+
}

main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/subutai-io/agent/agent/vars"
1515
"text/tabwriter"
1616
"strings"
17+
"github.com/subutai-io/agent/lib/container"
1718
)
1819

1920
var version = "unknown"
@@ -42,6 +43,9 @@ var (
4243
listName = listCmd.Flag("name", "container/template name").Short('n').String()
4344
listParents = listCmd.Flag("parents", "list parents").Short('p').Bool()
4445

46+
existsCmd = app.Command("exists", "Check if container/template exists, exit code 0 - exists, 1 - not found")
47+
existsCmdName = existsCmd.Arg("name", "name of container/template").Required().String()
48+
4549
//attach command
4650
/*
4751
subutai attach foo
@@ -369,6 +373,10 @@ func main() {
369373
cli.LxcList(*listName, false, false, true, *listParents)
370374
case listAll.FullCommand():
371375
cli.LxcList(*listName, true, true, false, *listParents)
376+
case existsCmd.FullCommand():
377+
if !container.LxcInstanceExists(*existsCmdName) {
378+
os.Exit(1)
379+
}
372380
case daemonCmd.FullCommand():
373381
config.InitAgentDebug()
374382
agent.Start()

0 commit comments

Comments
 (0)