Class: Fog::Network::AzureRM::NetworkSecurityGroup

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/azurerm/models/network/network_security_group.rb

Overview

Network Security Group model for Network Service

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(nsg) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fog/azurerm/models/network/network_security_group.rb', line 16

def self.parse(nsg)
  hash = {}
  hash['id'] = nsg.id
  hash['name'] = nsg.name
  hash['resource_group'] = get_resource_from_resource_id(nsg.id, RESOURCE_GROUP_NAME)
  hash['location'] = nsg.location
  hash['network_interfaces_ids'] = nsg.network_interfaces.map(&:id) unless nsg.network_interfaces.nil?
  hash['subnets_ids'] = nsg.subnets.map(&:id) unless nsg.subnets.nil?
  hash['security_rules'] = []
  hash['default_security_rules'] = []
  hash['tags'] = nsg.tags

  nsg.security_rules.each do |sr|
    security_rule = Fog::Network::AzureRM::NetworkSecurityRule.new
    hash['security_rules'] << security_rule.merge_attributes(Fog::Network::AzureRM::NetworkSecurityRule.parse(sr))
  end unless nsg.security_rules.nil?

  nsg.default_security_rules.each do |dsr|
    security_rule = Fog::Network::AzureRM::NetworkSecurityRule.new
    hash['default_security_rules'] << security_rule.merge_attributes(Fog::Network::AzureRM::NetworkSecurityRule.parse(dsr))
  end

  hash
end

Instance Method Details

#add_security_rules(security_rules) ⇒ Object



65
66
67
68
69
# File 'lib/fog/azurerm/models/network/network_security_group.rb', line 65

def add_security_rules(security_rules)
  validate_security_rules(security_rules)
  nsg = service.add_security_rules(resource_group, name, security_rules)
  merge_attributes(Fog::Network::AzureRM::NetworkSecurityGroup.parse(nsg))
end

#destroyObject



49
50
51
# File 'lib/fog/azurerm/models/network/network_security_group.rb', line 49

def destroy
  service.delete_network_security_group(resource_group, name)
end

#remove_security_rule(security_rule_name) ⇒ Object



71
72
73
74
# File 'lib/fog/azurerm/models/network/network_security_group.rb', line 71

def remove_security_rule(security_rule_name)
  nsg = service.remove_security_rule(resource_group, name, security_rule_name)
  merge_attributes(Fog::Network::AzureRM::NetworkSecurityGroup.parse(nsg))
end

#saveObject



41
42
43
44
45
46
47
# File 'lib/fog/azurerm/models/network/network_security_group.rb', line 41

def save
  requires :name, :location, :resource_group

  validate_security_rules(security_rules) unless security_rules.nil?
  nsg = service.create_or_update_network_security_group(resource_group, name, location, security_rules, tags)
  merge_attributes(Fog::Network::AzureRM::NetworkSecurityGroup.parse(nsg))
end

#update_security_rules(security_rule_hash = {}) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/fog/azurerm/models/network/network_security_group.rb', line 53

def update_security_rules(security_rule_hash = {})
  raise('Provided hash can not be empty.') if security_rule_hash.empty? || security_rule_hash.nil?

  if !security_rule_hash[:security_rules].nil? && security_rule_hash.length == 1
    validate_security_rules(security_rule_hash[:security_rules])
    merge_attributes(security_rule_hash)
    nsg = service.create_or_update_network_security_group(resource_group, name, location, security_rules, tags)
    return merge_attributes(Fog::Network::AzureRM::NetworkSecurityGroup.parse(nsg))
  end
  raise 'Invalid hash key.'
end