Module: VagrantPlugins::SoftLayer::Util::Network
- Included in:
- Action::CreateInstance, Action::JoinLoadBalancer, Action::ReadSSHInfo, Action::RebuildInstance, Action::UpdateDNS
- Defined in:
- lib/vagrant-softlayer/util/network.rb
Instance Method Summary collapse
-
#hostname(env) ⇒ Object
Gets hostname of the instance starting from the environment.
-
#ip_address(env) ⇒ Object
Gets IP address of the instance starting from the environment.
-
#ip_address_id(env) ⇒ Object
Gets IP address ID of the instance starting from the environment.
-
#ip_address_record(env) ⇒ Object
Gets IP address record of the instance starting from the environment.
-
#ssh_keys(env, ids_only = false) ⇒ Object
Returns SSH keys starting from the configuration parameter.
Instance Method Details
#hostname(env) ⇒ Object
Gets hostname of the instance starting from the environment.
6 7 8 |
# File 'lib/vagrant-softlayer/util/network.rb', line 6 def hostname(env) env[:machine].provider_config.hostname || env[:machine].config.vm.hostname end |
#ip_address(env) ⇒ Object
Gets IP address of the instance starting from the environment.
Returns the private IP address if the instance has been defined as private only, the public IP address otherwise.
14 15 16 |
# File 'lib/vagrant-softlayer/util/network.rb', line 14 def ip_address(env) ip_address_record(env)[:address] end |
#ip_address_id(env) ⇒ Object
Gets IP address ID of the instance starting from the environment.
Returns the private IP address ID if the instance has been defined as private only, the public IP address ID otherwise.
22 23 24 |
# File 'lib/vagrant-softlayer/util/network.rb', line 22 def ip_address_id(env) ip_address_record(env)[:id] end |
#ip_address_record(env) ⇒ Object
Gets IP address record of the instance starting from the environment.
Returns an hash with the following structure:
:address :id
Returns the private IP address record if the instance has been defined as private only, the public IP address record otherwise.
35 36 37 38 39 40 41 42 43 |
# File 'lib/vagrant-softlayer/util/network.rb', line 35 def ip_address_record(env) data_type = env[:machine].provider_config.private_only ? "primaryBackendNetworkComponent" : "primaryNetworkComponent" mask = { data_type => { "primaryIpAddressRecord" => ["id", "ipAddress"] } } record = sl_warden { env[:sl_machine].object_mask(mask).getObject } return { :address => record[data_type]["primaryIpAddressRecord"]["ipAddress"], :id => record[data_type]["primaryIpAddressRecord"]["id"] } end |
#ssh_keys(env, ids_only = false) ⇒ Object
Returns SSH keys starting from the configuration parameter.
In the configuration, each key could be passed either as an id or as a label. The routine will detect this and lookup the id if needed.
The first parameter is the current environment.
The second parameter is useful for returning: if it is set the routine will return just the array of ids (this is needed, as an example, for reloading OS), otherwise an hash is returned (this latter case is needed instead for creating an instance).
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/vagrant-softlayer/util/network.rb', line 58 def ssh_keys(env, ids_only = false) account = ::SoftLayer::Service.new("SoftLayer_Account", env[:sl_credentials]) acc_keys = sl_warden { account.object_mask("id", "label").getSshKeys } key_ids = [] Array(env[:machine].provider_config.ssh_key).each do |key| pattern = key.is_a?(String) ? "label" : "id" key_hash = acc_keys.find { |acc_key| acc_key[pattern] == key } raise Errors::SLSshKeyNotFound, :key => key unless key_hash key_ids << key_hash["id"] end return (ids_only ? key_ids : key_ids.map { |key_id| { :id => key_id } }) end |