Module: Inception::CliHelpers::PrepareDeploySettings

Included in:
Inception::Cli
Defined in:
lib/inception/cli_helpers/prepare_deploy_settings.rb

Instance Method Summary collapse

Instance Method Details

#default_key_pair_nameObject



33
34
35
# File 'lib/inception/cli_helpers/prepare_deploy_settings.rb', line 33

def default_key_pair_name
  default_server_name
end

#default_server_nameObject



29
30
31
# File 'lib/inception/cli_helpers/prepare_deploy_settings.rb', line 29

def default_server_name
  "inception"
end

#private_key_path_for_inceptionObject



47
48
49
# File 'lib/inception/cli_helpers/prepare_deploy_settings.rb', line 47

def private_key_path_for_inception
  @private_key_path_for_inception ||= File.join(settings_dir, "ssh", settings.inception.key_pair.name)
end

#provision_or_reuse_public_ip_address_for_inceptionObject

Attempt to provision a new public IP; if none available, then look for a pre-provisioned public IP that’s not assigned to a server; else error. The user needs to go get more public IP addresses in this region.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/inception/cli_helpers/prepare_deploy_settings.rb', line 17

def provision_or_reuse_public_ip_address_for_inception
  say "Acquiring a public IP address... "
  if public_ip = provider_client.provision_or_reuse_public_ip_address
    say public_ip, :green
    settings.set("inception.provisioned.ip_address", public_ip)
    save_settings!
  else
    say "none available.", :red
    error "Please rustle up at least one public IP address and try again."
  end
end

#recreate_key_pair_for_inceptionObject



37
38
39
40
41
42
43
44
45
# File 'lib/inception/cli_helpers/prepare_deploy_settings.rb', line 37

def recreate_key_pair_for_inception
  key_pair_name = settings.set_default("inception.key_pair.name", default_key_pair_name)
  provider_client.delete_key_pair_if_exists(key_pair_name)
  key_pair = provider_client.create_key_pair(key_pair_name)
  settings.set("inception.key_pair.private_key", key_pair.private_key)
  settings.set("inception.key_pair.public_key", key_pair.public_key) # might be provided
  settings.set("inception.key_pair.fingerprint", key_pair.fingerprint)
  save_settings!
end

#recreate_private_key_file_for_inceptionObject

The keys for the inception server originate from the provider and are cached in the manifest. The private key is stored locally; the public key is placed on the inception server.



54
55
56
57
58
59
# File 'lib/inception/cli_helpers/prepare_deploy_settings.rb', line 54

def recreate_private_key_file_for_inception
  mkdir_p(File.dirname(private_key_path_for_inception))
  File.chmod(0700, File.dirname(private_key_path_for_inception))
  File.open(private_key_path_for_inception, "w") { |file| file << settings.inception.key_pair.private_key }
  File.chmod(0600, private_key_path_for_inception)
end

#update_git_configObject



3
4
5
6
7
8
9
10
11
# File 'lib/inception/cli_helpers/prepare_deploy_settings.rb', line 3

def update_git_config
  gitconfig = File.expand_path("~/.gitconfig")
  if File.exists?(gitconfig)
    say "Using your git user.name (#{`git config -f #{gitconfig} user.name`.strip})"
    settings.set("git.name", `git config -f #{gitconfig} user.name`.strip)
    settings.set("git.email", `git config -f #{gitconfig} user.email`.strip)
    save_settings!
  end
end

#validate_deploy_settingsObject

Required settings:

  • git.name

  • git.email



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/inception/cli_helpers/prepare_deploy_settings.rb', line 65

def validate_deploy_settings
  begin
    settings.git.name
    settings.git.email
  rescue ReadWriteSettings::MissingSetting => e
    error "Please setup local git user.name & user.email config; or specify git.name & git.email in settings.yml"
  end

  begin
    settings.provider.name
    settings.provider.credentials
  rescue ReadWriteSettings::MissingSetting => e
    error "Wooh there, we need provider.name & provider.credentials in settings.yml to proceed."
  end

  begin
    settings.inception.provisioned.ip_address
    settings.inception.key_pair.name
    settings.inception.key_pair.private_key
  rescue ReadWriteSettings::MissingSetting => e
    error "Wooh there, we need inception.provisioned.ip_address, inception.key_pair.name, & inception.key_pair.private_key in settings.yml to proceed."
  end
end