Class: VagrantPlugins::SoftLayer::Config
- Inherits:
-
Object
- Object
- VagrantPlugins::SoftLayer::Config
- Defined in:
- lib/vagrant-softlayer/config.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
The API key to access SoftLayer.
-
#datacenter ⇒ Object
The datacenter shortname.
-
#dedicated ⇒ Object
Whether to allocate a dedicated instance.
-
#disk_capacity ⇒ Object
The disk image capacity.
-
#domain ⇒ Object
The domain of the instance.
-
#endpoint_url ⇒ Object
The endpoint SoftLayer API url.
-
#hostname ⇒ Object
The hostname of the instance.
-
#hourly_billing ⇒ Object
The billing type of the instance (true for hourly, false for monthly).
-
#image_guid ⇒ Object
The global identifier of the compute or flex image to use.
-
#load_balancers ⇒ Object
readonly
The load balancers service groups to join.
-
#local_disk ⇒ Object
The disk type of the instance (true for local, false for SAN).
-
#manage_dns ⇒ Object
Automatically update DNS on create and destroy.
-
#max_memory ⇒ Object
The amount of RAM of the instance.
-
#network_speed ⇒ Object
Network port speed in Mbps.
-
#operating_system ⇒ Object
The instance operating system identifier.
-
#post_install ⇒ Object
URI of post-install script to download.
-
#private_only ⇒ Object
Whether or not the instance only has access to the private network.
-
#ssh_key ⇒ Object
The id or name of the ssh key to be provisioned.
-
#start_cpus ⇒ Object
The number of processors of the instance.
-
#user_data ⇒ Object
User defined metadata string.
-
#username ⇒ Object
The username to access SoftLayer.
-
#vlan_private ⇒ Object
The ID of the private VLAN.
-
#vlan_public ⇒ Object
The ID of the public VLAN.
Instance Method Summary collapse
- #finalize! ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#join_load_balancer(opts = {}) {|| ... } ⇒ Object
Set the load balancer service group to join.
-
#ssh_keys=(value) ⇒ Object
(also: #ssh_key_id=, #ssh_key_ids=, #ssh_key_name=, #ssh_key_names=)
Aliases for ssh_key for beautiful semantic.
- #validate(machine) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/vagrant-softlayer/config.rb', line 75 def initialize @api_key = UNSET_VALUE @endpoint_url = UNSET_VALUE @username = UNSET_VALUE @datacenter = UNSET_VALUE @dedicated = UNSET_VALUE @disk_capacity = UNSET_VALUE @domain = UNSET_VALUE @hostname = UNSET_VALUE @image_guid = UNSET_VALUE @hourly_billing = UNSET_VALUE @local_disk = UNSET_VALUE @max_memory = UNSET_VALUE @network_speed = UNSET_VALUE @operating_system = UNSET_VALUE @post_install = UNSET_VALUE @private_only = UNSET_VALUE @ssh_key = UNSET_VALUE @start_cpus = UNSET_VALUE @user_data = UNSET_VALUE @vlan_private = UNSET_VALUE @vlan_public = UNSET_VALUE @load_balancers = [] @manage_dns = UNSET_VALUE end |
Instance Attribute Details
#api_key ⇒ Object
The API key to access SoftLayer.
7 8 9 |
# File 'lib/vagrant-softlayer/config.rb', line 7 def api_key @api_key end |
#datacenter ⇒ Object
The datacenter shortname.
16 17 18 |
# File 'lib/vagrant-softlayer/config.rb', line 16 def datacenter @datacenter end |
#dedicated ⇒ Object
Whether to allocate a dedicated instance.
19 20 21 |
# File 'lib/vagrant-softlayer/config.rb', line 19 def dedicated @dedicated end |
#disk_capacity ⇒ Object
The disk image capacity
22 23 24 |
# File 'lib/vagrant-softlayer/config.rb', line 22 def disk_capacity @disk_capacity end |
#domain ⇒ Object
The domain of the instance.
25 26 27 |
# File 'lib/vagrant-softlayer/config.rb', line 25 def domain @domain end |
#endpoint_url ⇒ Object
The endpoint SoftLayer API url.
10 11 12 |
# File 'lib/vagrant-softlayer/config.rb', line 10 def endpoint_url @endpoint_url end |
#hostname ⇒ Object
The hostname of the instance.
28 29 30 |
# File 'lib/vagrant-softlayer/config.rb', line 28 def hostname @hostname end |
#hourly_billing ⇒ Object
The billing type of the instance (true for hourly, false for monthly).
31 32 33 |
# File 'lib/vagrant-softlayer/config.rb', line 31 def hourly_billing @hourly_billing end |
#image_guid ⇒ Object
The global identifier of the compute or flex image to use.
34 35 36 |
# File 'lib/vagrant-softlayer/config.rb', line 34 def image_guid @image_guid end |
#load_balancers ⇒ Object (readonly)
The load balancers service groups to join.
70 71 72 |
# File 'lib/vagrant-softlayer/config.rb', line 70 def load_balancers @load_balancers end |
#local_disk ⇒ Object
The disk type of the instance (true for local, false for SAN).
37 38 39 |
# File 'lib/vagrant-softlayer/config.rb', line 37 def local_disk @local_disk end |
#manage_dns ⇒ Object
Automatically update DNS on create and destroy.
73 74 75 |
# File 'lib/vagrant-softlayer/config.rb', line 73 def manage_dns @manage_dns end |
#max_memory ⇒ Object
The amount of RAM of the instance.
40 41 42 |
# File 'lib/vagrant-softlayer/config.rb', line 40 def max_memory @max_memory end |
#network_speed ⇒ Object
Network port speed in Mbps.
43 44 45 |
# File 'lib/vagrant-softlayer/config.rb', line 43 def network_speed @network_speed end |
#operating_system ⇒ Object
The instance operating system identifier.
46 47 48 |
# File 'lib/vagrant-softlayer/config.rb', line 46 def @operating_system end |
#post_install ⇒ Object
URI of post-install script to download.
49 50 51 |
# File 'lib/vagrant-softlayer/config.rb', line 49 def post_install @post_install end |
#private_only ⇒ Object
Whether or not the instance only has access to the private network.
52 53 54 |
# File 'lib/vagrant-softlayer/config.rb', line 52 def private_only @private_only end |
#ssh_key ⇒ Object
The id or name of the ssh key to be provisioned.
55 56 57 |
# File 'lib/vagrant-softlayer/config.rb', line 55 def ssh_key @ssh_key end |
#start_cpus ⇒ Object
The number of processors of the instance.
58 59 60 |
# File 'lib/vagrant-softlayer/config.rb', line 58 def start_cpus @start_cpus end |
#user_data ⇒ Object
User defined metadata string.
61 62 63 |
# File 'lib/vagrant-softlayer/config.rb', line 61 def user_data @user_data end |
#username ⇒ Object
The username to access SoftLayer.
13 14 15 |
# File 'lib/vagrant-softlayer/config.rb', line 13 def username @username end |
#vlan_private ⇒ Object
The ID of the private VLAN.
64 65 66 |
# File 'lib/vagrant-softlayer/config.rb', line 64 def vlan_private @vlan_private end |
#vlan_public ⇒ Object
The ID of the public VLAN.
67 68 69 |
# File 'lib/vagrant-softlayer/config.rb', line 67 def vlan_public @vlan_public end |
Instance Method Details
#finalize! ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/vagrant-softlayer/config.rb', line 136 def finalize! # Try to get username and api key from environment variables. # They will default to nil if the environment variables are not present. @api_key = ENV["SL_API_KEY"] if @api_key == UNSET_VALUE @username = ENV["SL_USERNAME"] if @username == UNSET_VALUE # Endpoint url defaults to public SoftLayer API url. @endpoint_url = API_PUBLIC_ENDPOINT if @endpoint_url == UNSET_VALUE # No default datacenter. @datacenter = nil if @datacenter == UNSET_VALUE # Shared instance by default. @dedicated = false if @dedicated == UNSET_VALUE # 25GB disk capacity image by default. @disk_capacity = nil if @disk_capacity == UNSET_VALUE # Domain should be specified in Vagrantfile, so we set default to nil. @domain = nil if @domain == UNSET_VALUE # Hostname should be specified in Vagrantfile, either using `config.vm.hostname` # or the provider specific configuration entry. @hostname = nil if @hostname == UNSET_VALUE # Bill hourly by default. @hourly_billing = true if @hourly_billing == UNSET_VALUE # Disable the use of a specific block device image so we can leave the OS template as default @image_guid = nil if @image_guid == UNSET_VALUE # Use local disk by default. @local_disk = true if @local_disk == UNSET_VALUE # 1Gb of RAM by default. @max_memory = 1024 if @max_memory == UNSET_VALUE # 10Mbps by default. @network_speed = 10 if @network_speed == UNSET_VALUE # Provision with the latest Ubuntu by default. @operating_system = "UBUNTU_LATEST" if @operating_system == UNSET_VALUE # No post install script by default. @post_install = nil if @post_install == UNSET_VALUE # Private-network only is false by default. @private_only = false if @private_only == UNSET_VALUE # SSH key should be specified in Vagrantfile, so we set default to nil. @ssh_key = nil if @ssh_key == UNSET_VALUE # One processor by default. @start_cpus = 1 if @start_cpus == UNSET_VALUE # No user metadata by default. @user_data = nil if @user_data == UNSET_VALUE # No specific private VLAN by default. @vlan_private = nil if @vlan_private == UNSET_VALUE # No specific public VLAN by default. @vlan_public = nil if @vlan_public == UNSET_VALUE # DNS management off by default @manage_dns = false if @manage_dns == UNSET_VALUE end |
#join_load_balancer(opts = {}) {|| ... } ⇒ Object
Set the load balancer service group to join.
Available options:
:method => Routing method. Default to round robin. :port => Load balancer virtual port. :type => Routing type. Default to TCP. :vip => Load balancer virtual IP address.
An optional block will accept parameters for the balanced service. Available parameters:
:destination_port => TCP port on the node. :health_check => Service health check. Default to ping. :weight => Service weight. Default to 1.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/vagrant-softlayer/config.rb', line 119 def join_load_balancer(opts = {}, &block) # Defaults opts[:method] ||= "ROUND ROBIN" opts[:type] ||= "TCP" opts[:service] = OpenStruct.new(:destination_port => nil, :health_check => "PING", :weight => 1) yield opts[:service] if block_given? # Convert all options that belongs to # an enumeration in uppercase. opts[:method].upcase! opts[:type].upcase! opts[:service].health_check.upcase! @load_balancers << opts end |
#ssh_keys=(value) ⇒ Object Also known as: ssh_key_id=, ssh_key_ids=, ssh_key_name=, ssh_key_names=
Aliases for ssh_key for beautiful semantic.
205 206 207 |
# File 'lib/vagrant-softlayer/config.rb', line 205 def ssh_keys=(value) @ssh_key = value end |
#validate(machine) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/vagrant-softlayer/config.rb', line 213 def validate(machine) errors = [] errors << I18n.t("vagrant_softlayer.config.api_key_required") if !@api_key errors << I18n.t("vagrant_softlayer.config.username_required") if !@username errors << I18n.t("vagrant_softlayer.config.domain_required") if !@domain errors << I18n.t("vagrant_softlayer.config.ssh_key_required") if !@ssh_key errors << I18n.t("vagrant_softlayer.config.img_guid_os_code_mutually_exclusive") if @image_guid && @operating_system errors << I18n.t("vagrant_softlayer.config.img_guid_capacity_mutually_exclusive") if @image_guid && @disk_capacity # Fail if both `vm.hostname` and `provider.hostname` are nil. if !@hostname && !machine.config.vm.hostname errors << I18n.t("vagrant_softlayer.config.hostname_required") end # Fail if a load balancer has been specified without vip, port or destination port. unless @load_balancers.empty? @load_balancers.each do |lb| errors << I18n.t("vagrant_softlayer.config.lb_port_vip_required") unless (lb[:vip] && lb[:port] && lb[:service].destination_port) end end # Fail if two or more load balancers has been specified with same vip and port. if @load_balancers.map { |lb| { :port => lb[:port], :vip => lb[:vip] } }.uniq! errors << I18n.t("vagrant_softlayer.config.lb_duplicate") end { "SoftLayer" => errors } end |