Class: Fog::AWS::AutoScaling::Mock

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/aws/auto_scaling.rb,
lib/fog/aws/requests/auto_scaling/delete_policy.rb,
lib/fog/aws/requests/auto_scaling/execute_policy.rb,
lib/fog/aws/requests/auto_scaling/resume_processes.rb,
lib/fog/aws/requests/auto_scaling/describe_policies.rb,
lib/fog/aws/requests/auto_scaling/suspend_processes.rb,
lib/fog/aws/requests/auto_scaling/put_scaling_policy.rb,
lib/fog/aws/requests/auto_scaling/set_instance_health.rb,
lib/fog/aws/requests/auto_scaling/set_desired_capacity.rb,
lib/fog/aws/requests/auto_scaling/delete_scheduled_action.rb,
lib/fog/aws/requests/auto_scaling/create_auto_scaling_group.rb,
lib/fog/aws/requests/auto_scaling/delete_auto_scaling_group.rb,
lib/fog/aws/requests/auto_scaling/describe_adjustment_types.rb,
lib/fog/aws/requests/auto_scaling/enable_metrics_collection.rb,
lib/fog/aws/requests/auto_scaling/update_auto_scaling_group.rb,
lib/fog/aws/requests/auto_scaling/describe_scheduled_actions.rb,
lib/fog/aws/requests/auto_scaling/disable_metrics_collection.rb,
lib/fog/aws/requests/auto_scaling/create_launch_configuration.rb,
lib/fog/aws/requests/auto_scaling/delete_launch_configuration.rb,
lib/fog/aws/requests/auto_scaling/describe_scaling_activities.rb,
lib/fog/aws/requests/auto_scaling/describe_auto_scaling_groups.rb,
lib/fog/aws/requests/auto_scaling/describe_launch_configurations.rb,
lib/fog/aws/requests/auto_scaling/describe_scaling_process_types.rb,
lib/fog/aws/requests/auto_scaling/describe_auto_scaling_instances.rb,
lib/fog/aws/requests/auto_scaling/describe_metric_collection_types.rb,
lib/fog/aws/requests/auto_scaling/put_scheduled_update_group_action.rb,
lib/fog/aws/requests/auto_scaling/terminate_instance_in_auto_scaling_group.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



188
189
190
191
192
193
194
195
196
197
198
# File 'lib/fog/aws/auto_scaling.rb', line 188

def initialize(options={})

  @aws_access_key_id = options[:aws_access_key_id]

  @region = options[:region] || 'us-east-1'

  unless ['ap-northeast-1', 'ap-southeast-1', 'eu-west-1', 'sa-east-1', 'us-east-1', 'us-west-1', 'us-west-2'].include?(@region)
    raise ArgumentError, "Unknown region: #{@region.inspect}"
  end

end

Class Method Details

.dataObject



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
173
174
175
176
177
178
179
180
181
182
# File 'lib/fog/aws/auto_scaling.rb', line 145

def self.data
  @data ||= Hash.new do |hash, region|
    owner_id = Fog::AWS::Mock.owner_id
    hash[region] = Hash.new do |region_hash, key|
      region_hash[key] = {
        :adjustment_types => [
          'ChangeInCapacity',
          'ExactCapacity',
          'PercentChangeInCapacity'
        ],
        :auto_scaling_groups => {},
        :health_states => ['Healthy', 'Unhealthy'],
        :launch_configurations => {},
        :metric_collection_types => {
          :granularities => [ '1Minute' ],
          :metrics => [
            'GroupMinSize',
            'GroupMaxSize',
            'GroupDesiredCapacity',
            'GroupInServiceInstances',
            'GroupPendingInstances',
            'GroupTerminatingInstances',
            'GroupTotalInstances'
          ],
        },
        :process_types => [
          'AZRebalance',
          'AlarmNotification',
          'HealthCheck',
          'Launch',
          'ReplaceUnhealthy',
          'ScheduledActions',
          'Terminate'
        ]
      }
    end
  end
end

.resetObject



184
185
186
# File 'lib/fog/aws/auto_scaling.rb', line 184

def self.reset
  @data = nil
end

Instance Method Details

#create_auto_scaling_group(auto_scaling_group_name, availability_zones, launch_configuration_name, max_size, min_size, options = {}) ⇒ Object



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
# File 'lib/fog/aws/requests/auto_scaling/create_auto_scaling_group.rb', line 69

