lib/fog/azurerm/requests/network/remove_security_rule.rb in fog-azure-rm-0.0.4 vs lib/fog/azurerm/requests/network/remove_security_rule.rb in fog-azure-rm-0.0.5
- old
+ new
@@ -2,25 +2,25 @@
module Network
class AzureRM
# Real class for Network Request
class Real
def remove_security_rule(resource_group_name, security_group_name, security_rule_name)
- Fog::Logger.debug "Deleting security rule #{security_rule_name} from Network Security Group #{security_group_name}."
- promise = @network_client.network_security_groups.get(resource_group_name, security_group_name)
- result = promise.value!
- nsg = result.body
- updated_security_rule_list = remove_security_rule_from_list(nsg.properties.security_rules, security_rule_name)
- nsg.properties.security_rules = updated_security_rule_list
+ msg = "Deleting security rule #{security_rule_name} from Network Security Group #{security_group_name}."
+ Fog::Logger.debug msg
+
+ nsg = @network_client.network_security_groups.get(resource_group_name, security_group_name)
+ updated_security_rule_list = remove_security_rule_from_list(nsg.security_rules, security_rule_name)
+ nsg.security_rules = updated_security_rule_list
+
begin
- promise = @network_client.network_security_groups.begin_create_or_update(resource_group_name, security_group_name, nsg)
- result = promise.value!
- Fog::Logger.debug "Security Rule #{security_rule_name} deleted from Network Security Group #{security_group_name} successfully!"
- Azure::ARM::Network::Models::NetworkSecurityGroup.serialize_object(result.body)
+ nsg = @network_client.network_security_groups.begin_create_or_update(resource_group_name, security_group_name, nsg)
rescue MsRestAzure::AzureOperationError => e
- msg = "Exception in deleting Security Rule #{security_rule_name} from Network Security Group #{security_group_name} . #{e.body['error']['message']}"
- raise msg
+ raise_azure_exception(e, msg)
end
+
+ Fog::Logger.debug "Security Rule #{security_rule_name} deleted from Network Security Group #{security_group_name} successfully!"
+ nsg
end
def remove_security_rule_from_list(security_rule_list, rule_name)
unless security_rule_list.nil?
return security_rule_list.select { |sr| sr.name != rule_name }
@@ -29,11 +29,11 @@
end
# Mock class for Network Request
class Mock
def remove_security_rule(resource_group_name, security_group_name, _security_rule_name)
- {
+ network_security_group = {
'id' => "/subscriptions/########-####-####-####-############/resourceGroups/#{resource_group_name}/providers/Microsoft.Network/networkSecurityGroups/#{name}",
'name' => security_group_name,
'type' => 'Microsoft.Network/networkSecurityGroups',
'location' => 'location',
'properties' =>
@@ -146,9 +146,11 @@
],
'resourceGuid' => '9dca97e6-4789-4ebd-86e3-52b8b0da6cd4',
'provisioningState' => 'Updating'
}
}
+ nsg_mapper = Azure::ARM::Network::Models::NetworkSecurityGroup.mapper
+ @network_client.deserialize(nsg_mapper, network_security_group, 'result.body')
end
end
end
end
end