Class: Fog::AWS::ElasticBeanstalk::Environment

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/aws/models/beanstalk/environment.rb

Instance Method Summary collapse

Instance Method Details

#destroyObject



115
116
117
118
119
# File 'lib/fog/aws/models/beanstalk/environment.rb', line 115

def destroy
  requires :id
  service.terminate_environment({'EnvironmentId' => id})
  true
end

#eventsObject

Return events related to this version



57
58
59
60
# File 'lib/fog/aws/models/beanstalk/environment.rb', line 57

def events
  requires :id
  service.events.all({'EnvironmentId' => id})
end

#healthy?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/fog/aws/models/beanstalk/environment.rb', line 27

def healthy?
  health == 'Green'
end

#live_resourcesObject

Returns the current live resources for this environment



40
41
42
43
44
45
# File 'lib/fog/aws/models/beanstalk/environment.rb', line 40

def live_resources
  requires :id
  data = service.describe_environment_resources({'EnvironmentId' => id}).body['DescribeEnvironmentResourcesResult']['EnvironmentResources']
  data.delete('EnvironmentName') # Delete the environment name from the result, only return actual resources
  data
end

#load_balancer(elb_connection = Fog::AWS[:elb]) ⇒ Object

Returns the load balancer object associated with the environment.



48
49
50
51
52
53
54
# File 'lib/fog/aws/models/beanstalk/environment.rb', line 48

def load_balancer(elb_connection = Fog::AWS[:elb])
  if resources.nil?
    elb_connection.load_balancers.get(live_resources['LoadBalancers'].first['Name'])
  else
    elb_connection.load_balancers.get(resources['LoadBalancer']['LoadBalancerName'])
  end
end

#ready?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/fog/aws/models/beanstalk/environment.rb', line 31

def ready?
  status == 'Ready'
end

#rebuildObject

Rebuilds the environment



70
71
72
73
74
# File 'lib/fog/aws/models/beanstalk/environment.rb', line 70

def rebuild
  requires :id
  service.rebuild_environment({'EnvironmentId' => id})
  reload
end

#restart_app_serverObject

Restarts the app servers in this environment



63
64
65
66
67
# File 'lib/fog/aws/models/beanstalk/environment.rb', line 63

def restart_app_server
  requires :id
  service.restart_app_server({'EnvironmentId' => id})
  reload
end

#saveObject



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/fog/aws/models/beanstalk/environment.rb', line 121

def save
  requires :name, :application_name
  requires_one :template_name, :solution_stack_name

  options = {
      'ApplicationName' => application_name,
      'CNAMEPrefix' => cname_prefix,
      'Description' => description,
      'EnvironmentName' => name,
      'OptionSettings' => option_settings,
      'OptionsToRemove' => options_to_remove,
      'SolutionStackName' => solution_stack_name,
      'TemplateName' => template_name,
      'VersionLabel' => version_label
  }
  options.delete_if {|key, value| value.nil?}

  data = service.create_environment(options).body['CreateEnvironmentResult']
  merge_attributes(data)
  true
end

#swap_cnames(source) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/fog/aws/models/beanstalk/environment.rb', line 76

def swap_cnames(source)
  requires :name
  service.swap_environment_cnames({
      'SourceEnvironmentName' => source.name,
      'DestinationEnvironmentName' => name
                                     })
  source.reload
  reload
end

#terminated?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/fog/aws/models/beanstalk/environment.rb', line 35

def terminated?
  status == 'Terminated'
end

#versionObject

Return the version object for this environment



87
88
89
90
# File 'lib/fog/aws/models/beanstalk/environment.rb', line 87

def version
  requires :application_name, :version_label
  service.versions.get(application_name, version_label)
end

#version=(new_version) ⇒ Object

Update the running version of this environment



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/fog/aws/models/beanstalk/environment.rb', line 93

def version=(new_version)
  requires :id
  if new_version.is_a?(String)
    new_version_label = new_version
  elsif new_version.is_a?(Fog::AWS::ElasticBeanstalk::Version)
    new_version_label = new_version.label
  else
    raise "Unknown type for new_version, must be either String or Fog::AWS::ElasticBeanstalk::Version"
  end

  if new_version.nil?
    raise "Version label not specified."
  end

  data = service.update_environment({
      'EnvironmentId' => id,
      'VersionLabel' => new_version_label
                                }).body['UpdateEnvironmentResult']

  merge_attributes(data)
end