Skip to content

Commit 0478aae

Browse files
committed
Merged in sdk_networking (pull request vchs#2)
Add classes for different network types
2 parents 94eb4a9 + 344ff97 commit 0478aae

22 files changed

+199
-17
lines changed

lib/ruby_vcloud_sdk/client.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Client
1818
public :vdcs, :list_vdcs, :find_vdc_by_name, :catalogs,
1919
:list_catalogs, :catalog_exists?, :find_catalog_by_name,
2020
:vdc_exists?, :vapps, :list_vapps, :find_vapp_by_name,
21-
:vapp_exists?, :organizations, :roles, :entity
21+
:vapp_exists?, :organizations, :roles, :entity, :networks
2222

2323
def initialize(url, username, password, options = {}, logger = nil)
2424
@url = url
@@ -111,5 +111,10 @@ def vapp_template(id)
111111
vapp_template = connection.get("/api/vAppTemplate/#{id}")
112112
VCloudSdk::VappTemplate.new(@session, vapp_template)
113113
end
114+
115+
def network(id)
116+
network = connection.get("/api/network/#{id}")
117+
VCloudSdk::Network.new(@session, network.href)
118+
end
114119
end
115120
end

lib/ruby_vcloud_sdk/infrastructure.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ def vapps
2323
end
2424
end
2525

26+
def networks
27+
networks_link = @session.query_list.networks_query_list
28+
query_list = VCloudSdk::QueryList.new(@session, networks_link)
29+
30+
query_list.networks.map do |network_link|
31+
VCloudSdk::Network.new(@session, network_link)
32+
end
33+
end
34+
2635
def roles
2736
roles_link = @session.query_list.roles_query_list
2837
query_list = VCloudSdk::QueryList.new(@session, roles_link)

lib/ruby_vcloud_sdk/network.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ def ip_ranges
2525
.reduce(IpRanges.new) do |result, i|
2626
result + IpRanges.new("#{i.start_address}-#{i.end_address}")
2727
end
28+
rescue
29+
nil
30+
end
31+
32+
def href_id
33+
entity_xml.href_id
2834
end
2935

3036
def allocated_ips

lib/ruby_vcloud_sdk/nic.rb

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,37 @@ class NIC
44

55
def_delegators :@entity_xml,
66
:ip_address, :is_connected, :mac_address,
7-
:ip_address_allocation_mode, :network
7+
:ip_address_allocation_mode, :network, :element_name
88

99
attr_reader :is_primary
1010

11-
def initialize(entity_xml, is_primary)
11+
def initialize(entity_xml, is_primary, vm)
1212
@entity_xml = entity_xml
1313
@is_primary = is_primary
14+
@vm = vm
1415
end
1516

1617
def network_connection_index
1718
@entity_xml.network_connection_index.to_i
1819
end
1920

20-
def is_connected
21-
@entity_xml.is_connected == "true"
21+
def network_name
22+
@entity_xml.network
23+
end
24+
25+
def network
26+
@vm.vapp.find_network_by_name(@entity_xml.network)
27+
end
28+
29+
def to_hash
30+
{
31+
name: element_name,
32+
mac_address: mac_address,
33+
ip_address: ip_address,
34+
network_identifier: network.try(:href_id),
35+
is_primary: @is_primary,
36+
is_connected: is_connected
37+
}
2238
end
2339

2440
alias_method :nic_index, :network_connection_index

lib/ruby_vcloud_sdk/organization.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ def catalogs
3535
end
3636
end
3737

38+
def networks
39+
entity_xml.networks.map do |network_link|
40+
VCloudSdk::Network.new(@session, network_link)
41+
end
42+
end
43+
3844
def to_hash
3945
{ :identifier => id,
4046
:label => @link.name }

lib/ruby_vcloud_sdk/query_list.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ def initialize(session, link)
1515
@link = link
1616
end
1717

18-
1918
def vapps
2019
entity_xml.vapps
2120
end
2221

22+
def networks
23+
entity_xml.networks
24+
end
25+
2326
def roles
2427
entity_xml.roles
2528
end

lib/ruby_vcloud_sdk/vapp.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,21 @@ def to_hash
173173
:memory_allocation_mb => @link.memory_allocation_mb }
174174
end
175175

176+
def vdc
177+
VCloudSdk::VDC.new(@session, entity_xml.vdc_link)
178+
end
179+
180+
def find_network_by_name(network_name)
181+
network_link = entity_xml.
182+
network_config_section.
183+
network_configs.
184+
select { |vapp_network| vapp_network.network_name == network_name }.
185+
first.try(:link)
186+
187+
return unless network_link
188+
VCloudSdk::Network.new(@session, network_link)
189+
end
190+
176191
private
177192

178193
def recompose_from_vapp_template_param(template)

lib/ruby_vcloud_sdk/vdc.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ def storage_profile_xml_node(name)
214214
storage_profile
215215
end
216216

217+
def org
218+
VCloudSdk::Organization.new(@session, entity_xml.org_link)
219+
end
220+
217221
private
218222

219223
def storage_profile_records

lib/ruby_vcloud_sdk/vm.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,10 @@ def list_networks
130130
end
131131

132132
def nics
133-
primary_index = entity_xml
134-
.network_connection_section
135-
.primary_network_connection_index
136133
entity_xml
137-
.network_connection_section
138-
.network_connections
139-
.map do |network_connection|
140-
VCloudSdk::NIC.new(network_connection,
141-
network_connection.network_connection_index == primary_index)
142-
end
134+
.hardware_section
135+
.nics
136+
.map { |nic| VCloudSdk::NIC.new(nic, nic.is_primary, self) }
143137
end
144138

145139
def independent_disks

lib/ruby_vcloud_sdk/xml/constants.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ module Xml
167167
"application/vnd.vmware.vcloud.networkSection+xml",
168168
:NETWORK_CONFIG_SECTION =>
169169
"application/vnd.vmware.vcloud.networkConfigSection+xml",
170+
:NETWORK_CARD_SECTION =>
171+
"application/vnd.vmware.vcloud.networkConfigSection+xml",
170172
:PRODUCT_SECTIONS =>
171173
"application/vnd.vmware.vcloud.productSections+xml",
172174
:NETWORK_CONNECTION_SECTION =>

0 commit comments

Comments
 (0)