def create_auto_scaling_group(auto_scaling_group_name, availability_zones, launch_configuration_name, max_size, min_size, options = {})
  if data[:auto_scaling_groups].has_key?(auto_scaling_group_name)
    raise Fog::AWS::AutoScaling::IdentifierTaken.new("AutoScalingGroup by this name already exists - A group with the name #{auto_scaling_group_name} already exists")
  end
  unless data[:launch_configurations].has_key?(launch_configuration_name)
    raise Fog::AWS::AutoScaling::ValidationError.new('Launch configuration name not found - null')
  end
  data[:auto_scaling_groups][auto_scaling_group_name] = {
    'AutoScalingGroupARN'     => "arn:aws:autoscaling:eu-west-1:000000000000:autoScalingGroup:00000000-0000-0000-0000-000000000000:autoScalingGroupName/#{auto_scaling_group_name}",
    'AutoScalingGroupName'    => launch_configuration_name,
    'AvailabilityZones'       => availability_zones.to_a,
    'CreatedTime'             => Time.now.utc,
    'DefaultCooldown'         => 0,
    'DesiredCapacity'         => 0,
    'EnabledMetrics'          => [],
    'HealthCheckGracePeriod'  => 0,
    'HealthCheckType'         => 'EC2',
    'Instances'               => [],
    'LaunchConfigurationName' => launch_configuration_name,
    'LoadBalancerNames'       => [],
    'MaxSize'                 => max_size,
    'MinSize'                 => min_size,
    'PlacementGroup'          => nil,
    'SuspendedProcesses'      => [],
    'VPCZoneIdentifier'       => nil
  }.merge!(options)

  response = Excon::Response.new
  response.status = 200
  response.body = {
    'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
  }
  response
end

#create_launch_configuration(image_id, instance_type, launch_configuration_name, options = {}) ⇒ Object



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
# File 'lib/fog/aws/requests/auto_scaling/create_launch_configuration.rb', line 74

def create_launch_configuration(image_id, instance_type, launch_configuration_name, options = {})
  if data[:launch_configurations].has_key?(launch_configuration_name)
    raise Fog::AWS::AutoScaling::IdentifierTaken.new("Launch Configuration by this name already exists - A launch configuration already exists with the name #{launch_configuration_name}")
  end
  data[:launch_configurations][launch_configuration_name] = {
    'BlockDeviceMappings'     => [],
    'CreatedTime'             => Time.now.utc,
    'ImageId'                 => image_id,
    'InstanceMonitoring'      => { 'Enabled' => true },
    'InstanceType'            => instance_type,
    'KernelId'                => nil,
    'KeyName'                 => nil,
    'LaunchConfigurationARN'  => "arn:aws:autoscaling:eu-west-1:000000000000:launchConfiguration:00000000-0000-0000-0000-000000000000:launchConfigurationName/#{launch_configuration_name}",
    'LaunchConfigurationName' => launch_configuration_name,
    'RamdiskId'               => nil,
    'SecurityGroups'          => [],
    'UserData'                => nil
  }.merge!(options)

  response = Excon::Response.new
  response.status = 200
  response.body = {
    'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
  }
  response
end

#dataObject



200
201
202
# File 'lib/fog/aws/auto_scaling.rb', line 200

def data
  self.class.data[@region][@aws_access_key_id]
end

#delete_auto_scaling_group(auto_scaling_group_name) ⇒ Object



37
38
39
# File 'lib/fog/aws/requests/auto_scaling/delete_auto_scaling_group.rb', line 37

def delete_auto_scaling_group(auto_scaling_group_name)
  Fog::Mock.not_implemented
end

#delete_launch_configuration(launch_configuration_name) ⇒ Object



40
41
42
# File 'lib/fog/aws/requests/auto_scaling/delete_launch_configuration.rb', line 40

def delete_launch_configuration(launch_configuration_name)
  Fog::Mock.not_implemented
end

#delete_policy(auto_scaling_group_name, policy_name) ⇒ Object



39
40
41
# File 'lib/fog/aws/requests/auto_scaling/delete_policy.rb', line 39

def delete_policy(auto_scaling_group_name, policy_name)
  Fog::Mock.not_implemented
end

#delete_scheduled_action(auto_scaling_group_name, scheduled_action_name) ⇒ Object



40
41
42
# File 'lib/fog/aws/requests/auto_scaling/delete_scheduled_action.rb', line 40

def delete_scheduled_action(auto_scaling_group_name, scheduled_action_name)
  Fog::Mock.not_implemented
end

#describe_adjustment_typesObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fog/aws/requests/auto_scaling/describe_adjustment_types.rb', line 35

