vagrant-vcloud 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.rubocop.yml +34 -0
  4. data/README.md +19 -2
  5. data/Rakefile +1 -1
  6. data/lib/vagrant-vcloud.rb +11 -13
  7. data/lib/vagrant-vcloud/action.rb +74 -47
  8. data/lib/vagrant-vcloud/action/announce_ssh_exec.rb +4 -2
  9. data/lib/vagrant-vcloud/action/build_vapp.rb +134 -110
  10. data/lib/vagrant-vcloud/action/connect_vcloud.rb +31 -42
  11. data/lib/vagrant-vcloud/action/destroy.rb +34 -29
  12. data/lib/vagrant-vcloud/action/disconnect_vcloud.rb +7 -5
  13. data/lib/vagrant-vcloud/action/forward_ports.rb +42 -35
  14. data/lib/vagrant-vcloud/action/handle_nat_port_collisions.rb +26 -22
  15. data/lib/vagrant-vcloud/action/inventory_check.rb +79 -52
  16. data/lib/vagrant-vcloud/action/is_bridged.rb +30 -0
  17. data/lib/vagrant-vcloud/action/is_created.rb +13 -14
  18. data/lib/vagrant-vcloud/action/is_paused.rb +0 -2
  19. data/lib/vagrant-vcloud/action/is_running.rb +0 -2
  20. data/lib/vagrant-vcloud/action/message_already_running.rb +1 -1
  21. data/lib/vagrant-vcloud/action/message_cannot_suspend.rb +1 -1
  22. data/lib/vagrant-vcloud/action/message_not_created.rb +1 -1
  23. data/lib/vagrant-vcloud/action/message_will_not_destroy.rb +6 -1
  24. data/lib/vagrant-vcloud/action/power_off.rb +16 -21
  25. data/lib/vagrant-vcloud/action/power_on.rb +64 -28
  26. data/lib/vagrant-vcloud/action/read_ssh_info.rb +44 -28
  27. data/lib/vagrant-vcloud/action/read_state.rb +16 -23
  28. data/lib/vagrant-vcloud/action/resume.rb +5 -13
  29. data/lib/vagrant-vcloud/action/suspend.rb +5 -13
  30. data/lib/vagrant-vcloud/action/sync_folders.rb +82 -48
  31. data/lib/vagrant-vcloud/action/unmap_port_forwardings.rb +27 -29
  32. data/lib/vagrant-vcloud/command.rb +186 -0
  33. data/lib/vagrant-vcloud/config.rb +41 -20
  34. data/lib/vagrant-vcloud/driver/base.rb +170 -121
  35. data/lib/vagrant-vcloud/driver/meta.rb +64 -70
  36. data/lib/vagrant-vcloud/driver/version_5_1.rb +1038 -716
  37. data/lib/vagrant-vcloud/errors.rb +4 -4
  38. data/lib/vagrant-vcloud/model/forwarded_port.rb +4 -2
  39. data/lib/vagrant-vcloud/plugin.rb +30 -20
  40. data/lib/vagrant-vcloud/provider.rb +6 -6
  41. data/lib/vagrant-vcloud/util/compile_forwarded_ports.rb +1 -1
  42. data/lib/vagrant-vcloud/version.rb +1 -1
  43. data/locales/en.yml +6 -5
  44. data/vagrant-vcloud.gemspec +10 -7
  45. metadata +35 -4
@@ -1,29 +1,21 @@
1
- require "i18n"
2
-
3
1
  module VagrantPlugins
4
2
  module VCloud
5
3
  module Action
6
4
  class Resume
7
-
8
5
  def initialize(app, env)
9
6
  @app = app
10
- @logger = Log4r::Logger.new("vagrant_vcloud::action::resume")
7
+ @logger = Log4r::Logger.new('vagrant_vcloud::action::resume')
11
8
  end
12
9
 
13
10
  def call(env)
14
-
15
11
  cfg = env[:machine].provider_config
16
12
  cnx = cfg.vcloud_cnx.driver
17
13
 
18
- vAppId = env[:machine].get_vapp_id
19
- vmId = env[:machine].id
20
- vmName = env[:machine].name
21
-
22
- env[:ui].info("Powering on VM...")
23
- task_id = cnx.poweron_vm(vmId)
24
- wait = cnx.wait_task_completion(task_id)
14
+ vm_id = env[:machine].id
25
15
 
