Skip to content

Commit

Permalink
Updates name from to in module and tests, goreleaser-- tested and suc…
Browse files Browse the repository at this point in the history
…cessfully provisioned a machine

Signed-off-by: Joseph D. Marhee <jmarhee@interiorae.com>
  • Loading branch information
jmarhee committed Feb 18, 2021
1 parent 5d8ef3c commit 24e8056
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 65 deletions.
4 changes: 2 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ builds:
- env:
- CGO_ENABLED=0
- GO111MODULE=on
binary: docker-machine-driver-packet
binary: docker-machine-driver-equinix-metal
ldflags:
- -X github.com/packethost/docker-machine-driver-packet/pkg/drivers/packet/packet.version={{.Version}}
- -X github.com/packethost/docker-machine-driver-equinix-metal/pkg/drivers/equinix-metal/equinix-metal.version={{.Version}}
goos:
- windows
- darwin
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ containerbuild:
make build

clean:
rm -r docker-machine-driver-packet bin/docker-machine-driver-packet
rm -r docker-machine-driver-equinix-metal bin/docker-machine-driver-equinix-metal

compile:
GO111MODULE=on GOGC=off CGOENABLED=0 go build -ldflags "-s"
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ package main

import (
"github.com/docker/machine/libmachine/drivers/plugin"
packet "github.com/packethost/docker-machine-driver-packet/pkg/drivers/packet"
metal "github.com/packethost/docker-machine-driver-packet/pkg/drivers/equinix-metal"
)

