Class: Ey::Core::Client::Environment
- Inherits:
-
Model
- Object
- Cistern::Model
- Model
- Ey::Core::Client::Environment
show all
- Extended by:
- Associations
- Defined in:
- lib/ey-core/models/environment.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
assoc_accessor, assoc_coverage, assoc_reader, assoc_writer, associations, collection_reader
Methods inherited from Model
#destroy, range_parser, #save, #update!, #url
Instance Attribute Details
#application_id ⇒ Object
Returns the value of attribute application_id.
23
24
25
|
# File 'lib/ey-core/models/environment.rb', line 23
def application_id
@application_id
end
|
Instance Method Details
#application ⇒ Object
56
57
58
59
60
|
# File 'lib/ey-core/models/environment.rb', line 56
def application
if self.application_id
connection.applications.get(self.application_id)
end
end
|
#boot(options = {}) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/ey-core/models/environment.rb', line 62
def boot(options={})
options = Cistern::Hash.stringify_keys(options)
raise "configuration is a required key" unless options["configuration"]
raise "configuration['type'] is required" unless options["configuration"]["type"]
missing_keys = []
configuration = options["configuration"]
required_keys = %w(flavor volume_size mnt_volume_size)
if self.database_service
raise "application_id is a required key" unless options["application_id"]
configuration["logical_database"] = "#{self.name}_#{self.application.name}"
end
if configuration["type"] == 'custom'
apps = configuration["apps"] ||= {}
db_master = configuration["db_master"] ||= {}
db_slaves = configuration["db_slaves"] ||= []
utils = configuration["utils"] ||= []
missing_keys << "apps" unless apps.any?
(required_keys + ["count"]).each do |required|
missing_keys << "apps[#{required}]" unless apps[required]
end
unless configuration["database_service_id"]
missing_keys << "db_master" unless db_master.any?
required_keys.each do |key|
missing_keys << "db_master[#{key}]" unless db_master[key]
end
end
db_slaves.each_with_index do |slave, i|
(required_keys - ["volume_size", "mnt_volume_size"]).each do |key|
missing_keys << "db_slaves[#{i}][#{key}]" unless slave[key]
end
end
utils.each_with_index do |util, i|
required_keys.each do |key|
missing_keys << "utils[#{i}][#{key}]" unless util[key]
end
end
end
if missing_keys.any?
raise "Invalid configuration - The following keys are missing from the configuration:\n#{missing_keys.join(",\n")}"
end
params = {
"cluster_configuration" => {
"configuration" => configuration
}
}
connection.requests.new(self.connection.boot_environment(params.merge("id" => self.id)).body["request"])
end
|
#deploy(application, opts = {}) ⇒ Object
27
28
29
30
31
|
# File 'lib/ey-core/models/environment.rb', line 27
def deploy(application, opts={})
raise "Environment does not contain an app deployment for this application" unless self.applications.get(application.id)
raise ":ref is a required key" unless opts[:ref]
connection.requests.new(connection.deploy_environment_application({"deploy" => opts}.merge("id" => self.id, "application_id" => application.id)).body["request"])
end
|
#deprovision ⇒ Object
48
49
50
|
# File 'lib/ey-core/models/environment.rb', line 48
def deprovision
connection.requests.new(self.connection.deprovision_environment("id" => self.id).body["request"])
end
|
#destroy! ⇒ Object
52
53
54
|
# File 'lib/ey-core/models/environment.rb', line 52
def destroy!
connection.requests.new(self.connection.destroy_environment("id" => self.id).body["request"])
end
|
#run_action(application, action, task = {}) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/ey-core/models/environment.rb', line 36
def run_action(application, action, task={})
requires :id
response = self.connection.run_environment_application_action(
"environment" => self.id,
"application" => application.id,
"task" => task,
"action" => action,
)
connection.requests.new(response.body["request"])
end
|
#save! ⇒ Object
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/ey-core/models/environment.rb', line 123
def save!
requires :application_id, :account_id, :region
params = {
"url" => self.collection.url,
"account" => self.account_id,
"environment" => {
"name" => self.name,
"application_id" => self.application_id,
"region" => self.region,
},
}
params["environment"].merge!("database_service" => self.database_service.id) if self.database_service
if new_record?
merge_attributes(self.connection.create_environment(params).body["environment"])
else raise NotImplementedError end
end
|