vagrant-vcloud 0.1.2 → 0.2.0
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.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +34 -0
- data/README.md +19 -2
- data/Rakefile +1 -1
- data/lib/vagrant-vcloud.rb +11 -13
- data/lib/vagrant-vcloud/action.rb +74 -47
- data/lib/vagrant-vcloud/action/announce_ssh_exec.rb +4 -2
- data/lib/vagrant-vcloud/action/build_vapp.rb +134 -110
- data/lib/vagrant-vcloud/action/connect_vcloud.rb +31 -42
- data/lib/vagrant-vcloud/action/destroy.rb +34 -29
- data/lib/vagrant-vcloud/action/disconnect_vcloud.rb +7 -5
- data/lib/vagrant-vcloud/action/forward_ports.rb +42 -35
- data/lib/vagrant-vcloud/action/handle_nat_port_collisions.rb +26 -22
- data/lib/vagrant-vcloud/action/inventory_check.rb +79 -52
- data/lib/vagrant-vcloud/action/is_bridged.rb +30 -0
- data/lib/vagrant-vcloud/action/is_created.rb +13 -14
- data/lib/vagrant-vcloud/action/is_paused.rb +0 -2
- data/lib/vagrant-vcloud/action/is_running.rb +0 -2
- data/lib/vagrant-vcloud/action/message_already_running.rb +1 -1
- data/lib/vagrant-vcloud/action/message_cannot_suspend.rb +1 -1
- data/lib/vagrant-vcloud/action/message_not_created.rb +1 -1
- data/lib/vagrant-vcloud/action/message_will_not_destroy.rb +6 -1
- data/lib/vagrant-vcloud/action/power_off.rb +16 -21
- data/lib/vagrant-vcloud/action/power_on.rb +64 -28
- data/lib/vagrant-vcloud/action/read_ssh_info.rb +44 -28
- data/lib/vagrant-vcloud/action/read_state.rb +16 -23
- data/lib/vagrant-vcloud/action/resume.rb +5 -13
- data/lib/vagrant-vcloud/action/suspend.rb +5 -13
- data/lib/vagrant-vcloud/action/sync_folders.rb +82 -48
- data/lib/vagrant-vcloud/action/unmap_port_forwardings.rb +27 -29
- data/lib/vagrant-vcloud/command.rb +186 -0
- data/lib/vagrant-vcloud/config.rb +41 -20
- data/lib/vagrant-vcloud/driver/base.rb +170 -121
- data/lib/vagrant-vcloud/driver/meta.rb +64 -70
- data/lib/vagrant-vcloud/driver/version_5_1.rb +1038 -716
- data/lib/vagrant-vcloud/errors.rb +4 -4
- data/lib/vagrant-vcloud/model/forwarded_port.rb +4 -2
- data/lib/vagrant-vcloud/plugin.rb +30 -20
- data/lib/vagrant-vcloud/provider.rb +6 -6
- data/lib/vagrant-vcloud/util/compile_forwarded_ports.rb +1 -1
- data/lib/vagrant-vcloud/version.rb +1 -1
- data/locales/en.yml +6 -5
- data/vagrant-vcloud.gemspec +10 -7
- metadata +35 -4
| @@ -1,64 +1,53 @@ | |
| 1 | 
            -
            require "log4r"
         | 
| 2 | 
            -
             | 
| 3 1 | 
             
            module VagrantPlugins
         | 
| 4 2 | 
             
              module VCloud
         | 
| 5 3 | 
             
                module Action
         | 
| 6 4 | 
             
                  class ConnectVCloud
         | 
| 7 5 | 
             
                    def initialize(app, env)
         | 
| 8 6 | 
             
                      @app = app
         | 
