vagrant-softlayer 0.3.1 → 0.3.2

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.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +37 -24
  3. data/QUICKSTART.md +377 -0
  4. data/README.md +25 -20
  5. data/contrib/README.md +8 -1
  6. data/contrib/vagrant-softlayer-boxes +416 -408
  7. data/contrib/vagrant-softlayer-vlans +329 -0
  8. data/contrib/vagrantcloud/CENTOS_5_32.box +0 -0
  9. data/contrib/vagrantcloud/CENTOS_5_64.box +0 -0
  10. data/contrib/vagrantcloud/CENTOS_6_32.box +0 -0
  11. data/contrib/vagrantcloud/CENTOS_6_64.box +0 -0
  12. data/contrib/vagrantcloud/CENTOS_LATEST.box +0 -0
  13. data/contrib/vagrantcloud/CENTOS_LATEST_32.box +0 -0
  14. data/contrib/vagrantcloud/CENTOS_LATEST_64.box +0 -0
  15. data/contrib/vagrantcloud/CLOUDLINUX_5_32.box +0 -0
  16. data/contrib/vagrantcloud/CLOUDLINUX_5_64.box +0 -0
  17. data/contrib/vagrantcloud/CLOUDLINUX_6_32.box +0 -0
  18. data/contrib/vagrantcloud/CLOUDLINUX_6_64.box +0 -0
  19. data/contrib/vagrantcloud/CLOUDLINUX_LATEST.box +0 -0
  20. data/contrib/vagrantcloud/CLOUDLINUX_LATEST_32.box +0 -0
  21. data/contrib/vagrantcloud/CLOUDLINUX_LATEST_64.box +0 -0
  22. data/contrib/vagrantcloud/DEBIAN_5_32.box +0 -0
  23. data/contrib/vagrantcloud/DEBIAN_5_64.box +0 -0
  24. data/contrib/vagrantcloud/DEBIAN_6_32.box +0 -0
  25. data/contrib/vagrantcloud/DEBIAN_6_64.box +0 -0
  26. data/contrib/vagrantcloud/DEBIAN_7_32.box +0 -0
  27. data/contrib/vagrantcloud/DEBIAN_7_64.box +0 -0
  28. data/contrib/vagrantcloud/DEBIAN_LATEST.box +0 -0
  29. data/contrib/vagrantcloud/DEBIAN_LATEST_32.box +0 -0
  30. data/contrib/vagrantcloud/DEBIAN_LATEST_64.box +0 -0
  31. data/contrib/vagrantcloud/REDHAT_5_32.box +0 -0
  32. data/contrib/vagrantcloud/REDHAT_5_64.box +0 -0
  33. data/contrib/vagrantcloud/REDHAT_6_32.box +0 -0
  34. data/contrib/vagrantcloud/REDHAT_6_64.box +0 -0
  35. data/contrib/vagrantcloud/REDHAT_LATEST.box +0 -0
  36. data/contrib/vagrantcloud/REDHAT_LATEST_32.box +0 -0
  37. data/contrib/vagrantcloud/REDHAT_LATEST_64.box +0 -0
  38. data/contrib/vagrantcloud/SL_GENERIC.box +0 -0
  39. data/contrib/vagrantcloud/UBUNTU_10_32.box +0 -0
  40. data/contrib/vagrantcloud/UBUNTU_10_64.box +0 -0
  41. data/contrib/vagrantcloud/UBUNTU_12_32.box +0 -0
  42. data/contrib/vagrantcloud/UBUNTU_12_64.box +0 -0
  43. data/contrib/vagrantcloud/UBUNTU_14_32.box +0 -0
  44. data/contrib/vagrantcloud/UBUNTU_14_64.box +0 -0
  45. data/contrib/vagrantcloud/UBUNTU_8_32.box +0 -0
  46. data/contrib/vagrantcloud/UBUNTU_8_64.box +0 -0
  47. data/contrib/vagrantcloud/UBUNTU_LATEST.box +0 -0
  48. data/contrib/vagrantcloud/UBUNTU_LATEST_32.box +0 -0
  49. data/contrib/vagrantcloud/UBUNTU_LATEST_64.box +0 -0
  50. data/contrib/vagrantcloud/VYATTACE_6.5_64.box +0 -0
  51. data/contrib/vagrantcloud/VYATTACE_6.6_64.box +0 -0
  52. data/contrib/vagrantcloud/VYATTACE_LATEST.box +0 -0
  53. data/contrib/vagrantcloud/VYATTACE_LATEST_64.box +0 -0
  54. data/contrib/vagrantcloud/WIN_2003-DC-SP2-1_32.box +0 -0
  55. data/contrib/vagrantcloud/WIN_2003-DC-SP2-1_64.box +0 -0
  56. data/contrib/vagrantcloud/WIN_2003-ENT-SP2-5_32.box +0 -0
  57. data/contrib/vagrantcloud/WIN_2003-ENT-SP2-5_64.box +0 -0
  58. data/contrib/vagrantcloud/WIN_2003-STD-SP2-5_32.box +0 -0
  59. data/contrib/vagrantcloud/WIN_2003-STD-SP2-5_64.box +0 -0
  60. data/contrib/vagrantcloud/WIN_2008-DC-R2_64.box +0 -0
  61. data/contrib/vagrantcloud/WIN_2008-DC-SP2_32.box +0 -0
  62. data/contrib/vagrantcloud/WIN_2008-DC-SP2_64.box +0 -0
  63. data/contrib/vagrantcloud/WIN_2008-ENT-R2_64.box +0 -0
  64. data/contrib/vagrantcloud/WIN_2008-ENT-SP2_32.box +0 -0
  65. data/contrib/vagrantcloud/WIN_2008-ENT-SP2_64.box +0 -0
  66. data/contrib/vagrantcloud/WIN_2008-STD-R2-SP1_64.box +0 -0
  67. data/contrib/vagrantcloud/WIN_2008-STD-R2_64.box +0 -0
  68. data/contrib/vagrantcloud/WIN_2008-STD-SP2_32.box +0 -0
  69. data/contrib/vagrantcloud/WIN_2008-STD-SP2_64.box +0 -0
  70. data/contrib/vagrantcloud/WIN_2012-DC_64.box +0 -0
  71. data/contrib/vagrantcloud/WIN_2012-STD_64.box +0 -0
  72. data/contrib/vagrantcloud/WIN_LATEST.box +0 -0
  73. data/contrib/vagrantcloud/WIN_LATEST_32.box +0 -0
  74. data/contrib/vagrantcloud/WIN_LATEST_64.box +0 -0
  75. data/lib/vagrant-softlayer/action.rb +20 -16
  76. data/lib/vagrant-softlayer/action/create_instance.rb +24 -8
  77. data/lib/vagrant-softlayer/action/setup_softlayer.rb +2 -1
  78. data/lib/vagrant-softlayer/action/sync_folders.rb +99 -99
  79. data/lib/vagrant-softlayer/action/wait_for_rebuild.rb +36 -36
  80. data/lib/vagrant-softlayer/config.rb +10 -2
  81. data/lib/vagrant-softlayer/errors.rb +33 -29
  82. data/lib/vagrant-softlayer/plugin.rb +77 -77
  83. data/lib/vagrant-softlayer/util/load_balancer.rb +103 -103
  84. data/lib/vagrant-softlayer/util/network.rb +75 -73
  85. data/lib/vagrant-softlayer/util/warden.rb +38 -38
  86. data/lib/vagrant-softlayer/version.rb +5 -5
  87. data/locales/en.yml +6 -0
  88. data/spec/vagrant-softlayer/config_spec.rb +4 -2
  89. data/vagrant-softlayer.gemspec +55 -55
  90. metadata +71 -2
