Permalink
Browse files

Fix #4244

Signed-off-by: Mario Kleinsasser <mario.kleinsasser@gmail.com>

Change fmt

Signed-off-by: Mario Kleinsasser <mario.kleinsasser@gmail.com>

Correct lint

Signed-off-by: Mario Kleinsasser <mario.kleinsasser@gmail.com>

Change the subnet check logic

Signed-off-by: Mario Kleinsasser <mario.kleinsasser@gmail.com>
  • Loading branch information...
m4r10k authored and shin- committed Sep 6, 2017
1 parent 295730c commit 83812d4275e984d13ffbb54675839f50e84dc992
Showing with 30 additions and 13 deletions.
  1. +30 −13 drivers/azure/azureutil/azureutil.go
@@ -232,23 +232,40 @@ func (a AzureClient) GetSubnet(resourceGroup, virtualNetwork, name string) (netw
return a.subnetsClient().Get(resourceGroup, virtualNetwork, name, "")
}
// CreateSubnet creates or updates a subnet if it does not already exist.
func (a AzureClient) CreateSubnet(ctx *DeploymentContext, resourceGroup, virtualNetwork, name, subnetPrefix string) error {
log.Info("Configuring subnet.", logutil.Fields{
"name": name,
"vnet": virtualNetwork,
"cidr": subnetPrefix})
_, err := a.subnetsClient().CreateOrUpdate(resourceGroup, virtualNetwork, name,
network.Subnet{
Properties: &network.SubnetPropertiesFormat{
AddressPrefix: to.StringPtr(subnetPrefix),
},
}, nil)
if err != nil {
subnet, err := a.GetSubnet(resourceGroup, virtualNetwork, name)
if err == nil {
log.Info("Subnet already exists.")
ctx.SubnetID = to.String(subnet.ID)
return err
}
subnet, err := a.subnetsClient().Get(resourceGroup, virtualNetwork, name, "")
ctx.SubnetID = to.String(subnet.ID)
// If the subnet is not found, create it
if err.(autorest.DetailedError).StatusCode == 404 {
log.Info("Configuring subnet.", logutil.Fields{
"name": name,
"vnet": virtualNetwork,
"cidr": subnetPrefix})
_, err = a.subnetsClient().CreateOrUpdate(resourceGroup, virtualNetwork, name,
network.Subnet{
Properties: &network.SubnetPropertiesFormat{
AddressPrefix: to.StringPtr(subnetPrefix),
},
}, nil)
if err != nil {
return err
}
subnet, err = a.subnetsClient().Get(resourceGroup, virtualNetwork, name, "")
ctx.SubnetID = to.String(subnet.ID)
return err
}
log.Warn("Create subnet operation error %v: ", err)
return err
}
// CleanupSubnetIfExists removes a subnet if there are no IP configurations

0 comments on commit 83812d4

Please sign in to comment.