vagrant-softlayer 0.3.3 → 0.4.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 +16 -16
- data/CHANGELOG.md +61 -49
- data/QUICKSTART.md +380 -376
- data/README.md +258 -256
- data/contrib/vagrant-softlayer-boxes +418 -416
- data/contrib/vagrant-softlayer-vlans +339 -329
- data/lib/vagrant-softlayer/action/create_instance.rb +74 -74
- data/lib/vagrant-softlayer/action/setup_softlayer.rb +39 -39
- data/lib/vagrant-softlayer/action/update_dns.rb +94 -94
- data/lib/vagrant-softlayer/action/wait_for_provision.rb +40 -40
- data/lib/vagrant-softlayer/action/wait_for_rebuild.rb +38 -36
- data/lib/vagrant-softlayer/config.rb +282 -268
- data/lib/vagrant-softlayer/util/load_balancer.rb +96 -103
- data/lib/vagrant-softlayer/util/network.rb +75 -75
- data/lib/vagrant-softlayer/util/warden.rb +38 -38
- data/lib/vagrant-softlayer/version.rb +5 -5
- data/spec/vagrant-softlayer/config_spec.rb +271 -267
- data/vagrant-softlayer.gemspec +55 -55
- metadata +4 -4
@@ -1,74 +1,74 @@
|
|
1
|
-
module VagrantPlugins
|
2
|
-
module SoftLayer
|
3
|
-
module Action
|
4
|
-
# This creates a new instance.
|
5
|
-
class CreateInstance
|
6
|
-
include Util::Network
|
7
|
-
include Util::Warden
|
8
|
-
|
9
|
-
def initialize(app, env)
|
10
|
-
@app = app
|
11
|
-
end
|
12
|
-
|
13
|
-
def call(env)
|
14
|
-
@env = env
|
15
|
-
|
16
|
-
@env[:ui].info I18n.t("vagrant_softlayer.vm.creating")
|
17
|
-
|
18
|
-
sl_warden { env[:
|
19
|
-
|
20
|
-
result = sl_warden { env[:
|
21
|
-
@env[:machine].id = result["id"].to_s
|
22
|
-
|
23
|
-
@app.call(@env)
|
24
|
-
end
|
25
|
-
|
26
|
-
def get_hostname
|
27
|
-
@env[:machine].provider_config.hostname || @env[:machine].config.vm.hostname
|
28
|
-
end
|
29
|
-
|
30
|
-
def get_vlan_id(vlan_name, vlan_space)
|
31
|
-
return vlan_name unless vlan_name.kind_of?(String)
|
32
|
-
|
33
|
-
routers = @env[:
|
34
|
-
|
35
|
-
routers.each do |router|
|
36
|
-
next if @env[:machine].provider_config.datacenter && router["datacenter"]["name"] != @env[:machine].provider_config.datacenter
|
37
|
-
router["networkVlans"].each do |vlan|
|
38
|
-
vlan_qualified_name = [ router["hostname"].split('.').reverse.join('.'), vlan["vlanNumber"] ].join('.')
|
39
|
-
return vlan["id"] if vlan.has_key?("name") && vlan["type"]["keyName"] == "STANDARD" && vlan["networkSpace"] == vlan_space.to_s.upcase && (vlan["name"] == vlan_name || vlan_qualified_name == vlan_name)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
raise Errors::SLVlanIdNotFound, :vlan_space => vlan_space.to_s, :vlan_name => vlan_name.inspect
|
44
|
-
end
|
45
|
-
|
46
|
-
def order_template
|
47
|
-
template = {
|
48
|
-
"dedicatedAccountHostOnlyFlag" => @env[:machine].provider_config.dedicated,
|
49
|
-
"domain" => @env[:machine].provider_config.domain,
|
50
|
-
"hostname" => get_hostname,
|
51
|
-
"hourlyBillingFlag" => @env[:machine].provider_config.hourly_billing,
|
52
|
-
"localDiskFlag" => @env[:machine].provider_config.local_disk,
|
53
|
-
"maxMemory" => @env[:machine].provider_config.max_memory,
|
54
|
-
"networkComponents" => [ { :maxSpeed => @env[:machine].provider_config.network_speed } ],
|
55
|
-
"privateNetworkOnlyFlag" => @env[:machine].provider_config.private_only,
|
56
|
-
"sshKeys" => ssh_keys(@env),
|
57
|
-
"startCpus" => @env[:machine].provider_config.start_cpus
|
58
|
-
}
|
59
|
-
|
60
|
-
template["blockDevices"] = @env[:machine].provider_config.disk_capacity.map{ |key,value| { "device"=> key.to_s, "diskImage" => { "capacity" => value.to_s } } } if @env[:machine].provider_config.disk_capacity
|
61
|
-
template["blockDeviceTemplateGroup"] = { :globalIdentifier => @env[:machine].provider_config.image_guid } if @env[:machine].provider_config.image_guid
|
62
|
-
template["datacenter"] = { :name => @env[:machine].provider_config.datacenter } if @env[:machine].provider_config.datacenter
|
63
|
-
template["operatingSystemReferenceCode"] = @env[:machine].provider_config.operating_system if !@env[:machine].provider_config.image_guid
|
64
|
-
template["postInstallScriptUri"] = @env[:machine].provider_config.post_install if @env[:machine].provider_config.post_install
|
65
|
-
template["primaryBackendNetworkComponent"] = { :networkVlan => { :id => get_vlan_id(@env[:machine].provider_config.vlan_private, :private) } } if @env[:machine].provider_config.vlan_private
|
66
|
-
template["primaryNetworkComponent"] = { :networkVlan => { :id => get_vlan_id(@env[:machine].provider_config.vlan_public, :public) } } if @env[:machine].provider_config.vlan_public
|
67
|
-
template["userData"] = [ { :value => @env[:machine].provider_config.user_data } ] if @env[:machine].provider_config.user_data
|
68
|
-
|
69
|
-
return template
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
1
|
+
module VagrantPlugins
|
2
|
+
module SoftLayer
|
3
|
+
module Action
|
4
|
+
# This creates a new instance.
|
5
|
+
class CreateInstance
|
6
|
+
include Util::Network
|
7
|
+
include Util::Warden
|
8
|
+
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
@env = env
|
15
|
+
|
16
|
+
@env[:ui].info I18n.t("vagrant_softlayer.vm.creating")
|
17
|
+
|
18
|
+
sl_warden { env[:sl_client]["SoftLayer_Product_Order"].verifyOrder(env[:sl_client]["SoftLayer_Virtual_Guest"].generateOrderTemplate(order_template)) }
|
19
|
+
|
20
|
+
result = sl_warden { env[:sl_client]["SoftLayer_Virtual_Guest"].createObject(order_template) }
|
21
|
+
@env[:machine].id = result["id"].to_s
|
22
|
+
|
23
|
+
@app.call(@env)
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_hostname
|
27
|
+
@env[:machine].provider_config.hostname || @env[:machine].config.vm.hostname
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_vlan_id(vlan_name, vlan_space)
|
31
|
+
return vlan_name unless vlan_name.kind_of?(String)
|
32
|
+
|
33
|
+
routers = @env[:sl_client]["SoftLayer_Account"].object_mask("mask[routers,routers.datacenter,routers.networkVlans,routers.networkVlans.networkSpace,routers.networkVlans.type]").getObject["routers"]
|
34
|
+
|
35
|
+
routers.each do |router|
|
36
|
+
next if @env[:machine].provider_config.datacenter && router["datacenter"]["name"] != @env[:machine].provider_config.datacenter
|
37
|
+
router["networkVlans"].each do |vlan|
|
38
|
+
vlan_qualified_name = [ router["hostname"].split('.').reverse.join('.'), vlan["vlanNumber"] ].join('.')
|
39
|
+
return vlan["id"] if vlan.has_key?("name") && vlan["type"]["keyName"] == "STANDARD" && vlan["networkSpace"] == vlan_space.to_s.upcase && (vlan["name"] == vlan_name || vlan_qualified_name == vlan_name)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
raise Errors::SLVlanIdNotFound, :vlan_space => vlan_space.to_s, :vlan_name => vlan_name.inspect
|
44
|
+
end
|
45
|
+
|
46
|
+
def order_template
|
47
|
+
template = {
|
48
|
+
"dedicatedAccountHostOnlyFlag" => @env[:machine].provider_config.dedicated,
|
49
|
+
"domain" => @env[:machine].provider_config.domain,
|
50
|
+
"hostname" => get_hostname,
|
51
|
+
"hourlyBillingFlag" => @env[:machine].provider_config.hourly_billing,
|
52
|
+
"localDiskFlag" => @env[:machine].provider_config.local_disk,
|
53
|
+
"maxMemory" => @env[:machine].provider_config.max_memory,
|
54
|
+
"networkComponents" => [ { :maxSpeed => @env[:machine].provider_config.network_speed } ],
|
55
|
+
"privateNetworkOnlyFlag" => @env[:machine].provider_config.private_only,
|
56
|
+
"sshKeys" => ssh_keys(@env),
|
57
|
+
"startCpus" => @env[:machine].provider_config.start_cpus
|
58
|
+
}
|
59
|
+
|
60
|
+
template["blockDevices"] = @env[:machine].provider_config.disk_capacity.map{ |key,value| { "device"=> key.to_s, "diskImage" => { "capacity" => value.to_s } } } if @env[:machine].provider_config.disk_capacity
|
61
|
+
template["blockDeviceTemplateGroup"] = { :globalIdentifier => @env[:machine].provider_config.image_guid } if @env[:machine].provider_config.image_guid
|
62
|
+
template["datacenter"] = { :name => @env[:machine].provider_config.datacenter } if @env[:machine].provider_config.datacenter
|
63
|
+
template["operatingSystemReferenceCode"] = @env[:machine].provider_config.operating_system if !@env[:machine].provider_config.image_guid
|
64
|
+
template["postInstallScriptUri"] = @env[:machine].provider_config.post_install if @env[:machine].provider_config.post_install
|
65
|
+
template["primaryBackendNetworkComponent"] = { :networkVlan => { :id => get_vlan_id(@env[:machine].provider_config.vlan_private, :private) } } if @env[:machine].provider_config.vlan_private
|
66
|
+
template["primaryNetworkComponent"] = { :networkVlan => { :id => get_vlan_id(@env[:machine].provider_config.vlan_public, :public) } } if @env[:machine].provider_config.vlan_public
|
67
|
+
template["userData"] = [ { :value => @env[:machine].provider_config.user_data } ] if @env[:machine].provider_config.user_data
|
68
|
+
|
69
|
+
return template
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -1,39 +1,39 @@
|
|
1
|
-
require "log4r"
|
2
|
-
|
3
|
-
module VagrantPlugins
|
4
|
-
module SoftLayer
|
5
|
-
module Action
|
6
|
-
# This action creates the SoftLayer service objects and
|
7
|
-
# puts them into keys in the environment.
|
8
|
-
# Also, if a machine id is found, another key called
|
9
|
-
# `:sl_machine` and containing the masked object is created.
|
10
|
-
class SetupSoftLayer
|
11
|
-
def initialize(app, env)
|
12
|
-
@app = app
|
13
|
-
@logger = Log4r::Logger.new("vagrant_softlayer::action::connect_softlayer")
|
14
|
-
end
|
15
|
-
|
16
|
-
def call(env)
|
17
|
-
@logger.info("Creating the SoftLayer service objects...")
|
18
|
-
|
19
|
-
env[:sl_credentials] = {
|
20
|
-
:api_key => env[:machine].provider_config.api_key,
|
21
|
-
:endpoint_url => env[:machine].provider_config.endpoint_url,
|
22
|
-
:
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
env[:
|
28
|
-
|
29
|
-
unless env[:machine].id.nil? || env[:machine].id.empty?
|
30
|
-
env[:sl_machine] = env[:
|
31
|
-
end
|
32
|
-
|
33
|
-
# Carry on
|
34
|
-
@app.call(env)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module SoftLayer
|
5
|
+
module Action
|
6
|
+
# This action creates the SoftLayer service objects and
|
7
|
+
# puts them into keys in the environment.
|
8
|
+
# Also, if a machine id is found, another key called
|
9
|
+
# `:sl_machine` and containing the masked object is created.
|
10
|
+
class SetupSoftLayer
|
11
|
+
def initialize(app, env)
|
12
|
+
@app = app
|
13
|
+
@logger = Log4r::Logger.new("vagrant_softlayer::action::connect_softlayer")
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
@logger.info("Creating the SoftLayer service objects...")
|
18
|
+
|
19
|
+
env[:sl_credentials] = {
|
20
|
+
:api_key => env[:machine].provider_config.api_key,
|
21
|
+
:endpoint_url => env[:machine].provider_config.endpoint_url,
|
22
|
+
:timeout => env[:machine].provider_config.api_timeout,
|
23
|
+
:user_agent => "vagrant-softlayer",
|
24
|
+
:username => env[:machine].provider_config.username
|
25
|
+
}
|
26
|
+
|
27
|
+
env[:sl_client] = ::SoftLayer::Client.new(env[:sl_credentials])
|
28
|
+
|
29
|
+
unless env[:machine].id.nil? || env[:machine].id.empty?
|
30
|
+
env[:sl_machine] = env[:sl_client]["SoftLayer_Virtual_Guest"].object_with_id(env[:machine].id.to_i)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Carry on
|
34
|
+
@app.call(env)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -1,94 +1,94 @@
|
|
1
|
-
module VagrantPlugins
|
2
|
-
module SoftLayer
|
3
|
-
module Action
|
4
|
-
# Look for the DNS zone relative to the configured domain and,
|
5
|
-
# on return path, perform an API call to add or remove the A
|
6
|
-
# resource record for the host.
|
7
|
-
class UpdateDNS
|
8
|
-
include Util::Network
|
9
|
-
include Util::Warden
|
10
|
-
|
11
|
-
def initialize(app, env)
|
12
|
-
@app = app
|
13
|
-
@logger = Log4r::Logger.new("vagrant_softlayer::action::update_dns")
|
14
|
-
end
|
15
|
-
|
16
|
-
def call(env)
|
17
|
-
@env = env
|
18
|
-
|
19
|
-
update_dns
|
20
|
-
|
21
|
-
@app.call(@env)
|
22
|
-
end
|
23
|
-
|
24
|
-
def add_record
|
25
|
-
template = {
|
26
|
-
"data" => ip_address(@env),
|
27
|
-
"domainId" => @dns_zone["id"],
|
28
|
-
"host" => hostname(@env),
|
29
|
-
"ttl" => 86400,
|
30
|
-
"type" => "a"
|
31
|
-
}
|
32
|
-
@env[:ui].info I18n.t("vagrant_softlayer.vm.creating_dns_record")
|
33
|
-
@logger.debug("Creating DNS A record for #{template['host']}.#{@dns_zone[:name]} (IP address #{template['data']}).")
|
34
|
-
resource = sl_warden { @resource.createObject(template) }
|
35
|
-
self.dns_id = resource["id"]
|
36
|
-
end
|
37
|
-
|
38
|
-
def delete_record
|
39
|
-
@env[:ui].info I18n.t("vagrant_softlayer.vm.deleting_dns_record")
|
40
|
-
@logger.debug("Deleting stored DNS A record (ID #{self.dns_id}).")
|
41
|
-
warn_msg = lambda { @env[:ui].warn I18n.t("vagrant_softlayer.errors.dns_record_not_found") }
|
42
|
-
sl_warden(warn_msg) { @resource.object_with_id(self.dns_id).deleteObject }
|
43
|
-
end
|
44
|
-
|
45
|
-
def dns_id
|
46
|
-
id = nil
|
47
|
-
id_file = @env[:machine].data_dir.join("dns_id")
|
48
|
-
id = id_file.read.chomp.to_i if id_file.file?
|
49
|
-
return id
|
50
|
-
end
|
51
|
-
|
52
|
-
def dns_id=(value)
|
53
|
-
@logger.info("New machine DNS ID: #{value.inspect}")
|
54
|
-
|
55
|
-
# The file that will store the id if we have one. This allows the
|
56
|
-
# ID to persist across Vagrant runs.
|
57
|
-
id_file = @env[:machine].data_dir.join("dns_id")
|
58
|
-
|
59
|
-
if value
|
60
|
-
# Write the "id" file with the id given.
|
61
|
-
id_file.open("w+") do |f|
|
62
|
-
f.write(value)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def update_dns
|
68
|
-
unless @env[:machine].provider_config.manage_dns
|
69
|
-
@logger.debug("Not managing DNS. Going ahead.")
|
70
|
-
return
|
71
|
-
end
|
72
|
-
|
73
|
-
# Lookup the DNS zone
|
74
|
-
zone =
|
75
|
-
domain = @env[:machine].provider_config.domain
|
76
|
-
|
77
|
-
@logger.debug("Looking for #{domain} zone into the SoftLayer zone list.")
|
78
|
-
@dns_zone = sl_warden { zone.getByDomainName(domain).first }
|
79
|
-
raise Errors::SLDNSZoneNotFound, :zone => domain unless @dns_zone
|
80
|
-
@logger.debug("Found DNS zone: #{@dns_zone.inspect}")
|
81
|
-
|
82
|
-
# Add or remove the resource record
|
83
|
-
@resource =
|
84
|
-
case @env[:machine_action]
|
85
|
-
when :up
|
86
|
-
add_record unless self.dns_id
|
87
|
-
when :destroy
|
88
|
-
delete_record
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
1
|
+
module VagrantPlugins
|
2
|
+
module SoftLayer
|
3
|
+
module Action
|
4
|
+
# Look for the DNS zone relative to the configured domain and,
|
5
|
+
# on return path, perform an API call to add or remove the A
|
6
|
+
# resource record for the host.
|
7
|
+
class UpdateDNS
|
8
|
+
include Util::Network
|
9
|
+
include Util::Warden
|
10
|
+
|
11
|
+
def initialize(app, env)
|
12
|
+
@app = app
|
13
|
+
@logger = Log4r::Logger.new("vagrant_softlayer::action::update_dns")
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
@env = env
|
18
|
+
|
19
|
+
update_dns
|
20
|
+
|
21
|
+
@app.call(@env)
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_record
|
25
|
+
template = {
|
26
|
+
"data" => ip_address(@env),
|
27
|
+
"domainId" => @dns_zone["id"],
|
28
|
+
"host" => hostname(@env),
|
29
|
+
"ttl" => 86400,
|
30
|
+
"type" => "a"
|
31
|
+
}
|
32
|
+
@env[:ui].info I18n.t("vagrant_softlayer.vm.creating_dns_record")
|
33
|
+
@logger.debug("Creating DNS A record for #{template['host']}.#{@dns_zone[:name]} (IP address #{template['data']}).")
|
34
|
+
resource = sl_warden { @resource.createObject(template) }
|
35
|
+
self.dns_id = resource["id"]
|
36
|
+
end
|
37
|
+
|
38
|
+
def delete_record
|
39
|
+
@env[:ui].info I18n.t("vagrant_softlayer.vm.deleting_dns_record")
|
40
|
+
@logger.debug("Deleting stored DNS A record (ID #{self.dns_id}).")
|
41
|
+
warn_msg = lambda { @env[:ui].warn I18n.t("vagrant_softlayer.errors.dns_record_not_found") }
|
42
|
+
sl_warden(warn_msg) { @resource.object_with_id(self.dns_id).deleteObject }
|
43
|
+
end
|
44
|
+
|
45
|
+
def dns_id
|
46
|
+
id = nil
|
47
|
+
id_file = @env[:machine].data_dir.join("dns_id")
|
48
|
+
id = id_file.read.chomp.to_i if id_file.file?
|
49
|
+
return id
|
50
|
+
end
|
51
|
+
|
52
|
+
def dns_id=(value)
|
53
|
+
@logger.info("New machine DNS ID: #{value.inspect}")
|
54
|
+
|
55
|
+
# The file that will store the id if we have one. This allows the
|
56
|
+
# ID to persist across Vagrant runs.
|
57
|
+
id_file = @env[:machine].data_dir.join("dns_id")
|
58
|
+
|
59
|
+
if value
|
60
|
+
# Write the "id" file with the id given.
|
61
|
+
id_file.open("w+") do |f|
|
62
|
+
f.write(value)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def update_dns
|
68
|
+
unless @env[:machine].provider_config.manage_dns
|
69
|
+
@logger.debug("Not managing DNS. Going ahead.")
|
70
|
+
return
|
71
|
+
end
|
72
|
+
|
73
|
+
# Lookup the DNS zone
|
74
|
+
zone = @env[:sl_client]["SoftLayer_Dns_Domain"]
|
75
|
+
domain = @env[:machine].provider_config.domain
|
76
|
+
|
77
|
+
@logger.debug("Looking for #{domain} zone into the SoftLayer zone list.")
|
78
|
+
@dns_zone = sl_warden { zone.getByDomainName(domain).first }
|
79
|
+
raise Errors::SLDNSZoneNotFound, :zone => domain unless @dns_zone
|
80
|
+
@logger.debug("Found DNS zone: #{@dns_zone.inspect}")
|
81
|
+
|
82
|
+
# Add or remove the resource record
|
83
|
+
@resource = @env[:sl_client]["SoftLayer_Dns_Domain_ResourceRecord"]
|
84
|
+
case @env[:machine_action]
|
85
|
+
when :up
|
86
|
+
add_record unless self.dns_id
|
87
|
+
when :destroy
|
88
|
+
delete_record
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -1,40 +1,40 @@
|
|
1
|
-
require "log4r"
|
2
|
-
|
3
|
-
module VagrantPlugins
|
4
|
-
module SoftLayer
|
5
|
-
module Action
|
6
|
-
# Waits until the new machine has been provisioned.
|
7
|
-
class WaitForProvision
|
8
|
-
include Util::Warden
|
9
|
-
|
10
|
-
def initialize(app, env)
|
11
|
-
@app = app
|
12
|
-
@logger = Log4r::Logger.new("vagrant_softlayer::action::wait_for_provision")
|
13
|
-
end
|
14
|
-
|
15
|
-
def call(env)
|
16
|
-
env[:ui].info I18n.t("vagrant_softlayer.vm.wait_for_provision")
|
17
|
-
|
18
|
-
env[:sl_machine] = env[:
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
#
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
env[:ui].info I18n.t("vagrant_softlayer.vm.provisioned")
|
34
|
-
|
35
|
-
@app.call(env)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module SoftLayer
|
5
|
+
module Action
|
6
|
+
# Waits until the new machine has been provisioned.
|
7
|
+
class WaitForProvision
|
8
|
+
include Util::Warden
|
9
|
+
|
10
|
+
def initialize(app, env)
|
11
|
+
@app = app
|
12
|
+
@logger = Log4r::Logger.new("vagrant_softlayer::action::wait_for_provision")
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
env[:ui].info I18n.t("vagrant_softlayer.vm.wait_for_provision")
|
17
|
+
|
18
|
+
env[:sl_machine] = env[:sl_client]["SoftLayer_Virtual_Guest"].object_with_id(env[:machine].id.to_i)
|
19
|
+
|
20
|
+
virtual_server = ::SoftLayer::VirtualServer.server_with_id(env[:machine].id.to_i, :client => env[:sl_client])
|
21
|
+
|
22
|
+
#Rechecks every 10 sec
|
23
|
+
ready = virtual_server.wait_until_ready((env[:machine].provider_config.provision_timeout.to_f/10).ceil, env[:machine].provider_config.transaction_wait, 10) do |server_ready|
|
24
|
+
unless server_ready
|
25
|
+
provision_status = env[:sl_machine].getActiveTransaction
|
26
|
+
provision_status = " Provision status: #{provision_status["transactionStatus"]["friendlyName"]} (#{provision_status["transactionStatus"]["name"]})." if provision_status && ! provision_status.empty?
|
27
|
+
@logger.info("#{env[:machine].provider_config.hostname} is still provisioning. Retrying in 10 seconds.#{provision_status}")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
raise Errors::SLProvisionTimeoutError unless ready
|
32
|
+
|
33
|
+
env[:ui].info I18n.t("vagrant_softlayer.vm.provisioned")
|
34
|
+
|
35
|
+
@app.call(env)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|