Skip to content

Commit 2567201

Browse files
Merge pull request docker-archive-public#3194 from ahmetalpbalkan/azure-static-ip
azure: Add --azure-static-public-ip flag
2 parents 3e1aaca + b898c07 commit 2567201

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

docs/drivers/azure.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Optional:
5858
- `--azure-private-ip-address`: Specify a static private IP address for the machine.
5959
- `--azure-use-private-ip`: Use private IP address of the machine to connect.
6060
- `--azure-no-public-ip`: Do not create a public IP address for the machine.
61+
- `--azure-static-public-ip`: Assign a static public IP address to the machine.
6162
- `--azure-docker-port`: Port number for Docker engine [$AZURE_DOCKER_PORT]
6263
- `--azure-environment`: Azure environment (e.g. `AzurePublicCloud`, `AzureChinaCloud`).
6364

@@ -86,6 +87,7 @@ Environment variables and default values:
8687
| `--azure-private-ip-address` | - | - |
8788
| `--azure-use-private-ip` | - | - |
8889
| `--azure-no-public-ip` | - | - |
90+
| `--azure-static-public-ip` | - | - |
8991
| `--azure-docker-port` | `AZURE_DOCKER_PORT` | `2376` |
9092

9193
## Notes

drivers/azure/azure.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const (
4646
flAzurePorts = "azure-open-port"
4747
flAzurePrivateIPAddr = "azure-private-ip-address"
4848
flAzureUsePrivateIP = "azure-use-private-ip"
49+
flAzureStaticPublicIP = "azure-static-public-ip"
4950
flAzureNoPublicIP = "azure-no-public-ip"
5051
)
5152

@@ -71,10 +72,11 @@ type Driver struct {
7172
SubnetPrefix string
7273
AvailabilitySet string
7374

74-
OpenPorts []string
75-
PrivateIPAddr string
76-
UsePrivateIP bool
77-
NoPublicIP bool
75+
OpenPorts []string
76+
PrivateIPAddr string
77+
UsePrivateIP bool
78+
NoPublicIP bool
79+
StaticPublicIP bool
7880

7981
// Ephemeral fields
8082
ctx *azureutil.DeploymentContext
@@ -183,6 +185,10 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
183185
Name: flAzureNoPublicIP,
184186
Usage: "Do not create a public IP address for the machine",
185187
},
188+
mcnflag.BoolFlag{
189+
Name: flAzureStaticPublicIP,
190+
Usage: "Assign a static public IP address to the machine",
191+
},
186192
mcnflag.StringSliceFlag{
187193
Name: flAzurePorts,
188194
Usage: "Make the specified port number accessible from the Internet",
@@ -225,6 +231,7 @@ func (d *Driver) SetConfigFromFlags(fl drivers.DriverOptions) error {
225231
d.PrivateIPAddr = fl.String(flAzurePrivateIPAddr)
226232
d.UsePrivateIP = fl.Bool(flAzureUsePrivateIP)
227233
d.NoPublicIP = fl.Bool(flAzureNoPublicIP)
234+
d.StaticPublicIP = fl.Bool(flAzureStaticPublicIP)
228235
d.DockerPort = fl.Int(flAzureDockerPort)
229236

230237
// Set flags on the BaseDriver
@@ -307,7 +314,7 @@ func (d *Driver) Create() error {
307314
if d.NoPublicIP {
308315
log.Info("Not creating a public IP address.")
309316
} else {
310-
if err := c.CreatePublicIPAddress(d.ctx, d.ResourceGroup, d.naming().IP(), d.Location); err != nil {
317+
if err := c.CreatePublicIPAddress(d.ctx, d.ResourceGroup, d.naming().IP(), d.Location, d.StaticPublicIP); err != nil {
311318
return err
312319
}
313320
}

drivers/azure/azureutil/azureutil.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,23 @@ func (a AzureClient) DeleteNetworkSecurityGroupIfExists(resourceGroup, name stri
142142
func() (autorest.Response, error) { return a.securityGroupsClient().Delete(resourceGroup, name) })
143143
}
144144

145-
func (a AzureClient) CreatePublicIPAddress(ctx *DeploymentContext, resourceGroup, name, location string) error {
146-
log.Info("Creating public IP address...", logutil.Fields{"name": name})
145+
func (a AzureClient) CreatePublicIPAddress(ctx *DeploymentContext, resourceGroup, name, location string, isStatic bool) error {
146+
log.Info("Creating public IP address...", logutil.Fields{
147+
"name": name,
148+
"static": isStatic})
149+
150+
var ipType network.IPAllocationMethod
151+
if isStatic {
152+
ipType = network.Static
153+
} else {
154+
ipType = network.Dynamic
155+
}
156+
147157
_, err := a.publicIPAddressClient().CreateOrUpdate(resourceGroup, name,
148158
network.PublicIPAddress{
149159
Location: to.StringPtr(location),
150160
Properties: &network.PublicIPAddressPropertiesFormat{
151-
PublicIPAllocationMethod: network.Dynamic,
161+
PublicIPAllocationMethod: ipType,
152162
},
153163
})
154164
if err != nil {

0 commit comments

Comments
 (0)