package server import ( "context" "github.com/hetznercloud/hcloud-go/hcloud" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) 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: "", 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 == "" { return cli.ShowSubcommandHelp(c) } 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: "", Subcommands: []*cli.Command{ serverNewHetznerCloudCommand, }, }