[vcloud_director|tests] Add generator tests.
This commit is contained in:
parent
0573ceebc3
commit
1648c933e0
|
@ -22,4 +22,5 @@ spec/credentials.yml
|
||||||
vendor/*
|
vendor/*
|
||||||
tags
|
tags
|
||||||
tests/digitalocean/fixtures/
|
tests/digitalocean/fixtures/
|
||||||
|
tests/vcloud_director/fixtures/vcloud/v1.5/schema/*.xsd
|
||||||
tests/vcloud_director/vcr_cassettes/
|
tests/vcloud_director/vcr_cassettes/
|
||||||
|
|
|
@ -59,15 +59,11 @@ module Fog
|
||||||
private
|
private
|
||||||
|
|
||||||
def header
|
def header
|
||||||
'<GuestCustomizationSection xmlns="http://www.vmware.com/vcloud/v1.5"
|
<<-END
|
||||||
|
<GuestCustomizationSection xmlns="http://www.vmware.com/vcloud/v1.5"
|
||||||
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"
|
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"
|
||||||
type="application/vnd.vmware.vcloud.guestCustomizationSection+xml"
|
type="application/vnd.vmware.vcloud.guestCustomizationSection+xml">
|
||||||
ovf:required="false"
|
END
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://schemas.dmtf.org/ovf/envelope/1
|
|
||||||
http://schemas.dmtf.org/ovf/envelope/1/dsp8023_1.1.0.xsd
|
|
||||||
http://www.vmware.com/vcloud/v1.5
|
|
||||||
http://zone01.bluelock.com/api/v1.5/schema/master.xsd">'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# The order matters: http://communities.vmware.com/thread/448760?start=0&tstart=0
|
# The order matters: http://communities.vmware.com/thread/448760?start=0&tstart=0
|
||||||
|
@ -83,7 +79,7 @@ module Fog
|
||||||
# * " "
|
# * " "
|
||||||
# * ' '
|
# * ' '
|
||||||
def body(opts={})
|
def body(opts={})
|
||||||
body = "
|
<<-END
|
||||||
<ovf:Info>Specifies Guest OS Customization Settings</ovf:Info>
|
<ovf:Info>Specifies Guest OS Customization Settings</ovf:Info>
|
||||||
<Enabled>#{opts[:enabled]}</Enabled>
|
<Enabled>#{opts[:enabled]}</Enabled>
|
||||||
<ChangeSid>#{opts[:change_sid]}</ChangeSid>
|
<ChangeSid>#{opts[:change_sid]}</ChangeSid>
|
||||||
|
@ -94,11 +90,14 @@ module Fog
|
||||||
<AdminPasswordAuto>#{opts[:admin_password_auto]}</AdminPasswordAuto>
|
<AdminPasswordAuto>#{opts[:admin_password_auto]}</AdminPasswordAuto>
|
||||||
<ResetPasswordRequired>#{opts[:reset_password_required]}</ResetPasswordRequired>
|
<ResetPasswordRequired>#{opts[:reset_password_required]}</ResetPasswordRequired>
|
||||||
<CustomizationScript>#{CGI::escapeHTML(opts[:customization_script]).gsub(/\r/, " ")}</CustomizationScript>
|
<CustomizationScript>#{CGI::escapeHTML(opts[:customization_script]).gsub(/\r/, " ")}</CustomizationScript>
|
||||||
<ComputerName>#{opts[:computer_name]}</ComputerName>"
|
<ComputerName>#{opts[:computer_name]}</ComputerName>
|
||||||
|
END
|
||||||
end
|
end
|
||||||
|
|
||||||
def tail
|
def tail
|
||||||
'</GuestCustomizationSection>'
|
<<-END
|
||||||
|
</GuestCustomizationSection>
|
||||||
|
END
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -115,17 +115,22 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
def header
|
def header
|
||||||
'<vcloud:RasdItemsList xmlns:vcloud="http://www.vmware.com/vcloud/v1.5"
|
<<-END
|
||||||
|
<vcloud:RasdItemsList xmlns:vcloud="http://www.vmware.com/vcloud/v1.5"
|
||||||
xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"
|
xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"
|
||||||
type="application/vnd.vmware.vcloud.rasdItemsList+xml">'
|
type="application/vnd.vmware.vcloud.rasdItemsList+xml">
|
||||||
|
END
|
||||||
end
|
end
|
||||||
|
|
||||||
def tail
|
def tail
|
||||||
'</vcloud:RasdItemsList>'
|
<<-END
|
||||||
|
</vcloud:RasdItemsList>
|
||||||
|
END
|
||||||
end
|
end
|
||||||
|
|
||||||
def hard_disk_item(opts={})
|
def hard_disk_item(opts={})
|
||||||
"<vcloud:Item>
|
<<-END
|
||||||
|
<vcloud:Item>
|
||||||
<rasd:AddressOnParent>#{opts[:address_on_parent]}</rasd:AddressOnParent>
|
<rasd:AddressOnParent>#{opts[:address_on_parent]}</rasd:AddressOnParent>
|
||||||
<rasd:Description>#{opts[:description]}</rasd:Description>
|
<rasd:Description>#{opts[:description]}</rasd:Description>
|
||||||
<rasd:ElementName>#{opts[:name]}</rasd:ElementName>
|
<rasd:ElementName>#{opts[:name]}</rasd:ElementName>
|
||||||
|
@ -133,28 +138,33 @@ module Fog
|
||||||
<rasd:InstanceID>#{opts[:id]}</rasd:InstanceID>
|
<rasd:InstanceID>#{opts[:id]}</rasd:InstanceID>
|
||||||
<rasd:Parent>#{opts[:parent]}</rasd:Parent>
|
<rasd:Parent>#{opts[:parent]}</rasd:Parent>
|
||||||
<rasd:ResourceType>17</rasd:ResourceType>
|
<rasd:ResourceType>17</rasd:ResourceType>
|
||||||
</vcloud:Item>"
|
</vcloud:Item>
|
||||||
|
END
|
||||||
end
|
end
|
||||||
|
|
||||||
def ide_controller_item(opts={})
|
def ide_controller_item(opts={})
|
||||||
"<vcloud:Item>
|
<<-END
|
||||||
|
<vcloud:Item>
|
||||||
<rasd:Address>#{opts[:address]}</rasd:Address>
|
<rasd:Address>#{opts[:address]}</rasd:Address>
|
||||||
<rasd:Description>#{opts[:description]}</rasd:Description>
|
<rasd:Description>#{opts[:description]}</rasd:Description>
|
||||||
<rasd:ElementName>#{opts[:name]}</rasd:ElementName>
|
<rasd:ElementName>#{opts[:name]}</rasd:ElementName>
|
||||||
<rasd:InstanceID>#{opts[:id]}</rasd:InstanceID>
|
<rasd:InstanceID>#{opts[:id]}</rasd:InstanceID>
|
||||||
<rasd:ResourceType>5</rasd:ResourceType>
|
<rasd:ResourceType>5</rasd:ResourceType>
|
||||||
</vcloud:Item>"
|
</vcloud:Item>
|
||||||
|
END
|
||||||
end
|
end
|
||||||
|
|
||||||
def scsi_controller(opts={})
|
def scsi_controller(opts={})
|
||||||
"<vcloud:Item>
|
<<-END
|
||||||
|
<vcloud:Item>
|
||||||
<rasd:Address>#{opts[:address]}</rasd:Address>
|
<rasd:Address>#{opts[:address]}</rasd:Address>
|
||||||
<rasd:Description>#{opts[:description]}</rasd:Description>
|
<rasd:Description>#{opts[:description]}</rasd:Description>
|
||||||
<rasd:ElementName>#{opts[:name]}</rasd:ElementName>
|
<rasd:ElementName>#{opts[:name]}</rasd:ElementName>
|
||||||
<rasd:InstanceID>#{opts[:id]}</rasd:InstanceID>
|
<rasd:InstanceID>#{opts[:id]}</rasd:InstanceID>
|
||||||
<rasd:ResourceSubType>#{opts[:resource_sub_type]}</rasd:ResourceSubType>
|
<rasd:ResourceSubType>#{opts[:resource_sub_type]}</rasd:ResourceSubType>
|
||||||
<rasd:ResourceType>6</rasd:ResourceType>
|
<rasd:ResourceType>6</rasd:ResourceType>
|
||||||
</vcloud:Item>"
|
</vcloud:Item>
|
||||||
|
END
|
||||||
end
|
end
|
||||||
|
|
||||||
# helpers
|
# helpers
|
||||||
|
|
|
@ -48,11 +48,12 @@ module Fog
|
||||||
|
|
||||||
# 1.5
|
# 1.5
|
||||||
def header
|
def header
|
||||||
'<Metadata xmlns="http://www.vmware.com/vcloud/v1.5"
|
<<-END
|
||||||
type="application/vnd.vmware.vcloud.metadata+xml"
|
<Metadata
|
||||||
|
xmlns="http://www.vmware.com/vcloud/v1.5"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://10.194.1.65/api/v1.5/schema/master.xsd">
|
type="application/vnd.vmware.vcloud.metadata+xml">
|
||||||
'
|
END
|
||||||
end
|
end
|
||||||
|
|
||||||
def metadata_entry
|
def metadata_entry
|
||||||
|
@ -69,33 +70,33 @@ module Fog
|
||||||
#end
|
#end
|
||||||
|
|
||||||
def tail
|
def tail
|
||||||
'</Metadata>'
|
<<-END
|
||||||
|
</Metadata>
|
||||||
|
END
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class MetadataV51 < MetadataBase
|
class MetadataV51 < MetadataBase
|
||||||
def metadata_entry(key, value)
|
def metadata_entry(key, value)
|
||||||
body = <<EOF
|
<<-END
|
||||||
<MetadataEntry
|
<MetadataEntry type="application/vnd.vmware.vcloud.metadata.value+xml">
|
||||||
type="application/vnd.vmware.vcloud.metadata.value+xml">
|
|
||||||
<Key>#{key}</Key>
|
<Key>#{key}</Key>
|
||||||
<TypedValue
|
<TypedValue xsi:type="MetadataStringValue">
|
||||||
xsi:type="MetadataStringValue">
|
|
||||||
<Value>#{value}</Value>
|
<Value>#{value}</Value>
|
||||||
</TypedValue>
|
</TypedValue>
|
||||||
</MetadataEntry>
|
</MetadataEntry>
|
||||||
EOF
|
END
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class MetadataV15 < MetadataBase
|
class MetadataV15 < MetadataBase
|
||||||
def metadata_entry(key, value)
|
def metadata_entry(key, value)
|
||||||
body = <<EOF
|
<<-END
|
||||||
<MetadataEntry>
|
<MetadataEntry>
|
||||||
<Key>#{key}</Key>
|
<Key>#{key}</Key>
|
||||||
<Value>#{value}</Value>
|
<Value>#{value}</Value>
|
||||||
</MetadataEntry>
|
</MetadataEntry>
|
||||||
EOF
|
END
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -85,18 +85,15 @@ module Fog
|
||||||
private
|
private
|
||||||
|
|
||||||
def header
|
def header
|
||||||
'<NetworkConnectionSection xmlns="http://www.vmware.com/vcloud/v1.5"
|
<<-END
|
||||||
|
<NetworkConnectionSection xmlns="http://www.vmware.com/vcloud/v1.5"
|
||||||
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"
|
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"
|
||||||
type="application/vnd.vmware.vcloud.networkConnectionSection+xml"
|
type="application/vnd.vmware.vcloud.networkConnectionSection+xml">
|
||||||
ovf:required="false"
|
END
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://schemas.dmtf.org/ovf/envelope/1
|
|
||||||
http://schemas.dmtf.org/ovf/envelope/1/dsp8023_1.1.0.xsd
|
|
||||||
http://www.vmware.com/vcloud/v1.5 http://10.194.1.65/api/v1.5/schema/master.xsd">'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def body(opts={})
|
def body(opts={})
|
||||||
body = <<EOF
|
<<-END
|
||||||
<ovf:Info>#{opts[:info]}</ovf:Info>
|
<ovf:Info>#{opts[:info]}</ovf:Info>
|
||||||
<PrimaryNetworkConnectionIndex>#{opts[:primary_network_connection_index]}</PrimaryNetworkConnectionIndex>
|
<PrimaryNetworkConnectionIndex>#{opts[:primary_network_connection_index]}</PrimaryNetworkConnectionIndex>
|
||||||
<NetworkConnection
|
<NetworkConnection
|
||||||
|
@ -108,11 +105,13 @@ module Fog
|
||||||
<MACAddress>#{opts[:mac_address]}</MACAddress>
|
<MACAddress>#{opts[:mac_address]}</MACAddress>
|
||||||
<IpAddressAllocationMode>#{opts[:ip_address_allocation_mode]}</IpAddressAllocationMode>
|
<IpAddressAllocationMode>#{opts[:ip_address_allocation_mode]}</IpAddressAllocationMode>
|
||||||
</NetworkConnection>
|
</NetworkConnection>
|
||||||
EOF
|
END
|
||||||
end
|
end
|
||||||
|
|
||||||
def tail
|
def tail
|
||||||
'</NetworkConnectionSection>'
|
<<-END
|
||||||
|
</NetworkConnectionSection>
|
||||||
|
END
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Output of generators will be validated against the XML schema if copies of the
|
||||||
|
schema definition files are placed here.
|
|
@ -0,0 +1,42 @@
|
||||||
|
Shindo.tests('Compute::VcloudDirector | disks generator', ['vclouddirector', 'xsd']) do
|
||||||
|
|
||||||
|
require 'fog/vcloud_director/generators/compute/disks'
|
||||||
|
|
||||||
|
tests('#generate_xml').returns(String) do
|
||||||
|
@items =
|
||||||
|
{:disks=>
|
||||||
|
[{:address=>0,
|
||||||
|
:description=>"SCSI Controller",
|
||||||
|
:name=>"SCSI Controller 0",
|
||||||
|
:id=>2,
|
||||||
|
:resource_sub_type=>"VirtualSCSI",
|
||||||
|
:resource_type=>6},
|
||||||
|
{:address_on_parent=>0,
|
||||||
|
:description=>"Hard disk",
|
||||||
|
:name=>"Hard disk 1",
|
||||||
|
:id=>2000,
|
||||||
|
:parent=>2,
|
||||||
|
:resource_type=>17,
|
||||||
|
:capacity=>16384,
|
||||||
|
:bus_sub_type=>"VirtualSCSI",
|
||||||
|
:bus_type=>6},
|
||||||
|
{:address=>0,
|
||||||
|
:description=>"IDE Controller",
|
||||||
|
:name=>"IDE Controller 0",
|
||||||
|
:id=>3,
|
||||||
|
:resource_type=>5}]}
|
||||||
|
@xml = Fog::Generators::Compute::VcloudDirector::Disks.new(@items).generate_xml
|
||||||
|
@xml.class
|
||||||
|
end
|
||||||
|
|
||||||
|
tests('#parse').returns(Nokogiri::XML::Document) do
|
||||||
|
@doc = Nokogiri::XML::Document.parse(@xml)
|
||||||
|
@doc.class
|
||||||
|
end
|
||||||
|
|
||||||
|
tests('#validate').returns([]) do
|
||||||
|
pending unless VcloudDirector::Generators::Helpers.have_xsd?
|
||||||
|
VcloudDirector::Generators::Helpers.validate(@doc)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,36 @@
|
||||||
|
Shindo.tests('Compute::VcloudDirector | GuestCustomizationSection generator', ['vclouddirector', 'xsd']) do
|
||||||
|
|
||||||
|
require 'fog/vcloud_director/generators/compute/customization'
|
||||||
|
|
||||||
|
tests('#generate_xml').returns(String) do
|
||||||
|
@attrs =
|
||||||
|
{:type=>"application/vnd.vmware.vcloud.guestCustomizationSection+xml",
|
||||||
|
:href=>
|
||||||
|
"https://example.com/api/vApp/vm-2bbbf556-55dc-4974-82e6-aa6e814f0b64/guestCustomizationSection/",
|
||||||
|
:id=>"vm-2bbbf556-55dc-4974-82e6-aa6e814f0b64",
|
||||||
|
:enabled=>false,
|
||||||
|
:change_sid=>false,
|
||||||
|
:virtual_machine_id=>"2bbbf556-55dc-4974-82e6-aa6e814f0b64",
|
||||||
|
:join_domain_enabled=>false,
|
||||||
|
:use_org_settings=>false,
|
||||||
|
:admin_password_enabled=>false,
|
||||||
|
:admin_password_auto=>true,
|
||||||
|
:reset_password_required=>false,
|
||||||
|
:customization_script=>"hola\nmundo",
|
||||||
|
:has_customization_script=>true,
|
||||||
|
:computer_name=>"DEVWEB-001"}
|
||||||
|
@xml = Fog::Generators::Compute::VcloudDirector::Customization.new(@attrs).generate_xml
|
||||||
|
@xml.class
|
||||||
|
end
|
||||||
|
|
||||||
|
tests('#parse').returns(Nokogiri::XML::Document) do
|
||||||
|
@doc = Nokogiri::XML::Document.parse(@xml)
|
||||||
|
@doc.class
|
||||||
|
end
|
||||||
|
|
||||||
|
tests('#validate').returns([]) do
|
||||||
|
pending unless VcloudDirector::Generators::Helpers.have_xsd?
|
||||||
|
VcloudDirector::Generators::Helpers.validate(@doc)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,35 @@
|
||||||
|
class VcloudDirector
|
||||||
|
module Generators
|
||||||
|
module Helpers
|
||||||
|
|
||||||
|
def self.have_xsd?
|
||||||
|
if @have_xsd.nil?
|
||||||
|
unless @have_xsd = File.exist?(master)
|
||||||
|
Fog::Logger.warning('XML schema not present, skipping validation')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@have_xsd
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.validate(doc)
|
||||||
|
xsd.validate(doc).map(&:message)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def self.master
|
||||||
|
@master ||= File.expand_path('../../../fixtures/vcloud/v1.5/schema/master.xsd', __FILE__)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.xsd
|
||||||
|
if @xsd.nil?
|
||||||
|
Dir.chdir(File.dirname(master)) do
|
||||||
|
@xsd = Nokogiri::XML::Schema.new(File.read(File.basename(master)))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@xsd
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,41 @@
|
||||||
|
Shindo.tests('Compute::VcloudDirector | Metadata generator', ['vclouddirector', 'xsd']) do
|
||||||
|
|
||||||
|
require 'fog/vcloud_director/generators/compute/metadata'
|
||||||
|
|
||||||
|
@attrs = {:metadata => {'KEY' => 'VALUE'}}
|
||||||
|
|
||||||
|
tests('vCloud API 1.5') do
|
||||||
|
tests('#generate_xml').returns(String) do
|
||||||
|
@xml = Fog::Generators::Compute::VcloudDirector::MetadataV15.new(@attrs).generate_xml
|
||||||
|
@xml.class
|
||||||
|
end
|
||||||
|
|
||||||
|
tests('#parse').returns(Nokogiri::XML::Document) do
|
||||||
|
@doc = Nokogiri::XML::Document.parse(@xml)
|
||||||
|
@doc.class
|
||||||
|
end
|
||||||
|
|
||||||
|
tests('#validate').returns([]) do
|
||||||
|
pending unless VcloudDirector::Generators::Helpers.have_xsd?
|
||||||
|
VcloudDirector::Generators::Helpers.validate(@doc)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
tests('vCloud API 5.1') do
|
||||||
|
tests('#generate_xml').returns(String) do
|
||||||
|
@xml = Fog::Generators::Compute::VcloudDirector::MetadataV51.new(@attrs).generate_xml
|
||||||
|
@xml.class
|
||||||
|
end
|
||||||
|
|
||||||
|
tests('#parse').returns(Nokogiri::XML::Document) do
|
||||||
|
@doc = Nokogiri::XML::Document.parse(@xml)
|
||||||
|
@doc.class
|
||||||
|
end
|
||||||
|
|
||||||
|
tests('#validate').returns([]) do
|
||||||
|
pending unless VcloudDirector::Generators::Helpers.have_xsd?
|
||||||
|
VcloudDirector::Generators::Helpers.validate(@doc)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,33 @@
|
||||||
|
Shindo.tests('Compute::VcloudDirector | NetworkConnectionSection generator', ['vclouddirector', 'xsd']) do
|
||||||
|
|
||||||
|
require 'fog/vcloud_director/generators/compute/vm_network'
|
||||||
|
|
||||||
|
tests('#generate_xml').returns(String) do
|
||||||
|
@attrs =
|
||||||
|
{:type=>"application/vnd.vmware.vcloud.networkConnectionSection+xml",
|
||||||
|
:href=>
|
||||||
|
"https://example.com/api/vApp/vm-8b74d95a-ee91-4f46-88d8-fc92be0dbaae/networkConnectionSection/",
|
||||||
|
:id=>"vm-8b74d95a-ee91-4f46-88d8-fc92be0dbaae",
|
||||||
|
:primary_network_connection_index=>0,
|
||||||
|
:network=>"DevOps - Dev Network Connection",
|
||||||
|
:needs_customization=>true,
|
||||||
|
:network_connection_index=>0,
|
||||||
|
:ip_address=>"10.192.0.130",
|
||||||
|
:is_connected=>true,
|
||||||
|
:mac_address=>"00:50:56:01:00:8d",
|
||||||
|
:ip_address_allocation_mode=>"POOL"}
|
||||||
|
@xml = Fog::Generators::Compute::VcloudDirector::VmNetwork.new(@attrs).generate_xml
|
||||||
|
@xml.class
|
||||||
|
end
|
||||||
|
|
||||||
|
tests('#parse').returns(Nokogiri::XML::Document) do
|
||||||
|
@doc = Nokogiri::XML::Document.parse(@xml)
|
||||||
|
@doc.class
|
||||||
|
end
|
||||||
|
|
||||||
|
tests('#validate').returns([]) do
|
||||||
|
pending unless VcloudDirector::Generators::Helpers.have_xsd?
|
||||||
|
VcloudDirector::Generators::Helpers.validate(@doc)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,121 @@
|
||||||
|
module Fog
|
||||||
|
module Generators
|
||||||
|
module Compute
|
||||||
|
module VcloudDirector
|
||||||
|
# This is the data structure it accepts, this is the output of
|
||||||
|
# #get_vm_network
|
||||||
|
#
|
||||||
|
# {:type=>"application/vnd.vmware.vcloud.networkConnectionSection+xml",
|
||||||
|
# :href=>
|
||||||
|
# "https://example.com/api/vApp/vm-8b74d95a-ee91-4f46-88d8-fc92be0dbaae/networkConnectionSection/",
|
||||||
|
# :id=>"vm-8b74d95a-ee91-4f46-88d8-fc92be0dbaae",
|
||||||
|
# :primary_network_connection_index=>0,
|
||||||
|
# :network=>"DevOps - Dev Network Connection",
|
||||||
|
# :needs_customization=>true,
|
||||||
|
# :network_connection_index=>0,
|
||||||
|
# :ip_address=>"10.192.0.130",
|
||||||
|
# :is_connected=>true,
|
||||||
|
# :mac_address=>"00:50:56:01:00:8d",
|
||||||
|
# :ip_address_allocation_mode=>"POOL"}
|
||||||
|
#
|
||||||
|
# This is what it generates:
|
||||||
|
#
|
||||||
|
# <NetworkConnectionSection xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" type="application/vnd.vmware.vcloud.networkConnectionSection+xml" href="https://example.com/api/vApp/vm-8b74d95a-ee91-4f46-88d8-fc92be0dbaae/networkConnectionSection/" ovf:required="false" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.dmtf.org/ovf/envelope/1 http://schemas.dmtf.org/ovf/envelope/1/dsp8023_1.1.0.xsd http://www.vmware.com/vcloud/v1.5 http://10.194.1.65/api/v1.5/schema/master.xsd">
|
||||||
|
# <ovf:Info>Specifies the available VM network connections</ovf:Info>
|
||||||
|
# <PrimaryNetworkConnectionIndex>0</PrimaryNetworkConnectionIndex>
|
||||||
|
# <NetworkConnection network="DevOps - Dev Network Connection" needsCustomization="true">
|
||||||
|
# <NetworkConnectionIndex>0</NetworkConnectionIndex>
|
||||||
|
# <IpAddress>10.192.0.130</IpAddress>
|
||||||
|
# <IsConnected>true</IsConnected>
|
||||||
|
# <MACAddress>00:50:56:01:00:8d</MACAddress>
|
||||||
|
# <IpAddressAllocationMode>POOL</IpAddressAllocationMode>
|
||||||
|
# </NetworkConnection>
|
||||||
|
# <Link rel="edit" type="application/vnd.vmware.vcloud.networkConnectionSection+xml" href="https://example.com/api/vApp/vm-8b74d95a-ee91-4f46-88d8-fc92be0dbaae/networkConnectionSection/"/>
|
||||||
|
# </NetworkConnectionSection>
|
||||||
|
#
|
||||||
|
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/types/NetworkConnectionSectionType.html
|
||||||
|
# vCloud API Documentation
|
||||||
|
class VmNetwork
|
||||||
|
attr_reader :attrs
|
||||||
|
|
||||||
|
def initialize(attrs={})
|
||||||
|
@attrs = attrs
|
||||||
|
end
|
||||||
|
|
||||||
|
def generate_xml
|
||||||
|
output = ""
|
||||||
|
output << header
|
||||||
|
output << body(@attrs)
|
||||||
|
output << tail
|
||||||
|
output
|
||||||
|
end
|
||||||
|
|
||||||
|
def network
|
||||||
|
@attrs[:network]
|
||||||
|
end
|
||||||
|
|
||||||
|
def network=(new_network_name)
|
||||||
|
@attrs[:network] = new_network_name
|
||||||
|
end
|
||||||
|
|
||||||
|
def ip_address
|
||||||
|
@attrs[:ip_address]
|
||||||
|
end
|
||||||
|
|
||||||
|
def ip_address=(new_ip_address)
|
||||||
|
@attrs[:ip_address] = new_ip_address
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_connected
|
||||||
|
@attrs[:is_connected]
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_connected=(new_is_connected)
|
||||||
|
@attrs[:is_connected] = new_is_connected
|
||||||
|
end
|
||||||
|
|
||||||
|
def ip_address_allocation_mode
|
||||||
|
@attrs[:ip_address_allocation_mode]
|
||||||
|
end
|
||||||
|
|
||||||
|
def ip_address_allocation_mode=(new_ip_address_allocation_mode)
|
||||||
|
@attrs[:ip_address_allocation_mode] = new_ip_address_allocation_mode
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def header
|
||||||
|
'<NetworkConnectionSection xmlns="http://www.vmware.com/vcloud/v1.5"
|
||||||
|
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"
|
||||||
|
type="application/vnd.vmware.vcloud.networkConnectionSection+xml"
|
||||||
|
ovf:required="false"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://schemas.dmtf.org/ovf/envelope/1
|
||||||
|
http://schemas.dmtf.org/ovf/envelope/1/dsp8023_1.1.0.xsd
|
||||||
|
http://www.vmware.com/vcloud/v1.5 http://10.194.1.65/api/v1.5/schema/master.xsd">'
|
||||||
|
end
|
||||||
|
|
||||||
|
def body(opts={})
|
||||||
|
body = <<EOF
|
||||||
|
<ovf:Info>#{opts[:info]}</ovf:Info>
|
||||||
|
<PrimaryNetworkConnectionIndex>#{opts[:primary_network_connection_index]}</PrimaryNetworkConnectionIndex>
|
||||||
|
<NetworkConnection
|
||||||
|
network="#{opts[:network]}"
|
||||||
|
needsCustomization="#{opts[:needs_customization]}">
|
||||||
|
<NetworkConnectionIndex>#{opts[:network_connection_index]}</NetworkConnectionIndex>
|
||||||
|
<IpAddress>#{opts[:ip_address]}</IpAddress>
|
||||||
|
<IsConnected>#{opts[:is_connected]}</IsConnected>
|
||||||
|
<MACAddress>#{opts[:mac_address]}</MACAddress>
|
||||||
|
<IpAddressAllocationMode>#{opts[:ip_address_allocation_mode]}</IpAddressAllocationMode>
|
||||||
|
</NetworkConnection>
|
||||||
|
EOF
|
||||||
|
end
|
||||||
|
|
||||||
|
def tail
|
||||||
|
'</NetworkConnectionSection>'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue