Class: Chef::Provider::AzureVirtualNetwork

Inherits:
Chef::Provisioning::AzureRM::AzureProvider show all
Defined in:
lib/chef/provider/azure_virtual_network.rb

Instance Method Summary collapse

Methods inherited from Chef::Provisioning::AzureRM::AzureProvider

#action_handler, #compute_management_client, #network_management_client, #resource_management_client, #storage_management_client, #try_azure_operation

Instance Method Details

#create_or_update_virtual_networkObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/chef/provider/azure_virtual_network.rb', line 55

def create_or_update_virtual_network
  virtual_network = Azure::ARM::Network::Models::VirtualNetwork.new

  virtual_network.tags = new_resource.tags
  virtual_network.location = new_resource.location

  virtual_network.properties = create_virtual_network_properties(
    new_resource.address_prefixes, new_resource.subnets, new_resource.dns_servers)

  action_handler.report_progress 'Creating or Updating Virtual Network...'

  try_azure_operation('creating or updating network interface') do
    network_management_client.virtual_networks.create_or_update(new_resource.resource_group, new_resource.name, virtual_network)
  end
end

#create_subnet(subnet_name, subnet_address) ⇒ Object



90
91
92
93
94
95
96
97
# File 'lib/chef/provider/azure_virtual_network.rb', line 90

def create_subnet(subnet_name, subnet_address)
  subnet = Azure::ARM::Network::Models::Subnet.new
  subnet.name = subnet_name
  subnet.properties = Azure::ARM::Network::Models::SubnetPropertiesFormat.new
  subnet.properties.address_prefix = subnet_address

  subnet
end

#create_virtual_network_properties(address_prefixes, subnets, dns_servers) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/chef/provider/azure_virtual_network.rb', line 71

def create_virtual_network_properties(address_prefixes, subnets, dns_servers)
  props = Azure::ARM::Network::Models::VirtualNetworkPropertiesFormat.new

  props.address_space = Azure::ARM::Network::Models::AddressSpace.new
  props.address_space.address_prefixes = address_prefixes

  if dns_servers
    props.dhcp_options = Azure::ARM::Network::Models::DhcpOptions.new
    props.dhcp_options.dns_servers = dns_servers
  end

  props.subnets = []
  subnets.each do |subnet|
    props.subnets.push(create_subnet(subnet[:name], subnet[:address_prefix]))
  end

  props
end

#destroy_virtual_networkObject



48
49
50
51
52
53
# File 'lib/chef/provider/azure_virtual_network.rb', line 48

def destroy_virtual_network
  action_handler.report_progress 'Destroying Virtual Network...'
  try_azure_operation('destroying virtual network') do
    network_management_client.virtual_networks.delete(new_resource.resource_group, new_resource.name)
  end
end

#does_virtual_network_existObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/chef/provider/azure_virtual_network.rb', line 37

def does_virtual_network_exist
  virtual_network_list = try_azure_operation('listing virtual networks') do
    network_management_client.virtual_networks.list(new_resource.resource_group)
  end

  virtual_network_list.value.each do |virtual_network|
    return true if virtual_network.name == new_resource.name
  end
  false
end

#whyrun_supported?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/chef/provider/azure_virtual_network.rb', line 8

def whyrun_supported?
  true
end