mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
implement the put api to configure the network section in vapp
This commit is contained in:
parent
4bcc971f39
commit
bd32389a94
3 changed files with 97 additions and 2 deletions
|
@ -267,6 +267,7 @@ module Fog
|
|||
request :put_vapp_template_metadata_item_metadata
|
||||
request :put_vm
|
||||
request :put_vm_capabilities
|
||||
request :put_config_network_section_vapp
|
||||
|
||||
class Model < Fog::Model
|
||||
def initialize(attrs={})
|
||||
|
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in a new issue