diff --git a/go.mod b/go.mod index 0bb42a2..680d059 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.14 require ( github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect + github.com/carmo-evan/strtotime v0.0.0-20200108203155-3136cf889e3b // indirect github.com/docker/docker v0.0.0-20180805161158-f57f260b49b6 // indirect github.com/docker/machine v0.16.2 github.com/google/go-cmp v0.3.0 // indirect diff --git a/go.sum b/go.sum index 231e0e3..96601d6 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= +github.com/carmo-evan/strtotime v0.0.0-20200108203155-3136cf889e3b h1:U3vQoEOmB8zQ34LR8jQt6XMIdOiq49OZ1aPGjG1fJKE= +github.com/carmo-evan/strtotime v0.0.0-20200108203155-3136cf889e3b/go.mod h1:IqY2NtbgybBNEdxOZLXCF/OAAisAOiB4+F7/ovbQN8M= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= diff --git a/pkg/drivers/metal/metal.go b/pkg/drivers/metal/metal.go index fbff425..090f4a8 100644 --- a/pkg/drivers/metal/metal.go +++ b/pkg/drivers/metal/metal.go @@ -10,6 +10,7 @@ import ( "strings" "time" + "github.com/carmo-evan/strtotime" "github.com/docker/machine/libmachine/drivers" "github.com/docker/machine/libmachine/log" "github.com/docker/machine/libmachine/mcnflag" @@ -173,12 +174,14 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { if TerminationTime == "" { d.TerminationTime = nil } else { - layout := "2006-01-02T15:04:05.000Z" - TerminationTime, err := time.Parse(layout, TerminationTime) + Timestamp, err := strtotime.Parse(TerminationTime, time.Now().Unix()) if err != nil { return err } - d.TerminationTime.Time = TerminationTime + if Timestamp <= time.Now().Unix() { + return fmt.Errorf("--metal-termination-time cannot be in the past") + } + d.TerminationTime = &packngo.Timestamp{Time: time.Unix(Timestamp, 0)} } } @@ -267,6 +270,7 @@ func (d *Driver) Create() error { Tags: d.Tags, SpotInstance: d.SpotInstance, SpotPriceMax: d.SpotPriceMax, + TerminationTime: d.TerminationTime, } log.Info("Provisioning Equinix Metal server...")