class Chef::Provider::AzureNetworkInterface

Public Instance Methods

create_network_interface(name, tags, location) click to toggle source
# File lib/chef/provider/azure_network_interface.rb, line 90
def create_network_interface(name, tags, location)
  network_interface = Azure::ARM::Network::Models::NetworkInterface.new
  network_interface.name = name
  network_interface.tags = tags
  network_interface.location = location

  network_interface
end
create_network_interface_dns_settings(dns_servers) click to toggle source
# File lib/chef/provider/azure_network_interface.rb, line 110
def create_network_interface_dns_settings(dns_servers)
  dns_settings = Azure::ARM::Network::Models::NetworkInterfaceDnsSettings.new
  dns_settings.dns_servers = dns_servers
  dns_settings
end
create_network_interface_ip_configuration(ipconfig_name, private_ip_type, private_ip, subnet_ref, public_ip_ref) click to toggle source
# File lib/chef/provider/azure_network_interface.rb, line 116
def create_network_interface_ip_configuration(ipconfig_name, private_ip_type, private_ip, subnet_ref, public_ip_ref)
  ip_config = Azure::ARM::Network::Models::NetworkInterfaceIpConfiguration.new
  ip_config.name = ipconfig_name
  ip_config.properties = Azure::ARM::Network::Models::NetworkInterfaceIpConfigurationPropertiesFormat.new
  ip_config.properties.private_ipallocation_method = private_ip_type if private_ip_type
  ip_config.properties.private_ipaddress = private_ip if private_ip

  if subnet_ref
    ip_config.properties.subnet = Azure::ARM::Network::Models::Subnet.new
    ip_config.properties.subnet.id = subnet_ref
  end

  if public_ip_ref
    ip_config.properties.public_ipaddress = Azure::ARM::Network::Models::PublicIpAddress.new
    ip_config.properties.public_ipaddress.id = public_ip_ref
  end

  ip_config
end
create_network_interface_params() click to toggle source
# File lib/chef/provider/azure_network_interface.rb, line 72
def create_network_interface_params
  network_interface = create_network_interface(new_resource.name, new_resource.tags, new_resource.location)

  new_resource.virtual_network_resource_group(new_resource.resource_group) unless new_resource.virtual_network_resource_group
  subnet_ref = get_subnet_ref(new_resource.virtual_network_resource_group,
                              new_resource.virtual_network, new_resource.subnet)

  if new_resource.public_ip_resource
    public_ip_ref = get_public_ip(new_resource.public_ip_resource.resource_group, new_resource.public_ip_resource.name)
  end

  network_interface.properties = create_network_interface_properties(
    new_resource.name, new_resource.private_ip_allocation_method,
    new_resource.private_ip_address, subnet_ref, new_resource.dns_servers, public_ip_ref)

  network_interface
end
create_network_interface_properties(interface_name, private_ip_type, private_ip, subnet_ref, dns_servers, public_ip_ref) click to toggle source
# File lib/chef/provider/azure_network_interface.rb, line 99
def create_network_interface_properties(interface_name, private_ip_type, private_ip, subnet_ref, dns_servers, public_ip_ref)
  nic_properties = Azure::ARM::Network::Models::NetworkInterfacePropertiesFormat.new

  nic_properties.dns_settings = create_network_interface_dns_settings(dns_servers) if dns_servers

  ip_config = create_network_interface_ip_configuration("#{interface_name}-ipconfig", private_ip_type, private_ip, subnet_ref, public_ip_ref)
  nic_properties.ip_configurations = [ip_config]

  nic_properties
end
create_or_update_network_interface() click to toggle source
# File lib/chef/provider/azure_network_interface.rb, line 64
def create_or_update_network_interface
  network_interface_params = create_network_interface_params
  action_handler.report_progress 'Creating or Updating network interface...'
  try_azure_operation 'Creating or Updating network interface' do
    network_management_client.network_interfaces.create_or_update(new_resource.resource_group, new_resource.name, network_interface_params)
  end
end
destroy_network_interface() click to toggle source
# File lib/chef/provider/azure_network_interface.rb, line 57
def destroy_network_interface
  action_handler.report_progress 'Destroying network interface...'
  try_azure_operation 'destroying network interface' do
    network_management_client.network_interfaces.delete(new_resource.resource_group, new_resource.name)
  end
end
does_network_interface_exist() click to toggle source
# File lib/chef/provider/azure_network_interface.rb, line 46
def does_network_interface_exist
  network_interface_list = try_azure_operation('enumerating network interfaces') do
    network_management_client.network_interfaces.list(new_resource.resource_group)
  end

  network_interface_list.value.each do |network_interface|
    return true if network_interface.name == new_resource.name
  end
  false
end
get_public_ip(resource_group, resource_name) click to toggle source
# File lib/chef/provider/azure_network_interface.rb, line 136
def get_public_ip(resource_group, resource_name)
  result = try_azure_operation('getting public IP') do
    network_management_client.public_ip_addresses.get(resource_group, resource_name)
  end

  public_ip = result
  public_ip.id
end
get_subnet_ref(resource_group_name, vnet_name, subnet_name) click to toggle source
# File lib/chef/provider/azure_network_interface.rb, line 145
def get_subnet_ref(resource_group_name, vnet_name, subnet_name)
  [resource_group_name, vnet_name, subnet_name].each do |v|
    return nil if v.nil? || v.empty?
  end

  result = try_azure_operation('getting subnet') do
    network_management_client.subnets.get(resource_group_name, vnet_name, subnet_name)
  end
  subnet = result

  subnet.id
end
load_current_resource() click to toggle source
# File lib/chef/provider/azure_network_interface.rb, line 39
def load_current_resource
  if new_resource.public_ip_resource
    new_resource.public_ip_resource.location(new_resource.location)
    new_resource.public_ip_resource.resource_group(new_resource.resource_group) unless new_resource.public_ip_resource.resource_group
  end
end
whyrun_supported?() click to toggle source
# File lib/chef/provider/azure_network_interface.rb, line 8
def whyrun_supported?
  true
end