forked from coop-cloud/abra
WIP make a start on the hetzner command
This commit is contained in:
parent
9d621404fd
commit
d74b7636a1
2
TODO.md
2
TODO.md
|
@ -10,7 +10,7 @@
|
|||
- [x] `add`
|
||||
- [ ] `new`
|
||||
- [ ] `capsul`
|
||||
- [ ] `hetzner`
|
||||
- [ ] `hetzner` (XXX: in progress (decentral1se))
|
||||
- [x] `rm`
|
||||
- [x] `init`
|
||||
- [ ] `abra app`
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"coopcloud.tech/abra/config"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/hetznercloud/hcloud-go/hcloud"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
@ -77,12 +78,101 @@ var serverAddCommand = &cli.Command{
|
|||
},
|
||||
}
|
||||
|
||||
var HetznerCloudType string
|
||||
var HetznerCloudImage string
|
||||
var HetznerCloudSSHKeys cli.StringSlice
|
||||
var HetznerCloudLocation string
|
||||
var HetznerCloudAPIToken string
|
||||
var serverNewHetznerCloudCommand = &cli.Command{
|
||||
Name: "hetzner",
|
||||
Usage: "Create a new Hetzner virtual server",
|
||||
ArgsUsage: "<name>",
|
||||
Description: `
|
||||
Create a new Hetzner virtual server.
|
||||
|
||||
This command uses the uses the Hetzner Cloud API bindings to send a server
|
||||
creation request. You must already have a Hetzner Cloud account and an account
|
||||
API token before using this command.
|
||||
|
||||
Your token can be loaded from the environment using the HCLOUD_API_TOKEN
|
||||
environment variable or otherwise passing the "--env/-e" flag.
|
||||
`,
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "type",
|
||||
Aliases: []string{"t"},
|
||||
Usage: "Server type",
|
||||
Destination: &HetznerCloudType,
|
||||
Value: "cx11",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "image",
|
||||
Aliases: []string{"i"},
|
||||
Usage: "Image type",
|
||||
Value: "debian-10",
|
||||
Destination: &HetznerCloudImage,
|
||||
},
|
||||
&cli.StringSliceFlag{
|
||||
Name: "ssh-keys",
|
||||
Aliases: []string{"s"},
|
||||
Usage: "SSH keys",
|
||||
Destination: &HetznerCloudSSHKeys,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "location",
|
||||
Aliases: []string{"l"},
|
||||
Usage: "Server location",
|
||||
Value: "hel1",
|
||||
Destination: &HetznerCloudLocation,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "token",
|
||||
Aliases: []string{"T"},
|
||||
Usage: "Hetzner Cloud API token",
|
||||
EnvVars: []string{"HCLOUD_API_TOKEN"},
|
||||
Destination: &HetznerCloudAPIToken,
|
||||
},
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
name := c.Args().First()
|
||||
if name == "" {
|
||||
cli.ShowSubcommandHelp(c)
|
||||
return nil
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
client := hcloud.NewClient(hcloud.WithToken(HetznerCloudAPIToken))
|
||||
|
||||
// var sshkeys []hcloud.SSHKey
|
||||
// for _, sshkey := range HetznerCloudSSHKeys {
|
||||
// sshkeys = append(sshkeys, hcloud.SSHKey{Name: sshkey})
|
||||
// }
|
||||
|
||||
// TODO: finish passing arguments
|
||||
serverOpts := hcloud.ServerCreateOpts{
|
||||
Name: name,
|
||||
ServerType: &hcloud.ServerType{Name: HetznerCloudType},
|
||||
Image: &hcloud.Image{Name: HetznerCloudImage},
|
||||
// SSHKeys: HetznerCloudSSHKeys,
|
||||
// Location: HetznerCloudLocation,
|
||||
}
|
||||
_, _, err := client.Server.Create(ctx, serverOpts)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var serverNewCommand = &cli.Command{
|
||||
Name: "new",
|
||||
Usage: "Create a new server using a 3rd party provider",
|
||||
Description: "Use a provider plugin to create a new server which can then be used to house a new Co-op Cloud installation.",
|
||||
ArgsUsage: "<provider>",
|
||||
HideHelp: true,
|
||||
Subcommands: []*cli.Command{
|
||||
serverNewHetznerCloudCommand,
|
||||
},
|
||||
}
|
||||
|
||||
var serverRemoveCommand = &cli.Command{
|
||||
|
|
1
go.mod
1
go.mod
|
@ -12,6 +12,7 @@ require (
|
|||
github.com/docker/go-units v0.4.0
|
||||
github.com/fvbommel/sortorder v1.0.2 // indirect
|
||||
github.com/go-git/go-git/v5 v5.4.2
|
||||
github.com/hetznercloud/hcloud-go v1.28.0 // indirect
|
||||
github.com/moby/sys/mount v0.2.0 // indirect
|
||||
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6
|
||||
github.com/morikuni/aec v1.0.0 // indirect
|
||||
|
|
2
go.sum
2
go.sum
|
@ -431,6 +431,8 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
|
|||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||
github.com/hetznercloud/hcloud-go v1.28.0 h1:T2a0CVGETf7BoWIdZ/TACqmTZAa/ROutcfdUHYiPAQ4=
|
||||
github.com/hetznercloud/hcloud-go v1.28.0/go.mod h1:2C5uMtBiMoFr3m7lBFPf7wXTdh33CevmZpQIIDPGYJI=
|
||||
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174 h1:WlZsjVhE8Af9IcZDGgJGQpNflI3+MJSBhsgT5PCtzBQ=
|
||||
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
|
|
Loading…
Reference in New Issue