26
- true
16
+ env[:ui].info('Powering on VM...')
17
+ task_id = cnx.poweron_vm(vm_id)
18
+ cnx.wait_task_completion(task_id)
27
19
 
28
20
  @app.call env
29
21
  end
@@ -1,29 +1,21 @@
1
- require "i18n"
2
-
3
1
  module VagrantPlugins
4
2
  module VCloud
5
3
  module Action
6
4
  class Suspend
7
-
8
5
  def initialize(app, env)
9
6
  @app = app
10
- @logger = Log4r::Logger.new("vagrant_vcloud::action::suspend")
7
+ @logger = Log4r::Logger.new('vagrant_vcloud::action::suspend')
11
8
  end
12
9
 
13
10
  def call(env)
14
-
15
11
  cfg = env[:machine].provider_config
16
12
  cnx = cfg.vcloud_cnx.driver
17
13
 
18
- vAppId = env[:machine].get_vapp_id
19
- vmId = env[:machine].id
20
- vmName = env[:machine].name
21
-
22
- env[:ui].info("Suspending VM...")
23
- task_id = cnx.suspend_vm(vmId)
24
- wait = cnx.wait_task_completion(task_id)
14
+ vm_id = env[:machine].id
25
15
 
26
- true
16
+ env[:ui].info('Suspending VM...')
17
+ task_id = cnx.suspend_vm(vm_id)
18
+ cnx.wait_task_completion(task_id)
27
19
 
28
20
  @app.call env
29
21
  end
@@ -1,57 +1,73 @@
1
1
  # The MIT License (MIT)
2
2
  # Copyright (c) 2013 Mitchell Hashimoto
3
3
 
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
- # this software and associated documentation files (the "Software"), to deal in
6
- # the Software without restriction, including without limitation the rights to
7
- # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8
- # of the Software, and to permit persons to whom the Software is furnished to do
9
- # so, subject to the following conditions:
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to
6
+ # deal in the Software without restriction, including without limitation the
7
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8
+ # sell copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
10
 
11
11
  # The above copyright notice and this permission notice shall be included in all
12
12
  # copies or substantial portions of the Software.
13
13
 
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
- # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
- # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
- # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
- # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20
+ # IN THE SOFTWARE.
20
21
 
21
- require "log4r"
22
- require "vagrant/util/subprocess"
23
- require "vagrant/util/scoped_hash_override"
24
- require "vagrant/util/which"
22
+ require 'vagrant/util/subprocess'
23
+ require 'vagrant/util/scoped_hash_override'
24
+ require 'vagrant/util/which'
25
25
 
26
26
  module VagrantPlugins
27
27
  module VCloud
28
28
  module Action
29
+ # This class syncs Vagrant folders using RSYNC, this code has been ported
30
+ # from vagrant-aws (https://github.com/mitchellh/vagrant-aws)
29
31
  class SyncFolders
30
32
  include Vagrant::Util::ScopedHashOverride
31
33
 
32
34
  def initialize(app, env)
33
35
  @app = app
34
- @logger = Log4r::Logger.new("vagrant_vcloud::action::sync_folders")
36
+ @logger = Log4r::Logger.new('vagrant_vcloud::action::sync_folders')
35
37
  end
36
38
 
37
39
  def call(env)
38
40
  @app.call(env)
39
41
 
40
- ### COMPLETELY REDO USING UNISON!!!!
41
-
42
42
  ssh_info = env[:machine].ssh_info
43
43
 
44
+ unless Vagrant::Util::Which.which('rsync')
45
+ env[:ui].warn(
46
+ I18n.t(
47
+ 'vagrant_vcloud.sync.rsync_not_found_warning',
48
+ :side => 'host'
49
+ )
50
+ )
51
+ return
52
+ end
53
+
54
+ if env[:machine].communicate.execute('which rsync',
55
+ :error_check => false) != 0
56
+ env[:ui].warn(
57
+ I18n.t(
58
+ 'vagrant_vcloud.sync.rsync_not_found_warning',
59
+ :side => 'guest'
60
+ )
61
+ )
62
+ return
63
+ end
64
+
44
65
  env[:machine].config.vm.synced_folders.each do |id, data|
45
- data = scoped_hash_override(data, :vcloud)
66
+ data = scoped_hash_override(data, :vCloud)
46
67
 
47
68
  # Ignore disabled shared folders
48
69
  next if data[:disabled]
49
70
 
50
- unless Vagrant::Util::Which.which('rsync')
51
- env[:ui].warn(I18n.t('vagrant_vcloud.rsync_not_found_warning'))
52
- break
53
- end
54
-
55
71
  hostpath = File.expand_path(data[:hostpath], env[:root_path])
56
72
  guestpath = data[:guestpath]
57
73
 
@@ -61,56 +77,74 @@ module VagrantPlugins
61
77
 
62
78
  # on windows rsync.exe requires cygdrive-style paths
63
79
  if Vagrant::Util::Platform.windows?
64
- hostpath = hostpath.gsub(/^(\w):/) { "/cygdrive/#{$1}" }
80
+ hostpath = hostpath.gsub(/^(\w):/) { "/cygdrive/\1" }
65
81
  end
66
82
 
67
- env[:ui].info(I18n.t("vagrant_vcloud.rsync_folder",
68
- :hostpath => hostpath,
69
- :guestpath => guestpath))
83
+ env[:ui].info(
84
+ I18n.t(
85
+ 'vagrant_vcloud.sync.rsync_folder',
86
+ :hostpath => hostpath,
87
+ :guestpath => guestpath
88
+ )
89
+ )
70
90
 
71
91
  # Create the host path if it doesn't exist and option flag is set
72
92
  if data[:create]
73
93
  begin
74
- FileUtils::mkdir_p(hostpath)
94
+ FileUtils.mkdir_p(hostpath)
75
95
  rescue => err
76
96
  raise Errors::MkdirError,
77
- :hostpath => hostpath,
78
- :err => err
97
+ :hostpath => hostpath,
98
+ :err => err
79
99
  end
80
100
  end
81
101
 
82
102
  # Create the guest path
83
103
  env[:machine].communicate.sudo("mkdir -p '#{guestpath}'")
84
104
  env[:machine].communicate.sudo(
85
- "chown #{ssh_info[:username]} '#{guestpath}'")
86
-
87
- # Since Vagrant 1.4 the private key path may be an array
88
- ssh_key_paths = ssh_info[:private_key_path].is_a?(Array) ? ssh_info[:private_key_path] : [ ssh_info[:private_key_path] ]
89
- ssh_keys = ssh_key_paths.map {|p| "-i '#{p}'"}.join(" ")
105
+ "chown -R #{ssh_info[:username]} '#{guestpath}'"
106
+ )
107
+
108
+ # collect rsync excludes specified :rsync_excludes=>['path1',...]
109
+ # in synced_folder options
110
+ excludes = [
111
+ '.vagrant/',
112
+ 'Vagrantfile',
113
+ *Array(data[:rsync_excludes])
114
+ ].uniq
90
115
 
91
116
  # Rsync over to the guest path using the SSH info
92
117
  command = [
93
- "rsync", "--verbose", "--archive", "-z",
94
- "--exclude", ".vagrant/", "--exclude", "Vagrantfile",
95
- "-e", "ssh -p #{ssh_info[:port]} -o StrictHostKeyChecking=no #{ssh_keys}",
96
- hostpath,
97
- "#{ssh_info[:username]}@#{ssh_info[:host]}:#{guestpath}"]
118
+ 'rsync', '--verbose', '--archive', '-z',
119
+ *excludes.map { |e|['--exclude', e] }.flatten,
120
+ '-e', "ssh -p #{ssh_info[:port]} -o StrictHostKeyChecking=no " +
121
+ "#{ssh_key_options(ssh_info)}", hostpath,
122
+ "#{ssh_info[:username]}@#{ssh_info[:host]}:#{guestpath}"
123
+ ]
98
124
 
99
125
  # we need to fix permissions when using rsync.exe on windows, see
100
- # http://stackoverflow.com/questions/5798807/rsync-permission-denied-created-directories-have-no-permissions
126
+ # http://stackoverflow.com/questions/5798807/rsync-permission-
127
+ # denied-created-directories-have-no-permissions
101
128
  if Vagrant::Util::Platform.windows?
102
- command.insert(1, "--chmod", "ugo=rwX")
129
+ command.insert(1, '--chmod', 'ugo=rwX')
103
130
  end
104
131
 
105
132
  r = Vagrant::Util::Subprocess.execute(*command)
106
133
  if r.exit_code != 0
107
- raise Errors::RsyncError,
108
- :guestpath => guestpath,
109
- :hostpath => hostpath,
110
- :stderr => r.stderr
134
+ fail Errors::RsyncError,
135
+ :guestpath => guestpath,
136
+ :hostpath => hostpath,
137
+ :stderr => r.stderr
111
138
  end
112
139
  end
113
140
  end
141
+
142
+ private
143
+
144
+ def ssh_key_options(ssh_info)
145
+ # Ensure that `private_key_path` is an Array (for Vagrant < 1.4)
146
+ Array(ssh_info[:private_key_path]).map { |path| "-i '#{path}' " }.join
147
+ end
114
148
  end
115
149
  end
116
150
  end
@@ -1,6 +1,4 @@
1
- require "set"
2
-
3
- require "log4r"
1
+ require 'set'
4
2
 
5
3
  module VagrantPlugins
6
4
  module VCloud
@@ -22,51 +20,51 @@ module VagrantPlugins
22
20
  # to other host ports.
23
21
  #
24
22
  class UnmapPortForwardings
25
-
26
-
27
23
  def initialize(app, env)
28
24
  @app = app
29
- @logger = Log4r::Logger.new("vagrant_vcloud::action::unmap_port_forwardings")
25
+ @logger = Log4r::Logger.new(
26
+ 'vagrant_vcloud::action::unmap_port_forwardings'
27
+ )
30
28
  end
31
29
 
32
30
  def call(env)
33
-
34
31
  cfg = env[:machine].provider_config
35
32
  cnx = cfg.vcloud_cnx.driver
36
- vmName = env[:machine].name
37
- vAppId = env[:machine].get_vapp_id
33
+ vapp_id = env[:machine].get_vapp_id
34
+ vm_name = env[:machine].name
38
35
 
39
36
  cfg.org = cnx.get_organization_by_name(cfg.org_name)
40
37
  cfg.vdc_network_id = cfg.org[:networks][cfg.vdc_network_name]
41
38
 
42
- @logger.debug("Getting vapp info...")
43
- vm = cnx.get_vapp(vAppId)
44
- myhash = vm[:vms_hash][vmName.to_sym]
39
+ @logger.debug('Getting vApp information...')
40
+ vm = cnx.get_vapp(vapp_id)
41
+ myhash = vm[:vms_hash][vm_name.to_sym]
45
42
 
46
- @logger.debug("Getting port forwarding rules...")
47
- rules = cnx.get_vapp_port_forwarding_rules(vAppId)
43
+ @logger.debug('Getting port forwarding rules...')
44
+ rules = cnx.get_vapp_port_forwarding_rules(vapp_id)
48
45
 
49
- newRuleSet = rules.select { |h| !myhash[:vapp_scoped_local_id].include? h[:vapp_scoped_local_id] }
46
+ # FIXME: not familiar with this syntax (tsugliani)
47
+ new_rule_set = rules.select {
48
+ |h| !myhash[:vapp_scoped_local_id].include? h[:vapp_scoped_local_id]
49
+ }
50
50
 
51
- @logger.debug("OUR NEW RULE SET, PURGED: #{newRuleSet}")
51
+ @logger.debug("OUR NEW RULE SET, PURGED: #{new_rule_set}")
52
52
 
53
- removePorts = cnx.set_vapp_port_forwarding_rules(
54
- vAppId,
55
- "Vagrant-vApp-Net",
56
- {
57
- :fence_mode => "natRouted",
58
- :parent_network => cfg.vdc_network_id,
59
- :nat_policy_type => "allowTraffic",
60
- :nat_rules => newRuleSet
61
- })
53
+ remove_ports = cnx.set_vapp_port_forwarding_rules(
54
+ vapp_id,
55
+ 'Vagrant-vApp-Net',
56
+ :fence_mode => 'natRouted',
57
+ :parent_network => cfg.vdc_network_id,
58
+ :nat_policy_type => 'allowTraffic',
59
+ :nat_rules => new_rule_set
60
+ )
62
61
 
63
- wait = cnx.wait_task_completion(removePorts)
62
+ wait = cnx.wait_task_completion(remove_ports)
64
63
 
65
- if !wait[:errormsg].nil?
66
- raise Errors::ComposeVAppError, :message => wait[:errormsg]
64
+ unless wait[:errormsg].nil?
65
+ fail Errors::ComposeVAppError, :message => wait[:errormsg]
67
66
  end
68
67
 
69
-
70
68
  @app.call(env)
71
69
  end
72
70
  end
@@ -0,0 +1,186 @@
1
+ require 'awesome_print'
2
+ require 'terminal-table'
3
+
4
+ module VagrantPlugins
5
+ module VCloud
6
+ class Command < Vagrant.plugin('2', :command)
7
+ def self.synopsis
8
+ 'outputs status of the vCloud Director setup [vcloud provider only]'
9
+ end
10
+
11
+ def execute
12
+ options = {}
13
+ opts = OptionParser.new do |o|
14
+ o.banner = 'Usage: vagrant vcloud-status [--all]'
15
+
16
+ # We can probably extend this if needed for specific information
17
+ o.on('-a', '--all', 'Displays all available information') do |f|
18
+ options[:all] = true
19
+ end
20
+ end
21
+
22
+ @argv = parse_options(opts)
23
+ return unless @argv
24
+
25
+ # initialize some variables
26
+ vapp_id = nil
27
+ cfg = nil
28
+
29
+ # Go through the vagrant machines
30
+ with_target_vms(@argv) do |machine|
31
+
32
+ # FIXME/Bug: why does the provider switch to virtualbox when
33
+ # destroying VMs within the the vApp:
34
+ # .vagrant/machines/<machine>/virtualbox Cannot trace why this
35
+ # happens :-( (tsugliani)
36
+ if machine.provider_name != :vcloud
37
+ # Not a vCloud Director provider, exit with explicit error message
38
+ puts "#{machine.provider_name} provider is incompatible with " +
39
+ 'this command'
40
+ exit 1
41
+ end
42
+
43
+ # Force reloads on objects by fetching the ssh_info
44
+ machine.provider.ssh_info
45
+
46
+ # populate cfg & vApp Id for later use.
47
+ cfg = machine.provider_config
48
+ vapp_id = machine.get_vapp_id
49
+ break
50
+ end
51
+
52
+ # Set our handlers to the driver and objects
53
+ cnx = cfg.vcloud_cnx.driver
54
+ vapp = cnx.get_vapp(vapp_id)
55
+
56
+ organization = cnx.get_organization_by_name(cfg.org_name)
57
+ cfg.vdc_id = cnx.get_vdc_id_by_name(organization, cfg.vdc_name)
58
+
59
+ # Create a new table for the general information
60
+ table = Terminal::Table.new
61
+ table.title = "Vagrant vCloud Director Status : #{cfg.hostname}"
62
+
63
+ table << ['Organization Name', cfg.org_name]
64
+ table << ['Organization vDC Name', cfg.vdc_name]
65
+ table << ['Organization vDC ID', cfg.vdc_id]
66
+ table << ['Organization vDC Network Name', cfg.vdc_network_name]
67
+ table << ['Organization vDC Edge Gateway Name',
68
+ cfg.vdc_edge_gateway] unless cfg.vdc_edge_gateway.nil?
69
+ table << ['Organization vDC Edge IP',
70
+ cfg.vdc_edge_gateway_ip] unless cfg.vdc_edge_gateway_ip.nil?
71
+ table << :separator
72
+ table << ['vApp Name', vapp[:name]]
73
+ table << ['vAppID', vapp_id]
74
+
75
+ vapp[:vms_hash].each do |vm|
76
+ # This should be checked indivudually
77
+ # When 1 VM is destroyed, ID is still populated, should be cleaned.
78
+ table << ["-> #{vm[0]}", vm[1][:id]]
79
+ end
80
+
81
+ # Print the General Information Table
82
+ puts table
83
+
84
+ # Display Network information only if --all is passed to the cmd
85
+ if options[:all] == true
86
+
87
+ # FIXME: this needs to be fixed to accomodate the bridged scenario
88
+ # potentially showing only the assigned IPs in the VMs
89
+
90
+ vapp_edge_ip = cnx.get_vapp_edge_public_ip(vapp_id)
91
+ vapp_edge_rules = cnx.get_vapp_port_forwarding_rules(vapp_id)
92
+ edge_gateway_rules = cnx.get_edge_gateway_rules(cfg.vdc_edge_gateway,
93
+ cfg.vdc_id)
94
+
95
+ # Create a new table for the network information
96
+ network_table = Terminal::Table.new
97
+ network_table.title = 'Vagrant vCloud Director Network Map'
98
+
99
+ network_table << ['VM Name', 'Destination NAT Mapping', 'Enabled']
100
+ network_table << :separator
101
+
102
+ # Fetching Destination NAT Rules for each vApp/Edge/VM/Mapping
103
+ edge_gateway_rules.each do |edge_gateway_rule|
104
+ vapp_edge_rules.each do |vapp_edge_rule|
105
+
106
+ # Only check DNAT and src/dst
107
+ if edge_gateway_rule[:rule_type] == 'DNAT' &&
108
+ edge_gateway_rule[:original_ip] == cfg.vdc_edge_gateway_ip &&
109
+ edge_gateway_rule[:translated_ip] == vapp_edge_ip
110
+
111
+ # Loop on every VM in the vApp
112
+ vapp[:vms_hash].each do |vm|
113
+ # Only Map valid vAppEdge scope to VM scope
114
+ vm_scope = vm[1][:vapp_scoped_local_id]
115
+ vapp_edge_scope = vapp_edge_rule[:vapp_scoped_local_id]
116
+
117
+ if vm_scope == vapp_edge_scope
118
+
119
+ # Generate DNAT Mappings for the valid machines
120
+ # If rules don't match, you will not see them !
121
+ network_table << [
122
+ "#{vm[0]}",
123
+ "#{cfg.vdc_edge_gateway_ip}:" +
124
+ "#{vapp_edge_rule[:nat_external_port]}" +
125
+ " -> #{vapp_edge_ip}:" +
126
+ "#{vapp_edge_rule[:nat_external_port]}" +
127
+ " -> #{vm[1][:addresses][0]}:" +
128
+ "#{vapp_edge_rule[:nat_internal_port]}",
129
+ edge_gateway_rule[:is_enabled]
130
+ ]
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
136
+
137
+ # Fetching Source NAT Rules for the vApp
138
+ network_table << :separator
139
+ network_table << ['Network Name', 'Source NAT Mapping', 'Enabled']
140
+ network_table << :separator
141
+
142
+ edge_gateway_rules.each do |edge_gateway_rule|
143
+ # Only check SNAT and src/dst
144
+ if edge_gateway_rule[:rule_type] == 'SNAT' &&
145
+ edge_gateway_rule[:original_ip] == vapp_edge_ip &&
146
+ edge_gateway_rule[:translated_ip] == cfg.vdc_edge_gateway_ip
147
+
148
+ network_table << [
149
+ edge_gateway_rule[:interface_name],
150
+ "#{vapp_edge_ip} -> #{cfg.vdc_edge_gateway_ip}",
151
+ edge_gateway_rule[:is_enabled]
152
+ ]
153
+ end
154
+ end
155
+
156
+ # Fetching Edge Gateway Firewall Rules
157
+ network_table << :separator
158
+ network_table << ['Rule# - Description', 'Firewall Rules', 'Enabled']
159
+ network_table << :separator
160
+ edge_gateway_rules.each do |edge_gateway_rule|
161
+ # Only add firewall rules
162
+ if edge_gateway_rule[:rule_type] == 'Firewall'
163
+ network_table << [
164
+ "#{edge_gateway_rule[:id]} - " +
165
+ "(#{edge_gateway_rule[:description]})",
166
+ "#{edge_gateway_rule[:policy]} " +
167
+ "SRC:#{edge_gateway_rule[:source_ip]}:" +
168
+ "#{edge_gateway_rule[:source_portrange]} to " +
169
+ "DST:#{edge_gateway_rule[:destination_ip]}:" +
170
+ "#{edge_gateway_rule[:destination_portrange]}",
171
+ "#{edge_gateway_rule[:is_enabled]}"
172
+ ]
173
+ end
174
+ end
175
+
176
+ # Print the Network Table
177
+ puts
178
+ puts network_table
179
+
180
+ end
181
+
182
+ 0
183
+ end
184
+ end
185
+ end
186
+ end