Skip to content
Snippets Groups Projects
Unverified Commit d88c82a6 authored by Jonas Stoehr's avatar Jonas Stoehr Committed by GitHub
Browse files

Merge pull request #60 from fnkr/firewalls

Add support for firewalls
parents 85653447 786c54db
No related branches found
No related tags found
No related merge requests found
MIT License MIT License
Copyright (c) 2017-2020 The docker-machine-driver-hetzner team Copyright (c) 2017-2021 The docker-machine-driver-hetzner team
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
......
...@@ -103,6 +103,7 @@ $ docker-machine create \ ...@@ -103,6 +103,7 @@ $ docker-machine create \
- `--hetzner-volumes`: Volume IDs or names which should be attached to the server - `--hetzner-volumes`: Volume IDs or names which should be attached to the server
- `--hetzner-networks`: Network IDs or names which should be attached to the server private network interface - `--hetzner-networks`: Network IDs or names which should be attached to the server private network interface
- `--hetzner-use-private-network`: Use private network - `--hetzner-use-private-network`: Use private network
- `--hetzner-firewalls`: Firewall IDs or names which should be applied on the server
- `--hetzner-server-label`: `key=value` pairs of additional metadata to assign to the server. - `--hetzner-server-label`: `key=value` pairs of additional metadata to assign to the server.
#### Existing SSH keys #### Existing SSH keys
...@@ -134,6 +135,7 @@ was used during creation. ...@@ -134,6 +135,7 @@ was used during creation.
| `--hetzner-additional-key` | `HETZNER_ADDITIONAL_KEYS` | - | | `--hetzner-additional-key` | `HETZNER_ADDITIONAL_KEYS` | - |
| `--hetzner-user-data` | `HETZNER_USER_DATA` | - | | `--hetzner-user-data` | `HETZNER_USER_DATA` | - |
| `--hetzner-networks` | `HETZNER_NETWORKS` | - | | `--hetzner-networks` | `HETZNER_NETWORKS` | - |
| `--hetzner-firewalls` | `HETZNER_FIREWALLS` | - |
| `--hetzner-volumes` | `HETZNER_VOLUMES` | - | | `--hetzner-volumes` | `HETZNER_VOLUMES` | - |
| `--hetzner-use-private-network` | `HETZNER_USE_PRIVATE_NETWORK` | false | | `--hetzner-use-private-network` | `HETZNER_USE_PRIVATE_NETWORK` | false |
| `--hetzner-server-label` | `HETZNER_SERVER_LABELS` | `[]` | | `--hetzner-server-label` | `HETZNER_SERVER_LABELS` | `[]` |
......
...@@ -41,6 +41,7 @@ type Driver struct { ...@@ -41,6 +41,7 @@ type Driver struct {
volumes []string volumes []string
networks []string networks []string
UsePrivateNetwork bool UsePrivateNetwork bool
firewalls []string
cachedServer *hcloud.Server cachedServer *hcloud.Server
serverLabels map[string]string serverLabels map[string]string
...@@ -64,6 +65,7 @@ const ( ...@@ -64,6 +65,7 @@ const (
flagVolumes = "hetzner-volumes" flagVolumes = "hetzner-volumes"
flagNetworks = "hetzner-networks" flagNetworks = "hetzner-networks"
flagUsePrivateNetwork = "hetzner-use-private-network" flagUsePrivateNetwork = "hetzner-use-private-network"
flagFirewalls = "hetzner-firewalls"
flagAdditionalKeys = "hetzner-additional-key" flagAdditionalKeys = "hetzner-additional-key"
flagServerLabel = "hetzner-server-label" flagServerLabel = "hetzner-server-label"
) )
...@@ -151,6 +153,12 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag { ...@@ -151,6 +153,12 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Name: flagUsePrivateNetwork, Name: flagUsePrivateNetwork,
Usage: "Use private network", Usage: "Use private network",
}, },
mcnflag.StringSliceFlag{
EnvVar: "HETZNER_FIREWALLS",
Name: flagFirewalls,
Usage: "Firewall IDs or names which should be applied on the server",
Value: []string{},
},
mcnflag.StringSliceFlag{ mcnflag.StringSliceFlag{
EnvVar: "HETZNER_ADDITIONAL_KEYS", EnvVar: "HETZNER_ADDITIONAL_KEYS",
Name: flagAdditionalKeys, Name: flagAdditionalKeys,
...@@ -179,6 +187,7 @@ func (d *Driver) SetConfigFromFlags(opts drivers.DriverOptions) error { ...@@ -179,6 +187,7 @@ func (d *Driver) SetConfigFromFlags(opts drivers.DriverOptions) error {
d.volumes = opts.StringSlice(flagVolumes) d.volumes = opts.StringSlice(flagVolumes)
d.networks = opts.StringSlice(flagNetworks) d.networks = opts.StringSlice(flagNetworks)
d.UsePrivateNetwork = opts.Bool(flagUsePrivateNetwork) d.UsePrivateNetwork = opts.Bool(flagUsePrivateNetwork)
d.firewalls = opts.StringSlice(flagFirewalls)
d.additionalKeys = opts.StringSlice(flagAdditionalKeys) d.additionalKeys = opts.StringSlice(flagAdditionalKeys)
err := d.setLabelsFromFlags(opts) err := d.setLabelsFromFlags(opts)
...@@ -327,6 +336,7 @@ func (d *Driver) Create() error { ...@@ -327,6 +336,7 @@ func (d *Driver) Create() error {
UserData: d.userData, UserData: d.userData,
Labels: d.serverLabels, Labels: d.serverLabels,
} }
networks := []*hcloud.Network{} networks := []*hcloud.Network{}
for _, networkIDorName := range d.networks { for _, networkIDorName := range d.networks {
network, _, err := d.getClient().Network.Get(context.Background(), networkIDorName) network, _, err := d.getClient().Network.Get(context.Background(), networkIDorName)
...@@ -340,6 +350,19 @@ func (d *Driver) Create() error { ...@@ -340,6 +350,19 @@ func (d *Driver) Create() error {
} }
srvopts.Networks = networks srvopts.Networks = networks
firewalls := []*hcloud.ServerCreateFirewall{}
for _, firewallIDorName := range d.firewalls {
firewall, _, err := d.getClient().Firewall.Get(context.Background(), firewallIDorName)
if err != nil {
return errors.Wrap(err, "could not get firewall by ID or name")
}
if firewall == nil {
return errors.Errorf("firewall '%s' not found", firewallIDorName)
}
firewalls = append(firewalls, &hcloud.ServerCreateFirewall{Firewall: *firewall})
}
srvopts.Firewalls = firewalls
volumes := []*hcloud.Volume{} volumes := []*hcloud.Volume{}
for _, volumeIDorName := range d.volumes { for _, volumeIDorName := range d.volumes {
volume, _, err := d.getClient().Volume.Get(context.Background(), volumeIDorName) volume, _, err := d.getClient().Volume.Get(context.Background(), volumeIDorName)
......
...@@ -6,8 +6,7 @@ require ( ...@@ -6,8 +6,7 @@ require (
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/docker/docker v0.0.0-20181018193557-f7e5154f37a4 // indirect github.com/docker/docker v0.0.0-20181018193557-f7e5154f37a4 // indirect
github.com/docker/machine v0.16.2 github.com/docker/machine v0.16.2
github.com/google/go-cmp v0.3.0 // indirect github.com/hetznercloud/hcloud-go v1.24.0
github.com/hetznercloud/hcloud-go v1.17.0
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/pkg/errors v0.8.1 github.com/pkg/errors v0.8.1
github.com/sirupsen/logrus v1.4.2 // indirect github.com/sirupsen/logrus v1.4.2 // indirect
......
...@@ -11,10 +11,13 @@ github.com/docker/machine v0.16.2 h1:jyF9k3Zg+oIGxxSdYKPScyj3HqFZ6FjgA/3sblcASiU ...@@ -11,10 +11,13 @@ github.com/docker/machine v0.16.2 h1:jyF9k3Zg+oIGxxSdYKPScyj3HqFZ6FjgA/3sblcASiU
github.com/docker/machine v0.16.2/go.mod h1:I8mPNDeK1uH+JTcUU7X0ZW8KiYz0jyAgNaeSJ1rCfDI= github.com/docker/machine v0.16.2/go.mod h1:I8mPNDeK1uH+JTcUU7X0ZW8KiYz0jyAgNaeSJ1rCfDI=
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/hetznercloud/hcloud-go v1.14.0 h1:6IdF0Vox/6j1pyEdUCbFPIzEH/K9xZZzVuSFro8Y2vw= github.com/hetznercloud/hcloud-go v1.14.0 h1:6IdF0Vox/6j1pyEdUCbFPIzEH/K9xZZzVuSFro8Y2vw=
github.com/hetznercloud/hcloud-go v1.14.0/go.mod h1:8lR3yHBHZWy2uGcUi9Ibt4UOoop2wrVdERJgCtxsF3Q= github.com/hetznercloud/hcloud-go v1.14.0/go.mod h1:8lR3yHBHZWy2uGcUi9Ibt4UOoop2wrVdERJgCtxsF3Q=
github.com/hetznercloud/hcloud-go v1.17.0 h1:IKH0GLLoTEfgMuBY+GaaVTwjYChecrHFVo4/t0sIkGU= github.com/hetznercloud/hcloud-go v1.17.0 h1:IKH0GLLoTEfgMuBY+GaaVTwjYChecrHFVo4/t0sIkGU=
github.com/hetznercloud/hcloud-go v1.17.0/go.mod h1:8lR3yHBHZWy2uGcUi9Ibt4UOoop2wrVdERJgCtxsF3Q= github.com/hetznercloud/hcloud-go v1.17.0/go.mod h1:8lR3yHBHZWy2uGcUi9Ibt4UOoop2wrVdERJgCtxsF3Q=
github.com/hetznercloud/hcloud-go v1.24.0 h1:/CeHDzhH3Fhm83pjxvE3xNNLbvACl0Lu1/auJ83gG5U=
github.com/hetznercloud/hcloud-go v1.24.0/go.mod h1:3YmyK8yaZZ48syie6xpm3dt26rtB6s65AisBHylXYFA=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
...@@ -41,5 +44,6 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w ...@@ -41,5 +44,6 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k= golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k=
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment