Class: VagrantPlugins::SoftLayer::Action::CreateInstance

Inherits:
Object
  • Object
show all
Includes:
Util::Network, Util::Warden
Defined in:
lib/vagrant-softlayer/action/create_instance.rb

Overview

This creates a new instance.

Instance Method Summary collapse

Methods included from Util::Warden

#sl_warden

Methods included from Util::Network

#hostname, #ip_address, #ip_address_id, #ip_address_record, #ssh_keys

Constructor Details

#initialize(app, env) ⇒ CreateInstance

Returns a new instance of CreateInstance.



9
10
11
# File 'lib/vagrant-softlayer/action/create_instance.rb', line 9

def initialize(app, env)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/vagrant-softlayer/action/create_instance.rb', line 13

def call(env)
  @env = env
  
  @env[:ui].info I18n.t("vagrant_softlayer.vm.creating")
  
  result = sl_warden { env[:sl_connection].createObject(order_template) }
  @env[:machine].id = result["id"].to_s

  @app.call(@env)
end

#get_hostnameObject



24
25
26
# File 'lib/vagrant-softlayer/action/create_instance.rb', line 24

def get_hostname
  @env[:machine].provider_config.hostname || @env[:machine].config.vm.hostname
end

#order_templateObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/vagrant-softlayer/action/create_instance.rb', line 28

def order_template
  template = {
    "dedicatedAccountHostOnlyFlag" => @env[:machine].provider_config.dedicated,
    "domain"                       => @env[:machine].provider_config.domain,
    "hostname"                     => get_hostname,
    "hourlyBillingFlag"            => @env[:machine].provider_config.hourly_billing,
    "localDiskFlag"                => @env[:machine].provider_config.local_disk,
    "maxMemory"                    => @env[:machine].provider_config.max_memory,
    "networkComponents"            => [ { :maxSpeed => @env[:machine].provider_config.network_speed } ],
    "operatingSystemReferenceCode" => @env[:machine].provider_config.operating_system,
    "privateNetworkOnlyFlag"       => @env[:machine].provider_config.private_only,
    "sshKeys"                      => ssh_keys(@env),
    "startCpus"                    => @env[:machine].provider_config.start_cpus
  }

  template["datacenter"] = { :name => @env[:machine].provider_config.datacenter } if @env[:machine].provider_config.datacenter
  template["postInstallScriptUri"] = @env[:machine].provider_config.post_install if @env[:machine].provider_config.post_install
  template["primaryNetworkComponent"] = { :networkVlan => { :id => @env[:machine].provider_config.vlan_public } } if @env[:machine].provider_config.vlan_public
  template["primaryBackendNetworkComponent"] = { :networkVlan => { :id => @env[:machine].provider_config.vlan_private } } if @env[:machine].provider_config.vlan_private
  template["userData"] = [ { :value => @env[:machine].provider_config.user_data } ] if @env[:machine].provider_config.user_data

  return template
end