| 9 | 
            -
                      @logger = Log4r::Logger.new( | 
| 7 | 
            +
                      @logger = Log4r::Logger.new('vagrant_vcloud::action::connect_vcloud')
         | 
| 10 8 | 
             
                    end
         | 
| 11 9 |  | 
| 12 10 | 
             
                    def call(env)
         | 
| 13 11 | 
             
                      config = env[:machine].provider_config
         | 
| 14 12 |  | 
| 15 | 
            -
             | 
| 16 | 
            -
                         | 
| 17 | 
            -
                        if !config.vcloud_cnx
         | 
| 18 | 
            -
                          @logger.info("Connecting to vCloud Director...")
         | 
| 13 | 
            +
                      if !config.vcloud_cnx
         | 
| 14 | 
            +
                        @logger.info('Connecting to vCloud Director...')
         | 
| 19 15 |  | 
| 20 16 | 
             
                          @logger.debug("config.hostname    : #{config.hostname}")
         | 
| 21 17 | 
             
                          @logger.debug("config.username    : #{config.username}")
         | 
| 22 | 
            -
                          @logger.debug("config.password    :  | 
| 18 | 
            +
                          @logger.debug("config.password    : <hidden>")
         | 
| 23 19 | 
             
                          @logger.debug("config.org_name    : #{config.org_name}")
         | 
| 24 20 |  | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
                            @logger.debug(
         | 
| 41 | 
            -
                              "x-vcloud-authorization=#{config.vcloud_cnx.driver.auth_key}"
         | 
| 42 | 
            -
                            )
         | 
| 43 | 
            -
                          else
         | 
| 44 | 
            -
                            @logger.info("Login failed in to #{config.hostname}.")
         | 
| 45 | 
            -
                            env[:ui].error("Login failed in to #{config.hostname}.")
         | 
| 46 | 
            -
                            raise
         | 
| 47 | 
            -
                          end
         | 
| 48 | 
            -
                        else
         | 
| 49 | 
            -
                          @logger.info("Already logged in, using current session")
         | 
| 21 | 
            +
                        # Create the vcloud-rest connection object with the configuration
         | 
| 22 | 
            +
                        # information.
         | 
| 23 | 
            +
                        config.vcloud_cnx = Driver::Meta.new(
         | 
| 24 | 
            +
                          config.hostname,
         | 
| 25 | 
            +
                          config.username,
         | 
| 26 | 
            +
                          config.password,
         | 
| 27 | 
            +
                          config.org_name
         | 
| 28 | 
            +
                        )
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                        @logger.info('Logging into vCloud Director...')
         | 
| 31 | 
            +
                        config.vcloud_cnx.login
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                        # Check for the vCloud Director authentication token
         | 
| 34 | 
            +
                        if config.vcloud_cnx.driver.auth_key
         | 
| 35 | 
            +
                          @logger.info('Logged in successfully!')
         | 
| 50 36 | 
             
                          @logger.debug(
         | 
| 51 | 
            -
             | 
| 37 | 
            +
                            "x-vcloud-authorization=#{config.vcloud_cnx.driver.auth_key}"
         | 
| 52 38 | 
             
                          )
         | 
| 39 | 
            +
                        else
         | 
| 40 | 
            +
                          @logger.info("Login failed in to #{config.hostname}.")
         | 
| 41 | 
            +
                          env[:ui].error("Login failed in to #{config.hostname}.")
         | 
| 42 | 
            +
                          raise
         | 
| 53 43 | 
             
                        end
         | 
| 54 | 
            -
             | 
| 55 | 
            -
                        @ | 
| 56 | 
            -
             | 
| 57 | 
            -
             | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 60 | 
            -
             | 
| 61 | 
            -
            #          end
         | 
| 44 | 
            +
                      else
         | 
| 45 | 
            +
                        @logger.info('Already logged in, using current session')
         | 
| 46 | 
            +
                        @logger.debug(
         | 
| 47 | 
            +
                            "x-vcloud-authorization=#{config.vcloud_cnx.driver.auth_key}"
         | 
| 48 | 
            +
                        )
         | 
| 49 | 
            +
                      end
         | 
| 50 | 
            +
                      @app.call env
         | 
| 62 51 |  | 
| 63 52 | 
             
                    end
         | 
| 64 53 | 
             
                  end
         | 
| @@ -1,60 +1,65 @@ | |
| 1 | 
            -
            require "i18n"
         | 
| 2 | 
            -
             | 
| 3 1 | 
             
            module VagrantPlugins
         | 
| 4 2 | 
             
              module VCloud
         | 
| 5 3 | 
             
                module Action
         | 
| 6 4 | 
             
                  class Destroy
         | 
| 7 | 
            -
             | 
| 8 5 | 
             
                    def initialize(app, env)
         | 
| 9 6 | 
             
                      @app = app
         | 
| 10 | 
            -
                      @logger = Log4r::Logger.new( | 
| 7 | 
            +
                      @logger = Log4r::Logger.new('vagrant_vcloud::action::destroy')
         | 
| 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 | 
            -
                       | 
| 18 | 
            -
                       | 
| 13 | 
            +
                      vapp_id = env[:machine].get_vapp_id
         | 
| 14 | 
            +
                      vm_id = env[:machine].id
         | 
| 19 15 |  | 
| 20 16 | 
             
                      cfg.org = cnx.get_organization_by_name(cfg.org_name)
         | 
| 21 17 | 
             
                      cfg.vdc_id = cnx.get_vdc_id_by_name(cfg.org, cfg.vdc_name)
         | 
| 22 18 |  | 
| 23 | 
            -
                       | 
| 19 | 
            +
                      test_vapp = cnx.get_vapp(vapp_id)
         | 
| 24 20 |  | 
| 25 | 
            -
                      @logger.debug( | 
| 21 | 
            +
                      @logger.debug(
         | 
| 22 | 
            +
                        "Number of VMs in the vApp: #{test_vapp[:vms_hash].count}"
         | 
| 23 | 
            +
                      )
         | 
| 26 24 |  | 
| 27 | 
            -
                      if  | 
| 28 | 
            -
                        env[:ui].info( | 
| 25 | 
            +
                      if test_vapp[:vms_hash].count == 1
         | 
| 26 | 
            +
                        env[:ui].info('Single VM left in the vApp, destroying the vApp...')
         | 
| 29 27 |  | 
| 30 28 | 
             
                        if cfg.vdc_edge_gateway_ip && cfg.vdc_edge_gateway
         | 
| 31 | 
            -
                          env[:ui].info( | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 29 | 
            +
                          env[:ui].info(
         | 
| 30 | 
            +
                            "Removing NAT rules on [#{cfg.vdc_edge_gateway}] " +
         | 
| 31 | 
            +
                            "for IP [#{cfg.vdc_edge_gateway_ip}]."
         | 
| 32 | 
            +
                          )
         | 
| 33 | 
            +
                          @logger.debug(
         | 
| 34 | 
            +
                            "Deleting Edge Gateway rules - vdc id: #{cfg.vdc_id}"
         | 
| 35 | 
            +
                          )
         | 
| 36 | 
            +
                          edge_remove = cnx.remove_edge_gateway_rules(
         | 
| 37 | 
            +
                            cfg.vdc_edge_gateway,
         | 
| 38 | 
            +
                            cfg.vdc_id,
         | 
| 39 | 
            +
                            cfg.vdc_edge_gateway_ip,
         | 
| 40 | 
            +
                            vapp_id
         | 
| 41 | 
            +
                          )
         | 
| 34 42 | 
             
                          cnx.wait_task_completion(edge_remove)
         | 
| 35 43 | 
             
                        end
         | 
| 36 44 |  | 
| 37 | 
            -
                        env[:ui].info( | 
| 38 | 
            -
                         | 
| 39 | 
            -
                        @logger.debug("vApp Delete task id #{ | 
| 40 | 
            -
                        cnx.wait_task_completion( | 
| 45 | 
            +
                        env[:ui].info('Destroying vApp...')
         | 
| 46 | 
            +
                        vapp_delete_task = cnx.delete_vapp(vapp_id)
         | 
| 47 | 
            +
                        @logger.debug("vApp Delete task id #{vapp_delete_task}")
         | 
| 48 | 
            +
                        cnx.wait_task_completion(vapp_delete_task)
         | 
| 41 49 |  | 
| 42 | 
            -
             | 
| 43 | 
            -
                         | 
| 44 | 
            -
                        ####env[:machine].provider.driver.delete
         | 
| 45 | 
            -
                        env[:machine].id=nil
         | 
| 46 | 
            -
                        env[:machine].vappid=nil
         | 
| 50 | 
            +
                        env[:machine].id = nil
         | 
| 51 | 
            +
                        env[:machine].vappid = nil
         | 
| 47 52 | 
             
                      else
         | 
| 48 | 
            -
                        env[:ui].info( | 
| 49 | 
            -
                         | 
| 50 | 
            -
                        @logger.debug("VM Delete task id #{ | 
| 51 | 
            -
                        cnx.wait_task_completion( | 
| 52 | 
            -
             | 
| 53 | 
            +
                        env[:ui].info('Destroying VM...')
         | 
| 54 | 
            +
                        vm_delete_task = cnx.delete_vm(vm_id)
         | 
| 55 | 
            +
                        @logger.debug("VM Delete task id #{vm_delete_task}")
         | 
| 56 | 
            +
                        cnx.wait_task_completion(vm_delete_task)
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                        env[:machine].id = nil
         | 
| 53 59 | 
             
                      end
         | 
| 54 60 |  | 
| 55 61 | 
             
                      @app.call env
         | 
| 56 62 | 
             
                    end
         | 
| 57 | 
            -
             | 
| 58 63 | 
             
                  end
         | 
| 59 64 | 
             
                end
         | 
| 60 65 | 
             
              end
         | 
| @@ -4,14 +4,16 @@ module VagrantPlugins | |
| 4 4 | 
             
                  class DisconnectVCloud
         | 
| 5 5 | 
             
                    def initialize(app, env)
         | 
| 6 6 | 
             
                      @app = app
         | 
| 7 | 
            -
                      @logger = Log4r::Logger.new( | 
| 7 | 
            +
                      @logger = Log4r::Logger.new(
         | 
| 8 | 
            +
                        'vagrant_vcloud::action::disconnect_vcloud'
         | 
| 9 | 
            +
                      )
         | 
| 8 10 | 
             
                    end
         | 
| 9 11 |  | 
| 10 12 | 
             
                    def call(env)
         | 
| 11 13 | 
             
                      begin
         | 
| 12 | 
            -
             | 
| 14 | 
            +
                        @logger.info('Disconnecting from vCloud Director...')
         | 
| 13 15 |  | 
| 14 | 
            -
                        # Fetch the global vCloud Director connection handle | 
| 16 | 
            +
                        # Fetch the global vCloud Director connection handle
         | 
| 15 17 | 
             
                        cnx = env[:machine].provider_config.vcloud_cnx.driver
         | 
| 16 18 |  | 
| 17 19 | 
             
                        # Delete the current vCloud Director Session
         | 
| @@ -19,11 +21,11 @@ module VagrantPlugins | |
| 19 21 |  | 
| 20 22 | 
             
                        # If session key doesn't exist, we are disconnected
         | 
| 21 23 | 
             
                        if !cnx.auth_key
         | 
| 22 | 
            -
                          @logger.info( | 
| 24 | 
            +
                          @logger.info('Disconnected from vCloud Director successfully!')
         | 
| 23 25 | 
             
                        end
         | 
| 24 26 |  | 
| 25 27 | 
             
                      rescue Exception => e
         | 
| 26 | 
            -
                        # | 
| 28 | 
            +
                        # Raise a properly namespaced error for Vagrant
         | 
| 27 29 | 
             
                        raise Errors::VCloudError, :message => e.message
         | 
| 28 30 | 
             
                      end
         | 
| 29 31 | 
             
                    end
         | 
| @@ -6,17 +6,16 @@ module VagrantPlugins | |
| 6 6 |  | 
| 7 7 | 
             
                    def initialize(app, env)
         | 
| 8 8 | 
             
                      @app = app
         | 
| 9 | 
            -
                      @logger = Log4r::Logger.new( | 
| 9 | 
            +
                      @logger = Log4r::Logger.new('vagrant_vcloud::action::forward_ports')
         | 
| 10 10 | 
             
                    end
         | 
| 11 11 |  | 
| 12 | 
            -
                    #--------------------------------------------------------------
         | 
| 13 | 
            -
                    # Execution
         | 
| 14 | 
            -
                    #--------------------------------------------------------------
         | 
| 15 12 | 
             
                    def call(env)
         | 
| 16 13 | 
             
                      @env = env
         | 
| 17 14 |  | 
| 18 | 
            -
                      # Get the ports we | 
| 19 | 
            -
                      env[:forwarded_ports] ||= compile_forwarded_ports( | 
| 15 | 
            +
                      # Get the ports we are forwarding
         | 
| 16 | 
            +
                      env[:forwarded_ports] ||= compile_forwarded_ports(
         | 
| 17 | 
            +
                        env[:machine].config
         | 
| 18 | 
            +
                      )
         | 
| 20 19 |  | 
| 21 20 | 
             
                      forward_ports
         | 
| 22 21 |  | 
| @@ -28,34 +27,42 @@ module VagrantPlugins | |
| 28 27 |  | 
| 29 28 | 
             
                      cfg = @env[:machine].provider_config
         | 
| 30 29 | 
             
                      cnx = cfg.vcloud_cnx.driver
         | 
| 31 | 
            -
                       | 
| 32 | 
            -
                       | 
| 30 | 
            +
                      vapp_id = @env[:machine].get_vapp_id
         | 
| 31 | 
            +
                      vm_name = @env[:machine].name
         | 
| 33 32 |  | 
| 34 | 
            -
                       | 
| 35 | 
            -
                       | 
| 36 | 
            -
             | 
| 37 | 
            -
                       | 
| 38 | 
            -
                       | 
| 39 | 
            -
                       | 
| 33 | 
            +
                      # FIXME: why are we overriding this here ?
         | 
| 34 | 
            +
                      #        It's already been taken care during the initial
         | 
| 35 | 
            +
                      #        InventoryCheck. (tsugliani)
         | 
| 36 | 
            +
                      #
         | 
| 37 | 
            +
                      # cfg.org = cnx.get_organization_by_name(cfg.org_name)
         | 
| 38 | 
            +
                      # cfg.vdc_network_id = cfg.org[:networks][cfg.vdc_network_name]
         | 
| 40 39 |  | 
| 40 | 
            +
                      @logger.debug('Getting VM info...')
         | 
| 41 | 
            +
                      vm = cnx.get_vapp(vapp_id)
         | 
| 42 | 
            +
                      vm_info = vm[:vms_hash][vm_name.to_sym]
         | 
| 41 43 |  | 
| 42 44 | 
             
                      @env[:forwarded_ports].each do |fp|
         | 
| 45 | 
            +
                        # FIXME: Useless variable assignement 'message_attributes'
         | 
| 46 | 
            +
                        # (tsugliani)
         | 
| 43 47 | 
             
                        message_attributes = {
         | 
| 44 | 
            -
                          :guest_port | 
| 45 | 
            -
                          :host_port | 
| 48 | 
            +
                          :guest_port   => fp.guest_port,
         | 
| 49 | 
            +
                          :host_port    => fp.host_port
         | 
| 46 50 | 
             
                        }
         | 
| 47 51 |  | 
| 48 | 
            -
                        @env[:ui].info( | 
| 52 | 
            +
                        @env[:ui].info(
         | 
| 53 | 
            +
                          "Forwarding Ports: VM port #{fp.guest_port} -> " +
         | 
| 54 | 
            +
                          "vShield Edge port #{fp.host_port}"
         | 
| 55 | 
            +
                        )
         | 
| 49 56 |  | 
| 50 57 | 
             
                        # Add the options to the ports array to send to the driver later
         | 
| 51 58 | 
             
                        ports << {
         | 
| 52 | 
            -
                          :guestip | 
| 53 | 
            -
                          :nat_internal_port | 
| 54 | 
            -
                          :hostip | 
| 55 | 
            -
                          :nat_external_port | 
| 56 | 
            -
                          :name | 
| 57 | 
            -
                          :nat_protocol | 
| 58 | 
            -
                          :vapp_scoped_local_id | 
| 59 | 
            +
                          :guestip                => fp.guest_ip,
         | 
| 60 | 
            +
                          :nat_internal_port      => fp.guest_port,
         | 
| 61 | 
            +
                          :hostip                 => fp.host_ip,
         | 
| 62 | 
            +
                          :nat_external_port      => fp.host_port,
         | 
| 63 | 
            +
                          :name                   => fp.id,
         | 
| 64 | 
            +
                          :nat_protocol           => fp.protocol.upcase,
         | 
| 65 | 
            +
                          :vapp_scoped_local_id   => vm_info[:vapp_scoped_local_id]
         | 
| 59 66 | 
             
                        }
         | 
| 60 67 | 
             
                      end
         | 
| 61 68 |  | 
| @@ -65,18 +72,18 @@ module VagrantPlugins | |
| 65 72 | 
             
                        @logger.debug("Current network id #{cfg.vdc_network_id}")
         | 
| 66 73 |  | 
| 67 74 | 
             
                        ### Here we apply the nat_rules to the vApp we just built
         | 
| 68 | 
            -
             | 
| 69 | 
            -
             | 
| 70 | 
            -
                           | 
| 71 | 
            -
                          "Vagrant-vApp-Net",
         | 
| 75 | 
            +
                        add_ports = cnx.add_vapp_port_forwarding_rules(
         | 
| 76 | 
            +
                          vapp_id,
         | 
| 77 | 
            +
                          'Vagrant-vApp-Net',
         | 
| 72 78 | 
             
                          {
         | 
| 73 | 
            -
                            :fence_mode | 
| 74 | 
            -
                            :parent_network | 
| 75 | 
            -
                            :nat_policy_type | 
| 76 | 
            -
                            :nat_rules | 
| 77 | 
            -
                          } | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 79 | 
            +
                            :fence_mode       => 'natRouted',
         | 
| 80 | 
            +
                            :parent_network   => cfg.vdc_network_id,
         | 
| 81 | 
            +
                            :nat_policy_type  => 'allowTraffic',
         | 
| 82 | 
            +
                            :nat_rules        => ports
         | 
| 83 | 
            +
                          }
         | 
| 84 | 
            +
                        )
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                        wait = cnx.wait_task_completion(add_ports)
         | 
| 80 87 |  | 
| 81 88 | 
             
                        if !wait[:errormsg].nil?
         | 
| 82 89 | 
             
                          raise Errors::ComposeVAppError, :message => wait[:errormsg]
         | 
| @@ -1,5 +1,4 @@ | |
| 1 | 
            -
            require  | 
| 2 | 
            -
            require "log4r"
         | 
| 1 | 
            +
            require 'set'
         | 
| 3 2 |  | 
| 4 3 | 
             
            module VagrantPlugins
         | 
| 5 4 | 
             
              module VCloud
         | 
| @@ -21,14 +20,15 @@ module VagrantPlugins | |
| 21 20 | 
             
                  #     to other host ports.
         | 
| 22 21 | 
             
                  #
         | 
| 23 22 | 
             
                  class HandleNATPortCollisions
         | 
| 24 | 
            -
             | 
| 25 23 | 
             
                    def initialize(app, env)
         | 
| 26 24 | 
             
                      @app    = app
         | 
| 27 | 
            -
                      @logger = Log4r::Logger.new( | 
| 25 | 
            +
                      @logger = Log4r::Logger.new(
         | 
| 26 | 
            +
                        'vagrant_vcloud::action::handle_port_collisions'
         | 
| 27 | 
            +
                      )
         | 
| 28 28 | 
             
                    end
         | 
| 29 29 |  | 
| 30 30 | 
             
                    def call(env)
         | 
| 31 | 
            -
                      @logger.info( | 
| 31 | 
            +
                      @logger.info('Detecting any forwarded port collisions...')
         | 
| 32 32 |  | 
| 33 33 | 
             
                      # Determine a list of usable ports for repair
         | 
| 34 34 | 
             
                      usable_ports = Set.new(env[:machine].config.vm.usable_port_range)
         | 
| @@ -40,15 +40,10 @@ module VagrantPlugins | |
| 40 40 |  | 
| 41 41 | 
             
                      cfg = env[:machine].provider_config
         | 
| 42 42 | 
             
                      cnx = cfg.vcloud_cnx.driver
         | 
| 43 | 
            -
                       | 
| 44 | 
            -
                      vAppId = env[:machine].get_vapp_id
         | 
| 45 | 
            -
             | 
| 46 | 
            -
                      @logger.debug("Getting vapp info...")
         | 
| 47 | 
            -
                      vm = cnx.get_vapp(vAppId)
         | 
| 48 | 
            -
                      myhash = vm[:vms_hash][vmName.to_sym]
         | 
| 43 | 
            +
                      vapp_id = env[:machine].get_vapp_id
         | 
| 49 44 |  | 
| 50 | 
            -
                      @logger.debug( | 
| 51 | 
            -
                      rules = cnx.get_vapp_port_forwarding_external_ports( | 
| 45 | 
            +
                      @logger.debug('Getting port forwarding rules...')
         | 
| 46 | 
            +
                      rules = cnx.get_vapp_port_forwarding_external_ports(vapp_id)
         | 
| 52 47 |  | 
| 53 48 | 
             
                      # Pass two, detect/handle any collisions
         | 
| 54 49 | 
             
                      with_forwarded_ports(env) do |options|
         | 
| @@ -73,7 +68,10 @@ module VagrantPlugins | |
| 73 68 |  | 
| 74 69 | 
             
                            # If the port is in use, then we can't use this either...
         | 
| 75 70 | 
             
                            if rules.include?(repaired_port)
         | 
| 76 | 
            -
                              @logger.info( | 
| 71 | 
            +
                              @logger.info(
         | 
| 72 | 
            +
                                "Repaired port also in use: #{repaired_port}." +
         | 
| 73 | 
            +
                                'Trying another...'
         | 
| 74 | 
            +
                              )
         | 
| 77 75 | 
             
                              next
         | 
| 78 76 | 
             
                            end
         | 
| 79 77 |  | 
| @@ -84,21 +82,27 @@ module VagrantPlugins | |
| 84 82 | 
             
                          # If we have no usable ports then we can't repair
         | 
| 85 83 | 
             
                          if !repaired_port && usable_ports.empty?
         | 
| 86 84 | 
             
                            raise Errors::ForwardPortAutolistEmpty,
         | 
| 87 | 
            -
             | 
| 88 | 
            -
             | 
| 89 | 
            -
             | 
| 85 | 
            +
                                  :vm_name    => env[:machine].name,
         | 
| 86 | 
            +
                                  :guest_port => guest_port.to_s,
         | 
| 87 | 
            +
                                  :host_port  => host_port.to_s
         | 
| 90 88 | 
             
                          end
         | 
| 91 89 |  | 
| 92 90 | 
             
                          # Modify the args in place
         | 
| 93 91 | 
             
                          options[:host] = repaired_port
         | 
| 94 92 |  | 
| 95 | 
            -
                          @logger.info( | 
| 93 | 
            +
                          @logger.info(
         | 
| 94 | 
            +
                            "Repaired FP collision: #{host_port} to #{repaired_port}"
         | 
| 95 | 
            +
                          )
         | 
| 96 96 |  | 
| 97 97 | 
             
                          # Notify the user
         | 
| 98 | 
            -
                          env[:ui].info( | 
| 99 | 
            -
             | 
| 100 | 
            -
             | 
| 101 | 
            -
             | 
| 98 | 
            +
                          env[:ui].info(
         | 
| 99 | 
            +
                            I18n.t(
         | 
| 100 | 
            +
                              'vagrant.actions.vm.forward_ports.fixed_collision',
         | 
| 101 | 
            +
                              :host_port  => host_port.to_s,
         | 
| 102 | 
            +
                              :guest_port => guest_port.to_s,
         | 
| 103 | 
            +
                              :new_port   => repaired_port.to_s
         | 
| 104 | 
            +
                            )
         | 
| 105 | 
            +
                          )
         | 
| 102 106 | 
             
                        end
         | 
| 103 107 | 
             
                      end
         | 
| 104 108 |  | 
| @@ -1,73 +1,79 @@ | |
| 1 | 
            -
            require  | 
| 2 | 
            -
            require "log4r"
         | 
| 1 | 
            +
            require 'etc'
         | 
| 3 2 |  | 
| 4 3 | 
             
            module VagrantPlugins
         | 
| 5 4 | 
             
              module VCloud
         | 
| 6 5 | 
             
                module Action
         | 
| 7 6 | 
             
                  class InventoryCheck
         | 
| 8 | 
            -
             | 
| 9 7 | 
             
                    def initialize(app, env)
         | 
| 10 8 | 
             
                      @app = app
         | 
| 11 | 
            -
                      @logger = Log4r::Logger.new( | 
| 9 | 
            +
                      @logger = Log4r::Logger.new('vagrant_vcloud::action::inventory_check')
         | 
| 12 10 | 
             
                    end
         | 
| 13 11 |  | 
| 14 12 | 
             
                    def call(env)
         | 
| 15 13 | 
             
                      vcloud_check_inventory(env)
         | 
| 16 | 
            -
             | 
| 14 | 
            +
             | 
| 17 15 | 
             
                      @app.call env
         | 
| 18 16 | 
             
                    end
         | 
| 19 17 |  | 
| 20 18 | 
             
                    def vcloud_upload_box(env)
         | 
| 21 | 
            -
             | 
| 22 19 | 
             
                      cfg = env[:machine].provider_config
         | 
| 23 20 | 
             
                      cnx = cfg.vcloud_cnx.driver
         | 
| 24 21 |  | 
| 25 | 
            -
                       | 
| 26 | 
            -
                       | 
| 22 | 
            +
                      box_dir = env[:machine].box.directory.to_s
         | 
| 23 | 
            +
                      box_file = env[:machine].box.name.to_s
         | 
| 27 24 |  | 
| 28 | 
            -
                       | 
| 25 | 
            +
                      box_ovf = "#{box_dir}/#{box_file}.ovf"
         | 
| 29 26 |  | 
| 30 | 
            -
                      # Still relying on ruby-progressbar because report_progress | 
| 31 | 
            -
             | 
| 32 | 
            -
                      @logger.debug("OVF File: #{ | 
| 33 | 
            -
                       | 
| 27 | 
            +
                      # Still relying on ruby-progressbar because report_progress
         | 
| 28 | 
            +
                      # basically sucks.
         | 
| 29 | 
            +
                      @logger.debug("OVF File: #{box_ovf}")
         | 
| 30 | 
            +
                      upload_ovf = cnx.upload_ovf(
         | 
| 34 31 | 
             
                        cfg.vdc_id,
         | 
| 35 32 | 
             
                        env[:machine].box.name.to_s,
         | 
| 36 | 
            -
                         | 
| 37 | 
            -
                         | 
| 33 | 
            +
                        'Vagrant Box',
         | 
| 34 | 
            +
                        box_ovf,
         | 
| 38 35 | 
             
                        cfg.catalog_id,
         | 
| 39 36 | 
             
                        {
         | 
| 40 | 
            -
                          :progressbar_enable => true
         | 
| 41 | 
            -
                           | 
| 42 | 
            -
                          #:chunksize => 262144
         | 
| 37 | 
            +
                          :progressbar_enable => true,
         | 
| 38 | 
            +
                          :chunksize => (cfg.upload_chunksize || 1_048_576)
         | 
| 43 39 | 
             
                        }
         | 
| 44 40 | 
             
                      )
         | 
| 45 41 |  | 
| 46 | 
            -
                      env[:ui].info( | 
| 47 | 
            -
             | 
| 42 | 
            +
                      env[:ui].info(
         | 
| 43 | 
            +
                        "Adding [#{env[:machine].box.name.to_s}] to " +
         | 
| 44 | 
            +
                        "Catalog [#{cfg.catalog_name}]"
         | 
| 45 | 
            +
                      )
         | 
| 46 | 
            +
                      add_ovf_to_catalog = cnx.wait_task_completion(upload_ovf)
         | 
| 48 47 |  | 
| 49 | 
            -
                       | 
| 50 | 
            -
                         | 
| 48 | 
            +
                      unless add_ovf_to_catalog[:errormsg].nil?
         | 
| 49 | 
            +
                        fail Errors::CatalogAddError,
         | 
| 50 | 
            +
                             :message => add_ovf_to_catalog[:errormsg]
         | 
| 51 51 | 
             
                      end
         | 
| 52 52 |  | 
| 53 53 | 
             
                      # Retrieve catalog_item ID
         | 
| 54 | 
            -
                      cfg.catalog_item = cnx.get_catalog_item_by_name( | 
| 55 | 
            -
             | 
| 54 | 
            +
                      cfg.catalog_item = cnx.get_catalog_item_by_name(
         | 
| 55 | 
            +
                        cfg.catalog_id,
         | 
| 56 | 
            +
                        env[:machine].box.name.to_s
         | 
| 57 | 
            +
                      )
         | 
| 56 58 | 
             
                    end
         | 
| 57 59 |  | 
| 58 60 | 
             
                    def vcloud_create_catalog(env)
         | 
| 59 61 | 
             
                      cfg = env[:machine].provider_config
         | 
| 60 62 | 
             
                      cnx = cfg.vcloud_cnx.driver
         | 
| 61 63 |  | 
| 62 | 
            -
                       | 
| 63 | 
            -
             | 
| 64 | 
            -
             | 
| 65 | 
            -
             | 
| 64 | 
            +
                      catalog_creation = cnx.create_catalog(
         | 
| 65 | 
            +
                        cfg.org_id,
         | 
| 66 | 
            +
                        cfg.catalog_name,
         | 
| 67 | 
            +
                        "Created by #{Etc.getlogin} " +
         | 
| 68 | 
            +
                        "running on #{Socket.gethostname.downcase} " +
         | 
| 69 | 
            +
                        "using vagrant-vcloud on #{Time.now.strftime("%B %d, %Y")}"
         | 
| 70 | 
            +
                      )
         | 
| 71 | 
            +
                      cnx.wait_task_completion(catalog_creation[:task_id])
         | 
| 66 72 |  | 
| 73 | 
            +
                      @logger.debug("Catalog Creation result: #{catalog_creation.inspect}")
         | 
| 67 74 | 
             
                      env[:ui].info("Catalog [#{cfg.catalog_name}] successfully created.")
         | 
| 68 75 |  | 
| 69 | 
            -
                      cfg.catalog_id =  | 
| 70 | 
            -
             | 
| 76 | 
            +
                      cfg.catalog_id = catalog_creation[:catalog_id]
         | 
| 71 77 | 
             
                    end
         | 
| 72 78 |  | 
| 73 79 | 
             
                    def vcloud_check_inventory(env)
         | 
| @@ -83,72 +89,93 @@ module VagrantPlugins | |
| 83 89 | 
             
                      cfg.vdc_id = cnx.get_vdc_id_by_name(cfg.org, cfg.vdc_name)
         | 
| 84 90 |  | 
| 85 91 | 
             
                      cfg.catalog = cnx.get_catalog_by_name(cfg.org, cfg.catalog_name)
         | 
| 86 | 
            -
                      
         | 
| 87 92 | 
             
                      cfg.catalog_id = cnx.get_catalog_id_by_name(cfg.org, cfg.catalog_name)
         | 
| 88 93 |  | 
| 89 94 | 
             
                      if cfg.catalog_id.nil?
         | 
| 90 95 | 
             
                        env[:ui].warn("Catalog [#{cfg.catalog_name}] does not exist!")
         | 
| 91 96 |  | 
| 92 97 | 
             
                        user_input = env[:ui].ask(
         | 
| 93 | 
            -
                          "Would you like to create the [#{cfg.catalog_name}] catalog?\ | 
| 98 | 
            +
                          "Would you like to create the [#{cfg.catalog_name}] catalog?\n" +
         | 
| 99 | 
            +
                          'Choice (yes/no): '
         | 
| 94 100 | 
             
                        )
         | 
| 95 101 |  | 
| 96 | 
            -
                        if user_input.downcase ==  | 
| 102 | 
            +
                        if user_input.downcase == 'yes' || user_input.downcase == 'y'
         | 
| 97 103 | 
             
                          vcloud_create_catalog(env)
         | 
| 98 104 | 
             
                        else
         | 
| 99 | 
            -
                          env[:ui].error( | 
| 105 | 
            +
                          env[:ui].error('Catalog not created, exiting...')
         | 
| 100 106 |  | 
| 101 107 | 
             
                          # FIXME: wrong error message
         | 
| 102 | 
            -
                          raise VagrantPlugins::VCloud::Errors::VCloudError, | 
| 103 | 
            -
                                :message =>  | 
| 108 | 
            +
                          raise VagrantPlugins::VCloud::Errors::VCloudError,
         | 
| 109 | 
            +
                                :message => 'Catalog not available, exiting...'
         | 
| 104 110 |  | 
| 105 111 | 
             
                        end
         | 
| 106 112 | 
             
                      end
         | 
| 107 113 |  | 
| 108 | 
            -
                      
         | 
| 109 | 
            -
             | 
| 110 | 
            -
             | 
| 114 | 
            +
                      @logger.debug(
         | 
| 115 | 
            +
                        "Getting catalog item with cfg.catalog_id: [#{cfg.catalog_id}] " +
         | 
| 116 | 
            +
                        "and machine name [#{env[:machine].box.name.to_s}]"
         | 
| 117 | 
            +
                      )
         | 
| 118 | 
            +
                      cfg.catalog_item = cnx.get_catalog_item_by_name(
         | 
| 119 | 
            +
                        cfg.catalog_id,
         | 
| 120 | 
            +
                        env[:machine].box.name.to_s
         | 
| 121 | 
            +
                      )
         | 
| 122 | 
            +
             | 
| 111 123 | 
             
                      @logger.debug("Catalog item is now #{cfg.catalog_item}")
         | 
| 112 | 
            -
                      cfg.vdc_network_id = cfg.org[:networks][cfg.vdc_network_name]
         | 
| 113 124 |  | 
| 125 | 
            +
                      # This only works with Org Admin role or higher
         | 
| 126 | 
            +
                      cfg.vdc_network_id = cfg.org[:networks][cfg.vdc_network_name]
         | 
| 127 | 
            +
                      if !cfg.vdc_network_id
         | 
| 128 | 
            +
                        # TEMP FIX: permissions issues at the Org Level for vApp authors
         | 
| 129 | 
            +
                        #           to "view" Org vDC Networks but they can see them at the
         | 
| 130 | 
            +
                        #           Organization vDC level (tsugliani)
         | 
| 131 | 
            +
                        cfg.vdc_network_id = cfg.vdc[:networks][cfg.vdc_network_name]
         | 
| 132 | 
            +
                        if !cfg.vdc_network_id
         | 
| 133 | 
            +
                          raise 'vCloud User credentials has insufficient privileges'
         | 
| 134 | 
            +
                        end
         | 
| 135 | 
            +
                      end
         | 
| 114 136 |  | 
| 115 137 | 
             
                      # Checking Catalog mandatory requirements
         | 
| 116 138 | 
             
                      if !cfg.catalog_id
         | 
| 117 139 | 
             
                        @logger.info("Catalog [#{cfg.catalog_name}] STILL does not exist!")
         | 
| 118 140 |  | 
| 119 141 | 
             
                          # FIXME: wrong error message
         | 
| 120 | 
            -
                          raise VagrantPlugins::VCloud::Errors::VCloudError, | 
| 121 | 
            -
                                :message =>  | 
| 142 | 
            +
                          raise VagrantPlugins::VCloud::Errors::VCloudError,
         | 
| 143 | 
            +
                                :message => 'Catalog not available, exiting...'
         | 
| 122 144 |  | 
| 123 145 | 
             
                      else
         | 
| 124 146 | 
             
                        @logger.info("Catalog [#{cfg.catalog_name}] exists")
         | 
| 125 147 | 
             
                      end
         | 
| 126 148 |  | 
| 127 149 | 
             
                      if !cfg.catalog_item
         | 
| 128 | 
            -
                        env[:ui].warn( | 
| 150 | 
            +
                        env[:ui].warn(
         | 
| 151 | 
            +
                          "Catalog item [#{env[:machine].box.name.to_s}] " +
         | 
| 152 | 
            +
                          "in Catalog [#{cfg.catalog_name}] does not exist!"
         | 
| 153 | 
            +
                        )
         | 
| 129 154 |  | 
| 130 155 | 
             
                        user_input = env[:ui].ask(
         | 
| 131 | 
            -
                          "Would you like to upload the [#{env[:machine].box.name.to_s}]  | 
| 132 | 
            -
                          "[#{cfg.catalog_name}] Catalog?\ | 
| 156 | 
            +
                          "Would you like to upload the [#{env[:machine].box.name.to_s}] " +
         | 
| 157 | 
            +
                          "box to [#{cfg.catalog_name}] Catalog?\n" +
         | 
| 158 | 
            +
                          'Choice (yes/no): '
         | 
| 133 159 | 
             
                        )
         | 
| 134 160 |  | 
| 135 | 
            -
                        if user_input.downcase ==  | 
| 161 | 
            +
                        if user_input.downcase == 'yes' || user_input.downcase == 'y'
         | 
| 136 162 | 
             
                          env[:ui].info("Uploading [#{env[:machine].box.name.to_s}]...")
         | 
| 137 163 | 
             
                          vcloud_upload_box(env)
         | 
| 138 164 | 
             
                        else
         | 
| 139 | 
            -
                          env[:ui].error( | 
| 165 | 
            +
                          env[:ui].error('Catalog item not available, exiting...')
         | 
| 140 166 |  | 
| 141 167 | 
             
                          # FIXME: wrong error message
         | 
| 142 | 
            -
                          raise VagrantPlugins::VCloud::Errors::VCloudError, | 
| 143 | 
            -
                                :message =>  | 
| 144 | 
            -
             | 
| 168 | 
            +
                          raise VagrantPlugins::VCloud::Errors::VCloudError,
         | 
| 169 | 
            +
                                :message => 'Catalog item not available, exiting...'
         | 
| 145 170 | 
             
                        end
         | 
| 146 171 |  | 
| 147 172 | 
             
                      else
         | 
| 148 | 
            -
                        @logger.info( | 
| 173 | 
            +
                        @logger.info(
         | 
| 174 | 
            +
                          "Using catalog item [#{env[:machine].box.name.to_s}] " +
         | 
| 175 | 
            +
                          "in Catalog [#{cfg.catalog_name}]..."
         | 
| 176 | 
            +
                        )
         | 
| 149 177 | 
             
                      end
         | 
| 150 178 | 
             
                    end
         | 
| 151 | 
            -
             | 
| 152 179 | 
             
                  end
         | 
| 153 180 | 
             
                end
         | 
| 154 181 | 
             
              end
         |