Class: Chef::Provider::AzureNetworkInterface
Instance Method Summary
collapse
-
#create_network_interface(name, tags, location) ⇒ Object
-
#create_network_interface_dns_settings(dns_servers) ⇒ Object
-
#create_network_interface_ip_configuration(ipconfig_name, private_ip_type, private_ip, subnet_ref, public_ip_ref) ⇒ Object
-
#create_network_interface_params ⇒ Object
-
#create_network_interface_properties(interface_name, private_ip_type, private_ip, subnet_ref, dns_servers, public_ip_ref) ⇒ Object
-
#create_or_update_network_interface ⇒ Object
-
#destroy_network_interface ⇒ Object
-
#does_network_interface_exist ⇒ Object
-
#get_public_ip(resource_group, resource_name) ⇒ Object
-
#get_subnet_ref(resource_group_name, vnet_name, subnet_name) ⇒ Object
-
#load_current_resource ⇒ Object
-
#whyrun_supported? ⇒ Boolean
#action_handler, #compute_management_client, #network_management_client, #resource_management_client, #resource_manager_endpoint_url, #storage_management_client, #try_azure_operation
Instance Method Details
#create_network_interface(name, tags, location) ⇒ Object
90
91
92
93
94
95
96
97
|
# 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) ⇒ Object
110
111
112
113
114
|
# 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) ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# 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 ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# 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) ⇒ Object
99
100
101
102
103
104
105
106
107
108
|
# 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 ⇒ Object
64
65
66
67
68
69
70
|
# 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 ⇒ Object
57
58
59
60
61
62
|
# 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 ⇒ Object
46
47
48
49
50
51
52
53
54
55
|
# 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) ⇒ Object
136
137
138
139
140
141
142
143
|
# 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) ⇒ Object
145
146
147
148
149
150
151
152
153
154
155
156
|
# 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 ⇒ Object
39
40
41
42
43
44
|
# 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? ⇒ Boolean
8
9
10
|
# File 'lib/chef/provider/azure_network_interface.rb', line 8
def whyrun_supported?
true
end
|