Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make network optionnal for instantiate request #3981

Merged
merged 3 commits into from
Feb 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/fog/vcloud_director/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ class TaskError < Fog::VcloudDirector::Errors::TaskError; end
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={})
Expand Down Expand Up @@ -701,9 +702,9 @@ def data
:name => org_name,
:uuid => uuid
},

:tags => {},

:tasks => {},

:vapps => {
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,29 @@ def populate_uris(options = {})
options
end

def generate_instantiate_vapp_template_request(options ={})
def generate_instantiate_vapp_template_request(options ={})

#overriding some params so they work with new standardised generator
options[:InstantiationParams] =
options[:InstantiationParams] =
{
:NetworkConfig =>
:NetworkConfig =>
[{
:networkName => options[:network_name],
:networkHref => options[:network_uri],
:fenceMode => 'bridged'
}]
} unless options[:InstantiationParams]
} unless options[:InstantiationParams] || !options[:network_uri]
options[:name] = options.delete(:vapp_name) if options[:vapp_name]
options[:Description] = options.delete(:description) unless options[:Description]
if options[:vms_config] then
options[:source_vms] = options.delete(:vms_config)
options[:source_vms].each_with_index {|vm, i|options[:source_vms][i][:StorageProfileHref] = options[:source_vms][i].delete(:storage_profile_href) }
end
options[:Source] = options.delete(:template_uri) if options[:template_uri]







Fog::Generators::Compute::VcloudDirector::InstantiateVappTemplateParams.new(options).generate_xml


Expand Down Expand Up @@ -98,10 +98,10 @@ def endpoint
end_point
end
end

class Mock
# Assume the template is a single VM with one network interface and one disk.
def instantiate_vapp_template(vapp_name, template_id, options={})
def instantiate_vapp_template(vapp_name, template_id, options={})
unless data[:catalog_items].values.find {|i| i[:template_id] == template_id}
raise Fog::Compute::VcloudDirector::Forbidden.new(
'No such template.'
Expand All @@ -112,7 +112,7 @@ def instantiate_vapp_template(vapp_name, template_id, options={})
'No such VDC.'
)
end

vapp_uuid = uuid
vapp_id = "vapp-#{vapp_uuid}"
owner = {
Expand Down
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