Class: Bosh::Agent::Infrastructure::Openstack::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh_agent/infrastructure/openstack/settings.rb

Constant Summary collapse

VIP_NETWORK_TYPE =
"vip"
DHCP_NETWORK_TYPE =
"dynamic"
MANUAL_NETWORK_TYPE =
"manual"
SUPPORTED_NETWORK_TYPES =
[
    VIP_NETWORK_TYPE, DHCP_NETWORK_TYPE, MANUAL_NETWORK_TYPE
]

Instance Method Summary collapse

Instance Method Details

#authorized_keysString

Returns the authorized keys filename for the Bosh user.

Returns:

  • (String)

    authorized keys filename



35
36
37
# File 'lib/bosh_agent/infrastructure/openstack/settings.rb', line 35

def authorized_keys
  File.join(File::SEPARATOR, "home", BOSH_APP_USER, ".ssh", "authorized_keys")
end

#get_network_settings(network_name, network_properties) ⇒ Hash

Gets the network settings for this agent.

Parameters:

  • network_name (String)

    Network name

  • network_properties (Hash)

    Network properties

Returns:

  • (Hash)

    Network settings



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/bosh_agent/infrastructure/openstack/settings.rb', line 62

def get_network_settings(network_name, network_properties)
  type = network_properties["type"] || "manual"
  unless type && SUPPORTED_NETWORK_TYPES.include?(type)
    raise Bosh::Agent::StateError, "Unsupported network type '%s', valid types are: %s" %
                                   [type, SUPPORTED_NETWORK_TYPES.join(", ")]
  end

  # Nothing to do for "vip" and "manual" networks
  return nil if [VIP_NETWORK_TYPE, MANUAL_NETWORK_TYPE].include? type

  Bosh::Agent::Util.get_network_info
end

#load_settingsHash

Loads the the settings for this agent and set ups the public OpenSSH key.

Returns:

  • (Hash)

    Agent Settings



26
27
28
29
# File 'lib/bosh_agent/infrastructure/openstack/settings.rb', line 26

def load_settings
  setup_openssh_key
  Infrastructure::Openstack::Registry.get_settings
end

#loggerLogger

Returns the logger

Returns:

  • (Logger)

    Bosh Agent logger



18
19
20
# File 'lib/bosh_agent/infrastructure/openstack/settings.rb', line 18

def logger
  Bosh::Agent::Config.logger
end

#setup_openssh_keyvoid

This method returns an undefined value.

Retrieves the public OpenSSH key and stores it at the authorized_keys file.



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/bosh_agent/infrastructure/openstack/settings.rb', line 43

def setup_openssh_key
  public_key = Infrastructure::Openstack::Registry.get_openssh_key
  return if public_key.nil? || public_key.empty?

  FileUtils.mkdir_p(File.dirname(authorized_keys))
  FileUtils.chmod(0700, File.dirname(authorized_keys))
  FileUtils.chown(Bosh::Agent::BOSH_APP_USER, Bosh::Agent::BOSH_APP_GROUP, File.dirname(authorized_keys))

  File.open(authorized_keys, "w") { |f| f.write(public_key) }
  FileUtils.chown(Bosh::Agent::BOSH_APP_USER, Bosh::Agent::BOSH_APP_GROUP, authorized_keys)
  FileUtils.chmod(0644, authorized_keys)
end