def provision
      @logger.notify "Provisioning OpenStack"

      @hosts.each do |host|
        ip = get_ip
        hostname = ip.ip.gsub('.','-')
        host[:vmhostname] = hostname + '.rfc1918.puppetlabs.net'
        create_or_associate_keypair(host, hostname)
        @logger.debug "Provisioning #{host.name} (#{host[:vmhostname]})"
        options = {
          :flavor_ref => flavor(host[:flavor]).id,
          :image_ref  => image(host[:image]).id,
          :nics       => [ {'net_id' => network(@options[:openstack_network]).id } ],
          :name       => host[:vmhostname],
          :hostname   => host[:vmhostname],
          :user_data  => host[:user_data] || "#cloud-config\nmanage_etc_hosts: true\n",
          :key_name   => host[:keyname],
        }
        options[:security_groups] = security_groups(@options[:security_group]) unless @options[:security_group].nil?
        vm = @compute_client.servers.create(options)

        #wait for the new instance to start up
        try = 1
        attempts = @options[:timeout].to_i / SLEEPWAIT

        while try <= attempts
          begin
            vm.wait_for(5) { ready? }
            break
          rescue Fog::Errors::TimeoutError => e
            if try >= attempts
              @logger.debug "Failed to connect to new OpenStack instance #{host.name} (#{host[:vmhostname]})"
              raise e
            end
            @logger.debug "Timeout connecting to instance #{host.name} (#{host[:vmhostname]}), trying again..."
          end
          sleep SLEEPWAIT
          try += 1
        end

        # Associate a public IP to the server
        ip.server = vm
        host[:ip] = ip.ip

        @logger.debug "OpenStack host #{host.name} (#{host[:vmhostname]}) assigned ip: #{host[:ip]}"

        #set metadata
        vm.metadata.update({:jenkins_build_url => @options[:jenkins_build_url].to_s,
                            :department        => @options[:department].to_s,
                            :project           => @options[:project].to_s })
        @vms << vm

        # Wait for the host to accept ssh logins
        host.wait_for_port(22)

        #enable root if user is not root
        enable_root(host)

        provision_storage(host, vm) if @options[:openstack_volume_support]
        @logger.notify "OpenStack Volume Support Disabled, can't provision volumes" if not @options[:openstack_volume_support]
      end

      hack_etc_hosts @hosts, @options

    end
def provision
      @logger.notify "Provisioning OpenStack"

      @hosts.each do |host|
        ip = get_ip
        hostname = ip.ip.gsub('.','-')
        host[:vmhostname] = hostname + '.rfc1918.puppetlabs.net'
        create_or_associate_keypair(host, hostname)
        @logger.debug "Provisioning #{host.name} (#{host[:vmhostname]})"
        options = {
          :flavor_ref => flavor(host[:flavor]).id,
          :image_ref  => image(host[:image]).id,
          :nics       => [ {'net_id' => network(@options[:openstack_network]).id } ],
          :name       => host[:vmhostname],
          :hostname   => host[:vmhostname],
          :user_data  => host[:user_data] || "#cloud-config\nmanage_etc_hosts: true\n",
          :key_name   => host[:keyname],
        }
        options[:security_groups] = security_groups(@options[:security_group]) unless @options[:security_group].nil?
        vm = @compute_client.servers.create(options)

        #wait for the new instance to start up
        try = 1
        attempts = @options[:timeout].to_i / SLEEPWAIT

        while try <= attempts
          begin
            vm.wait_for(5) { ready? }
            break
          rescue Fog::Errors::TimeoutError => e
            if try >= attempts
              @logger.debug "Failed to connect to new OpenStack instance #{host.name} (#{host[:vmhostname]})"
              raise e
            end
            @logger.debug "Timeout connecting to instance #{host.name} (#{host[:vmhostname]}), trying again..."
          end
          sleep SLEEPWAIT
          try += 1
        end

        # Associate a public IP to the server
        ip.server = vm
        host[:ip] = ip.ip

        @logger.debug "OpenStack host #{host.name} (#{host[:vmhostname]}) assigned ip: #{host[:ip]}"

        #set metadata
        vm.metadata.update({:jenkins_build_url => @options[:jenkins_build_url].to_s,
                            :department        => @options[:department].to_s,
                            :project           => @options[:project].to_s })
        @vms << vm

        # Wait for the host to accept ssh logins
        host.wait_for_port(22)

        #enable root if user is not root
        enable_root(host)

        provision_storage(host, vm) if @options[:openstack_volume_support]
        @logger.notify "OpenStack Volume Support Disabled, can't provision volumes" if not @options[:openstack_volume_support]
      end

      hack_etc_hosts @hosts, @options

    end
Create new instances in OpenStack