Skip to content

Commit

Permalink
Fix termination-time flag and add possibility to use strtotime strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Miouge1 committed Apr 22, 2021
1 parent efe3d51 commit d33ea2c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
10 changes: 7 additions & 3 deletions pkg/drivers/metal/metal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)}
}
}

Expand Down Expand Up @@ -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...")
Expand Down

0 comments on commit d33ea2c

Please sign in to comment.