def describe_adjustment_types()
  results = { 'AdjustmentTypes' => [] }
  data[:adjustment_types].each do |adjustment_type|
    results['AdjustmentTypes'] << { 'AdjustmentType' => adjustment_type }
  end
  response = Excon::Response.new
  response.status = 200
  response.body = {
    'DescribeAdjustmentTypesResult' => results,
    'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
  }
  response
end

#describe_auto_scaling_groups(options = {}) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/fog/aws/requests/auto_scaling/describe_auto_scaling_groups.rb', line 108

def describe_auto_scaling_groups(options = {})
  results = { 'AutoScalingGroups' => [] }
  data[:auto_scaling_groups].each do |asg_name, asg_data|
    results['AutoScalingGroups'] << {
      'AutoScalingGroupName' => asg_name
    }.merge!(asg_data)
  end
  response = Excon::Response.new
  response.status = 200
  response.body = {
    'DescribeAutoScalingGroupsResult' => results,
    'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
  }
  response
end

#describe_auto_scaling_instances(options = {}) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/fog/aws/requests/auto_scaling/describe_auto_scaling_instances.rb', line 73

def describe_auto_scaling_instances(options = {})
  results = { 'AutoScalingInstances' => [] }
  data[:auto_scaling_groups].each do |asg_name, asg_data|
    lc_name = data[asg_data][lc_name]
    asg_data['Instances'].each do |instance|
      results['AutoScalingInstances'] << {
        'AutoScalingGroupName' => asg_name
      }.merge!(instance)
    end
  end
  response = Excon::Response.new
  response.status = 200
  response.body = {
    'DescribeAutoScalingInstancesResult' => results,
    'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
  }
  response
end

#describe_launch_configurations(options = {}) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/fog/aws/requests/auto_scaling/describe_launch_configurations.rb', line 88

def describe_launch_configurations(options = {})
  results = { 'LaunchConfigurations' => [] }
  data[:launch_configurations].each do |lc_name, lc_data|
    results['LaunchConfigurations'] << {
      'LaunchConfigurationName' => lc_name
    }.merge!(lc_data)
  end
  response = Excon::Response.new
  response.status = 200
  response.body = {
    'DescribeLaunchConfigurationsResult' => results,
    'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
  }
  response
end

#describe_metric_collection_typesObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fog/aws/requests/auto_scaling/describe_metric_collection_types.rb', line 37

def describe_metric_collection_types()
  results = {
    'Granularities' => [],
    'Metrics' => []
  }
  data[:metric_collection_types][:granularities].each do |granularity|
    results['Granularities'] << { 'Granularity' => granularity }
  end
  data[:metric_collection_types][:metrics].each do |metric|
    results['Metrics'] << { 'Metric' => metric }
  end
  response = Excon::Response.new
  response.status = 200
  response.body = {
    'DescribeMetricCollectionTypesResult' => results,
    'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
  }
  response
end

#describe_policies(options = {}) ⇒ Object



77
78
79
# File 'lib/fog/aws/requests/auto_scaling/describe_policies.rb', line 77

def describe_policies(options = {})
  Fog::Mock.not_implemented
end

#describe_scaling_activities(options = {}) ⇒ Object



80
81
82
# File 'lib/fog/aws/requests/auto_scaling/describe_scaling_activities.rb', line 80

def describe_scaling_activities(options = {})
  Fog::Mock.not_implemented
end

#describe_scaling_process_typesObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fog/aws/requests/auto_scaling/describe_scaling_process_types.rb', line 36

def describe_scaling_process_types()
  results = { 'Processes' => [] }
  data[:process_types].each do |process_type|
    results['Processes'] << { 'ProcessName' => process_type }
  end
  response = Excon::Response.new
  response.status = 200
  response.body = {
    'DescribeScalingProcessTypesResult' => results,
    'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
  }
  response
end

#describe_scheduled_actions(options = {}) ⇒ Object



80
81
82
# File 'lib/fog/aws/requests/auto_scaling/describe_scheduled_actions.rb', line 80

def describe_scheduled_actions(options = {})
  Fog::Mock.not_implemented
end

#disable_metrics_collection(auto_scaling_group_name, options = {}) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/fog/aws/requests/auto_scaling/disable_metrics_collection.rb', line 44

def disable_metrics_collection(auto_scaling_group_name, options = {})
  unless data[:auto_scaling_groups].has_key?(auto_scaling_group_name)
    Fog::AWS::AutoScaling::ValidationError.new("Group #{auto_scaling_group_name} not found")
  end

  Fog::Mock.not_implemented
end

#enable_metrics_collection(auto_scaling_group_name, granularity, options = {}) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/fog/aws/requests/auto_scaling/enable_metrics_collection.rb', line 51

