Class: Azure::Vnet
- Inherits:
-
Object
- Object
- Azure::Vnet
- Defined in:
- lib/azure/service_management/vnet.rb
Instance Attribute Summary collapse
-
#affinity_group ⇒ Object
Returns the value of attribute affinity_group.
-
#name ⇒ Object
Returns the value of attribute name.
-
#state ⇒ Object
Returns the value of attribute state.
Instance Method Summary collapse
- #create(params) ⇒ Object
-
#initialize(connection) ⇒ Vnet
constructor
A new instance of Vnet.
- #parse(image) ⇒ Object
Constructor Details
#initialize(connection) ⇒ Vnet
Returns a new instance of Vnet.
60 61 62 |
# File 'lib/azure/service_management/vnet.rb', line 60 def initialize(connection) @connection = connection end |
Instance Attribute Details
#affinity_group ⇒ Object
Returns the value of attribute affinity_group.
58 59 60 |
# File 'lib/azure/service_management/vnet.rb', line 58 def affinity_group @affinity_group end |
#name ⇒ Object
Returns the value of attribute name.
58 59 60 |
# File 'lib/azure/service_management/vnet.rb', line 58 def name @name end |
#state ⇒ Object
Returns the value of attribute state.
58 59 60 |
# File 'lib/azure/service_management/vnet.rb', line 58 def state @state end |
Instance Method Details
#create(params) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/azure/service_management/vnet.rb', line 71 def create(params) response = @connection.query_azure("networking/media") if response.at_css("Error") && response.at_css("Code").text == "ResourceNotFound" builder = Nokogiri::XML::Builder.new do |xml| xml.NetworkConfiguration( "xmlns" => "http://schemas.microsoft.com/ServiceHosting/2011/07/NetworkConfiguration" ) do xml.VirtualNetworkConfiguration do xml.VirtualNetworkSites do xml.VirtualNetworkSite("name" => params[:azure_vnet_name], "AffinityGroup" => params[:azure_ag_name]) do if params[:azure_address_space] xml.AddressSpace do xml.AddressPrefix params[:azure_address_space] end end xml.Subnets do xml.Subnet("name" => params[:azure_subnet_name]) do xml.AddressPrefix params[:azure_address_space] end end end end end end end puts("Creating New Virtual Network: #{params[:azure_vnet_name]}...") response = builder else vnets = response.css("VirtualNetworkSite") vnet = nil vnets.each { |vn| vnet = vn if vn["name"] == params[:azure_vnet_name] } add = vnet.nil? vnet = Nokogiri::XML::Node.new("VirtualNetworkSite", response) if add vnet["name"] = params[:azure_vnet_name] vnet["AffinityGroup"] = params[:azure_ag_name] if add || !vnet.at_css("AddressSpace") ## create a new AddressSpace block in XML if VNet or AddressSpace block does not already exist addr_space = Nokogiri::XML::Node.new("AddressSpace", response) else ## retrieve object of existing AddressSpace if VNet or AddressSpace already exist addr_space = vnet.at_css("AddressSpace") end addr_prefix = Nokogiri::XML::Node.new("AddressPrefix", response) addr_prefix.content = params[:azure_address_space] if add || !vnet.at_css("Subnets") ## create a new Subnets block in XML if VNet or Subnets block does not already exist subnets = Nokogiri::XML::Node.new("Subnets", response) else ## retrieve object of existing Subnets if VNet or Subnets already exist subnets = vnet.at_css("Subnets") end saddr_prefix = Nokogiri::XML::Node.new("AddressPrefix", response) saddr_prefix.content = params[:azure_address_space] subnet = Nokogiri::XML::Node.new("Subnet", response) subnet["name"] = params[:azure_subnet_name] subnet.children = saddr_prefix subnets.children = subnet vnet.add_child(subnets) if add || !vnet.at_css("Subnets") addr_space.children = addr_prefix vnet.add_child(addr_space) if add || !vnet.at_css("AddressSpace") vnets.last.add_next_sibling(vnet) if add puts("Updating existing Virtual Network: #{params[:azure_vnet_name]}...") end @connection.query_azure("networking/media", "put", response.to_xml) end |
#parse(image) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/azure/service_management/vnet.rb', line 64 def parse(image) @name = image.at_css("Name").content @affinity_group = image.at_css("AffinityGroup") ? image.at_css("AffinityGroup").content : "" @state = image.at_css("State").content self end |