func main() {
plugin.RegisterDriver(new(packet.Driver))
plugin.RegisterDriver(new(metal.Driver))
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: BSD-3-Clause

package packet
package metal

import (
"fmt"
Expand Down Expand Up @@ -53,7 +53,7 @@ type Driver struct {
}

// NewDriver is a backward compatible Driver factory method. Using
// new(packet.Driver) is preferred.
// new(metal.Driver) is preferred.
func NewDriver(hostName, storePath string) *Driver {
return &Driver{
BaseDriver: &drivers.BaseDriver{
Expand All @@ -66,99 +66,99 @@ func NewDriver(hostName, storePath string) *Driver {
func (d *Driver) GetCreateFlags() []mcnflag.Flag {
return []mcnflag.Flag{
mcnflag.StringFlag{
Name: "packet-api-key",
Usage: "Packet api key",
EnvVar: "PACKET_API_KEY",
Name: "metal-api-key",
Usage: "Equinix Metal api key",
EnvVar: "METAL_API_KEY",
},
mcnflag.StringFlag{
Name: "packet-project-id",
Usage: "Packet Project Id",
EnvVar: "PACKET_PROJECT_ID",
Name: "metal-project-id",
Usage: "Equinix Metal Project Id",
EnvVar: "METAL_PROJECT_ID",
},
mcnflag.StringFlag{
Name: "packet-os",
Usage: "Packet OS",
Name: "metal-os",
Usage: "Equinix Metal OS",
Value: "ubuntu_16_04",
EnvVar: "PACKET_OS",
EnvVar: "METAL_OS",
},
mcnflag.StringFlag{
Name: "packet-facility-code",
Usage: "Packet facility code",
Name: "metal-facility-code",
Usage: "Equinix Metal facility code",
Value: "ewr1",
EnvVar: "PACKET_FACILITY_CODE",
EnvVar: "METAL_FACILITY_CODE",
},
mcnflag.StringFlag{
Name: "packet-plan",
Usage: "Packet Server Plan",
Name: "metal-plan",
Usage: "Equinix Metal Server Plan",
Value: "baremetal_0",
EnvVar: "PACKET_PLAN",
EnvVar: "METAL_PLAN",
},
mcnflag.StringFlag{
Name: "packet-hw-reservation-id",
Usage: "Packet Reserved hardware ID",
EnvVar: "PACKET_HW_ID",
Name: "metal-hw-reservation-id",
Usage: "Equinix Metal Reserved hardware ID",
EnvVar: "METAL_HW_ID",
},
mcnflag.StringFlag{
Name: "packet-billing-cycle",
Usage: "Packet billing cycle, hourly or monthly",
Name: "metal-billing-cycle",
Usage: "Equinix Metal billing cycle, hourly or monthly",
Value: "hourly",
EnvVar: "PACKET_BILLING_CYCLE",
EnvVar: "METAL_BILLING_CYCLE",
},
mcnflag.StringFlag{
Name: "packet-userdata",
Name: "metal-userdata",
Usage: "Path to file with cloud-init user-data",
EnvVar: "PACKET_USERDATA",
EnvVar: "METAL_USERDATA",
},
mcnflag.BoolFlag{
Name: "packet-spot-instance",
Usage: "Request a Packet Spot Instance",
EnvVar: "PACKET_SPOT_INSTANCE",
Name: "metal-spot-instance",
Usage: "Request a Equinix Metal Spot Instance",
EnvVar: "METAL_SPOT_INSTANCE",
},
mcnflag.StringFlag{
Name: "packet-spot-price-max",
Usage: "The maximum Packet Spot Price",
EnvVar: "PACKET_SPOT_PRICE_MAX",
Name: "metal-spot-price-max",
Usage: "The maximum Equinix Metal Spot Price",
EnvVar: "METAL_SPOT_PRICE_MAX",
},
mcnflag.StringFlag{
Name: "packet-termination-time",
Usage: "The Packet Instance Termination Time",
EnvVar: "PACKET_TERMINATION_TIME",
Name: "metal-termination-time",
Usage: "The Equinix Metal Instance Termination Time",
EnvVar: "METAL_TERMINATION_TIME",
},
mcnflag.StringFlag{
EnvVar: "PACKET_UA_PREFIX",
Name: "packet-ua-prefix",
Usage: "Prefix the User-Agent in Packet API calls with some 'product/version'",
EnvVar: "METAL_UA_PREFIX",
Name: "metal-ua-prefix",
Usage: "Prefix the User-Agent in Equinix Metal API calls with some 'product/version'",
},
}
}

func (d *Driver) DriverName() string {
return "packet"
return "metal"
}

func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
if strings.Contains(flags.String("packet-os"), "coreos") {
if strings.Contains(flags.String("metal-os"), "coreos") {
d.SSHUser = "core"
}
if strings.Contains(flags.String("packet-os"), "rancher") {
if strings.Contains(flags.String("metal-os"), "rancher") {
d.SSHUser = "rancher"
}

d.ApiKey = flags.String("packet-api-key")
d.ProjectID = flags.String("packet-project-id")
d.OperatingSystem = flags.String("packet-os")
d.Facility = flags.String("packet-facility-code")
d.BillingCycle = flags.String("packet-billing-cycle")
d.UserAgentPrefix = flags.String("packet-ua-prefix")
d.UserDataFile = flags.String("packet-userdata")
d.ApiKey = flags.String("metal-api-key")
d.ProjectID = flags.String("metal-project-id")
d.OperatingSystem = flags.String("metal-os")
d.Facility = flags.String("metal-facility-code")
d.BillingCycle = flags.String("metal-billing-cycle")
d.UserAgentPrefix = flags.String("metal-ua-prefix")
d.UserDataFile = flags.String("metal-userdata")

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

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

if d.SpotInstance {
SpotPriceMax := flags.String("packet-spot-price-max")
SpotPriceMax := flags.String("metal-spot-price-max")
if SpotPriceMax == "" {
d.SpotPriceMax = -1
} else {
Expand All @@ -169,7 +169,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.SpotPriceMax = SpotPriceMax
}

TerminationTime := flags.String("packet-termination-time")
TerminationTime := flags.String("metal-termination-time")
if TerminationTime == "" {
d.TerminationTime = nil
} else {
Expand All @@ -183,10 +183,10 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
}

if d.ApiKey == "" {
return fmt.Errorf("packet driver requires the --packet-api-key option")
return fmt.Errorf("metal driver requires the --metal-api-key option")
}
if d.ProjectID == "" {
return fmt.Errorf("packet driver requires the --packet-project-id option")
return fmt.Errorf("metal driver requires the --metal-project-id option")
}

return nil
Expand All @@ -208,7 +208,7 @@ func (d *Driver) PreCreateCheck() error {
return err
}
if !stringInSlice(d.OperatingSystem, flavors) {
return fmt.Errorf("specified --packet-os not one of %v", strings.Join(flavors, ", "))
return fmt.Errorf("specified --metal-os not one of %v", strings.Join(flavors, ", "))
}

if d.Facility == "any" {
Expand All @@ -226,7 +226,7 @@ func (d *Driver) PreCreateCheck() error {
}
}

return fmt.Errorf("packet requires a valid facility")
return fmt.Errorf("metal requires a valid facility")
}

func (d *Driver) Create() error {
Expand Down Expand Up @@ -269,7 +269,7 @@ func (d *Driver) Create() error {
SpotPriceMax: d.SpotPriceMax,
}

log.Info("Provisioning Packet server...")
log.Info("Provisioning Equinix Metal server...")
newDevice, _, err := client.Devices.Create(createRequest)
if err != nil {
//cleanup ssh keys if device faild
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package packet
package metal

import (
"testing"
Expand All @@ -12,8 +12,8 @@ func TestSetConfigFromFlags(t *testing.T) {

checkFlags := &drivers.CheckDriverOptions{
FlagsValues: map[string]interface{}{
"packet-api-key": "APIKEY",
"packet-project-id": "PROJECT",
"metal-api-key": "APIKEY",
"metal-project-id": "PROJECT",
},
CreateFlags: driver.GetCreateFlags(),
}
Expand Down

0 comments on commit 24e8056

Please sign in to comment.