Module: Ey::Core::TestHelpers::ResourceHelpers
- Included in:
- Ey::Core::TestHelpers
- Defined in:
- lib/ey-core/test_helpers/resource_helpers.rb
Instance Method Summary collapse
- #create_account_referral(client, options = {}) ⇒ Object
- #create_application(options = {}) ⇒ Object
- #create_cost(client, options = {}) ⇒ Object
- #create_database_service(options = {}) ⇒ Object
- #create_environment(options = {}) ⇒ Object
- #create_firewall(client, options = {}) ⇒ Object
- #create_logical_database(options = {}) ⇒ Object
- #create_provider_location(client, attributes = {}) ⇒ Object
- #create_server(client, options = {}) ⇒ Object
- #create_server_event(client, attributes = {}) ⇒ Object
- #create_untracked_server(options = {}) ⇒ Object
- #load_blueprint(options = {}) ⇒ Object
Instance Method Details
#create_account_referral(client, options = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ey-core/test_helpers/resource_helpers.rb', line 63 def create_account_referral(client, ={}) referred = .delete(:referred) || create_account(client: client) referrer = .delete(:referrer) || create_account(client: client) account_referral_id = SecureRandom.uuid referral = client.data[:account_referrals][account_referral_id] = { "id" => account_referral_id, "referrer" => client.url_for("accounts/#{referrer.identity}"), "referred" => client.url_for("accounts/#{referred.identity}"), } client.account_referrals.new(referral) end |
#create_application(options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ey-core/test_helpers/resource_helpers.rb', line 13 def create_application(={}) account = .delete(:account) || create_account() = Cistern::Hash.stringify_keys() ["name"] ||= "application#{SecureRandom.hex(4)}" ["repository"] ||= "git://github.com/engineyard/todo.git" ["type"] ||= "rails4" account.applications.create!() end |
#create_cost(client, options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ey-core/test_helpers/resource_helpers.rb', line 38 def create_cost(client, ={}) account = [:account] || create_account(client: client) level = [:level] || "summarized" finality = [:finality] || "estimated" = [:related_resource_type] || "account" category = [:category] || "non-server" description = [:description] || "AWS Other Services" value = [:value] || "1763" environment = [:environment] || nil client.data[:costs] << { billing_month: "2015-07", data_type: "cost", level: level, finality: finality, related_resource_type: , category: category, units: "USD cents", description: description, value: value, account: client.url_for("accounts/#{account.identity}"), environment: environment } end |
#create_database_service(options = {}) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/ey-core/test_helpers/resource_helpers.rb', line 91 def create_database_service(={}) provider = [:provider] || create_provider(.merge(client: client)) database_service_params = Hashie::Mash.new( :name => Faker::Name.first_name, :provider => provider, ).merge(.fetch(:database_service, {})) database_server_params = Hashie::Mash.new( :location => "us-west-2c", :flavor => "db.m3.large", :engine => "postgres", :version => "9.3.5", ).merge(.fetch(:database_server, {})) client.database_services.create!(database_service_params.merge(database_server: database_server_params)).resource! end |
#create_environment(options = {}) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/ey-core/test_helpers/resource_helpers.rb', line 109 def create_environment(={}) account = [:account] || create_account() unless account.providers.first || [:provider] create_provider(account: account) end environment = [:environment] || {} application = [:application] || create_application(account: account) database_service = [:database_service] configuration = Cistern::Hash.stringify_keys([:configuration] || {}) configuration["type"] = "production-cluster" if configuration["type"] == "production" configuration["type"] ||= "solo" environment[:name] ||= .fetch(:name, SecureRandom.hex(3)) environment[:region] ||= "us-west-2" environment.merge!(application_id: application.id, account: account) environment.merge!(database_service: database_service) if database_service environment = client.environments.create!(environment) unless [:boot] == false request = environment.boot(configuration: configuration, application_id: application.id) request.ready! end environment end |
#create_firewall(client, options = {}) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ey-core/test_helpers/resource_helpers.rb', line 77 def create_firewall(client, ={}) provider = .fetch(:provider) { create_provider(client: client) } firewall_params = [:firewall] || {} name = firewall_params.delete(:name) || SecureRandom.hex(6) location = firewall_params.delete(:location) || "us-west-2" client.firewalls.create!( :name => name, :location => location, :provider => provider, ).resource! end |
#create_logical_database(options = {}) ⇒ Object
165 166 167 168 169 170 171 172 173 |
# File 'lib/ey-core/test_helpers/resource_helpers.rb', line 165 def create_logical_database(={}) database_service = .fetch(:database_service) { create_database_service() } database_service.databases.create!( :name => SecureRandom.hex(6), :username => "ey#{SecureRandom.hex(6)}", :password => SecureRandom.hex(8), ).resource! end |
#create_provider_location(client, attributes = {}) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/ey-core/test_helpers/resource_helpers.rb', line 136 def create_provider_location(client, attributes={}) attributes = Cistern::Hash.stringify_keys(attributes) if provider = attributes.delete("provider") attributes["provider"] = client.url_for("/providers/#{provider.id}") end attributes["id"] ||= client.uuid client.data[:provider_locations][attributes["id"]] = attributes client.provider_locations.new(attributes) end |
#create_server(client, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ey-core/test_helpers/resource_helpers.rb', line 24 def create_server(client, ={}) = Cistern::Hash.stringify_keys() environment = ["environment"] request = client.servers.create!({ :environment => environment, :flavor_id => 'm3.medium', :role => 'util', :name => 'resque', }.merge(["server"] || {})) request.resource! end |
#create_server_event(client, attributes = {}) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/ey-core/test_helpers/resource_helpers.rb', line 149 def create_server_event(client, attributes={}) attributes = Cistern::Hash.stringify_keys(attributes) attributes.fetch("type") if server = attributes.delete("server") attributes["server"] = client.url_for("/servers/#{server.id}") end event_id = attributes["id"] ||= SecureRandom.uuid client.server_events.new( client.data[:server_events][event_id] = attributes ) end |
#create_untracked_server(options = {}) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/ey-core/test_helpers/resource_helpers.rb', line 175 def create_untracked_server(={}) provider = .fetch(:provider) { create_provider() } untracked_server = [:untracked_server] || {} provisioner_id = untracked_server[:provisioner_id] || SecureRandom.uuid location = untracked_server[:location] || "us-west-2b" provisioned_id = untracked_server[:provisioned_id] || "i-#{SecureRandom.hex(4)}" state = untracked_server[:state] || "found" client.untracked_servers.create( :location => location, :provider => provider, :provisioned_id => provisioned_id, :provisioner_id => provisioner_id, :state => state, ) end |
#load_blueprint(options = {}) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/ey-core/test_helpers/resource_helpers.rb', line 5 def load_blueprint(={}) application = create_application(account: account) database_service = create_database_service(provider: account.providers.first) environment = create_environment(account: account, application: application, database_service: database_service, environment: {name: "environment#{SecureRandom.hex(4)}"}) [database_service, environment] end |