forked from fog/fog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added instantiate_vapp_template_params generator
- Loading branch information
Tim Lawrence
committed
Mar 11, 2016
1 parent
989aadb
commit d44ec12
Showing
8 changed files
with
235 additions
and
38 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
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
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
30 changes: 30 additions & 0 deletions
30
lib/fog/vcloud_director/generators/compute/instantiate_vapp_template_params.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,30 @@ | ||
require 'fog/vcloud_director/generators/compute/compose_common' | ||
|
||
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/VAppType.html | ||
class InstantiateVappTemplateParams | ||
attr_reader :options | ||
|
||
include ComposeCommon | ||
|
||
def generate_xml | ||
Nokogiri::XML::Builder.new do |xml| | ||
|
||
|
||
xml.InstantiateVAppTemplateParams((vapp_attrs)) { | ||
build_vapp_instantiation_params(xml) | ||
build_source_template(xml) | ||
build_source_items(xml) | ||
} | ||
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
30 changes: 30 additions & 0 deletions
30
spec/vcloud_director/fixtures/instantiate_vapp_template_params_full.xml
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,30 @@ | ||
<InstantiateVAppTemplateParams xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="VAPP_NAME" xml:lang="en"> | ||
<Description>MY VAPP</Description> | ||
<InstantiationParams> | ||
<NetworkConfigSection> | ||
<ovf:Info></ovf:Info> | ||
<NetworkConfig networkName="NETWORK"> | ||
<Configuration> | ||
<ParentNetwork href="http://vcloud/api/network/123456789"/> | ||
<FenceMode>bridged</FenceMode> | ||
</Configuration> | ||
</NetworkConfig> | ||
</NetworkConfigSection> | ||
</InstantiationParams> | ||
<Source href="http://vcloud/api/vapptemplate/123456789"/> | ||
<SourcedItem> | ||
<Source href="http://vcloud/api/vm/12345"/> | ||
<VmGeneralParams> | ||
<Name>VM1</Name> | ||
</VmGeneralParams> | ||
<StorageProfile href="http://vcloud/storage/123456789"/> | ||
</SourcedItem> | ||
<SourcedItem> | ||
<Source href="http://vcloud/api/vm/12345"/> | ||
<VmGeneralParams> | ||
<Name>VM2</Name> | ||
</VmGeneralParams> | ||
<StorageProfile href="http://vcloud/storage/123456789"/> | ||
</SourcedItem> | ||
<AllEULAsAccepted>true</AllEULAsAccepted> | ||
</InstantiateVAppTemplateParams> |
69 changes: 69 additions & 0 deletions
69
spec/vcloud_director/generators/compute/instantiate_vapp_template_params_spec.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,69 @@ | ||
require 'minitest/autorun' | ||
require 'nokogiri' | ||
require './lib/fog/vcloud_director/generators/compute/instantiate_vapp_template_params.rb' | ||
|
||
describe Fog::Generators::Compute::VcloudDirector::InstantiateVappTemplateParams do | ||
|
||
let(:xml) do | ||
params = { | ||
:name => 'VAPP_NAME', | ||
:Description => 'MY VAPP', | ||
:InstantiationParams => { | ||
:NetworkConfig => [ | ||
{ | ||
:networkName => 'NETWORK', | ||
:networkHref => 'http://vcloud/api/network/123456789', | ||
:fenceMode => 'bridged' | ||
} | ||
] | ||
}, | ||
:Source => 'http://vcloud/vapp_template/1234', | ||
:source_vms => [ | ||
{ | ||
:name => 'VM1', | ||
:href => 'http://vcloud/api/vm/12345', | ||
:StorageProfileHref => 'http://vcloud/storage/123456789' | ||
}, | ||
{ | ||
:name => 'VM2', | ||
:href => 'http://vcloud/api/vm/12345', | ||
:StorageProfileHref => 'http://vcloud/storage/123456789' | ||
} | ||
] | ||
|
||
} | ||
|
||
output = Fog::Generators::Compute::VcloudDirector::InstantiateVappTemplateParams.new(params).generate_xml | ||
Nokogiri::XML(output) | ||
end | ||
|
||
it "Generates InstantiateVAppTemplateParams" do | ||
xml.xpath('//InstantiateVAppTemplateParams').must_be_instance_of Nokogiri::XML::NodeSet | ||
end | ||
|
||
it "Has a valid Network" do | ||
node = xml.xpath('//xmlns:NetworkConfigSection') | ||
|
||
xml.xpath("//xmlns:NetworkConfig")[0].attr('networkName').must_equal "NETWORK" | ||
xml.xpath('//xmlns:ParentNetwork')[0].attr('href').must_equal 'http://vcloud/api/network/123456789' | ||
|
||
end | ||
|
||
it "Has valid source VAPP info" do | ||
node = xml.xpath('//xmlns:Source[@href="http://vcloud/vapp_template/1234"]') | ||
node.length.must_equal 1 | ||
end | ||
|
||
it "Has valid source VM info" do | ||
|
||
xml.xpath('//xmlns:StorageProfile[@href="http://vcloud/storage/123456789"]').length.must_equal 2 | ||
end | ||
|
||
it "Allows New VM Parameters" do | ||
nodes = xml.xpath('//xmlns:VmGeneralParams') | ||
nodes.length.must_equal 2 | ||
puts nodes | ||
|
||
end | ||
|
||
end |
63 changes: 63 additions & 0 deletions
63
spec/vcloud_director/requests/compute/instantiate_vapp_template_spec.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,63 @@ | ||
require 'minitest/autorun' | ||
require './lib/fog/vcloud_director/requests/compute/instantiate_vapp_template.rb' | ||
|
||
describe Fog::Compute::VcloudDirector::Real do | ||
|
||
let(:xml) do | ||
service = Fog::Compute::VcloudDirector.new() | ||
|
||
params = { | ||
:description => 'MY VAPP', | ||
:vdc_uri => 'http://vcloud/api/vdc/123456789', | ||
:network_uri => 'http://vcloud/api/network/123456789', | ||
:template_uri => 'http://vcloud/api/vapptemplate/123456789', | ||
:vapp_name => 'http://vcloud/api/vapp/123456789', | ||
:network_name => 'NETWORK', | ||
:vms_config => [ | ||
{ | ||
:name => 'VM1', | ||
:href => 'http://vcloud/api/vm/12345', | ||
:storage_profile_href => 'http://vcloud/storage/123456789' | ||
}, | ||
{ | ||
:name => 'VM2', | ||
:href => 'http://vcloud/api/vm/12345', | ||
:storage_profile_href => 'http://vcloud/storage/123456789' | ||
} | ||
] | ||
} | ||
|
||
|
||
Nokogiri::XML(service.send(:generate_instantiate_vapp_template_request,params)) | ||
end | ||
|
||
|
||
|
||
it "Generates InstantiateVAppTemplateParams" do | ||
|
||
xml.xpath('//InstantiateVAppTemplateParams').must_be_instance_of Nokogiri::XML::NodeSet | ||
end | ||
|
||
it "Has a valid Network" do | ||
node = xml.xpath('//xmlns:NetworkConfigSection') | ||
|
||
xml.xpath("//xmlns:NetworkConfig")[0].attr('networkName').must_equal "NETWORK" | ||
xml.xpath('//xmlns:ParentNetwork')[0].attr('href').must_equal 'http://vcloud/api/network/123456789' | ||
|
||
end | ||
|
||
it "Has valid source VAPP info" do | ||
node = xml.xpath('//xmlns:Source[@href="http://vcloud/api/vapptemplate/123456789"]') | ||
node.length.must_equal 1 | ||
end | ||
|
||
it "Has valid source VM info" do | ||
xml.xpath('//xmlns:Source[@name="VM1"]').length.must_equal 1 | ||
xml.xpath('//xmlns:StorageProfile[@href="http://vcloud/storage/123456789"]').length.must_equal 2 | ||
end | ||
|
||
|
||
|
||
|
||
|
||
end |