def enable_metrics_collection(auto_scaling_group_name, granularity, options = {})
  unless data[:auto_scaling_groups].has_key?(auto_scaling_group_name)
    Fog::AWS::AutoScaling::ValidationError.new("Group #{auto_scaling_group_name} not found")
  end
  unless data[:metric_collection_types][:granularities].include?(granularity)
    Fog::AWS::AutoScaling::ValidationError.new('Valid metrics granularity type is: [1Minute].')
  end

  Fog::Mock.not_implemented
end

#execute_policy(policy_name, options = {}) ⇒ Object



42
43
44
# File 'lib/fog/aws/requests/auto_scaling/execute_policy.rb', line 42

def execute_policy(policy_name, options = {})
  Fog::Mock.not_implemented
end

#put_scaling_policy(adjustment_type, auto_scaling_group_name, policy_name, scaling_adjustment, options = {}) ⇒ Object



58
59
60
# File 'lib/fog/aws/requests/auto_scaling/put_scaling_policy.rb', line 58

def put_scaling_policy(adjustment_type, auto_scaling_group_name, policy_name, scaling_adjustment, options = {})
  Fog::Mock.not_implemented
end

#put_scheduled_update_group_action(auto_scaling_group_name, scheduled_policy_name, time, options = {}) ⇒ Object



59
60
61
# File 'lib/fog/aws/requests/auto_scaling/put_scheduled_update_group_action.rb', line 59

def put_scheduled_update_group_action(auto_scaling_group_name, scheduled_policy_name, time, options = {})
  Fog::Mock.not_implemented
end

#reset_dataObject



204
205
206
# File 'lib/fog/aws/auto_scaling.rb', line 204

def reset_data
  self.class.data[@region].delete(@aws_access_key_id)
end

#resume_processes(auto_scaling_group_name, options = {}) ⇒ Object



42
43
44
# File 'lib/fog/aws/requests/auto_scaling/resume_processes.rb', line 42

def resume_processes(auto_scaling_group_name, options = {})
  Fog::Mock.not_implemented
end

#set_desired_capacity(auto_scaling_group_name, desired_capacity, options = {}) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/fog/aws/requests/auto_scaling/set_desired_capacity.rb', line 69

def set_desired_capacity(auto_scaling_group_name, desired_capacity, options = {})
  unless data[:auto_scaling_groups].has_key?(auto_scaling_group_name)
    Fog::AWS::AutoScaling::ValidationError.new('AutoScalingGroup name not found - null')
  end
  data[:auto_scaling_groups][auto_scaling_group_name]['DesiredCapacity'] = desired_capacity

  response = Excon::Response.new
  response.status = 200
  response.body = {
    'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
  }
  response
end

#set_instance_health(health_status, instance_id, options = {}) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/fog/aws/requests/auto_scaling/set_instance_health.rb', line 43

def set_instance_health(health_status, instance_id, options = {})
  unless data[:health_states].include?(health_status)
    raise Fog::AWS::AutoScaling::ValidationError.new('Valid instance health states are: [#{data[:health_states].join(", ")}].')
  end

  Fog::Mock.not_implemented
end

#suspend_processes(auto_scaling_group_name, options = {}) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/fog/aws/requests/auto_scaling/suspend_processes.rb', line 45

def suspend_processes(auto_scaling_group_name, options = {})
  unless data[:auto_scaling_groups].has_key?(auto_scaling_group_name)
    raise Fog::AWS::AutoScaling::ValidationError.new('AutoScalingGroup name not found - null')
  end

  Fog::Mock.not_implemented
end

#terminate_instance_in_auto_scaling_group(instance_id, should_decrement_desired_capacity) ⇒ Object



57
58
59
# File 'lib/fog/aws/requests/auto_scaling/terminate_instance_in_auto_scaling_group.rb', line 57

def terminate_instance_in_auto_scaling_group(instance_id, should_decrement_desired_capacity)
  Fog::Mock.not_implemented
end

#update_auto_scaling_group(auto_scaling_group_name, options = {}) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/fog/aws/requests/auto_scaling/update_auto_scaling_group.rb', line 61

def update_auto_scaling_group(auto_scaling_group_name, options = {})
  unless data[:auto_scaling_groups].has_key?(auto_scaling_group_name)
    raise Fog::AWS::AutoScaling::ValidationError.new('AutoScalingGroup name not found - null')
  end
  data[:auto_scaling_group_name][auto_scaling_group_name].merge!(options)

  response = Excon::Response.new
  response.status = 200
  response.body = {
    'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
  }
  response
end