Class: Fog::Network::AzureRM::NetworkInterface

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

Overview

NetworkInterface model class for Network Service

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(nic) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/fog/azurerm/models/network/network_interface.rb', line 26

def self.parse(nic)
  hash = {}
  hash['id'] = nic.id
  hash['name'] = nic.name
  hash['location'] = nic.location
  hash['resource_group'] = get_resource_from_resource_id(nic.id, RESOURCE_GROUP_NAME)
  hash['virtual_machine_id'] = nic.virtual_machine.id unless nic.virtual_machine.nil?
  hash['mac_address'] = nic.mac_address unless nic.mac_address.nil?
  hash['network_security_group_id'] = nil
  hash['network_security_group_id'] = nic.network_security_group.id unless nic.network_security_group.nil?
  ip_configuration = nic.ip_configurations[0] unless nic.ip_configurations.nil?
  unless ip_configuration.nil?
    hash['ip_configuration_name'] = ip_configuration.name
    hash['ip_configuration_id'] = ip_configuration.id
    hash['subnet_id'] = ip_configuration.subnet.id unless ip_configuration.subnet.nil?
    hash['private_ip_allocation_method'] = ip_configuration.private_ipallocation_method
    hash['private_ip_address'] = ip_configuration.private_ipaddress
    hash['public_ip_address_id'] = nil
    hash['public_ip_address_id'] = ip_configuration.public_ipaddress.id unless ip_configuration.public_ipaddress.nil?
    hash['load_balancer_backend_address_pools_ids'] = ip_configuration.load_balancer_backend_address_pools.map(&:id) unless ip_configuration.load_balancer_backend_address_pools.nil?
    hash['load_balancer_inbound_nat_rules_ids'] = ip_configuration.load_balancer_inbound_nat_rules.map(&:id) unless ip_configuration.load_balancer_inbound_nat_rules.nil?
  end
  nic_dns_settings = nic.dns_settings
  unless nic_dns_settings.nil?
    hash['dns_servers'] = nic_dns_settings.dns_servers
    hash['applied_dns_servers'] = nic_dns_settings.applied_dns_servers
    hash['internal_dns_name_label'] = nic_dns_settings.internal_dns_name_label
    hash['internal_fqd'] = nic_dns_settings.internal_fqdn
  end
  hash
end

Instance Method Details

#attach_network_security_group(network_security_group_id) ⇒ Object



88
89
90
91
92
# File 'lib/fog/azurerm/models/network/network_interface.rb', line 88

def attach_network_security_group(network_security_group_id)
  raise 'Network-Security-Group ID can not be nil.' if network_security_group_id.nil?
  nic = service.attach_resource_to_nic(resource_group, name, NETWORK_SECURITY_GROUP, network_security_group_id)
  merge_attributes(Fog::Network::AzureRM::NetworkInterface.parse(nic))
end

#attach_public_ip(public_ip_id) ⇒ Object



82
83
84
85
86
# File 'lib/fog/azurerm/models/network/network_interface.rb', line 82

def attach_public_ip(public_ip_id)
  raise 'Public-IP ID can not be nil.' if public_ip_id.nil?
  nic = service.attach_resource_to_nic(resource_group, name, PUBLIC_IP, public_ip_id)
  merge_attributes(Fog::Network::AzureRM::NetworkInterface.parse(nic))
end

#attach_subnet(subnet_id) ⇒ Object



76
77
78
79
80
# File 'lib/fog/azurerm/models/network/network_interface.rb', line 76

def attach_subnet(subnet_id)
  raise 'Subnet ID can not be nil.' if subnet_id.nil?
  nic = service.attach_resource_to_nic(resource_group, name, SUBNET, subnet_id)
  merge_attributes(Fog::Network::AzureRM::NetworkInterface.parse(nic))
end

#destroyObject



106
107
108
# File 'lib/fog/azurerm/models/network/network_interface.rb', line 106

def destroy
  service.delete_network_interface(resource_group, name)
end

#detach_network_security_groupObject



100
101
102
103
104
# File 'lib/fog/azurerm/models/network/network_interface.rb', line 100

def detach_network_security_group
  raise "Error detaching Network Security Group. No Security Group is attached to Network Interface #{name}" if network_security_group_id.nil?
  nic = service.detach_resource_from_nic(resource_group, name, NETWORK_SECURITY_GROUP)
  merge_attributes(Fog::Network::AzureRM::NetworkInterface.parse(nic))
end

#detach_public_ipObject



94
95
96
97
98
# File 'lib/fog/azurerm/models/network/network_interface.rb', line 94

def detach_public_ip
  raise "Error detaching Public IP. No Public IP is attached to Network Interface #{name}" if public_ip_address_id.nil?
  nic = service.detach_resource_from_nic(resource_group, name, PUBLIC_IP)
  merge_attributes(Fog::Network::AzureRM::NetworkInterface.parse(nic))
end

#saveObject



58
59
60
61
62
63
64
65
66
67
# File 'lib/fog/azurerm/models/network/network_interface.rb', line 58

def save
  requires :name
  requires :location
  requires :resource_group
  requires :subnet_id
  requires :ip_configuration_name
  requires :private_ip_allocation_method
  nic = service.create_or_update_network_interface(resource_group, name, location, subnet_id, public_ip_address_id, network_security_group_id, ip_configuration_name, private_ip_allocation_method, private_ip_address, load_balancer_backend_address_pools_ids, load_balancer_inbound_nat_rules_ids)
  merge_attributes(Fog::Network::AzureRM::NetworkInterface.parse(nic))
end

#update(updated_attributes = {}) ⇒ Object



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

def update(updated_attributes = {})
  validate_update_attributes!(updated_attributes)
  merge_attributes(updated_attributes)
  nic = service.create_or_update_network_interface(resource_group, name, location, subnet_id, public_ip_address_id, network_security_group_id, ip_configuration_name, private_ip_allocation_method, private_ip_address)
  merge_attributes(Fog::Network::AzureRM::NetworkInterface.parse(nic))
end

#validate_update_attributes!(hash) ⇒ Object



110
111
112
113
114
115
# File 'lib/fog/azurerm/models/network/network_interface.rb', line 110

def validate_update_attributes!(hash)
  restricted_attributes = [:name, :id, :resource_group, :location, :ip_configuration_name, :ip_configuration_id]
  hash_keys = hash.keys
  invalid_attributes = restricted_attributes & hash_keys
  raise "Attributes #{invalid_attributes.join(', ')} can not be updated." unless invalid_attributes.empty?
end