vcloud-walker 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. data/.gitignore +9 -0
  2. data/Gemfile +12 -0
  3. data/LICENSE +20 -0
  4. data/README.md +55 -0
  5. data/Rakefile +21 -0
  6. data/bin/vcloud-walk +41 -0
  7. data/docs/examples/catalogs.json +40 -0
  8. data/docs/examples/edgegateways.json +285 -0
  9. data/docs/examples/networks.json +53 -0
  10. data/docs/examples/vdcs.json +221 -0
  11. data/jenkins.sh +9 -0
  12. data/jenkins_integration_tests.sh +11 -0
  13. data/lib/vcloud/walker/fog_interface.rb +48 -0
  14. data/lib/vcloud/walker/resource/catalog.rb +29 -0
  15. data/lib/vcloud/walker/resource/catalog_item.rb +25 -0
  16. data/lib/vcloud/walker/resource/collection.rb +13 -0
  17. data/lib/vcloud/walker/resource/entity.rb +27 -0
  18. data/lib/vcloud/walker/resource/gateway_ipsec_vpn_service.rb +46 -0
  19. data/lib/vcloud/walker/resource/network.rb +38 -0
  20. data/lib/vcloud/walker/resource/organization.rb +45 -0
  21. data/lib/vcloud/walker/resource/vapp.rb +46 -0
  22. data/lib/vcloud/walker/resource/vdc.rb +35 -0
  23. data/lib/vcloud/walker/resource/vm.rb +85 -0
  24. data/lib/vcloud/walker/resource.rb +11 -0
  25. data/lib/vcloud/walker/vcloud_session.rb +13 -0
  26. data/lib/vcloud/walker/version.rb +5 -0
  27. data/lib/vcloud/walker.rb +23 -0
  28. data/scripts/configure_walker_ci_vse.rb +31 -0
  29. data/scripts/data/walker_ci/carrenza.yaml +17 -0
  30. data/scripts/data/walker_ci/skyscape.yaml +17 -0
  31. data/scripts/generate_fog_conf_file.sh +6 -0
  32. data/spec/fog_interface_spec.rb +93 -0
  33. data/spec/integration/vcloud_walker_spec.rb +74 -0
  34. data/spec/spec_helper.rb +45 -0
  35. data/spec/stubs/service_layer_stub.rb +109 -0
  36. data/spec/stubs/stubs.rb +46 -0
  37. data/spec/vcloud/walker_spec.rb +59 -0
  38. data/spec/walk/catalogs_spec.rb +31 -0
  39. data/spec/walk/entity_spec.rb +69 -0
  40. data/spec/walk/gateway_ipsec_vpn_service_spec.rb +157 -0
  41. data/spec/walk/network_spec.rb +70 -0
  42. data/spec/walk/organization_spec.rb +53 -0
  43. data/spec/walk/vapp_spec.rb +24 -0
  44. data/spec/walk/vdcs_spec.rb +30 -0
  45. data/spec/walk/vm_spec.rb +122 -0
  46. data/vcloud-walker.gemspec +31 -0
  47. metadata +274 -0
