class Fog::Network::AzureRM::NetworkInterface

NetworkInterface model class for Network Service

Public Class Methods

parse(nic) click to toggle source
# File lib/fog/azurerm/models/network/network_interface.rb, line 27
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?
  hash['tags'] = nic.tags
  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

Public Instance Methods

attach_network_security_group(network_security_group_id) click to toggle source
# File lib/fog/azurerm/models/network/network_interface.rb, line 90
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) click to toggle source
# File lib/fog/azurerm/models/network/network_interface.rb, line 84
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) click to toggle source
# File lib/fog/azurerm/models/network/network_interface.rb, line 78
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
destroy() click to toggle source
# File lib/fog/azurerm/models/network/network_interface.rb, line 108
def destroy
  service.delete_network_interface(resource_group, name)
end
detach_network_security_group() click to toggle source
# File lib/fog/azurerm/models/network/network_interface.rb, line 102
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_ip() click to toggle source
# File lib/fog/azurerm/models/network/network_interface.rb, line 96
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
save() click to toggle source
# File lib/fog/azurerm/models/network/network_interface.rb, line 60
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, tags)
  merge_attributes(Fog::Network::AzureRM::NetworkInterface.parse(nic))
end
update(updated_attributes = {}) click to toggle source
# File lib/fog/azurerm/models/network/network_interface.rb, line 71
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) click to toggle source
# File lib/fog/azurerm/models/network/network_interface.rb, line 112
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