Class: VagrantPlugins::Openstack::Action::CreateServer
- Inherits:
-
Object
- Object
- VagrantPlugins::Openstack::Action::CreateServer
- Includes:
- Vagrant::Util::Retryable
- Defined in:
- lib/vagrant-openstack-provider/action/create_server.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ CreateServer
constructor
A new instance of CreateServer.
Constructor Details
#initialize(app, env) ⇒ CreateServer
Returns a new instance of CreateServer.
13 14 15 16 |
# File 'lib/vagrant-openstack-provider/action/create_server.rb', line 13 def initialize(app, env) @app = app @logger = Log4r::Logger.new("vagrant_openstack::action::create_server") end |
Instance Method Details
#call(env) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/vagrant-openstack-provider/action/create_server.rb', line 18 def call(env) config = env[:machine].provider_config client = env[:openstack_client] # Find the flavor env[:ui].info(I18n.t("vagrant_openstack.finding_flavor")) flavors = client.get_all_flavors(env) flavor = find_matching(flavors, config.flavor) raise Errors::NoMatchingFlavor if !flavor # Find the image env[:ui].info(I18n.t("vagrant_openstack.finding_image")) images = client.get_all_images(env) image = find_matching(images, config.image) raise Errors::NoMatchingImage if !image # Figure out the name for the server server_name = config.server_name || env[:machine].name # Output the settings we're going to use to the user env[:ui].info(I18n.t("vagrant_openstack.launching_server")) env[:ui].info(" -- Flavor : #{flavor.name}") env[:ui].info(" -- FlavorRef : #{flavor.id}") env[:ui].info(" -- Image : #{image.name}") env[:ui].info(" -- KeyPair : #{config.keypair_name}") env[:ui].info(" -- ImageRef : #{image.id}") env[:ui].info(" -- Disk Config : #{config.disk_config}") if config.disk_config env[:ui].info(" -- Network : #{config.network}") if config.network env[:ui].info(" -- Tenant : #{config.tenant_name}") env[:ui].info(" -- Name : #{server_name}") #TODO(julienvey) add metadata #TODO(julienvey) add availability_zone #TODO(julienvey) add disk_config server_id = client.create_server(env, server_name, image.id, flavor.id, config.keypair_name) #TODO(julienvey) Find a network if provided #if config.network # network = find_matching(env[:openstack_network].networks, config.network) # options[:nics] = [{"net_id" => network.id}] if network #end # Store the ID right away so we can track it env[:machine].id = server_id # Wait for the server to finish building env[:ui].info(I18n.t("vagrant_openstack.waiting_for_build")) timeout(200) do while client.get_server_details(env, server_id)['status'] != 'ACTIVE' do sleep 3 @logger.debug("Waiting for server to be ACTIVE") end end if config.floating_ip env[:ui].info("Using floating IP #{config.floating_ip}") client.add_floating_ip(env, server_id, config.floating_ip) end if !env[:interrupted] # Clear the line one more time so the progress is removed env[:ui].clear_line # Wait for SSH to become available host = env[:machine].provider_config.floating_ip ssh_timeout = env[:machine].provider_config.ssh_timeout sleep 240 if !port_open?(env, host, 22, ssh_timeout) env[:ui].error(I18n.t("vagrant_openstack.timeout")) raise Errors::SshUnavailable, :host => host, :timeout => ssh_timeout end env[:ui].info(I18n.t("vagrant_openstack.ready")) end @app.call(env) end |