Skip to content

Commit

Permalink
Add packet as provider
Browse files Browse the repository at this point in the history
This commit adds packet.com as a provisioner which is already
available in the upstream package, but wasn't exposed via flags
or code. Tested e2e with the ewr1 region including create and
delete.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Nov 10, 2019
1 parent c3afdbb commit 59ba2a6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
26 changes: 22 additions & 4 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

func init() {
inletsCmd.AddCommand(createCmd)
createCmd.Flags().StringP("provider", "p", "digitalocean", "The cloud provider - digitalocean, scaleway, or civo")
createCmd.Flags().StringP("provider", "p", "digitalocean", "The cloud provider - digitalocean, packet, scaleway, or civo")
createCmd.Flags().StringP("region", "r", "lon1", "The region for your cloud provider")

createCmd.Flags().StringP("inlets-token", "t", "", "The inlets auth token for your exit node")
Expand All @@ -30,6 +30,7 @@ func init() {
createCmd.Flags().String("secret-key", "", "The access token for your cloud (Scaleway)")
createCmd.Flags().String("secret-key-file", "", "Read this file for the access token for your cloud (Scaleway)")
createCmd.Flags().String("organisation-id", "", "Organisation ID (Scaleway)")
createCmd.Flags().String("project-id", "", "Project ID (Packet.com)")

createCmd.Flags().StringP("remote-tcp", "c", "", `Remote host for inlets-pro to use for forwarding TCP connections`)

Expand Down Expand Up @@ -92,6 +93,8 @@ func runCreate(cmd *cobra.Command, _ []string) error {

} else if provider == "scaleway" {
region = "fr-par-1"
} else if provider == "packet" {
region = "ams1"
}

var secretKey string
Expand Down Expand Up @@ -124,7 +127,9 @@ func runCreate(cmd *cobra.Command, _ []string) error {

userData := makeUserdata(inletsToken, inletsControlPort, remoteTCP)

hostReq, err := createHost(provider, name, region, userData)
projectID, _ := cmd.Flags().GetString("project-id")

hostReq, err := createHost(provider, name, region, projectID, userData)
if err != nil {
return err
}
Expand Down Expand Up @@ -201,6 +206,8 @@ Command:
func getProvisioner(provider, accessToken, secretKey, organisationID, region string) (provision.Provisioner, error) {
if provider == "digitalocean" {
return provision.NewDigitalOceanProvisioner(accessToken)
} else if provider == "packet" {
return provision.NewPacketProvisioner(accessToken)
} else if provider == "civo" {
return pkg.NewCivoProvisioner(accessToken)
} else if provider == "scaleway" {
Expand All @@ -214,7 +221,7 @@ func generateAuth() (string, error) {
return pwdRes, pwdErr
}

func createHost(provider, name, region, userData string) (*provision.BasicHost, error) {
func createHost(provider, name, region, projectID, userData string) (*provision.BasicHost, error) {
if provider == "digitalocean" {
return &provision.BasicHost{
Name: name,
Expand All @@ -224,6 +231,17 @@ func createHost(provider, name, region, userData string) (*provision.BasicHost,
UserData: userData,
Additional: map[string]string{},
}, nil
} else if provider == "packet" {
return &provision.BasicHost{
Name: name,
OS: "ubuntu_16_04",
Plan: "t1.small.x86",
Region: region,
UserData: userData,
Additional: map[string]string{
"project_id": projectID,
},
}, nil
} else if provider == "scaleway" {
return &provision.BasicHost{
Name: name,
Expand All @@ -244,7 +262,7 @@ func createHost(provider, name, region, userData string) (*provision.BasicHost,
}, nil
}

return nil, fmt.Errorf("no provisioner for provider: %s", provider)
return nil, fmt.Errorf("no provisioner for provider: %q", provider)
}

func makeUserdata(authToken string, inletsControlPort int, remoteTCP string) string {
Expand Down
1 change: 0 additions & 1 deletion cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func init() {
deleteCmd.Flags().String("secret-key", "", "The access token for your cloud (Scaleway)")
deleteCmd.Flags().String("secret-key-file", "", "Read this file for the access token for your cloud (Scaleway)")
deleteCmd.Flags().String("organisation-id", "", "Organisation ID (Scaleway)")

}

// clientCmd represents the client sub command.
Expand Down
2 changes: 2 additions & 0 deletions vendor/github.com/packethost/packngo/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 59ba2a6

Please sign in to comment.