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.
29
30
31
|
# File 'lib/ey-core/models/environment.rb', line 29
def application_id
@application_id
end
|
Instance Method Details
#application ⇒ Object
62
63
64
65
66
|
# File 'lib/ey-core/models/environment.rb', line 62
def application
if self.application_id
connection.applications.get(self.application_id)
end
end
|
#boot(options = {}) ⇒ Object
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
122
123
124
125
126
127
|
# File 'lib/ey-core/models/environment.rb', line 68
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
33
34
35
36
37
|
# File 'lib/ey-core/models/environment.rb', line 33
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
54
55
56
|
# File 'lib/ey-core/models/environment.rb', line 54
def deprovision
connection.requests.new(self.connection.deprovision_environment("id" => self.id).body["request"])
end
|
#destroy! ⇒ Object
58
59
60
|
# File 'lib/ey-core/models/environment.rb', line 58
def destroy!
connection.requests.new(self.connection.destroy_environment("id" => self.id).body["request"])
end
|
#run_action(application, action, task = {}) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/ey-core/models/environment.rb', line 42
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/ey-core/models/environment.rb', line 129
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
|