-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3981 from tinguelyp/master
make network optionnal for instantiate request
- Loading branch information
Showing
4 changed files
with
108 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
lib/fog/vcloud_director/generators/compute/network_config_section.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
module Fog | ||
module Generators | ||
module Compute | ||
module VcloudDirector | ||
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/types/NetworkConfigSectionType.html | ||
class NetworkConfigSection | ||
attr_reader :options | ||
|
||
def initialize(options={}) | ||
@options = options | ||
end | ||
|
||
def generate_xml | ||
body = Nokogiri::XML::Builder.new do |xml| | ||
attrs = { | ||
:xmlns => 'http://www.vmware.com/vcloud/v1.5', | ||
'xmlns:ovf' => 'http://schemas.dmtf.org/ovf/envelope/1' | ||
} | ||
xml.NetworkConfigSection(attrs){ | ||
xml['ovf'].Info | ||
options[:NetworkConfig].each do |network_config| | ||
network_name = {networkName: network_config[:networkName]} if network_config[:networkName] | ||
xml.NetworkConfig(network_name){ | ||
xml.Description network_config[:Description] | ||
if configuration = network_config[:Configuration] | ||
xml.Configuration { | ||
if ipScopes = configuration[:IpScopes] | ||
xml.IpScopes { | ||
if ipScope = ipScopes[:IpScope] | ||
xml.IpScope { | ||
xml.IsInherited ipScope[:IsInherited] | ||
xml.Gateway ipScope[:Gateway] | ||
xml.Netmask ipScope[:Netmask] | ||
xml.Dns1 ipScope[:Dns1] if ipScope[:Dns1] | ||
xml.Dns2 ipScope[:Dns2] if ipScope[:Dns2] | ||
xml.IsEnabled ipScope[:IsEnabled] if ipScope[:IsEnabled] | ||
if ipRanges = ipScope[:IpRanges] | ||
xml.IpRanges { | ||
if ipRange = ipRanges[:IpRange] | ||
xml.IpRange { | ||
xml.StartAddress ipRange[:StartAddress] | ||
xml.EndAddress ipRange[:EndAddress] | ||
} | ||
end | ||
} | ||
end | ||
} | ||
end | ||
} | ||
end | ||
if parent_network = configuration[:ParentNetwork] | ||
xml.ParentNetwork({href: parent_network[:href], id: parent_network[:id], name: parent_network[:name]}) | ||
end | ||
xml.FenceMode configuration[:FenceMode] if configuration[:FenceMode] | ||
xml.RetainNetInfoAcrossDeployments configuration[:RetainNetInfoAcrossDeployments] if configuration[:RetainNetInfoAcrossDeployments] | ||
} | ||
end #Configuraton | ||
xml.IsDeployed configuration[:IsDeployed] if configuration[:IsDeployed] | ||
} | ||
end | ||
} | ||
end.to_xml | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
lib/fog/vcloud_director/requests/compute/put_config_network_section_vapp.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Fog | ||
module Compute | ||
class VcloudDirector | ||
class Real | ||
require 'fog/vcloud_director/generators/compute/network_config_section' | ||
# Update the network config section of a vApp. | ||
# | ||
# | ||
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/PUT-NetworkConfigSection-vApp.html | ||
# @since vCloud API version 0.9 | ||
def put_config_network_section_vapp(id, options={}) | ||
body = Fog::Generators::Compute::VcloudDirector::NetworkConfigSection.new(options).generate_xml | ||
|
||
request( | ||
:body => body, | ||
:expects => 202, | ||
:headers => {'Content-Type' => 'application/vnd.vmware.vcloud.networkConfigSection+xml'}, | ||
:method => 'PUT', | ||
:parser => Fog::ToHashDocument.new, | ||
:path => "vApp/#{id}/networkConfigSection" | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |