lib/vagrant-vcloud/action/power_on.rb in vagrant-vcloud-0.1.2 vs lib/vagrant-vcloud/action/power_on.rb in vagrant-vcloud-0.2.0

- old
+ new

@@ -1,48 +1,84 @@ -require "i18n" - module VagrantPlugins module VCloud module Action class PowerOn def initialize(app, env) @app = app - @logger = Log4r::Logger.new("vagrant_vcloud::action::power_on") + @logger = Log4r::Logger.new('vagrant_vcloud::action::power_on') end def call(env) @env = env - cfg = env[:machine].provider_config cnx = cfg.vcloud_cnx.driver - vmName = env[:machine].name - vAppId = env[:machine].get_vapp_id + vapp_id = env[:machine].get_vapp_id - env[:ui].info("Booting VM...") + env[:ui].info('Booting VM...') - testIp = cnx.get_vapp_edge_public_ip(vAppId) + if cfg.network_bridge.nil? + test_ip = cnx.get_vapp_edge_public_ip(vapp_id) + end - poweronVM = cnx.poweron_vm(env[:machine].id) - cnx.wait_task_completion(poweronVM) + poweron_vm = cnx.poweron_vm(env[:machine].id) + cnx.wait_task_completion(poweron_vm) - if testIp.nil? && cfg.vdc_edge_gateway_ip && cfg.vdc_edge_gateway - @logger.debug("This is our first boot, we should map ports on org edge!") + if test_ip.nil? && \ + cfg.vdc_edge_gateway_ip && \ + cfg.vdc_edge_gateway && \ + cfg.network_bridge.nil? - env[:ui].info("Creating NAT rules on [#{cfg.vdc_edge_gateway}] for IP [#{cfg.vdc_edge_gateway_ip}].") + @logger.debug( + 'This is our first boot, we should map ports on the ' \ + 'Organization vDC vShield Edge Gateway!' + ) - edgeMap = cnx.set_edge_gateway_rules(cfg.vdc_edge_gateway, cfg.vdc_id, cfg.vdc_edge_gateway_ip, vAppId) - cnx.wait_task_completion(edgeMap) - end + ### TMP FIX: tsugliani + ### We need to verify the vShield Edge Gateway rules don't already + ### exist. + ### Removing any rule previously set for that same source IP + # ---- + if cfg.vdc_edge_gateway_ip && cfg.vdc_edge_gateway + env[:ui].info( + "Removing NAT rules on [#{cfg.vdc_edge_gateway}] " + + "for IP [#{cfg.vdc_edge_gateway_ip}]." + ) + @logger.debug( + 'Cleaning possible conflicting Edge Gateway rules - ' + + "Organization vDC id: #{cfg.vdc_id}" + ) + edge_remove = cnx.remove_edge_gateway_rules( + cfg.vdc_edge_gateway, + cfg.vdc_id, + cfg.vdc_edge_gateway_ip, + vapp_id + ) + cnx.wait_task_completion(edge_remove) + end + # ---- + env[:ui].info( + "Creating NAT rules on [#{cfg.vdc_edge_gateway}] " + + "for IP [#{cfg.vdc_edge_gateway_ip}]." + ) + # Set the vShield Edge Gateway rules + edge_map = cnx.set_edge_gateway_rules( + cfg.vdc_edge_gateway, + cfg.vdc_id, + cfg.vdc_edge_gateway_ip, + vapp_id + ) + + # Wait for task to complete. + cnx.wait_task_completion(edge_map) + end + @app.call(env) end end end end end - - -