Class: Ey::Core::Client::Environment

Inherits:
Model
  • Object
show all
Extended by:
Associations
Defined in:
lib/ey-core/models/environment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Associations

assoc_accessor, assoc_coverage, assoc_reader, assoc_writer, associations, collection_reader

Methods inherited from Model

#destroy, range_parser, #save, #to_s, #update!, #url

Instance Attribute Details

#application_idObject

Returns the value of attribute application_id.



38
39
40
# File 'lib/ey-core/models/environment.rb', line 38

def application_id
  @application_id
end

Instance Method Details

#applicationObject



80
81
82
83
84
# File 'lib/ey-core/models/environment.rb', line 80

def application
  if self.application_id
    connection.applications.get(self.application_id)
  end
end

#apply(type = "main", data = {}) ⇒ Object



68
69
70
# File 'lib/ey-core/models/environment.rb', line 68

def apply(type="main", data={})
  connection.requests.new(self.connection.apply_environment_updates("id" => self.id, "type" => type, "data" => data).body["request"])
end

#blueprintsObject



86
87
88
89
# File 'lib/ey-core/models/environment.rb', line 86

def blueprints
  requires :id
  self.connection.blueprints.all(environment: self.identity)
end

#boot(options = {}) ⇒ Object



131
132
133
134
# File 'lib/ey-core/models/environment.rb', line 131

def boot(options={})
  options = Cistern::Hash.stringify_keys(options)
  connection.requests.new(self.connection.boot_environment(boot_params(options)).body["request"])
end

#deploy(application, opts = {}) ⇒ Object

Parameters:

Options Hash (opts):



47
48
49
50
51
# File 'lib/ey-core/models/environment.rb', line 47

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

#deprovisionObject



72
73
74
# File 'lib/ey-core/models/environment.rb', line 72

def deprovision
  connection.requests.new(self.connection.deprovision_environment("id" => self.id).body["request"])
end

#destroy!Object



76
77
78
# File 'lib/ey-core/models/environment.rb', line 76

def destroy!
  connection.requests.new(self.connection.destroy_environment("id" => self.id).body["request"])
end

#download_recipesObject



125
126
127
128
129
# File 'lib/ey-core/models/environment.rb', line 125

def download_recipes
  tempfile = Tempfile.new("cookbooks-#{self.name}.tar.gz")
  File.open(tempfile, 'wb') { |f| f.write self.connection.request(url: self.custom_recipes).body }
  tempfile
end

#latest_deploy(app) ⇒ Object



40
41
42
43
# File 'lib/ey-core/models/environment.rb', line 40

def latest_deploy(app)
  deployments = connection.deployments.all(environment_id: self.id, application_id: app.id)
  deployments.first
end

#maintenance(application, action) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/ey-core/models/environment.rb', line 102

def maintenance(application, action)
  requires :identity

  params = {
    "id"             => self.identity,
    "application_id" => application.id,
    "maintenance"    => {
      "action" => action
    }
  }

  self.connection.requests.new(self.connection.change_environment_maintenance(params).body["request"])
end

#restart_app_serversObject



116
117
118
119
120
121
122
123
# File 'lib/ey-core/models/environment.rb', line 116

def restart_app_servers
  params = {
    "id"             => self.identity,
    "application_id" => self.applications.first.id,
  }

  self.connection.requests.new(self.connection.restart_environment_app_servers(params).body["request"])
end

#run_action(application, action, task = {}) ⇒ Object

Parameters:



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ey-core/models/environment.rb', line 56

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



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/ey-core/models/environment.rb', line 141

def save!
  if new_record?
    requires :application_id, :account_id, :region

    params = {
      "url"         => self.collection.url,
      "account"     => self.,
      "environment" => {
        "name"                         => self.name,
        "application_id"               => self.application_id,
        "region"                       => self.region,
        "stack_name"                   => self.stack_name,
        "database_stack"               => self.database_stack,
        "release_label"                => self.release_label,
        "language"                     => self.language,
        "database_backup_limit"        => self.database_backup_limit,
        "encrypted_ebs_for_everything" => self.encrypted_ebs_for_everything,
      },
    }

    params["environment"].merge!("database_service" => self.database_service.id) if self.database_service

    merge_attributes(self.connection.create_environment(params).body["environment"])
  else
    requires :identity
    attributes = Cistern::Hash.slice(Cistern::Hash.stringify_keys(self.attributes), "nane", "release_label")
    connection.update_environment(
      "id"     => self.identity,
      "environment" => attributes,
    )
  end
end

#save_blueprint(options = {}) ⇒ Object



91
92
93
94
95
# File 'lib/ey-core/models/environment.rb', line 91

def save_blueprint(options={})
  requires :id
  raise "name is a required key" unless options["name"]
  self.connection.blueprints.new(self.connection.blueprint_environment("id" => self.id, "name" => options["name"]).body["blueprint"])
end

#unassign!Object



136
137
138
139
# File 'lib/ey-core/models/environment.rb', line 136

def unassign!
  requires :id
  merge_attributes(self.connection.unassign_environment("id" => self.id).body["environment"])
end

#upload_recipes(file) ⇒ Object



97
98
99
100
# File 'lib/ey-core/models/environment.rb', line 97

def upload_recipes(file)
  # file should be a StringIO
  self.connection.upload_recipes_for_environment("file" => file, "id" => self.identity)
end