@@ -1,29 +1,33 @@
1
- module VagrantPlugins
2
- module SoftLayer
3
- module Errors
4
- class VagrantSoftLayerError < Vagrant::Errors::VagrantError
5
- error_namespace("vagrant_softlayer.errors")
6
- end
7
-
8
- class SLApiError < VagrantSoftLayerError
9
- error_key(:api_error)
10
- end
11
-
12
- class SLCertificateError < VagrantSoftLayerError
13
- error_key(:certificate_error)
14
- end
15
-
16
- class SLDNSZoneNotFound < VagrantSoftLayerError
17
- error_key(:dns_zone_not_found)
18
- end
19
-
20
- class SLLoadBalancerNotFound < VagrantSoftLayerError
21
- error_key(:load_balancer_not_found)
22
- end
23
-
24
- class SLSshKeyNotFound < VagrantSoftLayerError
25
- error_key(:ssh_key_not_found)
26
- end
27
- end
28
- end
29
- end
1
+ module VagrantPlugins
2
+ module SoftLayer
3
+ module Errors
4
+ class VagrantSoftLayerError < Vagrant::Errors::VagrantError
5
+ error_namespace("vagrant_softlayer.errors")
6
+ end
7
+
8
+ class SLApiError < VagrantSoftLayerError
9
+ error_key(:api_error)
10
+ end
11
+
12
+ class SLCertificateError < VagrantSoftLayerError
13
+ error_key(:certificate_error)
14
+ end
15
+
16
+ class SLDNSZoneNotFound < VagrantSoftLayerError
17
+ error_key(:dns_zone_not_found)
18
+ end
19
+
20
+ class SLLoadBalancerNotFound < VagrantSoftLayerError
21
+ error_key(:load_balancer_not_found)
22
+ end
23
+
24
+ class SLSshKeyNotFound < VagrantSoftLayerError
25
+ error_key(:ssh_key_not_found)
26
+ end
27
+
28
+ class SLVlanIdNotFound < VagrantSoftLayerError
29
+ error_key(:vlan_id_not_found)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,77 +1,77 @@
1
- begin
2
- require "vagrant"
3
- rescue LoadError
4
- raise "The Vagrant SoftLayer plugin must be run within Vagrant."
5
- end
6
-
7
- # This is a sanity check to make sure no one is attempting to install
8
- # this into an early Vagrant version.
9
- if Vagrant::VERSION < "1.3.0"
10
- raise "The Vagrant SoftLayer plugin is only compatible with Vagrant 1.3+"
11
- end
12
-
13
- module VagrantPlugins
14
- module SoftLayer
15
- class Plugin < Vagrant.plugin("2")
16
- name "SoftLayer"
17
- description <<-DESC
18
- This plugin installs a provider that allows Vagrant to manage
19
- SoftLayer CCI.
20
- DESC
21
-
22
- command(:rebuild) do
23
- require_relative 'command/rebuild'
24
- Command::Rebuild
25
- end
26
-
27
- config(:softlayer, :provider) do
28
- require_relative "config"
29
- Config
30
- end
31
-
32
- provider(:softlayer) do
33
- init_logging
34
- init_i18n
35
-
36
- require_relative "provider"
37
- Provider
38
- end
39
-
40
- # This initializes the I18n load path so that the plugin specific
41
- # transations work.
42
- def self.init_i18n
43
- I18n.load_path << File.expand_path("locales/en.yml", SoftLayer.source_root)
44
- I18n.reload!
45
- end
46
-
47
- # This sets up our log level to be whatever VAGRANT_LOG is.
48
- def self.init_logging
49
- require "log4r"
50
-
51
- level = nil
52
- begin
53
- level = Log4r.const_get(ENV["VAGRANT_LOG"].upcase)
54
- rescue NameError
55
- # This means that the logging constant wasn't found,
56
- # which is fine. We just keep `level` as `nil`. But
57
- # we tell the user.
58
- level = nil
59
- end
60
-
61
- # Some constants, such as "true" resolve to booleans, so the
62
- # above error checking doesn't catch it. This will check to make
63
- # sure that the log level is an integer, as Log4r requires.
64
- level = nil if !level.is_a?(Integer)
65
-
66
- # Set the logging level on all "vagrant" namespaced
67
- # logs as long as we have a valid level.
68
- if level
69
- logger = Log4r::Logger.new("vagrant_softlayer")
70
- logger.outputters = Log4r::Outputter.stderr
71
- logger.level = level
72
- logger = nil
73
- end
74
- end
75
- end
76
- end
77
- end
1
+ begin
2
+ require "vagrant"
3
+ rescue LoadError
4
+ raise "The Vagrant SoftLayer plugin must be run within Vagrant."
5
+ end
6
+
7
+ # This is a sanity check to make sure no one is attempting to install
8
+ # this into an early Vagrant version.
9
+ if Vagrant::VERSION < "1.3.0"
10
+ raise "The Vagrant SoftLayer plugin is only compatible with Vagrant 1.3+"
11
+ end
12
+
13
+ module VagrantPlugins
14
+ module SoftLayer
15
+ class Plugin < Vagrant.plugin("2")
16
+ name "SoftLayer"
17
+ description <<-DESC
18
+ This plugin installs a provider that allows Vagrant to manage
19
+ SoftLayer CCI.
20
+ DESC
21
+
22
+ command(:rebuild) do
23
+ require_relative 'command/rebuild'
24
+ Command::Rebuild
25
+ end
26
+
27
+ config(:softlayer, :provider) do
28
+ require_relative "config"
29
+ Config
30
+ end
31
+
32
+ provider(:softlayer) do
33
+ init_logging
34
+ init_i18n
35
+
36
+ require_relative "provider"
37
+ Provider
38
+ end
39
+
40
+ # This initializes the I18n load path so that the plugin specific
41
+ # transations work.
42
+ def self.init_i18n
43
+ I18n.load_path << File.expand_path("locales/en.yml", SoftLayer.source_root)
44
+ I18n.reload!
45
+ end
46
+
47
+ # This sets up our log level to be whatever VAGRANT_LOG is.
48
+ def self.init_logging
49
+ require "log4r"
50
+
51
+ level = nil
52
+ begin
53
+ level = Log4r.const_get(ENV["VAGRANT_LOG"].upcase)
54
+ rescue NameError
55
+ # This means that the logging constant wasn't found,
56
+ # which is fine. We just keep `level` as `nil`. But
57
+ # we tell the user.
58
+ level = nil
59
+ end
60
+
61
+ # Some constants, such as "true" resolve to booleans, so the
62
+ # above error checking doesn't catch it. This will check to make
63
+ # sure that the log level is an integer, as Log4r requires.
64
+ level = nil if !level.is_a?(Integer)
65
+
66
+ # Set the logging level on all "vagrant" namespaced
67
+ # logs as long as we have a valid level.
68
+ if level
69
+ logger = Log4r::Logger.new("vagrant_softlayer")
70
+ logger.outputters = Log4r::Outputter.stderr
71
+ logger.level = level
72
+ logger = nil
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -1,103 +1,103 @@
1
- module VagrantPlugins
2
- module SoftLayer
3
- module Util
4
- # This mixin contains utility methods for load balancer management.
5
- module LoadBalancer
6
- # Whether load balancer management is enabled or not.
7
- def enabled?
8
- if @env[:machine].provider_config.load_balancers.empty?
9
- @logger.debug("No load balancer has been defined. Going ahead.")
10
- return false
11
- end
12
-
13
- # Currently we don't do load balancing for private machines.
14
- if @env[:machine].provider_config.private_only
15
- @logger.info("Load balancing doesn't work for private machines. Going ahead.")
16
- return false
17
- end
18
- true
19
- end
20
-
21
- # Get existing stuff.
22
- def read_load_balancers
23
- mask = [
24
- "id",
25
- "ipAddress.ipAddress",
26
- "virtualServers.serviceGroups.services.groupReferences",
27
- "virtualServers.serviceGroups.services.healthChecks"
28
- ]
29
- @logger.debug("Looking for existing load balancers.")
30
- @load_balancers = sl_warden { @services["Account"].object_mask(mask).getAdcLoadBalancers }
31
- @logger.debug("Got load balancer configuration:")
32
- @logger.debug("-- #{@load_balancers}")
33
- end
34
-
35
- # For each load balancer, check if total connections
36
- # are less than 100% and, if so, rebalance the allocations.
37
- def rebalance!
38
- read_load_balancers
39
-
40
- @load_balancers.each do |load_balancer|
41
- next if load_balancer["virtualServers"].empty?
42
- next if 100 == load_balancer["virtualServers"].inject(0) { |sum, vs| sum += vs["allocation"] }
43
-
44
- # Create allocation slots.
45
- count = load_balancer["virtualServers"].count
46
- allocation = [100 / count] * count
47
- (100 % count).times { |i| allocation[i] += 1 }
48
-
49
- # Rebalance allocations.
50
- load_balancer["virtualServers"].each do |vs|
51
- vs["allocation"] = allocation.pop
52
- end
53
-
54
- # Update the VIP object.
55
- @logger.debug("Rebalancing VIP #{load_balancer['id']}")
56
- @logger.debug("-- #{load_balancer}")
57
- @services["VirtualIpAddress"].object_with_id(load_balancer["id"]).editObject("virtualServers" => load_balancer["virtualServers"])
58
- end
59
- end
60
-
61
- # Initial setup.
62
- def setup
63
- # A plethora of service objects is required for managing
64
- # load balancers. We instanciate'em all here.
65
- @services = {
66
- "Account" => ::SoftLayer::Service.new("SoftLayer_Account", @env[:sl_credentials])
67
- }
68
- [
69
- "Health_Check_Type",
70
- "Routing_Method",
71
- "Routing_Type",
72
- "Service",
73
- "Service_Group",
74
- "VirtualIpAddress",
75
- "VirtualServer"
76
- ].each do |service|
77
- @services[service] = ::SoftLayer::Service.new(
78
- "SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_#{service}",
79
- @env[:sl_credentials]
80
- )
81
- end
82
-
83
- # We create enumerations for the various configurables.
84
- @enums = {}
85
- [
86
- "Health_Check_Type",
87
- "Routing_Method",
88
- "Routing_Type"
89
- ].each do |service|
90
- {}.tap do |enum|
91
- sl_warden { @services[service].getAllObjects }.each do |record|
92
- enum[record["name"].upcase] = record["id"]
93
- end
94
- @enums[service] = enum
95
- end
96
- end
97
-
98
- read_load_balancers
99
- end
100
- end
101
- end
102
- end
103
- end
1
+ module VagrantPlugins
2
+ module SoftLayer
3
+ module Util
4
+ # This mixin contains utility methods for load balancer management.
5
+ module LoadBalancer
6
+ # Whether load balancer management is enabled or not.
7
+ def enabled?
8
+ if @env[:machine].provider_config.load_balancers.empty?
9
+ @logger.debug("No load balancer has been defined. Going ahead.")
10
+ return false
11
+ end
12
+
13
+ # Currently we don't do load balancing for private machines.
14
+ if @env[:machine].provider_config.private_only
15
+ @logger.info("Load balancing doesn't work for private machines. Going ahead.")
16
+ return false
17
+ end
18
+ true
19
+ end
20
+
21
+ # Get existing stuff.
22
+ def read_load_balancers
23
+ mask = [
24
+ "id",
25
+ "ipAddress.ipAddress",
26
+ "virtualServers.serviceGroups.services.groupReferences",
27
+ "virtualServers.serviceGroups.services.healthChecks"
28
+ ]
29
+ @logger.debug("Looking for existing load balancers.")
30
+ @load_balancers = sl_warden { @services["Account"].object_mask(mask).getAdcLoadBalancers }
31
+ @logger.debug("Got load balancer configuration:")
32
+ @logger.debug("-- #{@load_balancers}")
33
+ end
34
+
35
+ # For each load balancer, check if total connections
36
+ # are less than 100% and, if so, rebalance the allocations.
37
+ def rebalance!
38
+ read_load_balancers
39
+
40
+ @load_balancers.each do |load_balancer|
41
+ next if load_balancer["virtualServers"].empty?
42
+ next if 100 == load_balancer["virtualServers"].inject(0) { |sum, vs| sum += vs["allocation"] }
43
+
44
+ # Create allocation slots.
45
+ count = load_balancer["virtualServers"].count
46
+ allocation = [100 / count] * count
47
+ (100 % count).times { |i| allocation[i] += 1 }
48
+
49
+ # Rebalance allocations.
50
+ load_balancer["virtualServers"].each do |vs|
51
+ vs["allocation"] = allocation.pop
52
+ end
53
+
54
+ # Update the VIP object.
55
+ @logger.debug("Rebalancing VIP #{load_balancer['id']}")
56
+ @logger.debug("-- #{load_balancer}")
57
+ @services["VirtualIpAddress"].object_with_id(load_balancer["id"]).editObject("virtualServers" => load_balancer["virtualServers"])
58
+ end
59
+ end
60
+
61
+ # Initial setup.
62
+ def setup
63
+ # A plethora of service objects is required for managing
64
+ # load balancers. We instanciate'em all here.
65
+ @services = {
66
+ "Account" => ::SoftLayer::Service.new("SoftLayer_Account", @env[:sl_credentials])
67
+ }
68
+ [
69
+ "Health_Check_Type",
70
+ "Routing_Method",
71
+ "Routing_Type",
72
+ "Service",
73
+ "Service_Group",
74
+ "VirtualIpAddress",
75
+ "VirtualServer"
76
+ ].each do |service|
77
+ @services[service] = ::SoftLayer::Service.new(
78
+ "SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_#{service}",
79
+ @env[:sl_credentials]
80
+ )
81
+ end
82
+
83
+ # We create enumerations for the various configurables.
84
+ @enums = {}
85
+ [
86
+ "Health_Check_Type",
87
+ "Routing_Method",
88
+ "Routing_Type"
89
+ ].each do |service|
90
+ {}.tap do |enum|
91
+ sl_warden { @services[service].getAllObjects }.each do |record|
92
+ enum[record["name"].upcase] = record["id"]
93
+ end
94
+ @enums[service] = enum
95
+ end
96
+ end
97
+
98
+ read_load_balancers
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -1,73 +1,75 @@
1
- module VagrantPlugins
2
- module SoftLayer
3
- module Util
4
- module Network
5
- # Gets hostname of the instance starting from the environment.
6
- def hostname(env)
7
- env[:machine].provider_config.hostname || env[:machine].config.vm.hostname
8
- end
9
-
10
- # Gets IP address of the instance starting from the environment.
11
- #
12
- # Returns the private IP address if the instance has been
13
- # defined as private only, the public IP address otherwise.
14
- def ip_address(env)
15
- ip_address_record(env)[:address]
16
- end
17
-
18
- # Gets IP address ID of the instance starting from the environment.
19
- #
20
- # Returns the private IP address ID if the instance has been
21
- # defined as private only, the public IP address ID otherwise.
22
- def ip_address_id(env)
23
- ip_address_record(env)[:id]
24
- end
25
-
26
- # Gets IP address record of the instance starting from the environment.
27
- #
28
- # Returns an hash with the following structure:
29
- #
30
- # :address
31
- # :id
32
- #
33
- # Returns the private IP address record if the instance has been
34
- # defined as private only, the public IP address record otherwise.
35
- def ip_address_record(env)
36
- data_type = env[:machine].provider_config.private_only ? "primaryBackendNetworkComponent" : "primaryNetworkComponent"
37
- mask = { data_type => { "primaryIpAddressRecord" => ["id", "ipAddress"] } }
38
- record = sl_warden { env[:sl_machine].object_mask(mask).getObject }
39
- return {
40
- :address => record[data_type]["primaryIpAddressRecord"]["ipAddress"],
41
- :id => record[data_type]["primaryIpAddressRecord"]["id"]
42
- }
43
- end
44
-
45
- # Returns SSH keys starting from the configuration parameter.
46
- #
47
- # In the configuration, each key could be passed either as an
48
- # id or as a label. The routine will detect this and lookup
49
- # the id if needed.
50
- #
51
- # The first parameter is the current environment.
52
- #
53
- # The second parameter is useful for returning: if it is set
54
- # the routine will return just the array of ids (this is needed,
55
- # as an example, for reloading OS), otherwise an hash is
56
- # returned (this latter case is needed instead for creating
57
- # an instance).
58
- def ssh_keys(env, ids_only = false)
59
- account = ::SoftLayer::Service.new("SoftLayer_Account", env[:sl_credentials])
60
- acc_keys = sl_warden { account.object_mask("id", "label").getSshKeys }
61
- key_ids = []
62
- Array(env[:machine].provider_config.ssh_key).each do |key|
63
- pattern = key.is_a?(String) ? "label" : "id"
64
- key_hash = acc_keys.find { |acc_key| acc_key[pattern] == key }
65
- raise Errors::SLSshKeyNotFound, :key => key unless key_hash
66
- key_ids << key_hash["id"]
67
- end
68
- return (ids_only ? key_ids : key_ids.map { |key_id| { :id => key_id } })
69
- end
70
- end
71
- end
72
- end
73
- end
1
+ module VagrantPlugins
2
+ module SoftLayer
3
+ module Util
4
+ module Network
5
+ # Gets hostname of the instance starting from the environment.
6
+ def hostname(env)
7
+ env[:machine].provider_config.hostname || env[:machine].config.vm.hostname
8
+ end
9
+
10
+ # Gets IP address of the instance starting from the environment.
11
+ #
12
+ # Returns the private IP address if the instance has been
13
+ # defined as private only, the public IP address otherwise.
14
+ def ip_address(env)
15
+ ip_address_record(env)[:address]
16
+ end
17
+
18
+ # Gets IP address ID of the instance starting from the environment.
19
+ #
20
+ # Returns the private IP address ID if the instance has been
21
+ # defined as private only, the public IP address ID otherwise.
22
+ def ip_address_id(env)
23
+ ip_address_record(env)[:id]
24
+ end
25
+
26
+ # Gets IP address record of the instance starting from the environment.
27
+ #
28
+ # Returns an hash with the following structure:
29
+ #
30
+ # :address
31
+ # :id
32
+ #
33
+ # Returns the private IP address record if the instance has been
34
+ # defined as private only, the public IP address record otherwise
35
+ # unless the force_private_ip override is true.
36
+ def ip_address_record(env)
37
+ data_type = env[:machine].provider_config.private_only ? "primaryBackendNetworkComponent" : "primaryNetworkComponent"
38
+ data_type = "primaryBackendNetworkComponent" if env[:machine].provider_config.force_private_ip
39
+ mask = { data_type => { "primaryIpAddressRecord" => ["id", "ipAddress"] } }
40
+ record = sl_warden { env[:sl_machine].object_mask(mask).getObject }
41
+ return {
42
+ :address => record[data_type]["primaryIpAddressRecord"]["ipAddress"],
43
+ :id => record[data_type]["primaryIpAddressRecord"]["id"]
44
+ }
45
+ end
46
+
47
+ # Returns SSH keys starting from the configuration parameter.
48
+ #
49
+ # In the configuration, each key could be passed either as an
50
+ # id or as a label. The routine will detect this and lookup
51
+ # the id if needed.
52
+ #
53
+ # The first parameter is the current environment.
54
+ #
55
+ # The second parameter is useful for returning: if it is set
56
+ # the routine will return just the array of ids (this is needed,
57
+ # as an example, for reloading OS), otherwise an hash is
58
+ # returned (this latter case is needed instead for creating
59
+ # an instance).
60
+ def ssh_keys(env, ids_only = false)
61
+ account = ::SoftLayer::Service.new("SoftLayer_Account", env[:sl_credentials])
62
+ acc_keys = sl_warden { account.object_mask("id", "label").getSshKeys }
63
+ key_ids = []
64
+ Array(env[:machine].provider_config.ssh_key).each do |key|
65
+ pattern = key.is_a?(String) ? "label" : "id"
66
+ key_hash = acc_keys.find { |acc_key| acc_key[pattern] == key }
67
+ raise Errors::SLSshKeyNotFound, :key => key unless key_hash
68
+ key_ids << key_hash["id"]
69
+ end
70
+ return (ids_only ? key_ids : key_ids.map { |key_id| { :id => key_id } })
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end