Class: EY::CloudClient::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/engineyard-cloud-client/models/environment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#accountObject

Returns the value of attribute account.



60
61
62
# File 'lib/engineyard-cloud-client/models/environment.rb', line 60

def 
  @account
end

#appsObject

Returns the value of attribute apps.



60
61
62
# File 'lib/engineyard-cloud-client/models/environment.rb', line 60

def apps
  @apps
end

Class Method Details

.all(api) ⇒ Object

Return list of all Environments linked to all current user’s accounts



15
16
17
# File 'lib/engineyard-cloud-client/models/environment.rb', line 15

def self.all(api)
  self.from_array(api, api.get("/environments", "no_instances" => "true")["environments"])
end

.create(api, attrs = {}) ⇒ Object

Usage Environment.create(api, {

app: app,                            # requires: app.id
name: 'myapp_production',
region: 'us-west-1',                 # default: us-east-1
app_server_stack_name: 'nginx_thin', # default: nginx_passenger3
framework_env: 'staging'             # default: production
cluster_configuration: {
  configuration: 'single'            # default: single, cluster, custom
}

})

NOTE: Syntax above is for Ruby 1.9. In Ruby 1.8, keys must all be strings.

TODO - allow any attribute to be sent through that the API might allow; e.g. region, ruby_version, stack_label



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/engineyard-cloud-client/models/environment.rb', line 49

def self.create(api, attrs={})
  app    = attrs.delete("app")
  cluster_configuration = attrs.delete('cluster_configuration')
  raise EY::CloudClient::AttributeRequiredError.new("app", EY::CloudClient::App) unless app
  raise EY::CloudClient::AttributeRequiredError.new("name") unless attrs["name"]

  params = {"environment" => attrs.dup}
  unpack_cluster_configuration(params, cluster_configuration)
  response = api.post("/apps/#{app.id}/environments", params)
  self.from_hash(api, response['environment'])
end

.resolve(api, constraints) ⇒ Object

Return a constrained list of environments given a set of constraints like:

  • app_name: app name full or partial match string

  • account_name: account name full or partial match string

  • environment_name: environment name full or partial match string

  • remotes: An array of git remote URIs



26
27
28
29
30
31
32
# File 'lib/engineyard-cloud-client/models/environment.rb', line 26

def self.resolve(api, constraints)
  clean_constraints = constraints.reject { |k,v| v.nil? }
  params = {'constraints' => clean_constraints}
  response = api.get("/environments/resolve", params)['resolver']
  matches = from_array(api, response['matches'])
  ResolverResult.new(api, matches, response['errors'], response['suggestions'])
end

Instance Method Details

#account_nameObject



95
96
97
# File 'lib/engineyard-cloud-client/models/environment.rb', line 95

def 
   && .name
end

#add_app_environment(app_env) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/engineyard-cloud-client/models/environment.rb', line 74

def add_app_environment(app_env)
  @app_environments ||= []
  existing_app_env = @app_environments.detect { |ae| app_env.environment == ae.environment }
  unless existing_app_env
    @app_environments << app_env
  end
  existing_app_env || app_env
end

#app_environmentsObject



83
84
85
# File 'lib/engineyard-cloud-client/models/environment.rb', line 83

def app_environments
  @app_environments ||= []
end

#attributes=(attrs) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/engineyard-cloud-client/models/environment.rb', line 62

def attributes=(attrs)
      = attrs.delete('account')
  apps_attrs       = attrs.delete('apps')
  instances_attrs  = attrs.delete('instances')

  super

        if 
  set_apps      apps_attrs      if apps_attrs
  set_instances instances_attrs if instances_attrs
end

#bridgeObject



111
112
113
# File 'lib/engineyard-cloud-client/models/environment.rb', line 111

def bridge
  @bridge ||= instances.detect { |inst| inst.bridge? }
end

#bridge!(ignore_bad_bridge = false) ⇒ Object



115
116
117
118
119
120
121
122
# File 'lib/engineyard-cloud-client/models/environment.rb', line 115

def bridge!(ignore_bad_bridge = false)
  if bridge.nil?
    raise NoBridgeError.new(name)
  elsif !ignore_bad_bridge && bridge.status != "running"
    raise BadBridgeStatusError.new(bridge.status, api.endpoint)
  end
  bridge
end

#deploy_to_instancesObject



107
108
109
# File 'lib/engineyard-cloud-client/models/environment.rb', line 107

def deploy_to_instances
  instances.select { |inst| inst.has_app_code? }
end

#download_recipesObject

See Recipes#download



140
141
142
# File 'lib/engineyard-cloud-client/models/environment.rb', line 140

def download_recipes
  recipes.download
end

#instancesObject



91
92
93
# File 'lib/engineyard-cloud-client/models/environment.rb', line 91

def instances
  @instances ||= request_instances
end

#logsObject



103
104
105
# File 'lib/engineyard-cloud-client/models/environment.rb', line 103

def logs
  Log.from_array(api, api.get("/environments/#{id}/logs")["logs"])
end

#recipesObject



130
131
132
# File 'lib/engineyard-cloud-client/models/environment.rb', line 130

def recipes
  Recipes.new(api, self)
end

#run_custom_recipesObject

See Recipes#run



135
136
137
# File 'lib/engineyard-cloud-client/models/environment.rb', line 135

def run_custom_recipes
  recipes.run
end

#shorten_name_for(app) ⇒ Object



154
155
156
# File 'lib/engineyard-cloud-client/models/environment.rb', line 154

def shorten_name_for(app)
  name.gsub(/^#{Regexp.quote(app.name)}_/, '')
end

#ssh_username=(user) ⇒ Object



99
100
101
# File 'lib/engineyard-cloud-client/models/environment.rb', line 99

def ssh_username=(user)
  self.username = user
end

#updateObject Also known as: rebuild



124
125
126
127
# File 'lib/engineyard-cloud-client/models/environment.rb', line 124

def update
  api.put("/environments/#{id}/update_instances")
  true # raises on failure
end

#upload_recipes(file_to_upload) ⇒ Object

See Recipes#upload



150
151
152
# File 'lib/engineyard-cloud-client/models/environment.rb', line 150

def upload_recipes(file_to_upload)
  recipes.upload(file_to_upload)
end

#upload_recipes_at_path(recipes_path) ⇒ Object

See Recipes#upload_path



145
146
147
# File 'lib/engineyard-cloud-client/models/environment.rb', line 145

def upload_recipes_at_path(recipes_path)
  recipes.upload_path(recipes_path)
end