Skip to content

Commit

Permalink
Merge pull request #42 from TheAntColony/master
Browse files Browse the repository at this point in the history
Add Hardware reservation argument
  • Loading branch information
jasmingacic authored Feb 24, 2020
2 parents d6f0d5a + 923b80f commit 5158b10
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
bin/docker-machine-driver-*
checksums
.idea/

8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.2.1] - 2020-02-24
### Added
- Hardware reservation string argument to specift either an ID or 'next-available'

## [0.2.0] - 2019-08-26
### Added
- Replaced dependencies with go modules.
- Several fixes and tweaks.

## [0.1.5] - 2017-11-07
### Added
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
default: build

version := v0.1.5
version := v0.2.1
version_description := "Docker Machine Driver Plugin to Provision on Packet"
human_name := "$(version) - Docker Machine v0.8.2+"
version := "$(version)"
Expand Down
64 changes: 39 additions & 25 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,22 @@ var _ drivers.Driver = &Driver{}

type Driver struct {
*drivers.BaseDriver
ApiKey string
ProjectID string
Plan string
Facility string
OperatingSystem string
BillingCycle string
DeviceID string
UserData string
Tags []string
CaCertPath string
SSHKeyID string
UserDataFile string
SpotInstance bool
SpotPriceMax float64
TerminationTime *packngo.Timestamp
ApiKey string
ProjectID string
Plan string
HardwareReserverationID string
Facility string
OperatingSystem string
BillingCycle string
DeviceID string
UserData string
Tags []string
CaCertPath string
SSHKeyID string
UserDataFile string
SpotInstance bool
SpotPriceMax float64
TerminationTime *packngo.Timestamp
}

// NewDriver is a backward compatible Driver factory method. Using
Expand Down Expand Up @@ -85,6 +86,11 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Value: "baremetal_0",
EnvVar: "PACKET_PLAN",
},
mcnflag.StringFlag{
Name: "packet-hw-reservation-id",
Usage: "Packet Reserved hardware ID",
EnvVar: "PACKET_HW_ID",
},
mcnflag.StringFlag{
Name: "packet-billing-cycle",
Usage: "Packet billing cycle, hourly or monthly",
Expand Down Expand Up @@ -134,6 +140,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.UserDataFile = flags.String("packet-userdata")

d.Plan = flags.String("packet-plan")
d.HardwareReserverationID = flags.String("packet-hw-reservation-id")

d.SpotInstance = flags.Bool("packet-spot-instance")

Expand Down Expand Up @@ -228,18 +235,25 @@ func (d *Driver) Create() error {

d.SSHKeyID = key.ID

hardwareReservationId := ""
//check if hardware reservation requested
if d.HardwareReserverationID != "" {
hardwareReservationId = d.HardwareReserverationID
}

client := d.getClient()
createRequest := &packngo.DeviceCreateRequest{
Hostname: d.MachineName,
Plan: d.Plan,
Facility: d.Facility,
OS: d.OperatingSystem,
BillingCycle: d.BillingCycle,
ProjectID: d.ProjectID,
UserData: userdata,
Tags: d.Tags,
SpotInstance: d.SpotInstance,
SpotPriceMax: -1,
Hostname: d.MachineName,
Plan: d.Plan,
HardwareReservationID: hardwareReservationId,
Facility: d.Facility,
OS: d.OperatingSystem,
BillingCycle: d.BillingCycle,
ProjectID: d.ProjectID,
UserData: userdata,
Tags: d.Tags,
SpotInstance: d.SpotInstance,
SpotPriceMax: -1,
}

log.Info("Provisioning Packet server...")
Expand Down

0 comments on commit 5158b10

Please sign in to comment.