@@ -0,0 +1,221 @@
1
+ [
2
+ {
3
+ "id": "074aea1e-a5e9-4dd1-a028-40db8c98d237",
4
+ "name": "Test Vdc",
5
+ "description": "",
6
+ "vapps": [
7
+ {
8
+ "name": "vcloud-walker-vapp",
9
+ "status": "4",
10
+ "deployed": "true",
11
+ "id": "urn:vcloud:vapp:e6db5703-0f33-4c65-8e1f-f54ae0ff2864",
12
+ "description": "this app is used to run integration tests for vcloud-walker",
13
+ "network_config": [
14
+ {
15
+ "network_name": "Default",
16
+ "is_deployed": "true",
17
+ "description": "The nat network",
18
+ "config": {
19
+ "ipscopes": {
20
+ "IpScope": {
21
+ "IsInherited": "true",
22
+ "Gateway": "192.168.2.1",
23
+ "Netmask": "255.255.255.240",
24
+ "Dns1": "8.8.8.8",
25
+ "Dns2": "8.8.4.4",
26
+ "DnsSuffix": "tester.default",
27
+ "IsEnabled": "true",
28
+ "IpRanges": {
29
+ "IpRange": {
30
+ "StartAddress": "192.168.2.2",
31
+ "EndAddress": "192.168.2.14"
32
+ }
33
+ }
34
+ }
35
+ }
36
+ },
37
+ "parent_network": "Default"
38
+ }
39
+ ],
40
+ "network_section": {
41
+ "ovf_name": "Default",
42
+ "ovf:Description": "The nat network"
43
+ },
44
+ "vms": [
45
+ {
46
+ "id": "urn:vcloud:vm:d19d84a5-c950-4497-a638-23eccc4226a5",
47
+ "status": "4",
48
+ "operating_system": "Ubuntu Linux (64-bit)",
49
+ "network_connections": {
50
+ "network": "Default",
51
+ "needsCustomization": "true",
52
+ "NetworkConnectionIndex": "0",
53
+ "IpAddress": "192.168.2.2",
54
+ "IsConnected": "true",
55
+ "MACAddress": "00:50:56:01:0b:1a",
56
+ "IpAddressAllocationMode": "MANUAL"
57
+ },
58
+ "primary_network_connection_index": "0",
59
+ "cpu": "1 virtual CPU(s)",
60
+ "memory": "256 MB of memory",
61
+ "disks": [
62
+ {
63
+ "name": "Hard disk 1",
64
+ "size": 11265
65
+ }
66
+ ]
67
+ }
68
+ ]
69
+ },
70
+ {
71
+ "name": "vApp-2",
72
+ "status": "8",
73
+ "deployed": "true",
74
+ "id": "urn:vcloud:vapp:ee27028f-1424-4225-92a2-9deca813cca8",
75
+ "description": "vapp-2 test app",
76
+ "network_config": [
77
+ {
78
+ "network_name": "Default",
79
+ "is_deployed": "true",
80
+ "description": "The nat network",
81
+ "config": {
82
+ "ipscopes": {
83
+ "IpScope": {
84
+ "IsInherited": "true",
85
+ "Gateway": "192.168.2.1",
86
+ "Netmask": "255.255.255.240",
87
+ "Dns1": "8.8.8.8",
88
+ "Dns2": "8.8.4.4",
89
+ "DnsSuffix": "tester.default",
90
+ "IsEnabled": "true",
91
+ "IpRanges": {
92
+ "IpRange": {
93
+ "StartAddress": "192.168.2.2",
94
+ "EndAddress": "192.168.2.14"
95
+ }
96
+ }
97
+ }
98
+ }
99
+ },
100
+ "parent_network": "Default"
101
+ }
102
+ ],
103
+ "network_section": {
104
+ "ovf_name": "Default",
105
+ "ovf:Description": "The nat network"
106
+ },
107
+ "vms": [
108
+ {
109
+ "id": "urn:vcloud:vm:b0a89e9f-0339-4913-acdd-864b12898e53",
110
+ "status": "8",
111
+ "operating_system": "Ubuntu Linux (64-bit)",
112
+ "network_connections": {
113
+ "network": "Default",
114
+ "needsCustomization": "true",
115
+ "NetworkConnectionIndex": "0",
116
+ "IpAddress": "fe80:0:0:0:250:56ff:fe01:c18",
117
+ "IsConnected": "true",
118
+ "MACAddress": "00:50:56:01:0c:18",
119
+ "IpAddressAllocationMode": "DHCP"
120
+ },
121
+ "primary_network_connection_index": "0",
122
+ "cpu": "1 virtual CPU(s)",
123
+ "memory": "256 MB of memory",
124
+ "disks": [
125
+ {
126
+ "name": "Hard disk 1",
127
+ "size": 11265
128
+ }
129
+ ]
130
+ }
131
+ ]
132
+ },
133
+ {
134
+ "name": "vapp-1",
135
+ "status": "8",
136
+ "deployed": "true",
137
+ "id": "urn:vcloud:vapp:1cad91a8-04c2-4f0d-9c62-ad4463b5197f",
138
+ "description": "vapp 1",
139
+ "network_config": [
140
+ {
141
+ "network_name": "Default",
142
+ "is_deployed": "true",
143
+ "description": "The nat network",
144
+ "config": {
145
+ "ipscopes": {
146
+ "IpScope": {
147
+ "IsInherited": "true",
148
+ "Gateway": "192.168.2.1",
149
+ "Netmask": "255.255.255.240",
150
+ "Dns1": "8.8.8.8",
151
+ "Dns2": "8.8.4.4",
152
+ "DnsSuffix": "tester.default",
153
+ "IsEnabled": "true",
154
+ "IpRanges": {
155
+ "IpRange": {
156
+ "StartAddress": "192.168.2.2",
157
+ "EndAddress": "192.168.2.14"
158
+ }
159
+ }
160
+ }
161
+ }
162
+ },
163
+ "parent_network": "Default"
164
+ }
165
+ ],
166
+ "network_section": {
167
+ "ovf_name": "Default",
168
+ "ovf:Description": "The nat network"
169
+ },
170
+ "vms": [
171
+ {
172
+ "id": "urn:vcloud:vm:24bda672-cc1c-4d56-ab3b-19c0ba20d1b4",
173
+ "status": "8",
174
+ "operating_system": "Ubuntu Linux (64-bit)",
175
+ "network_connections": {
176
+ "network": "Default",
177
+ "needsCustomization": "true",
178
+ "NetworkConnectionIndex": "0",
179
+ "IpAddress": "fe80:0:0:0:250:56ff:fe01:c17",
180
+ "IsConnected": "true",
181
+ "MACAddress": "00:50:56:01:0c:17",
182
+ "IpAddressAllocationMode": "DHCP"
183
+ },
184
+ "primary_network_connection_index": "0",
185
+ "cpu": "1 virtual CPU(s)",
186
+ "memory": "256 MB of memory",
187
+ "disks": [
188
+ {
189
+ "name": "Hard disk 1",
190
+ "size": 11265
191
+ }
192
+ ]
193
+ }
194
+ ]
195
+ }
196
+ ],
197
+ "quotas": {
198
+ "network": 20,
199
+ "nic": 0,
200
+ "vm": 100
201
+ },
202
+ "compute_capacity": {
203
+ "Cpu": {
204
+ "Units": "MHz",
205
+ "Allocated": "0",
206
+ "Limit": "0",
207
+ "Reserved": "0",
208
+ "Used": "2000",
209
+ "Overhead": "0"
210
+ },
211
+ "Memory": {
212
+ "Units": "MB",
213
+ "Allocated": "0",
214
+ "Limit": "0",
215
+ "Reserved": "0",
216
+ "Used": "256",
217
+ "Overhead": "21"
218
+ }
219
+ }
220
+ }
221
+ ]
data/jenkins.sh ADDED
@@ -0,0 +1,9 @@
1
+ #!/bin/bash -x
2
+ set -e
3
+
4
+ rm -f Gemfile.lock
5
+ git clean -fdx
6
+
7
+ bundle install --path "${HOME}/bundles/${JOB_NAME}"
8
+ bundle exec rake
9
+ bundle exec rake publish_gem
@@ -0,0 +1,11 @@
1
+ #!/bin/bash -x
2
+ set -e
3
+ bundle install --path "${HOME}/bundles/${JOB_NAME}"
4
+
5
+ ./scripts/generate_fog_conf_file.sh
6
+
7
+ export FOG_RC=fog_integration_test.config
8
+
9
+ bundle exec rake integration_test
10
+
11
+ rm fog_integration_test.config
@@ -0,0 +1,48 @@
1
+ module Vcloud
2
+ module Walker
3
+ class FogInterface
4
+
5
+ def self.get_catalogs
6
+ org = get_org
7
+ org.catalogs.all(false)
8
+ end
9
+
10
+ def self.get_vdcs
11
+ org = get_org
12
+ org.vdcs.all(false)
13
+ end
14
+
15
+ def self.get_networks
16
+ org = get_org
17
+ org.networks.all(false)
18
+ end
19
+
20
+ # we use the request here as we don't yet have a model for Edge Gateways
21
+ def self.get_edge_gateways
22
+ vcloud = VcloudSession.instance
23
+ get_vdcs.collect do |vdc|
24
+ data = vcloud.get_org_vdc_gateways(vdc.id).body
25
+ if data[:EdgeGatewayRecord]
26
+ edge_gateways = data[:EdgeGatewayRecord].is_a?(Hash) ? [data[:EdgeGatewayRecord]] : data[:EdgeGatewayRecord]
27
+ edge_gateways.map do |edgeGateway|
28
+ vcloud.get_edge_gateway(edgeGateway[:href].split('/').last).body
29
+ end
30
+ end
31
+ end.flatten.compact
32
+ end
33
+
34
+ # service-layer
35
+ def self.get_vapp vapp_id
36
+ VcloudSession.instance.get_vapp(vapp_id).body
37
+ end
38
+
39
+ private
40
+ def self.get_org
41
+ vcloud = VcloudSession.instance
42
+ vcloud.organizations.get_by_name(vcloud.org_name)
43
+ end
44
+
45
+ end
46
+ end
47
+ end
48
+
@@ -0,0 +1,29 @@
1
+ module Vcloud
2
+ module Walker
3
+ module Resource
4
+ class Catalog < Entity
5
+ attr_reader :id, :name, :description, :items
6
+
7
+ def initialize(fog_catalog)
8
+ @id = fog_catalog.id
9
+ @name = fog_catalog.name
10
+ @description = fog_catalog.description
11
+ @items = CatalogItems.new(fog_catalog.catalog_items.all(false))
12
+ end
13
+
14
+ end
15
+
16
+ class Catalogs < Collection
17
+
18
+ def initialize fog_catalogs
19
+ fog_catalogs.each do |catalog|
20
+ self << Resource::Catalog.new(catalog)
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+ end
28
+ end
29
+
@@ -0,0 +1,25 @@
1
+ module Vcloud
2
+ module Walker
3
+ module Resource
4
+ class CatalogItem < Entity
5
+ attr_reader :id, :name, :description, :vapp_template_id
6
+
7
+ def initialize fog_catalog_item
8
+ @id = fog_catalog_item.id
9
+ @name = fog_catalog_item.name
10
+ @description = fog_catalog_item.description
11
+ @vapp_template_id = fog_catalog_item.vapp_template_id
12
+ end
13
+ end
14
+
15
+ class CatalogItems < Collection
16
+ def initialize fog_catalog_items
17
+ fog_catalog_items.each do |i|
18
+ self << Resource::CatalogItem.new(i)
19
+ end
20
+ end
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ module Vcloud
2
+ module Walker
3
+ module Resource
4
+ class Collection < Array
5
+ def to_summary
6
+ self.collect do |element|
7
+ element.to_summary
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,27 @@
1
+ module Vcloud
2
+ module Walker
3
+ module Resource
4
+ class Entity
5
+
6
+ def to_summary
7
+ h= {}
8
+ instance_variables.each { |atr|
9
+ atr_value = self.instance_variable_get(atr)
10
+ if atr_value.is_a?(Vcloud::Walker::Resource::Collection) || atr_value.is_a?(Entity)
11
+ h[atr.to_s.delete("@").to_sym] = atr_value.to_summary
12
+ else
13
+ h[atr.to_s.delete("@").to_sym] = atr_value
14
+ end
15
+ }
16
+ h
17
+ end
18
+
19
+ private
20
+ def extract_id(href)
21
+ href.split('/').last
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,46 @@
1
+ module Vcloud
2
+ module Walker
3
+ module Resource
4
+ class GatewayIpsecVpnService < Entity
5
+ attr_reader :IsEnabled, :Tunnels
6
+
7
+ def initialize fog_vpn_service
8
+ @IsEnabled = fog_vpn_service[:IsEnabled]
9
+ if fog_vpn_service[:Tunnel]
10
+ fog_vpn_tunnels = [fog_vpn_service[:Tunnel]].flatten
11
+ @Tunnels = populate_tunnel_info(fog_vpn_tunnels)
12
+ end
13
+ end
14
+
15
+ private
16
+ def populate_tunnel_info(fog_vpn_tunnels)
17
+ return if fog_vpn_tunnels.empty?
18
+ fog_vpn_tunnels.collect do |fog_vpn_tunnel|
19
+ @tunnel = {
20
+ :Name => fog_vpn_tunnel[:Name],
21
+ :Description => fog_vpn_tunnel[:Description],
22
+ :ThirdPartyPeerId => fog_vpn_tunnel[:IpsecVpnThirdPartyPeer][:PeerId],
23
+ :PeerId => fog_vpn_tunnel[:PeerId],
24
+ :LocalId => fog_vpn_tunnel[:LocalId],
25
+ :PeerIpAddress => fog_vpn_tunnel[:PeerIpAddress],
26
+ :LocalIpAddress => fog_vpn_tunnel[:LocalIpAddress],
27
+ :PeerSubnet => fog_vpn_tunnel[:PeerSubnet],
28
+ :LocalSubnet => fog_vpn_tunnel[:LocalSubnet],
29
+ :Mtu => fog_vpn_tunnel[:Mtu],
30
+ :IsEnabled => fog_vpn_tunnel[:IsEnabled],
31
+ :IsOperational => fog_vpn_tunnel[:IsOperational]
32
+ }
33
+
34
+ @tunnel[:SharedSecret] = "*" * 65 if fog_vpn_tunnel[:SharedSecret]
35
+ @tunnel[:SharedSecretEncrypted] = "******" if fog_vpn_tunnel[:SharedSecretEncrypted]
36
+ @tunnel[:EncryptionProtocol] = "******" if fog_vpn_tunnel[:EncryptionProtocol]
37
+ @tunnel
38
+ end
39
+ end
40
+
41
+
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,38 @@
1
+ module Vcloud
2
+ module Walker
3
+
4
+ module Resource
5
+
6
+ class Networks < Resource::Collection
7
+
8
+ def initialize fog_networks
9
+ fog_networks.each do |org_network|
10
+ self << Resource::Network.new(org_network)
11
+ end
12
+ end
13
+
14
+ end
15
+
16
+
17
+ class Network < Entity
18
+ attr_reader :id, :name, :description, :is_inherited, :gateway, :netmask, :dns1, :dns2, :dns_suffix, :ip_ranges
19
+
20
+ def initialize org_network
21
+ @id = org_network.id
22
+ @name = org_network.name
23
+ @description = org_network.description
24
+ @is_inherited = org_network.is_inherited
25
+ @gateway = org_network.gateway
26
+ @netmask = org_network.netmask
27
+ @dns1 = org_network.dns1
28
+ @dns2 = org_network.dns2
29
+ @dns_suffix = org_network.dns_suffix
30
+ @ip_ranges = org_network.ip_ranges
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+ end
37
+ end
38
+
@@ -0,0 +1,45 @@
1
+ module Vcloud
2
+ module Walker
3
+ module Resource
4
+ class Organization < Entity
5
+ def self.catalogs
6
+ fog_catalogs = FogInterface.get_catalogs
7
+ Catalogs.new(fog_catalogs).to_summary
8
+ end
9
+
10
+ def self.vdcs
11
+ fog_vdcs = FogInterface.get_vdcs
12
+ Vdcs.new(fog_vdcs).to_summary
13
+ end
14
+
15
+ def self.edgegateways
16
+ fog_edge_gateways = FogInterface.get_edge_gateways
17
+ fog_edge_gateways.collect do |edge_gw|
18
+ edge_gw[:id] = edge_gw[:href].split('/').last
19
+ edgegw_service_configuration = edge_gw[:Configuration][:EdgeGatewayServiceConfiguration]
20
+ if edgegw_service_configuration[:GatewayIpsecVpnService]
21
+ edgegw_service_configuration[:GatewayIpsecVpnService] = GatewayIpsecVpnService.new(edgegw_service_configuration[:GatewayIpsecVpnService]).to_summary
22
+ end
23
+ edge_gw
24
+ end
25
+ end
26
+
27
+ def self.networks
28
+ fog_networks = FogInterface.get_networks
29
+ Networks.new(fog_networks).to_summary
30
+ end
31
+
32
+ def self.organization
33
+ {
34
+ :vdcs => vdcs,
35
+ :networks => networks,
36
+ :catalogs => catalogs,
37
+ :edgegateways => edgegateways,
38
+ }
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+ end
45
+
@@ -0,0 +1,46 @@
1
+ module Vcloud
2
+ module Walker
3
+ module Resource
4
+ class VApp < Entity
5
+ attr_reader :id, :name, :status, :description, :network_config, :vms, :deployed, :network_section, :metadata
6
+
7
+ def initialize fog_vapp
8
+ @name = fog_vapp[:name]
9
+ @status = fog_vapp[:status]
10
+ @description = fog_vapp[:Description]
11
+ @deployed = fog_vapp[:deployed]
12
+ @id = extract_id(fog_vapp[:href])
13
+ @network_config = extract_network_config(fog_vapp[:NetworkConfigSection][:NetworkConfig])
14
+ @network_section = fog_vapp[:'ovf:NetworkSection'][:'ovf:Network']
15
+ @vms = Resource::Vms.new(fog_vapp[:Children][:Vm])
16
+ @metadata = Vcloud::Core::Vapp.get_metadata(id)
17
+ end
18
+
19
+ private
20
+ def extract_network_config network_configs
21
+ (network_configs.is_a?(Hash) ? [network_configs] : network_configs).collect do |network_config|
22
+ {
23
+ network_name: network_config[:networkName],
24
+ is_deployed: network_config[:IsDeployed],
25
+ description: network_config[:Description],
26
+ config: {
27
+ ipscopes: network_config[:Configuration][:IpScopes]
28
+ },
29
+ parent_network: network_config[:Configuration][:ParentNetwork] ? network_config[:Configuration][:ParentNetwork][:name] : nil
30
+ }
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ class VApps < Collection
37
+ def initialize ids
38
+ ids.each do |vapp_id|
39
+ vapp = FogInterface.get_vapp(vapp_id)
40
+ self << Resource::VApp.new(vapp)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,35 @@
1
+ module Vcloud
2
+ module Walker
3
+ module Resource
4
+ class Vdcs < Collection
5
+
6
+ def initialize fog_vdcs
7
+ fog_vdcs.each do |vdc|
8
+ self << Resource::Vdc.new(vdc)
9
+ end
10
+ end
11
+
12
+ end
13
+
14
+
15
+ class Vdc < Entity
16
+ attr_reader :vapps, :id, :name, :description, :quotas, :compute_capacity
17
+
18
+ def initialize(fog_vdc)
19
+ @id = fog_vdc.id
20
+ @name = fog_vdc.name
21
+ @description = fog_vdc.description
22
+ @vapps = Resource::VApps.new(fog_vdc.vapps.map(&:id))
23
+ @quotas = {network: fog_vdc.network_quota, nic: fog_vdc.nic_quota, vm: fog_vdc.vm_quota}
24
+ @compute_capacity = fog_vdc.compute_capacity
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+
33
+
34
+
35
+