Skip to content

Instantly share code, notes, and snippets.

@radamanthus
Last active August 8, 2017 06:45
Show Gist options
  • Save radamanthus/165b9396ede4df5e9c2cbef49590e574 to your computer and use it in GitHub Desktop.
Save radamanthus/165b9396ede4df5e9c2cbef49590e574 to your computer and use it in GitHub Desktop.
Engine Yard CoreAPI script to create an environment
#!/usr/bin/env ruby
# Very basic example of how to create a given environment
require 'ey-core'
require 'optparse'
require 'yaml'
APP_SERVER_COUNT = "1"
INSTANCE_SIZE = "m3_medium"
DATA_VOLUME_SIZE = 25
APP_MNT_SIZE = 18
DB_VOLUME_SIZE = 25
DB_MNT_SIZE = 17
STANDARD_CLUSTER_CONF = {
app_server_count: APP_SERVER_COUNT,
instance_size: INSTANCE_SIZE,
data_volume_size: DATA_VOLUME_SIZE,
app_mnt_size: APP_MNT_SIZE,
db_instance_size: INSTANCE_SIZE,
db_volume_size: DB_VOLUME_SIZE,
db_mnt_size: DB_MNT_SIZE,
configuration: "custom"
}
CONFIGURATION = {
framework_env: "production",
app_server_stack_name: "nginx_unicorn",
stack_label: "stable-v5-3.0",
ruby_version: "Ruby 2.3",
db_provider_name: "engine_yard",
db_stack_name: "postgres9_5",
region: "us-east-1"
}
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: create_env.rb [options]"
opts.on('-a', '--account NAME', 'Account name') { |v| options[:account_name] = v }
opts.on('-e', '--environment NAME', 'Environment name') { |v| options[:environment_name] = v }
opts.on('-c', '--configuration NAME', 'QA Configuration Name (refer to the configurations in the YT)') { |v| options[:config_name] = v }
opts.on('', '--application NAME', 'Application name') { |v| options[:application_name] = v }
end.parse!
# Token comes from '~/.eyrc'
eyrc = YAML.load_file(File.expand_path("~/.eyrc"))
client = Ey::Core::Client.new(token: eyrc['api_token'])
# Account name as shown in cloud.engineyard.com
account = client.accounts.first(name: options[:account_name])
puts "Creating environment #{options[:environment_name]} under account #{account.name}"
puts "..."
app = account.applications.first(name: options[:application_name])
config = CONFIGURATION
environment_params = {
account_id: account.id,
application_id: app.id,
name: options[:environment_name],
framework_env: config[:framework_env],
stack_name: config[:app_server_stack_name],
release_label: config[:stack_label],
language: config[:ruby_version],
database_stack: config[:db_stack_name],
region: config[:region]
}
env_provision_request = account.environments.create!(environment_params)
env = env_provision_request
puts "The request to create environment #{options[:environment_name]} was sent."
puts "To boot it, run: "
puts " ruby boot_env.rb --account=YourAccountName --environment=#{options[:environment_name]} --blueprint=YourBluePrint"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment