Class: Fog::Network::AzureRM::VirtualNetwork

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

Overview

This class is giving implementation of create/save and delete/destroy for virtual network.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(vnet) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fog/azurerm/models/network/virtual_network.rb', line 16

def self.parse(vnet)
  hash = {}
  hash['id'] = vnet.id
  hash['name'] = vnet.name
  hash['resource_group'] = get_resource_group_from_id(vnet.id)
  hash['location'] = vnet.location
  hash['dns_servers'] = vnet.dhcp_options.dns_servers unless vnet.dhcp_options.nil?
  hash['address_prefixes'] = vnet.address_space.address_prefixes unless vnet.address_space.address_prefixes.nil?
  hash['tags'] = vnet.tags

  subnets = []
  vnet.subnets.each do |subnet|
    subnet_object = Fog::Network::AzureRM::Subnet.new
    subnets.push(subnet_object.merge_attributes(Fog::Network::AzureRM::Subnet.parse(subnet)))
  end
  hash['subnets'] = subnets
  hash
end

Instance Method Details

#add_address_prefixes(address_prefixes_list) ⇒ Object



55
56
57
58
# File 'lib/fog/azurerm/models/network/virtual_network.rb', line 55

def add_address_prefixes(address_prefixes_list)
  virtual_network = service.add_address_prefixes_in_virtual_network(resource_group, name, address_prefixes_list)
  merge_attributes(Fog::Network::AzureRM::VirtualNetwork.parse(virtual_network))
end

#add_dns_servers(dns_servers_list) ⇒ Object



45
46
47
48
# File 'lib/fog/azurerm/models/network/virtual_network.rb', line 45

def add_dns_servers(dns_servers_list)
  virtual_network = service.add_dns_servers_in_virtual_network(resource_group, name, dns_servers_list)
  merge_attributes(Fog::Network::AzureRM::VirtualNetwork.parse(virtual_network))
end

#add_subnets(subnets_list) ⇒ Object



65
66
67
68
69
# File 'lib/fog/azurerm/models/network/virtual_network.rb', line 65

def add_subnets(subnets_list)
  validate_subnets!(subnets_list)
  virtual_network = service.add_subnets_in_virtual_network(resource_group, name, subnets_list)
  merge_attributes(Fog::Network::AzureRM::VirtualNetwork.parse(virtual_network))
end

#destroyObject



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

def destroy
  service.delete_virtual_network(resource_group, name)
end

#remove_address_prefixes(address_prefixes_list) ⇒ Object



60
61
62
63
# File 'lib/fog/azurerm/models/network/virtual_network.rb', line 60

def remove_address_prefixes(address_prefixes_list)
  virtual_network = service.remove_address_prefixes_from_virtual_network(resource_group, name, address_prefixes_list)
  merge_attributes(Fog::Network::AzureRM::VirtualNetwork.parse(virtual_network))
end

#remove_dns_servers(dns_servers_list) ⇒ Object



50
51
52
53
# File 'lib/fog/azurerm/models/network/virtual_network.rb', line 50

def remove_dns_servers(dns_servers_list)
  virtual_network = service.remove_dns_servers_from_virtual_network(resource_group, name, dns_servers_list)
  merge_attributes(Fog::Network::AzureRM::VirtualNetwork.parse(virtual_network))
end

#remove_subnets(subnet_names_list) ⇒ Object



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

def remove_subnets(subnet_names_list)
  virtual_network = service.remove_subnets_from_virtual_network(resource_group, name, subnet_names_list)
  merge_attributes(Fog::Network::AzureRM::VirtualNetwork.parse(virtual_network))
end

#saveObject



35
36
37
38
39
40
41
42
43
# File 'lib/fog/azurerm/models/network/virtual_network.rb', line 35

def save
  requires :name
  requires :location
  requires :resource_group
  validate_subnets!(subnets) unless subnets.nil?

  virtual_network = service.create_or_update_virtual_network(resource_group, name, location, dns_servers, subnets, address_prefixes, tags)
  merge_attributes(Fog::Network::AzureRM::VirtualNetwork.parse(virtual_network))
end

#update(vnet_hash) ⇒ Object



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

def update(vnet_hash)
  raise('Provided hash can not be empty.') if vnet_hash.empty? || vnet_hash.nil?
  validate_update_attributes!(vnet_hash)
  merge_attributes(vnet_hash)
  virtual_network = service.create_or_update_virtual_network(resource_group, name, location, dns_servers, subnets, address_prefixes, tags)
  merge_attributes(Fog::Network::AzureRM::VirtualNetwork.parse(virtual_network))
end